Forum: Mikrocontroller und Digitale Elektronik lcd-Ansteuerung funktioniert nicht


von lcd (Gast)


Lesenswert?

Hallo zusammen!
Ich habe ein kleines Programm geschrieben um die Ansteuerung eines LCD 
auszuprobieren. Dabei habe ich mich streng ans tutorial gehalten. 
Trotzdem funktionierts nicht. Das LCD zeigt nichts an. Kann mir jemand 
helfen? Was habe ich übersehen? Ich habe bereits ähnliche Beiträge im 
Forum durchsucht aber nichts vergleichbares gefunden. Mein Atmega32 
läuft mit 16MHz die Warteschleifen sind lang genug und mit dem Oszi 
überprüft.

Hier mein code:

.include "m32def.inc"

.equ LCD_DDR = DDRA
.equ LCD_PORT = PORTA
.def temp = r16
.def temp1 = r17
.def temp2 = r18
.def data = r19
.def command = r20

          ldi temp, LOW(RAMEND)        ;Stack-Pointer initialisieren
          out SPL, temp
          ldi temp, HIGH(RAMEND)
          out SPH, temp

          ldi temp, 0xFF            ;LCD_PORT als Ausgang definieren
          out LCD_DDR, temp

          rjmp main              ;Sprung zum Hauptprogramm


          ;Ein Daten-Byte an das LCD senden


lcd_data:      mov temp1, data            ;Oberes Nibble übertragen
          swap temp1
          andi temp1, 0b00001111
          sbr temp1, 1<<4            ;RS Pin auf 1 setzen für Daten
          out LCD_PORT, temp1
          rcall lcd_enable

          mov temp1, data            ;Unteres Nibble übertragen
          andi temp1, 0b00001111
          sbr temp1, 1<<4            ;RS Pin auf 1 setzen für Daten
          out LCD_PORT, temp1
          rcall lcd_enable
          rcall wait_50us
          ret


          ;Einen Befehl an das LCD senden


lcd_command:    mov temp1, command          ;Oberes Nibble übertragen
          swap temp1
          andi temp1, 0b00001111        ;RS Pin bleibt auf 0 für Daten
          out LCD_PORT, temp1
          rcall lcd_enable

          mov temp1, command          ;Unteres Nibble übertragen
          andi temp1, 0b00001111        ;RS Pin bleibt auf 0 für Daten
          out LCD_PORT, temp1
          rcall lcd_enable
          rcall wait_50us
          ret


          ;Enable Impuls


lcd_enable:      sbi LCD_PORT, 5
          nop
          nop
          nop
          nop
          nop
          nop
          nop
          nop
          nop
          nop
          nop
          nop
          nop
          cbi LCD_PORT, 5
          ret


          ;50us Warteschleife


wait_50us:      ldi r16, 0              ;50us warten
wait_50us_loop:    dec r16
          brne wait_50us_loop
          ret


          ;5ms Warteschleife


wait_5ms:      ldi r16, 0              ;5ms warten
wait_5ms_1:      ldi r17, 105
wait_5ms_loop:    dec r17
          brne wait_5ms_loop
          dec r16
          brne wait_5ms_1
          ret


          ;Initialisierung des LCD


lcd_init:      ldi temp2, 50            ;Wartezeit nach Einschalten
powerup_wait:    rcall wait_5ms
          dec temp2
          brne powerup_wait

          ldi temp, 0b00000011        ;Wird 3 mal hintereinander 
gesendet
          out LCD_PORT, temp
          rcall lcd_enable
          rcall wait_5ms
          rcall lcd_enable
          rcall wait_5ms
          rcall lcd_enable
          rcall wait_5ms

          ldi temp, 0b00000010        ;Umschalten in den 4-Bit-Modus
          out LCD_PORT, temp
          rcall lcd_enable
          rcall wait_5ms

          ldi command, 0b00101000        ;Konfiguration des LCD:
          rcall lcd_command          ;4-Bit, 2-Zeilig, 5x7 Pixel

          ldi command, 0b00001100        ;Display an, Cursor aus, 
Cursor-Blinken aus
          rcall lcd_command

          ldi command, 0b00000100        ;Inkrement, kein Scrollen
          rcall lcd_command
          ret


          ;Löschen der Anzeige


lcd_clear:      ldi command, 0b00000001
          rcall lcd_command
          rcall wait_5ms
          ret


          ;Cursor auf Home-Position


lcd_home:      ldi command, 0b00000010
          rcall lcd_command
          rcall wait_5ms
          ret




          ;=============
          ;Hauptprogramm
          ;=============



main:        rcall lcd_init
          rcall lcd_clear
loop:        ldi data, 'a'
          rcall lcd_data
          rjmp loop


          rjmp end

end:        rjmp end              ;Endlosschleife am Programmende

Vielen Dank für die Hilfe!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.