Hello
Thank you for your help, I change this way:
getkeyp:'----------------------------------------- Wait for keypress
FOR row = 0 TO 3 ' 4 rows in keypad
PORTB = 0 ' All output-pins low
TRISB = (DCD row) ^ $ff ' Set one row pin to output
col = PORTB >> 3 ' Read columns
IF col != $f THEN gotkey ' If any keydown, exit
NEXT row
GOTO getkeyp ' No keys down, go look again
gotkey: ' Change row and column to key number 1 – 16
key = (row * 3) + (NCD (col ^ $8f))
'------RB6--RB5--RB4--
' | | |
'RB0----1----2----3---row1
' | | |
'RB1----4----5----6---row2
' | | |
'RB2----7----8----9---row3
' | | |
'RB3----*----0----#---row4
' | | |
'-----col1--col2--col3
LOOKUP key,["1","4","7","*","2","5","8","0","3","6","9","# "],skey
LOOKUP key,["147*2580369#"],skey
'8f = %10001111 = LED,col1,col2,col3,row4,row3,row2,row1
@ DEVICE pic16F628, INTRC_OSC_NOCLKOUT
@ DEVICE pic16F628, WDT_ON
@ DEVICE pic16F628, PWRT_OFF
@ DEVICE pic16F628, BOD_ON
@ DEVICE pic16F628, MCLR_ON
@ DEVICE pic16F628, LVP_OFF
@ DEVICE pic16F628, CPD_OFF
@ DEVICE pic16F628, PROTECT_OFF
Include "modedefs.bas"
DEFINE OSC 4
col VAR BYTE ' Keypad column
row VAR BYTE ' Keypad row
key VAR BYTE ' Key value
i var byte
led var PortB.7
serpin VAR PortA.3 ' Serial output pin
CMCON = 7 ' PortA = digital I/O
VRCON = 0 ' Voltage reference disabled
OPTION_REG.7 = 0 ' Enable PORTB pull-ups
loop:
GOSUB getkey ' Get key from keypad
SEROUT2 serpin,84,[skey,10,13] ' Send key value out PortA.3
GOTO loop
getkey:
high led
PAUSE 50 ' Debounce key-input
getkeyu:'----------------------------------------- Wait for all keys up
PORTB = 0 ' All output-pins low
TRISB = $f0 ' Bottom 4-pins out, top 4-pins in 1111 0000
IF ((PORTB >> 4) != $f) THEN getkeyu ' If keys down, loop
PAUSE 50 ' Debounce key-input
getkeyp:'----------------------------------------- Wait for keypress
FOR row = 0 TO 3 ' 4 rows in keypad
PORTB = 0 ' All output-pins low
TRISB = (DCD row) ^ $ff ' Set one row pin to output
col = PORTB >> 4 ' Read columns
IF col != $f THEN gotkey ' If any keydown, exit
NEXT row
GOTO getkeyp ' No keys down, go look again
gotkey: ' Change row and column to key number 1 - 16
key = (row * 3) + (NCD (col ^ $f))
LOOKUP Key,["147*2580369#"],sKey ' 1 4 7 * 2 5 8 0 3 6 9 #
'LOOKUP Key,["*","7","4","1","0","8","5","2","#","9","6","3 "],sKey
PAUSE 50
low led
RETURN ' Subroutine over
END
Bookmarks