Hardware Reference
In-Depth Information
The function that outputs a character to the LCD and makes sure that the write operation
is complete is as follows:
putcLCD
psha
; save a copy of the data
bset
lcd_dat,lcd_RS
; select lcd Data register
bset
lcd_dat,lcd_E
; pull E to high
anda
#$F0
; mask out the lower 4 bits
lsra
; match the upper 4 bits with the LCD
lsra
; data pins
oraa
#$03
; keep signal E and RS unchanged
staa
lcd_dat
; send the upper 4 bits and E, RS signals
nop
; provide enough duration to the E signal
nop
;
nop
;
bclr
lcd_dat,lcd_E
; pull the E signal low
pula
; retrieve the character from the stack
anda
#$0F
; clear the upper 4 bits
lsla
; match the lower 4 bits with the LCD
lsla
; data pins
bset
lcd_dat,lcd_E
; pull the E signal high
oraa
#$03
; keep E and RS unchanged
staa
lcd_dat
nop
nop
nop
bclr
lcd_dat,lcd_E
; pull E low to complete the write cycle
ldy
#1
; wait until the write operation is
jsr
delayby50us
; complete
rts
The function that outputs a NULL-terminated string pointed to by the index register X is
as follows:
putsLCD
ldaa
1, x 1
; get one character from the string
beq
donePS
; reach NULL character?
jsr
putcLCD
bra
putsLCD
donePS
rts
Example 7.5
Write an assembly program to test the previous four subroutines by displaying the following
messages on two lines:
hello world!
LCD is working!
Solution: The program is as follows:
#include
“c:\miniide\hcs12.inc”
lcd_dat
equ
PTK
; LCD data pins (PK5 , PK2)
lcd_dir
equ
DDRK
; LCD data direction port
 
Search WWH ::




Custom Search