AS11, an absolute assembler for Motorola MCU's, version 1.2e

                        *
                        * Kpad4x4.asm - keypad routine for FOX11 board
                        *               with Wytec Phantom Monitor, (c)2003, EVBplus.com
                        *		Written By Wayne Chu
                        *
                        *     Function: It scans a keypad and outputs the key number in binary
                        *		format on the PB0-PB4 LEDs
                        *
                        *     Instructions:
                        *     If you have a 4 x 4 keypad, connect it to the keypad header J6.
                        *
                        *	   If you press any key on the keypad, the LEDs should show
                        *	   the key number that you pressed in binary format. Key number 00
                        *	   is shown as $10.
                        
                        ; The following signal definitions only apply to Wytec 4X4 membrane keypad:
                        
                        ; PD2 connects COL0 of the keypad via pin 1 of the 8-pin keypad header J6
                        ; PD3 connects COL1 of the keypad via pin 2 of the 8-pin keypad header J6
                        ; PD4 connects COL2 of the keypad via pin 3 of the 8-pin keypad header J6
                        ; PD5 connects COL3 of the keypad via pin 4 of the 8-pin keypad header J6
                        
                        ; PE0 connects ROW0 of the keypad via pin 5 of the 8-pin keypad header J6
                        ; PE1 connects ROW1 of the keypad via pin 6 of the 8-pin keypad header J6
                        ; PE2 connects ROW2 of the keypad via pin 7 of the 8-pin keypad header J6
                        ; PE3 connects ROW3 of the keypad via pin 8 of the 8-pin keypad header J6
                        
                        ; The PE0-PE3 has a 100K pull-up resistor in each line.
                        
0000                    porta:		equ	0
1404                    portb:		equ	$1404
1403                    portc:		equ	$1403
0008                    portd:		equ	8
0009                    ddrd:		equ	9
000a                    porte:		equ	$0a
1000                    REGBLK:		equ	$1000
                        
                        
0040                    		org	$40
0040                    ram:		rmb	1
0041                    temp:           rmb     1
                        
0042                    key_flag:	rmb	1
                        
00ff                    STACK:		equ	$FF
                        
09c4                    TEN_MS:		equ	2500	; 2500 x 8 cycles = 20,000 cycles = 10ms
                        
f000                    	org	$F000
f000 7e f0 41           	jmp	start
                        
                        * keypad scan for Wytec 4X4 membrane keypad
                        * at exit:  if a key is down, the carry bit =1 and the accumulator b
                        *	    holds the key number
                        *	    if no key is dwon the carry bit =0
                        *
f003 ce 10 00           keybrd:	ldx	#REGBLK                                                 n
f006 c6 03              	ldab	#3
                        *	ldaa	#11011111b
f008 86 df              	ldaa	#$df            ; starting with pd5 is low
f00a 97 41              	staa	temp
f00c                    next_row:
f00c a7 08              	staa	portd,x
f00e 01                 	nop			; add delay before checking key down
f00f 01                 	nop
f010 01                 	nop
f011 01                 	nop
f012 a6 0a              	ldaa	porte,x
f014 84 0f              	anda	#$0f            ; needs PE0-PE3 only
f016 81 0f              	cmpa	#$0f
f018 26 0f              	bne	keyin		; key input detected
f01a 5a                 	decb
f01b c1 ff              	cmpb	#$ff		; after 4 tests, accu B will be $ff
f01d 27 08              	beq	no_keyin
f01f 76 00 41            	ror	temp             ; check next column
f022 96 41              	ldaa	temp
f024 7e f0 0c           	jmp	next_row
                        *
f027                    no_keyin:
f027 0c                 	clc
f028 39                 	rts			; no key input
                        
f029 46                 keyin: 	rora
f02a 24 05              	bcc	key_ok
f02c cb 04              	addb    #4
f02e 7e f0 29           	jmp     keyin
f031 0d                 key_ok: sec
f032 39                 	rts
                        *
f033                    delay_10ms:
f033 18 3c              	pshy
f035 18 ce 09 c4        	ldy     #TEN_MS		; 2500 x 8 = 20,000 cycles = 10ms 
f039 18 09              del1:	dey			; 4 cycles
f03b 01                 	nop			; 1 cycle
f03c 26 fb              	bne	del1		; 3 cycles
f03e 18 38              	puly
f040 39                        	rts
                        
                        *
f041 8e 00 ff           start:	lds	#STACK
f044 ce 10 00           	ldx	#REGBLK
                        *	ldaa	#11111111b
f047 86 ff              	ldaa	#$ff
f049 a7 08              	staa	portd,x
                        *	ldaa 	#11111110b		; 0 =input, 1 = output
f04b 86 fe              	ldaa 	#$fe			; PD0=input
f04d a7 09              	staa 	ddrd,x
                        *
f04f                    begin:
f04f bd f0 03                   jsr	keybrd
f052 24 10              	bcc	nokey
f054 bd f0 33              	jsr	delay_10ms
f057 24 0b              	bcc	nokey
                        * key down
f059 5d                         tstb
f05a 26 02              	bne     not_zero
f05c c6 10              	ldab    #$10
f05e                    not_zero:
f05e f7 14 04           	stab	portb
f061 7e f0 4f           	jmp	begin
                        *
f064 bd f0 33           nokey:  jsr	delay_10ms
f067 7e f0 4f                   jmp	begin
                        *
fffe                    	org	$FFFE
fffe f0 41              	fdb	start
                        	end

Executed: Sat Dec 31 02:27:15 2005
Total cycles: 167, Total bytes: 108
Total errors: 0, Total warnings: 0
