Code:
.include "m8def.inc"
.def temp =r16
.def data =r17
ldi temp, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse
out SPL, temp
ldi temp, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse
out SPH, temp
;Ausgänge setzen
ldi temp,0b000111111 ;Portb pin 0-5 als Ausgang definieren
;0-3 = daten 4=Enable 5=RS
out DDRB,temp
ldi temp,0
out PORTB,temp
ldi temp,0b10000000
out DDRD,temp
ldi temp,255
out PortD,temp
loopvor:
sbis PinD,5
rjmp init
rjmp loopvor
;INITIALISIERUNG
init:
ldi data,0b00100000
rcall lcd_send
rcall lcd_send
ldi data,0b01000100
rcall lcd_send
rcall delay_39us
ldi data,0b00000000
rcall lcd_send
ldi data,0b11110000
rcall lcd_send
rcall delay_39us
ldi data,0b00000000
rcall lcd_send
ldi data,0b00010000
rcall lcd_send
rcall delay_2ms
ldi data,0b00000000
rcall lcd_send
ldi data,0b01100000
rcall lcd_send
main:
loop:
sbis PinD,6
rcall clear
sbis PinD,5
rcall send_h
ldi temp,0b01111111
out PORTD,temp
rjmp loop
lcd_send:
mov temp,data
swap temp
andi temp,0b00001111
out PortB,temp
rcall lcd_enable
mov temp,data
andi temp,0b00001111
out PortB,temp
rcall lcd_enable
ret
lcd_enable:
sbi PortB,4
nop
nop
nop
cbi PortB,4
ret
delay_39us:
ldi temp,100
delay39us_loop: dec temp
brne delay39us_loop
ret
delay_2ms:
ldi temp,25
delay2ms_loop: dec temp
brne delay2ms_loop
ret
clear:
ldi data,0b00000001
rcall lcd_send
ldi temp,255
out Portd,temp
rcall delay_2ms
ret
send_h:
ldi data,'h'
rcall lcd_data_send
ldi temp,255
out PortD,temp
rcall delay_2ms
ret
lcd_data_send:
mov temp,data
swap temp
andi temp,0b00001111
out PortB,temp
sbi PortB,5
rcall lcd_enable
mov temp,data
andi temp,0b000011111
out PortB,temp
sbi PortB,5
rcall lcd_enable
ret
Lesezeichen