Peterfr
30.10.2008, 16:20
Hallo Leute!!
seit 3 Tagen versuche ich mein LC-Display zum Laufen zu bringen.
LC-Display hab ich an den AtMEga8 angeschloßen.
Hier ist der Auszug aus dem Assemblercode!
include "m8def.inc"
;---------------------------------------------------------------------------
; Reset and Interrupt vector ; VNr. Beschreibung
rjmp main ; 1 POWER ON RESET
;---------------------------------------------------------------------------
; Start, Power ON, Reset
main: ldi r16,low(RAMEND)
out SPL,r16 ; Init Stackpointer LO
ldi r16,high(RAMEND)
out SPH,r16 ; Init Stackpointer HI
rcall LCD_init
;---------------------------------------------------------------------------
mainloop: rcall wait
ldi r16, 'T'
rcall LCD_data
ldi r16, 'e'
rcall LCD_data
ldi r16, 's'
rcall LCD_data
ldi r16, 't'
rcall LCD_data
rjmp mainloop
;================================================= ==========================
;hier Unterprogramme und Interruptroutinen zuf�gen
;---------------------------------------------------------------------------
wait: push r24
ldi r24,0x13 ; hier delay einstellen 13 = ca. 20yS
w1: subi r24,0x01
rcall wait20ms
brcc w1
pop r24
ret
;---------------------------------------------------------------------------
wait5ms: ldi r16, 255
ldi r17, 26
w5ms: dec r16
brne w5ms
dec r17
brne w5ms
ret
;---------------------------------------------------------------------------
wait20ms: ldi r16, 255
ldi r17,104
w20ms: dec r16
brne w20ms
dec r17
brne w20ms
ret
;---------------------------------------------------------------------------
LCD_init: sbi DDRD,4 ;LCD RS = OUT
sbi DDRD,5 ;LCD E = OUT
sbi DDRC,0 ;LCD D4 = OUT
sbi DDRC,1 ;LCD D5 = OUT
sbi DDRC,2 ;LCD D6 = OUT
sbi DDRC,3 ;LCD D7 = OUT
cbi PORTD,4 ;LDC RS = Low
;warte bis PowerUp
ldi r18,20
powerup: rcall wait5ms
dec r18
brne powerup ; Power-Up Wartezyklus min 30 ms
; sende init 1
ldi r16, 0b00100000 ; 4 Bit Modus aktivieren
out PORTD, r16
rcall LCD_enable ; Enable-Impuls
rcall wait5ms
ldi r16, 0b00101000
rcall LCD_cmd ; Function Set 4 Bit, 2 Zeilen, 5x7
rcall LCD_off
rcall LCD_clear
ldi r16, 0x06
rcall LCD_cmd ; Entry Mode Set, increase+shifted
rcall LCD_on
ret
;---------------------------------------------------------------------------
LCD_data: ldi r18,0b0000100 ;RS = hi
rjmp LCD_out
;---------------------------------------------------------------------------
LCD_cmd: ldi r18,0b0000000 ;RS = lo
LCD_out: mov r17, r16
swap r17
andi r16, 0b11110000
or r16,r18
andi r17, 0b11110000
or r17,r18
out PORTD, r16
rcall LCD_enable
out PORTD, r17
rcall LCD_enable
rcall wait5ms
ret
;---------------------------------------------------------------------------
LCD_enable: sbi PORTD, 5 ; Enable high
nop ; kurz warten
nop
nop
cbi PORTD, 5 ; Enable wieder low
ret
;---------------------------------------------------------------------------
LCD_clear: ldi r16, 0b00000001 ; Display l�schen
rcall LCD_cmd
rcall wait5ms
ret
;---------------------------------------------------------------------------
LCD_off: ldi r16, 0b00001000
rcall LCD_cmd
rcall wait5ms
ret
;---------------------------------------------------------------------------
LCD_on: ldi r16, 0x0E
rcall LCD_cmd
rcall wait5ms
ret
seit 3 Tagen versuche ich mein LC-Display zum Laufen zu bringen.
LC-Display hab ich an den AtMEga8 angeschloßen.
Hier ist der Auszug aus dem Assemblercode!
include "m8def.inc"
;---------------------------------------------------------------------------
; Reset and Interrupt vector ; VNr. Beschreibung
rjmp main ; 1 POWER ON RESET
;---------------------------------------------------------------------------
; Start, Power ON, Reset
main: ldi r16,low(RAMEND)
out SPL,r16 ; Init Stackpointer LO
ldi r16,high(RAMEND)
out SPH,r16 ; Init Stackpointer HI
rcall LCD_init
;---------------------------------------------------------------------------
mainloop: rcall wait
ldi r16, 'T'
rcall LCD_data
ldi r16, 'e'
rcall LCD_data
ldi r16, 's'
rcall LCD_data
ldi r16, 't'
rcall LCD_data
rjmp mainloop
;================================================= ==========================
;hier Unterprogramme und Interruptroutinen zuf�gen
;---------------------------------------------------------------------------
wait: push r24
ldi r24,0x13 ; hier delay einstellen 13 = ca. 20yS
w1: subi r24,0x01
rcall wait20ms
brcc w1
pop r24
ret
;---------------------------------------------------------------------------
wait5ms: ldi r16, 255
ldi r17, 26
w5ms: dec r16
brne w5ms
dec r17
brne w5ms
ret
;---------------------------------------------------------------------------
wait20ms: ldi r16, 255
ldi r17,104
w20ms: dec r16
brne w20ms
dec r17
brne w20ms
ret
;---------------------------------------------------------------------------
LCD_init: sbi DDRD,4 ;LCD RS = OUT
sbi DDRD,5 ;LCD E = OUT
sbi DDRC,0 ;LCD D4 = OUT
sbi DDRC,1 ;LCD D5 = OUT
sbi DDRC,2 ;LCD D6 = OUT
sbi DDRC,3 ;LCD D7 = OUT
cbi PORTD,4 ;LDC RS = Low
;warte bis PowerUp
ldi r18,20
powerup: rcall wait5ms
dec r18
brne powerup ; Power-Up Wartezyklus min 30 ms
; sende init 1
ldi r16, 0b00100000 ; 4 Bit Modus aktivieren
out PORTD, r16
rcall LCD_enable ; Enable-Impuls
rcall wait5ms
ldi r16, 0b00101000
rcall LCD_cmd ; Function Set 4 Bit, 2 Zeilen, 5x7
rcall LCD_off
rcall LCD_clear
ldi r16, 0x06
rcall LCD_cmd ; Entry Mode Set, increase+shifted
rcall LCD_on
ret
;---------------------------------------------------------------------------
LCD_data: ldi r18,0b0000100 ;RS = hi
rjmp LCD_out
;---------------------------------------------------------------------------
LCD_cmd: ldi r18,0b0000000 ;RS = lo
LCD_out: mov r17, r16
swap r17
andi r16, 0b11110000
or r16,r18
andi r17, 0b11110000
or r17,r18
out PORTD, r16
rcall LCD_enable
out PORTD, r17
rcall LCD_enable
rcall wait5ms
ret
;---------------------------------------------------------------------------
LCD_enable: sbi PORTD, 5 ; Enable high
nop ; kurz warten
nop
nop
cbi PORTD, 5 ; Enable wieder low
ret
;---------------------------------------------------------------------------
LCD_clear: ldi r16, 0b00000001 ; Display l�schen
rcall LCD_cmd
rcall wait5ms
ret
;---------------------------------------------------------------------------
LCD_off: ldi r16, 0b00001000
rcall LCD_cmd
rcall wait5ms
ret
;---------------------------------------------------------------------------
LCD_on: ldi r16, 0x0E
rcall LCD_cmd
rcall wait5ms
ret