AS11, an absolute assembler for Motorola MCU's, version 1.2e

                        *
                        * Kpad4x4.asm - keypad routine for the FOX11 board
                        *               with BUFFALO 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
                        
d000                    	org	$D000
d000 7e d0 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
                        *
d003 ce 10 00           keybrd:	ldx	#REGBLK                                                 n
d006 c6 03              	ldab	#3
                        *	ldaa	#11011111b
d008 86 df              	ldaa	#$df            ; starting with pd5 is low
d00a 97 41              	staa	temp
d00c                    next_row:
d00c a7 08              	staa	portd,x
d00e 01                 	nop			; add delay before checking key down
d00f 01                 	nop
d010 01                 	nop
d011 01                 	nop
d012 a6 0a              	ldaa	porte,x
d014 84 0f              	anda	#$0f            ; needs PE0-PE3 only
d016 81 0f              	cmpa	#$0f
d018 26 0f              	bne	keyin		; key input detected
d01a 5a                 	decb
d01b c1 ff              	cmpb	#$ff		; after 4 tests, accu B will be $ff
d01d 27 08              	beq	no_keyin
d01f 76 00 41            	ror	temp             ; check next column
d022 96 41              	ldaa	temp
d024 7e d0 0c           	jmp	next_row
                        *
d027                    no_keyin:
d027 0c                 	clc
d028 39                 	rts			; no key input
                        
d029 46                 keyin: 	rora
d02a 24 05              	bcc	key_ok
d02c cb 04              	addb    #4
d02e 7e d0 29           	jmp     keyin
d031 0d                 key_ok: sec
d032 39                 	rts
                        *
d033                    delay_10ms:
d033 18 3c              	pshy
d035 18 ce 09 c4        	ldy     #TEN_MS		; 2500 x 8 = 20,000 cycles = 10ms 
d039 18 09              del1:	dey			; 4 cycles
d03b 01                 	nop			; 1 cycle
d03c 26 fb              	bne	del1		; 3 cycles
d03e 18 38              	puly
d040 39                        	rts
                        
                        *
d041 8e 00 ff           start:	lds	#STACK
d044 ce 10 00           	ldx	#REGBLK
                        *	ldaa	#11111111b
d047 86 ff              	ldaa	#$ff
d049 a7 08              	staa	portd,x
                        *	ldaa 	#11111110b		; 0 =input, 1 = output
d04b 86 fe              	ldaa 	#$fe			; PD0=input
d04d a7 09              	staa 	ddrd,x
                        *
d04f                    begin:
d04f bd d0 03                   jsr	keybrd
d052 24 10              	bcc	nokey
d054 bd d0 33              	jsr	delay_10ms
d057 24 0b              	bcc	nokey
                        * key down
d059 5d                         tstb
d05a 26 02              	bne     not_zero
d05c c6 10              	ldab    #$10
d05e                    not_zero:
d05e f7 14 04           	stab	portb
d061 7e d0 4f           	jmp	begin
                        *
d064 bd d0 33           nokey:  jsr	delay_10ms
d067 7e d0 4f                   jmp	begin
                        *
                         	end

Executed: Sat Dec 31 02:24:52 2005
Total cycles: 167, Total bytes: 106
Total errors: 0, Total warnings: 0
