// 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 


// LCD
.equ   lcd_clk = PB0 // Lcd clock 
.equ   lcd_dat = PB1 // Lcd data
.equ   lcd_CS  = PB2 // crystal select  
.equ   lcd_res = PB3 // reset chip


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_line1:             // 
rcall  lcd_line        // 
ldi    tmp,0xB0        //  
rcall  lcd_cmd         //  
ret                    //  
lcd_line2:             // 
rcall  lcd_line        // 
ldi    tmp,0xB1        //  
rcall  lcd_cmd         //  
ret                    // 
lcd_line3:             // 
rcall  lcd_line        // 
ldi    tmp,0xB2        //  
rcall  lcd_cmd         //  
ret                    // 
lcd_line4:             // 
rcall  lcd_line        // 
ldi    tmp,0xB3        //  
rcall  lcd_cmd         //  
ret                    // 
lcd_line5:             // 
rcall  lcd_line        // 
ldi    tmp,0xB4        //  
rcall  lcd_cmd         //  
ret                    // 
lcd_line6:             // 
rcall  lcd_line        // 
ldi    tmp,0xB5        //  
rcall  lcd_cmd         //  
ret                    // 
lcd_line7:             // 
rcall  lcd_line        // 
ldi    tmp,0xB6        //  
rcall  lcd_cmd         //  
ret                    // 
lcd_line8:             // 
rcall  lcd_line        // 
ldi    tmp,0xB7        //  
rcall  lcd_cmd         //  
ret                    // 
lcd_line9:             // 
rcall  lcd_line        // 
ldi    tmp,0xB8        //  
rcall  lcd_cmd         //  
ret                    // 
lcd_line:              // 
ldi    tmp,0x10        // 
rcall  lcd_cmd         // 
ldi    tmp,0x00        //  
rcall  lcd_cmd         // 
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 command 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                    // 


// Пример рисования на жки !
testing:
rcall lcd_line2  // выбираем строку жки 
ldi   xl,'1'     // 
rcall print_char // 
ldi   xl,'2'     // 
rcall print_char // 
ret              // напечатали 12 и вышли.





print_char:           // Print ASCII char to the LCD Nokia 1110i
clr   xh              //  
ldi   tmp,5           // 
clr   tmp1            // 
muls  xl,tmp          // 
mov   xl,r0           // 
mov   xh,r1           // 
ldi   tmp,0xA0        // 
clr   tmp1            // 
sub   xl,tmp          // 
sbc   xh,tmp1         // 
ldi   ZH,high(Code*2) // 
ldi   ZL,low (Code*2) // 
add   ZL,XL           // 
adc   ZH,XH           //  
lpm   tmp,Z           // Flash addr --> tmp
rcall out_byte        // 
inc   ZL              // Z + 1
lpm   tmp,Z           // Flash addr --> tmp
rcall out_byte        // 
inc   ZL              // Z + 1
lpm   tmp,Z           // Flash addr --> tmp
rcall out_byte        // 
inc   ZL              // Z + 1
lpm   tmp,Z           // Flash addr --> tmp
rcall out_byte        // 
inc   ZL              // Z + 1
lpm   tmp,Z           // Flash addr --> tmp
rcall out_byte        // 
clr   tmp             // 
rcall out_byte        //  
ret                   // 


