; ********************************************************************* ; This set of functions and test program are written for Dragon12 demo ; board. Dragon12 grounds the R/W pin, which prevent the user from ; reading from the LCD kit. ; Author: Dr. Han-Way Huang ; Date: 08/02/2004 ; ********************************************************************* #include "c:\asmIDE\hcs12.inc" lcd_dat equ PORTK ; LCD data pins (PK5~PK2) lcd_dir equ DDRK ; LCD data direction port lcd_E equ $02 ; E signal pin lcd_RS equ $01 ; RS signal pin org $1500 lds #$1500 ; set up stack pointer ldy #2 jsr delayby100ms jsr openlcd ; initialize the LCD ldx #msg1lcd jsr puts2lcd ldaa #$C0 ; move to the second row jsr cmd2lcd ; " ldx #msg2lcd jsr puts2lcd swi msg1lcd fcc "hello world!" dc.b 0 msg2lcd fcc "I am ready!" dc.b 0 #include "c:\asmIDE\delay.asm" ; include delay routines here ; ****************************************************************************** ; This function sends a command in accumulator A to the LCD. ; ****************************************************************************** cmd2lcd psha ; save the command in stack bclr lcd_dat,lcd_RS ; select the instruction register bset lcd_dat,lcd_E ; pull the E sigal high anda #$F0 ; clear the lower 4 bits lsra ; match the upper four bits with the LCD lsra ; data pins oraa #lcd_E ; maintain the E signal value staa lcd_dat ; send the command, along with RS, E signals nop nop nop bclr lcd_dat,lcd_E ; pull the E signal low pula 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 #lcd_E ; maintain the E signal value staa lcd_dat ; send the lower 4 bits of command with E, and RS nop nop nop bclr lcd_dat,lcd_E ; clear E signal to complete the write operation ldy #1 ; adding this delay will complete the internal jsr delayby50us ; operation for most instructions rts ; ****************************************************************************** ; The following function performs initialization to the LCD used in Dragon12 ; demo board with 4-bit data width, two-line display, turn on display, cursor, ; and blinking. Shift cursor right, clear display and return to home position. ; ****************************************************************************** openlcd movb #$FF,lcd_dir ; configure port K for output ldy #10 jsr delayby10ms ldaa #$28 ; set 4-bit data, 2-line display, 5x8 font jsr cmd2lcd ; " ldaa #$0F ; turn on display, cursor, and blinking jsr cmd2lcd ; " ldaa #$06 ; move cursor right (entry mode set instruction) jsr cmd2lcd ; " ldaa #$01 ; clear cursor and return to home position jsr cmd2lcd ; " ldy #2 ; wait until "clear display" command is complete jsr delayby1ms ; " rts ; ****************************************************************************** ; The following function outputs the character in accumulator in A to LCD. ; ****************************************************************************** putc2lcd 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 four 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 length to E signal nop ; " nop ; " bclr lcd_dat,lcd_E ; pull the E signal low pula 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 following function outputs a NULL-terminated string pointed to by X. ; ****************************************************************************** puts2lcd ldaa 1,x+ ; get one character from the string beq done_puts ; reach NULL character? jsr putc2lcd bra puts2lcd done_puts rts end