; ********************************************************************* ; 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: 12/02/2004 ; ********************************************************************* #include "c:\miniIDE\hcs12.inc" lcdPort equ PTH ; LCD data pins lcdDIR equ DDRH ; LCD data direction port lcdE equ $80 ; E signal pin (PK7) lcdRW equ $20 ; R/W signal pin (PK5) lcdRS equ $10 ; RS signal pin (PK4) lcdCtlDir equ DDRK ; LCD control port direction register 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 bclr lcdPort,lcdRS+lcdRW ; select instruction register and Write bset lcdPort,lcdE ; pull the E sigal high staa lcdPort ; send the command, along with RS, E signals nop nop bclr lcdPort,lcdE ; pull the E signal low bset lcdPort,lcdRW ; pull R/W to high 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 8-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,lcdDIR ; configure port K for output bset lcdCtlDir,$B0 ; configure control pins for output ldy #5 ; wait for LCD to complete internal jsr delayby100ms ; configuration ldaa #$38 ; set 8-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 bset lcdPort,lcdRS ; select lcd Data register bclr lcdPort,lcdRW ; enable write to LCD bset lcdPort,lcdE ; pull E to high staa lcdPort ; send data to LCD nop ; provide enough length to E signal nop ; " bclr lcdPort,lcdE ; pull the E signal low bset lcdPort,lcdRW ; pull R/W high 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