* 6811 assembly code to interface with the Hitachi HD44780 LCD Screen Controller * this code contains all the necessary subroutines to write to the screen. * It also includes a simple main program that will execute the instructions. * The subroutines are designed to be transfered to other programs and simply dropped in. * * Important Note: This program requires a significant amount of space on the stack. Be * sure to initialize the stack before begining to run these routines. outa equ $ffb8 output the ASCII character in A outstrg equ $ffca output string at x ; string is terminated by $04 outcrlf equ $ffc4 output crlf outlhlf equ $ffb2 output left nibble of a in ASCII outrhlf equ $ffb5 output right nibble of a in ASCII out2bsp equ $ffc1 output 2byte value at x in HEX input equ $ffac a=input() ; a=0 if no char entered inchar equ $ffcd a=input() ; loop till user enters char upcase equ $ffa0 a=upcase(a) wchek equ $FFA3 z=1 if A={space,comma,tab} dchek equ $FFA6 z=1 if A={space,comma,tab,CR} porta equ $1000 portc equ $1003 ddrc equ $1007 * This is the main program that calls the subroutines. org $c000 jmp start temp rmb 1 test1 fcc "point a" fcb $04 test2 fcc "point b" fcb $04 start lds #$DFFF ; initialize the stack. Need lots of space!!!! ldaa #$3F jsr initlcd ldaa #$80 ; set address to 0 ldab #$00 jsr writelcd ldaa #$47 ; write a character ldab #$10 jsr writelcd ldaa #$6F ; write a character ldab #$10 jsr writelcd ldaa #$6F ; write a character ldab #$10 jsr writelcd ldaa #$64 ; write a character ldab #$10 jsr writelcd ldaa #$20 ; write a character ldab #$10 jsr writelcd ldaa #$4d ; write a character ldab #$10 jsr writelcd ldaa #$6f ; write a character ldab #$10 jsr writelcd ldaa #$72 ; write a character ldab #$10 jsr writelcd ldaa #$6e ; write a character ldab #$10 jsr writelcd ldaa #$69 ; write a character ldab #$10 jsr writelcd ldaa #$6e ; write a character ldab #$10 jsr writelcd ldaa #$67 ; write a character ldab #$10 jsr writelcd ldaa #$c0 ; write address ldab #$00 jsr writelcd ldaa #$44 ; write a character ldab #$10 jsr writelcd ldaa #$61 ; write a character ldab #$10 jsr writelcd ldaa #$76 ; write a character ldab #$10 jsr writelcd ldaa #$65 ; write a character ldab #$10 jsr writelcd swi * This is the initialization subroutine initlcd psha ; save the lcdtype ldaa #$00 ; clear ports A and C staa portc staa porta staa ddrc ldx #$9c40 ; wait for ~15ms loop dex cpx #$0000 bne loop ldaa #$ff ; set port c for output staa ddrc ldaa #$3f ; write the function set command staa portc ldab #$1E ; wait ~18 clock cycles idle0 decb cmpb #$00 bne idle0 ldaa #$20 ; pulse the enable bit staa porta ldab #$1E ; wait ~18 clock cycles idle decb cmpb #$00 bne idle ldaa #$00 ; turn off enable staa porta staa portc ldx #$2328 ; wait ~4.1 ms loop2 dex cpx #$00 bne loop2 ldaa #$3f ; write the function set command staa portc ldab #$1E ; wait ~18 clock cycles idle1 decb cmpb #$00 bne idle1 ldaa #$20 ; pulse the enable bit staa porta ldab #$1E ; wait ~18 clock cycles idle2 decb cmpb #$00 bne idle2 ldaa #$00 ; turn off enable staa porta staa portc ldx #$1f4 ; wait ~100 us loop3 dex cpx #$00 bne loop3 ldaa #$3f ; write the function set command staa portc ldab #$1E ; wait ~18 clock cycles idle2a decb cmpb #$00 bne idle2a ldaa #$20 ; pulse the enable bit staa porta ldab #$1E ; wait ~18 clock cycles idle3 decb cmpb #$00 bne idle3 ldaa #$00 ; turn off enable staa porta pula ; get the lcd type from the stack ldab #$00 jsr writelcd ; write the # of lines and font ldaa #$0C ; set some other condition ldab #$00 jsr writelcd ; write it to the screen ldaa #$01 ; yet another command to write ldab #$00 jsr writelcd ; guess what, we're going to write another command rts * This is the write command for the data, commands and addresses * This also includes the check on the busy flag. writelcd pshb ; store the rs and rw values psha ; store the data ldaa #$00 staa ddrc loop4 ldaa #$08 ; checking the busy flag staa porta ldab #$1E ; wait ~18 clock cycles idle4 decb cmpb #$00 bne idle4 ldaa #$28 ; pulse the enable staa porta ldab #$1E ; wait ~18 clock cycles idle5 decb cmpb #$00 bne idle5 ldaa portc anda #$80 cmpa #$80 beq loop4 ldaa #$00 ; clear the enable staa porta ldaa #$ff ; set portc for output staa ddrc pula ; write data to portc staa portc pulb ; write control pins to porta stab porta stab temp ldab #$1E ; wait ~18 clock cycles idle6 decb cmpb #$00 bne idle6 ldaa temp oraa #$20 ; enable the enable and write it to the port staa porta ldab #$1E ; wait ~18 clock cycles idle7 decb cmpb #$00 bne idle7 ldaa #$00 staa porta rts