
// LCD_line 1  send char 0x10, 0x00, 0xB0  // 96
// LCD_line 2  send char 0x10, 0x00, 0xB1  // 96
// LCD_line 3  send char 0x10, 0x00, 0xB2  // 96
// LCD_line 4  send char 0x10, 0x00, 0xB3  // 96
// LCD_line 5  send char 0x10, 0x00, 0xB4  // 96
// LCD_line 6  send char 0x10, 0x00, 0xB5  // 96
// LCD_line 7  send char 0x10, 0x00, 0xB6  // 96
// LCD_line 8  send char 0x10, 0x00, 0xB7  // 96 


init_lcd:              // Initialization LCD Nokia 1110i
cbi    portb,lcd_res   // 
rcall  wait_10us       // 
sbi    portb,lcd_res   // 
ldi    tmp,0xDA        // 
rcall  lcd_cmd         // 
ldi    tmp,0xFE        // 
rcall  lcd_cm          //  
ldi    tmp,0xD8        // 
rcall  lcd_cmd         //  
ldi    tmp,0x80        // 
rcall  lcd_cm          //  
ldi    tmp,0xDC        //  
rcall  lcd_cmd         // 
ldi    tmp,0x0D        // 
rcall  lcd_cm          // 
ldi    tmp,0xA1        //  
rcall  lcd_cmd         // 
rcall  lcd_line1       //  
rcall  clr_lcd         //  
ldi    tmp,0x13        //  
rcall  lcd_cmd         // 
ldi    tmp,0x90        //  0x90.....9F Contrast 
rcall  lcd_cmd         // 
ldi    tmp,0xA4        // 
rcall  lcd_cmd         // 
ldi    tmp,0x2F        //  
rcall  lcd_cmd         // 
ldi    tmp,0xA1        // 
rcall  lcd_cmd         //  
ldi    tmp,0xC0        // 
rcall  lcd_cmd         //
ldi    tmp,0xA6        // 
rcall  lcd_cmd         //  
ldi    tmp,0x40        // 
rcall  lcd_cmd         //    
ldi    tmp,0xAF        // 
rcall  lcd_cmd         //  
ret                    // 


clr_lcd:               // 
ldi    xl,low (864)    //  
ldi    xh,high(864)    // 
clcd:                  // 
clr    tmp             // 
rcall  out_byte        // 
sbiw   xl,1            //  
brne   clcd            // 
ret                    //  


clr_line:              // 
ldi    xl,low (96)     //  
ldi    xh,high(96)     // 
cline:                 // 
clr    tmp             // 
rcall  out_byte        // 
sbiw   xl,1            //  
brne   cline           // 
ret                    //   



lcd_cmd:               // Send command to LCD
cbi    portb,lcd_CS    // select chip  
sbi    portb,lcd_res   // 
cbi    portb,lcd_dat
sbi    portb,lcd_clk   // CLK -> 1 
nop                    // 
nop                    // 
cbi     portb,lcd_clk  // CLK -> 0 
lcd_cm:
ldi     loop,8         // 
outs11:                //   
clc                    // 
rol     tmp            // 
brcc    noc1           // 
sbi     portb,lcd_dat  // DATA=1
rjmp    drdy1          // 
noc1:                  // 
cbi     portb,lcd_dat  // DATA=0
drdy1:                 //  
nop                    // 
sbi     portb,lcd_clk  // CLK -> 1 
nop                    // 
nop                    // 
cbi     portb,lcd_clk  // CLK -> 0 
dec     loop           // 
brne    outs11         //  
sbi    portb,lcd_CS    // select chip  
clc
ret                    // 



out_byte:              // Send data to LCD
cbi    portb,lcd_CS    // select chip  
sbi    portb,lcd_res   // 
sbi    portb,lcd_dat
sbi    portb,lcd_clk   // CLK -> 1 
nop                    // 
nop                    // 
cbi     portb,lcd_clk  // CLK -> 0 
ldi     loop,8         // 
outs12:                //   
clc                    // 
rol     tmp            // 
brcc    noc2           // 
sbi     portb,lcd_dat  // DATA=1
rjmp    drdy2          // 
noc2:                  // 
cbi     portb,lcd_dat  // DATA=0
drdy2:                 //  
nop                    // 
sbi     portb,lcd_clk  // CLK -> 1 
nop                    // 
nop                    // 
cbi     portb,lcd_clk  // CLK -> 0 
dec     loop           // 
brne    outs12         //  
sbi    portb,lcd_CS    // select chip  
clc
ret                    // 
