Programmbeispiel: LCD-Ansteuerung

; Testprogramm for the RS232-Board with LCD
; Copyright by Thomas Wedemeyer 1996

; Definition Prozessortyp
cpu 80515 include stddef51.inc

RAMBASE set 8000h ;beginning of RAM area
LC_IW set 0000h ;LCD Instruction Register Write
LC_DW set 0001h ;LCD Data Register Write
LC_IR set 0002h ;LCD Instruction Register Read
LC_DR set 0003h ;LCD Data Register Read
ESC set 1bh

ORG RAMBASE
;*****************************************************************************
; LCD initialisation
;*****************************************************************************
LCD_init:
mov dptr,#LC_IW ; load adresspointer with LC_IW
mov a,#38h ; function set: 8-bit interface, 2 lines
movx @dptr,a ; movx accu to pointer-adress (LC_IW)
mov th0,#27h ; load timer0 with 10ms
mov tl0,#10h ;
mov tmod,#02h ; timer0 mode 1
setb tr0 ; start timer0
initl0: jnb tf0,initl0 ; wait until timer is 0
clr tf0 ; clear tf0
mov a,#38h ; function set: 8-bit interface, 2 lines
movx @dptr,a ; movx accu to pointer-adress (LC_IW)
mov th0,#27h ; load timer0 with 10ms
mov tl0,#10h ;
setb tr0 ; start timer0
initl1: jnb tf0,initl1 ; wait until timer is 0
clr tf0 ; clear tf0
mov a,#38h ; function set: 8-bit interface, 2 lines
movx @dptr,a ; movx accu to pointer-adress (LC_IW)
acall LC_BUSY ; wait until LCD ready
mov dptr,#LC_IW ;
mov a,#06h ; Entry Mode = Increment
movx @dptr,a ; Write instruction
acall LC_BUSY ; wait until LCD ready
mov dptr,#LC_IW ;
mov a,#0fh ; Display control = on, cursor on, flash on
movx @dptr,a ; Write instruction
acall LC_BUSY ; wait until LCD ready
mov dptr,#LC_IW ;
mov a,#01h ; clear display
movx @dptr,a ; Write instruction
acall LC_BUSY ; wait until LCD ready
;*****************************************************************************
; Start mainprogramm
;*****************************************************************************
main:

acall LC_WRITE ; Write CHR to LCD
db "RS232-SAB80C535"
db ESC ;
test: jmp test

;*****************************************************************************
; Wait for the Display
;*****************************************************************************
LC_BUSY:
push dpl ; push adress-pointer to stack
push dph ;
mov dptr,#LC_IR ; load adress-pointer with LC_IR
LC_BUS0:
movx a,@dptr ; move LC_IR to accu
jb acc.7,LC_BUS0 ;
pop dph ; pop stack to adress-pointer
pop dpl ;
ret
;*****************************************************************************
; Write Char to LCD
;*****************************************************************************
LC_WRITE:
POP DPH ;LOAD DPTR WITH FIRST CHAR
POP DPL
CLR A ;(ZERO OFFSET)
MOVC A,@A+DPTR ;FETCH FIRST CHAR IN STRING
LC_WRI_1:
push dpl ; save DPTR
push dph ;
mov dptr,#LC_DW ; Load LC_Data register adress
movx @dptr,A ;OUTPUT NEXT CHARACTER
acall LC_BUSY ;
pop dph ; load char adress
pop dpl ;
INC DPTR ;BUMP POINTER
CLR A
MOVC A,@A+DPTR ;GET NEXT CHARACTER
CJNE A,#ESC,LC_WRI_1 ;LOOP UNTIL ESCAPE READ
MOV A,#1
JMP @A+DPTR ;RETURN TO CODE AFTER ESCAPE
;