170 likes | 415 Views
Keypad. Lecture L4.6. Port Integration Module. Reference:. PIM_9C32 Block Guide V01.06. S12C32PIMV1.pdf. Axiom 4 x 4 Hex Keypad. Port P. PTP equ $258 ; Port P PTIP equ $259 ; Port P input DDRP equ $25A ; Direction
E N D
Keypad Lecture L4.6
Port Integration Module Reference: PIM_9C32 Block Guide V01.06 S12C32PIMV1.pdf
PTP equ $258 ; Port P PTIP equ $259 ; Port P input DDRP equ $25A ; Direction RDRP equ $25B ; portP reduced drive register PERP equ $25C ; portP pull device enable PPSP equ $25D ; portP pull polarity select PIEP equ $25E ; portP interrupt enable register PIFP equ $25F ; portP interrupt flag register
; keypad.asm ; AXIOM keypad org $800 outa equ $FF4F PTP equ $258 ; Port P DDRP equ $25A ; Direction PERP equ $25C ; portP pull device enable PPSP equ $25D ; portP pull polarity select
keycodes db $14 ; 0 db $88 ; 1 db $84 ; 2 db $82 ; 3 db $48 ; 4 db $44 ; 5 db $42 ; 6 db $28 ; 7 db $24 ; 8 db $22 ; 9 db $81 ; A db $41 ; B db $21 ; C db $11 ; D db $18 ; E/* db $12 ; F/#
; Initialize KEYPAD ; Port P 0-3 must be input with pull downs ; 4-7 must be output initkey ldaa #$F0 ; set Port P direction staa DDRP ldaa #$0f staa PPSP ; set for pull downs ldaa #$0f staa PERP ; enable pull downs rts
; scan all keys ; B = key pressed ; if B = #$10, no key pressed keyscan clrb ; B = index ldx #keycodes ks1 ldaa b,x staa ptp ;write next code nop ;wait to settle down nop ldaa ptp ;read it back cmpa b,x ;if key pressed, beq ks2 ; B = key incb ;else, inx index cmpb #$10 ; and scan all keys bne ks1 ;if no key pressed ks2 rts ; B = #$10 keycodes db $14 ; 0 db $88 ; 1 db $84 ; 2 db $82 ; 3 db $48 ; 4 db $44 ; 5 db $42 ; 6 db $28 ; 7 db $24 ; 8 db $22 ; 9 db $81 ; A db $41 ; B db $21 ; C db $11 ; D db $18 ; E/* db $12 ; F/#
; wait to press a key ; B = key value keypad bsr keyscan ;scan keypad cmpb #$10 ;until key pressed beq keypad rts
Debounce ; debounced key input getkey bsr keypad ;wait for key pshb ;save key value ldy #3 jsr ms_delay ;delay ~10 ms bsr keypad ;wait for key pula ;get 1st value sba ;if not same as 2nd bne getkey ;repeat rts ;B = key value
; wait to lift finger from key wait_keyup bsr keyscan ;scan keypad cmpb #$10 ;while key is pressed bne wait_keyup ldy #3 jsr ms_delay ;delay ~10 ms bsr keyscan ;scan keypad cmpb #$10 ;if key is pressed bne wait_keyup ;repeat rts #include ms_delay.asm #include hexasc.asm
org $4000 main bsr initkey ;initialize keypad mn1 jsr getkey ;get key input tba ;A = key hex value jsr hexasc ;convert to ascii jsr outa ;display on screen jsr wait_keyup ;wait to lift finger bra mn1 ;get more keys