;  KEYLCD-B.ASM
;	Example program using the KEYPAD and LCD_PORT on the Axiom
;       CMx12B32 boards.
;

; Memory Map Equates
RAMSTRT:	EQU	$0800	; start of internal ram
MONRAM:		EQU	$0A00	; monitor ram start
RAMSIZE:	EQU	$0400	; Size of internal ram
REGBS:  	EQU	$0000	; start of registers
ROMBS:  	EQU	$FD80	; start of initialization rom
DSTREE: 	EQU	$1000	; start of eeprom
DENDEE: 	EQU	$1FFF	; end of eeprom
STACK:		EQU	RAMSTRT+RAMSIZE	; top of stack

MONSTRT:        EQU     $2000   ; start of this program if running under monitor
PRGSTRT:        EQU     $8000   ; start of this program if running stand-alone

#include	equates.asm	; include register equates


; RAM
        ORG  RAMSTRT

CNT1	RMB	1	; temporary count variable
TMP1	RMB	1	; temporary storage variable
OLDKEY	RMB	1	; save key value for debounce



;**********************
; Program starts here *
;**********************

	ORG	MONSTRT
;	ORG	PRGSTRT
;	lds	#STACK	; initialize stack pointer (don't do this if under monitor)
START:
	jsr	INITKEY	; Initialize KEYPAD
	jsr	INITLCD	; Initialize LCD
	ldx	#PMT	; get message string
;;;;	jsr	LCDSTR	; display string
MainLoop:
	jsr	GETKEY	; get a key from keypad, returned in A
	jsr	LCDOUT	; display key value
	bra	MainLoop

ENDPROG:
        rts		; return (use this only if called, from monitor for example)
	jsr	COP_RESET	; clear watch-dog timer
	bra	ENDPROG	; endless loop


; The M68HC12A4 powers on with the COP (Computer Operating Properly)
; watchdog system enabled.  If you don't reset it occasionally in your software
; it will reset you.  This subroutine will reset the COP.
COP_RESET:
	ldaa	#$55	; get 1st COP reset value
	staa	COPRST	; store it
	ldaa	#$AA	; get 2nd COP reset value
	staa	COPRST	; store it
	rts

;**************
; TEXT TABLES *
;**************
PMT:    FCC   'Press Key: ',0



; Include External Subroutine Files
#include        lcd12b.asm     ; include 12B32 LCD functions
#include        key12b.asm     ; include KEYPAD B32 functions

         END


