I have the below code and work.
But ,when i push the number 4 show 3 , when i push the number 7 show 3 , when i push the number 2 show 4
when i push the number 3 show 7
How to make the row -> col and col -> row to show right;
Code:
Col VAR BYTE ' Keypad column
Row VAR BYTE ' Keypad row
Key VAR BYTE ' Key value
Lcdout $fe, 1, "Press any key" ' Display sign on message
Loop:
Gosub getkey ' Get a key from the keypad
Lcdout $fe,1, #key
goto loop
GetKey:
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
IF ((PORTB >> 4) != $f) THEN getkeyu ' If keys down, loop
PAUSE 50 ' Debounce key-input
GetKeyp: ' Wait for keypress
FOR col = 0 TO 3 ' 4 rows in keypad
PORTB = 0 ' All output-pins low
TRISB = (DCD col) ^ $ff ' Set one row pin to output
row = PORTB >> 4 ' Read columns
IF row != $f THEN gotkey ' If any keydown, exit
NEXT col
GOTO getkeyp ' No keys down, go look again
GotKey: ' Change row and column to key number 1 - 16
key = (col * 4) + (NCD (row ^ $f))
RETURN ' Subroutine over
Bookmarks