;
;  LCD12.ASM
;	LCD Display routines for Axiom HC12 development boards.
;
;  INITLCD:	Initialize the LCD display
;  LCDOUT:	Send a byte in A to the LCD data port
;  LCDCMD:	Send a byte in A to the LCD command port and wait
;

; Initialize LCD display
INITLCD:
	ldaa	#$3C 	; 2x40 Display
	jsr	LCDCMD	; write command
	ldaa	#$0f    ; Display and cursor on
	jsr	LCDCMD	; write command
	ldaa	#$14    ; shift cursor right
	jsr	LCDCMD	; write command
	ldaa	#$01    ; clear display and home cursor
	jsr	LCDCMD	; write command
	rts

LCDOUT:
	staa	$3f1	; output data to lcd
	jsr	delay100us ; WAIT this is too long, use a shorter one
	rts

; Send a command in A to the LCD command register
LCDCMD:
	staa	$3f0    ; write command
	jsr	delay40 ; wait
	rts


; wait 100 microseconds (approx.)
delay100us:
	psha
	clra
loop100:
	deca
	bne	loop100
	pula
	rts

; wait appropriate time for LCD command process
delay40:
	pshx
	ldx	#$0000
loop40:
	dex
	bne	loop40
	pulx
	rts