.org  $F08    // символы кодировки 5 х 7 точек.
chartab:
//  ASCII CODE from lcd 5 x 7 pixels 
Code:.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5f,0x00,0x00,0x00,0x07,0x00,0x07,0x00,0x14,0x7f,0x14,0x7f,0x14,0x24,0x2a,0x7f,0x2a,0x12,0x23,0x13,0x08,0x64,0x62,0x36,0x49,0x55,0x22,0x50,0x00,0x05,0x03,0x00,0x00,0x00,0x1c,0x22,0x41,0x00,0x00,0x41,0x22,0x1c,0x00,0x14,0x08,0x3e,0x08,0x14,0x08,0x08,0x3e,0x08,0x08,0x00,0x50,0x30,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x60,0x60,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x3e,0x51,0x49,0x45,0x3e,0x00,0x42,0x7f,0x40,0x00,0x42,0x61,0x51,0x49,0x46,0x21,0x41,0x45,0x4b,0x31,0x18,0x14,0x12,0x7f,0x10,0x27,0x45,0x45,0x45,0x39,0x3c,0x4a,0x49,0x49,0x30,0x01,0x71,0x09,0x05,0x03,0x36,0x49,0x49,0x49,0x36,0x06,0x49,0x49,0x29,0x1e,0x00,0x36,0x36,0x00,0x00,0x00,0x56,0x36,0x00,0x00,0x08,0x14,0x22,0x41,0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x41,0x22,0x14,0x08,0x02,0x01,0x51,0x09,0x06,0x32,0x49,0x79,0x41,0x3e,0x7e,0x11,0x11,0x11,0x7e,0x7f,0x49,0x49,0x49,0x36,0x3e,0x41,0x41,0x41,0x22,0x7f,0x41,0x41,0x22,0x1c,0x7f,0x49,0x49,0x49,0x41,0x7f,0x09,0x09,0x09,0x01,0x3e,0x41,0x49,0x49,0x7a,0x7f,0x08,0x08,0x08,0x7f,0x00,0x41,0x7f,0x41,0x00,0x20,0x40,0x41,0x3f,0x01,0x7f,0x08,0x14,0x22,0x41,0x7f,0x40,0x40,0x40,0x40,0x7f,0x02,0x0c,0x02,0x7f,0x7f,0x04,0x08,0x10,0x7f,0x3e,0x41,0x41,0x41,0x3e,0x7f,0x09,0x09,0x09,0x06,0x3e,0x41,0x51
     .db 0x21,0x5e,0x7f,0x09,0x19,0x29,0x46,0x46,0x49,0x49,0x49,0x31,0x01,0x01,0x7f,0x01,0x01,0x3f,0x40,0x40,0x40,0x3f,0x1f,0x20,0x40,0x20,0x1f,0x3f,0x40,0x38,0x40,0x3f,0x63,0x14,0x08,0x14,0x63,0x07,0x08,0x70,0x08,0x07,0x61,0x51,0x49,0x45,0x43,0x00,0x7f,0x41,0x41,0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x41,0x41,0x7f,0x00,0x04,0x02,0x01,0x02,0x04,0x40,0x40,0x40,0x40,0x40,0x00,0x01,0x02,0x04,0x00,0x20,0x54,0x54,0x54,0x78,0x7f,0x48,0x44,0x44,0x38,0x38,0x44,0x44,0x44,0x20,0x38,0x44,0x44,0x48,0x7f,0x38,0x54,0x54,0x54,0x18,0x08,0x7e,0x09,0x01,0x02, 0x0c,0x52,0x52,0x52,0x3e,0x7f,0x08,0x04,0x04,0x78,0x00,0x44,0x7d,0x40,0x00,0x20,0x40,0x44,0x3d,0x00,0x7f,0x10,0x28,0x44,0x00,0x00,0x41,0x7f,0x40,0x00,0x7c,0x04,0x18,0x04,0x78,0x7c,0x08,0x04,0x04,0x78, 0x38,0x44,0x44,0x44,0x38,0x7c,0x14,0x14,0x14,0x08,0x08,0x14,0x14,0x18,0x7c,0x7c,0x08,0x04,0x04,0x08,0x48,0x54,0x54,0x54,0x20,0x04,0x3f,0x44,0x40,0x20,0x3c,0x40,0x40,0x20,0x7c,0x1c,0x20,0x40,0x20,0x1c,0x3c,0x40,0x30,0x40,0x3c,0x44,0x28,0x10,0x28,0x44,0x0c,0x50,0x50,0x50,0x3c,0x44,0x64,0x54,0x4c,0x44,0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x41,0x36,0x08,0x00,0x10,0x08,0x08,0x10,0x08,0x78,0x46,0x41,0x46,0x78
