/*****************************************************
This program was produced by the
CodeWizardAVR V2.04.4a Advanced
Automatic Program Generator
© Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 15.09.2011
Author  : NeVaDa
Company : Computer
Comments: 


Chip type               : ATtiny85
AVR Core Clock frequency: 8,000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 128
*****************************************************/

#include <tiny85.h>

// I2C Bus functions
#asm
   .equ __i2c_port=0x18 ;PORTB
   .equ __sda_bit=4
   .equ __scl_bit=3
#endasm
#include <i2c.h>
#include <DELAY.h>
#define time 70

unsigned int i;
unsigned char bkgr,color;

// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Place your code here

}

// Declare your global variables here
void lcd_com(unsigned char data)
{
i2c_start();      //start I2C
i2c_write(0x78);  //command adress
i2c_write(data);  //comad
i2c_stop();       //stop I2C  
delay_ms(time);   // delay to process command
}

void lcd_com_2(unsigned char data1, unsigned char data2)
{
i2c_start();      //start I2C
i2c_write(0x78);  //command adress
i2c_write(data1);  //comad1
i2c_write(data2);  //comad2
i2c_stop();       //stop I2C  
delay_ms(time);   // delay to process command
}

void lcd_init (void)
{
  
  lcd_com(0x29);        //lcd capacitance
  lcd_com(0xEA);        //v bias rate    
  lcd_com_2(0x81,0xA8); //potentiometr  
  lcd_com(0x27);        //temp comp 
  
  lcd_com(0x8B);        //uto_increment order=1
  lcd_com(0xAF);        //ldc enable
  lcd_com(0xD4);        //256 colors
  lcd_com(0xA1);        //line rate
}

void lcd_clr (void)
{
 i2c_start();      //start I2C
 i2c_write(0x7A);  //data adress
  for (i=104*80;i>0;i--) {
    i2c_write(bkgr);  //write color
  };  
 i2c_stop();       //stop I2C   
}
void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port B initialization
// Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State5=T State4=T State3=T State2=T State1=T State0=T 
PORTB=0x00;
DDRB=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 7,813 kHz
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x05;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFh
// OC1A output: Disconnected
// OC1B output: Disconnected
// Timer1 Overflow Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
PLLCSR=0x00;

TCCR1=0x00;
GTCCR=0x00;
TCNT1=0x00;
OCR1A=0x00;
OCR1B=0x00;
OCR1C=0x00;

// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=0x00;
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x02;

// Universal Serial Interface initialization
// Mode: Disabled
// Clock source: Register & Counter=no clk.
// USI Counter Overflow Interrupt: Off
USICR=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
ACSR=0x80;
ADCSRB=0x00;

// I2C Bus initialization
i2c_init();
// Global enable interrupts
#asm("sei")
lcd_init();
i2c_start();
bkgr=0xFF;
lcd_clr();

while (1)
      {
      // Place your code here
      };
}
