LCD for ATmega8

Thread Starter

Sam0014

Joined Jan 21, 2013
3
Hello,
i have the following Program for the ATmega8 LCD. I found this Program in Internet to test my LCD but it didn't work.
The LCD is W162B and it is connected in 4bit-Interface with the µC.
This is the Code:

;; 4bit-Interface
;; DB4-DB7: PC0-PC3
;; RS: PC4
;; E: PC5
;; Takt: 8 MHz

.include "m8def.inc"
.def temp1 = r16
.def temp2 = r17
.def temp3 = r18

ldi temp1, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse
out SPL, temp1
ldi temp1, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse
out SPH, temp1
ldi temp1, 0xFF ; Port C = Ausgang
out DDRC, temp1
rcall lcd_init ; Display initialisieren
rcall lcd_clear ; Display löschen
ldi temp1, 'L' ; Zeichen anzeigen
rcall lcd_data
ldi temp1, 'C' ; Zeichen anzeigen
rcall lcd_data
ldi temp1, 'D' ; Zeichen anzeigen
rcall lcd_data
ldi temp1, 'I' ; Zeichen anzeigen
rcall lcd_data
ldi temp1, 'S' ; Zeichen anzeigen
rcall lcd_data
ldi temp1, 'P' ; Zeichen anzeigen
rcall lcd_data

ldi temp1, 'L' ; Zeichen anzeigen
rcall lcd_data

ldi temp1, 'Y' ; Zeichen anzeigen
rcall lcd_data */

loop:
rjmp loop

;sendet ein Datenbyte an das LCD
lcd_data:
mov temp2, temp1 ; "Sicherungskopie" für
; die Übertragung des 2.Nibbles
swap temp1 ; Vertauschen
andi temp1, 0b00001111 ; oberes Nibble auf Null setzen
sbr temp1, 1<<4 ; entspricht 0b00010000 (Anm.1)
out PORTC, temp1 ; ausgeben
rcall lcd_enable ; Enable-Routine aufrufen
andi temp2, 0b00001111 ; obere Hälfte auf Null setzen
sbr temp2, 1<<4 ; entspricht 0b00010000
out PORTC, temp2 ; ausgeben
rcall lcd_enable ; Enable-Routine aufrufen
rcall delay50us ; Delay-Routine aufrufen
ret ; zurück zum Hauptprogramm

; sendet einen Befehl an das LCD
lcd_command: ; wie lcd_data, nur RS=0
mov temp2, temp1
swap temp1
andi temp1, 0b00001111
out PORTC, temp1
rcall lcd_enable
andi temp2, 0b00001111
out PORTC, temp2
rcall lcd_enable
rcall delay50us
ret
lcd_enable:
sbi PORTC, 5 ; Enable high
nop ; mindestens 3 Taktzyklen warten
nop
nop
nop
nop
cbi PORTC, 5 ; Enable wieder low
ret ; Und wieder zurück
delay50us: ; 90us Pause
ldi temp1, $82 ; war 42
delay50us_:dec temp1
brne delay50us_
ret ; wieder zurück

; Längere Pause für manche Befehle
delay5ms: ; 5ms Pause
ldi temp1, $21
WGLOOP0: ldi temp2, $C9
WGLOOP1: dec temp2
brne WGLOOP1
dec temp1
brne WGLOOP0
ret ; wieder zurück

lcd_init:
ldi temp3,50
powerupwait:
rcall delay5ms
dec temp3
brne powerupwait
ldi temp1, 0b00000011 ; muss 3mal hintereinander gesendet
out PORTC, temp1 ; werden zur Initialisierung
rcall lcd_enable ; 1
rcall delay5ms
rcall lcd_enable ; 2
rcall delay5ms
rcall lcd_enable ; und 3!
rcall delay5ms
ldi temp1, 0b00000010 ; 4bit-Modus einstellen
out PORTC, temp1
rcall lcd_enable
rcall delay5ms
ldi temp1, 0b00101000 ; 4Bit / 2 Zeilen / 5x8
rcall lcd_command
ldi temp1, 0b00001100 ; Display ein / Cursor aus / kein Blinken
rcall lcd_command
ldi temp1, 0b00000100 ; inkrement / kein Scrollen
rcall lcd_command
ret

; Sendet den Befehl zur Löschung des Displays
lcd_clear:
ldi temp1, 0b00000001 ; Display löschen
rcall lcd_command
rcall delay5ms
ret

; Sendet den Befehl: Cursor Home
lcd_home:
ldi temp1, 0b00000010 ; Cursor Home
rcall lcd_command
rcall delay5ms
ret


Can somebody Please say where the error in this Code or if this can work!

Thanks a lot
 

tshuck

Joined Oct 18, 2012
3,534
If you were to write the code yourself, given the requirements for the LCD, you would be able to answer that. Don't trust the internet for your code.

My advice, write the code yourself.

By the way, comments in German only help people that read German...
 
Top