.include <m8def.inc> #define RS 2 //RS=PD2 #define E 3 //E=PD3 .def temp = r16 rjmp reset .org 40 reset: ldi r16, HIGH(RAMEND) ; out SPH,r16 ldi r16,LOW(RAMEND) out SPL,r16 ldi r16,0xfc ; PD2-PD7 out ddrd,r16 ldi r16,0x00 out portd,r16 rcall LCD_init sbi portb,6 ; rcall LCD_dat rjmp loop LCD_init: ldi temp,0x30 ; rcall LCD_com1 ; ldi temp,0x30 rcall LCD_com1 ldi temp,0x30 rcall LCD_com1 ldi temp,0x20 ;4 rcall LCD_com1 ldi temp,0x20 rcall LCD_com ldi temp,0x0c rcall LCD_com ldi temp,0x06 rcall LCD_com ldi temp,0x01 rcall LCD_com ret LCD_dat: ldi ZL, LOW(DB << 1) ldi ZH, HIGH(DB << 1) ldi r21,8 ; m1: lpm temp, Z+ rcall LCD_com dec r21 cpi r21,0 brne m1 ret LCD_com: ldi r24,(0<<RS)|(1<<E) sbic portb,6 ldi r24,(1<<RS)|(1<<E) out portD,r24 mov r23,temp andi temp,0b11110000 ; or temp,r24 ; E RS out portD,temp ldi r24,(0<<RS)|(0<<E) out portD,r24 ; rcall func_delay ldi r24,(0<<RS)|(1<<E) sbic portb,6 ldi r24,(1<<RS)|(1<<E) out portD,r24 andi r23,0b00001111 ; swap r23 mov temp,r23 or temp,r24 ; E RS out portD,temp ; ldi r24,(0<<RS)|(0<<E) out portD,r24 rcall func_delay ret LCD_com1: ldi r24,(0<<RS)|(1<<E) out portD,r24 or temp,r24 out portD,temp ldi r24,(0<<RS)|(0<<E) out portD,r24 rcall func_delay ret loop: rjmp loop func_delay: ; ldi r17,0x20 ldi r18,0x00 func_delay_subb: subi r18,1 sbci r17,0 brcc func_delay_subb ret DB: .db 0xA8,0x70,0x65,0xB3,0x65,0xE0,0x3A,0x29 ;
cbi portb,6 ; , ldi temp,0xc2 rcall LCD_com sbi portb,6 ; rcall LCD_dat
Source: https://habr.com/ru/post/166735/
All Articles