
Originally Posted by
Experimenter
mainloop:
gosub getkey
lcdout 254, 192, "key=",#key, " " ; line 2
if portD.0 = 0 then gosub flash
goto mainloop
flash:
portD.4=1
pause 500
portD.4=0
return
getkey:
pause 50 ;debounce
getkeyu:
' Wait for all keys up
PORTB = 0 ;all output pins low
TRISB = 110000 ;bottom 4 pins out, top 4 pins in
If ((PORTB >> 4) != 001111) Then getkeyu ' If any keys down, loop
Pause 50 ;debounce
getkeyp:
' Wait for keypress
For col = 0 To 3 ' 4 columns in keypad
PORTB = 0 ' All output pins low
TRISB = (dcd col) ^ $ff ' Set one column pin to output
row = PORTB >> 4 ' Read row
If row != 001111 Then gotkey ' If any keydown, exit
Next col
Goto getkeyp ' No keys down, go look again
' Change row and column to key number 1-12
gotkey:
key = (col * 3) + (ncd (row ^ 001111)) ;4RX3C matrix
return
Bookmarks