keypad lecture l4.6. port integration module pim_9c32 block guide v01.06 reference: s12c32pimv1.pdf

Post on 13-Dec-2015

214 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

  • Slide 1

Keypad Lecture L4.6 Slide 2 Port Integration Module PIM_9C32 Block Guide V01.06 Reference: S12C32PIMV1.pdf Slide 3 Axiom 4 x 4 Hex Keypad Slide 4 Port P Slide 5 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 Slide 6 Slide 7 Axiom 4 x 4 Hex Keypad Slide 8 ;keypad.asm ;AXIOM keypad org$800 outaequ$FF4F PTP equ $258 ; Port P DDRP equ $25A ; Direction PERP equ $25C ; portP pull device enable PPSP equ $25D ; portP pull polarity select Slide 9 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/# Slide 10 ; 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 Slide 11 ;scan all keys ;B = key pressed ;if B = #$10, no key pressed keyscan clrb; B = index ldx#keycodes ks1ldaab,x staaptp;write next code nop;wait to settle down nop ldaaptp;read it back cmpab,x;if key pressed, beqks2; B = key incb;else, inx index cmpb#$10; and scan all keys bneks1;if no key pressed ks2rts; 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/# Slide 12 ;wait to press a key ;B = key value keypad bsrkeyscan;scan keypad cmpb#$10;until key pressed beqkeypad rts Slide 13 Debounce ;debounced key input getkey bsrkeypad;wait for key pshb;save key value ldy#3 jsrms_delay;delay ~10 ms bsrkeypad;wait for key pula;get 1st value sba;if not same as 2nd bnegetkey;repeat rts;B = key value Slide 14 ;wait to lift finger from key wait_keyup bsrkeyscan;scan keypad cmpb#$10;while key is pressed bnewait_keyup ldy#3 jsrms_delay;delay ~10 ms bsrkeyscan;scan keypad cmpb#$10;if key is pressed bnewait_keyup;repeat rts #includems_delay.asm #includehexasc.asm Slide 15 org$4000 main bsrinitkey;initialize keypad mn1jsrgetkey;get key input tba;A = key hex value jsrhexasc;convert to ascii jsrouta;display on screen jsrwait_keyup;wait to lift finger bramn1;get more keys

top related