8051 LCD 'Hello World' - Ersetzt DB durch Variable
Ich verwende eine proprietäre 8051-Karte, um die Assembler-Programmierung zu erlernen. Ich arbeite derzeit an einem LCD-Programm "Hello World". Hier ist der Code.
lcd_cmd equ 0800h ;Write COMMAND reg address 0800h
lcd_st equ 0801h ;Read STATUS reg address 0801h
lcd_wr equ 0802h ;Write DATA reg address 0802h
lcd_rd equ 0803h ;Read DATA reg address 0803h
ORG 08100h
hello:
mov P2, #(lcd_cmd SHR 8) ;load P2 with high address
mov R0, #(lcd_cmd AND 255) ;load R0 with command reg addr
mov R7, #03h ;set LCD position, line=1, char=3
mov dptr, #mesg1 ;point to mesg1
acall wr_string ;write mesg1 to LCD
mov R7, #41h ;set LCD position, line= 2, char=1
mov dptr, #mesg2 ;point to mesg2
acall wr_string ;write mesg2 to LCD
stop: ajmp stop ;soft halt
wr_string:
acall lcd_busy ;wait until LCD not busy
mov a, R7 ;get LCD position
orl a, #080h ;msb set for LCD RAM address
movx @R0, a ;write lcd_cmd to set line & char
nxt_char:
acall lcd_busy ;wait until LCD not busy
clr a
movc a, @a+dptr
inc dptr ;point to next byte in string
jz str_end ;if 0 then end of string
mov R1, #(lcd_wr AND 255) ;Load R1 with wr_data address
movx @R1, a ;Write char to LCD
sjmp nxt_char ;get next char in string
str_end: ret
lcd_busy:
mov R1, #(lcd_st AND 255) ;Load R1 with status address
movx a, @R1 ;read LCD status
jb acc.7, lcd_busy ;keep checking until busy bit clear
ret
mesg1: db "Hello ",0
mesg2: db "World ",0
END
Alles funktioniert gut. Ich habe jedoch Probleme, eine Variable auf dem LCD auszugeben. Durch Ersetzen von # mesg1 durch einen Hex-Wert (um die Sache einfach zu halten) werden einfach verschlüsselte Zeichen auf dem Bildschirm angezeigt. Das Gleiche gilt für den Aufruf einer Unterroutine, die einfach jedes Mal einen Wert inkrementiert. Daher bin ich mir nicht sicher, in welchem Format die Daten vorliegen sollen, wenn sie in den DPTR verschoben werden.
Irgendetwas Dummes, das ich verpasst habe?
Vielen Dank!