Прошу прощения, если тема задублирована, искал по форуму - не нашел, может плохо искал, спорить не буду.
Код: Выделить всё
main:
rjmp init_stack
Init_Stack:
ldi temp, 0x01
sts stmc,temp
ldi temp,high(RAMEnd)
out SPH,temp
ldi temp,low(RAMEnd)
out SPL,temp
rcall init_ports
rcall init_timer
sei
rcall LCD_INIT
wait20ms:
push temp
lds temp,TCNT2
ldi temp1,0x0C
add temp,temp1
push temp1
Wait20ms_REDO:
lds temp1,TCNT2
cp temp1,temp
BREQ Wait20ms_RET
rjmp Wait20ms_REDO
Wait20ms_RET:
pop temp1
pop temp
; rcall Init_INT
ret
LCD_INIT:
push temp
push temp1
ldi temp,0x00
out portB,temp
; Инциализация 3 операции 0b00110000
; Первая операция
ldi temp,0b00110000
out portD,temp
ldi temp1,0x04
out portB,temp1
rcall wait20ms
ldi temp1,0x00
out portB,temp1
; Вторая операция
ldi temp,0b00110000
out portD,temp
ldi temp1,0x04
out portB,temp1
rcall wait20ms
ldi temp1,0x00
out portB,temp1
; Третья операция
ldi temp,0b00110000
out portD,temp
ldi temp1,0x04
out portB,temp1
;rcall wait20ms
ldi temp1,0x00
out portB,temp1
rcall wait1s
; Ширина шины 8 бит
ldi temp,0b00111000
out portD,temp
ldi temp1,0x04
out portB,temp1
rcall wait20ms
ldi temp1,0x00
out portB,temp1
; Смещение курсора, а не экрана
ldi temp,0b00000110
out portd,temp
ldi temp,0x04
out portB,temp
rcall wait20ms
ldi temp,0x00
out portB,temp
; Вывод отображения
ldi temp,0b00001111
out portD,temp
ldi temp1,0x04
out portB,temp1
rcall wait20ms
ldi temp1,0x00
out portB,temp1
; Очистить и курсор в первую позицию
ldi temp,0x01
out portD,temp
ldi temp,0x04
out portB,temp
rcall wait20ms
ldi temp,0x00
out portb,temp
ldi r22,0x79
ldi r21,0x30
; Направление сдвига курсора
ldi temp,0b00010100
out portd,temp
ldi temp,0x04
out portb,temp
rcall wait20ms
ldi temp,0x00
out portB,temp
REDO_WHILE:
; Установка курсора 1 сторка 1й символ
ldi temp,0x04
out portB,temp
inc r22
out portD,r22
rcall wait20ms
ldi temp,0x00
out portb,temp
; Вывод символа 0x44 - D
ldi temp1,0x05
out portB,temp1
out portD,r21
rcall wait20ms
ldi temp1,0x00
out portB,temp1
inc r21
;rcall wait20ms
cpi r21,0x3F
BRNE REDO_WHILE
END_WHILE:
pop temp1
pop temp
RET


