PDA

View Full Version : row -> col and col -> row



savnik
- 12th April 2007, 08:25
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;



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

skimask
- 12th April 2007, 13:33
I have the below code and work.
How to make the row -> col and col -> row

SWAP col,row

savnik
- 12th April 2007, 15:10
SWAP col,row
I swap col with row with no succes

skimask
- 12th April 2007, 16:57
I swap col with row with no succes

Maybe do a search on 'matrix keypad'

peterdeco1
- 12th April 2007, 17:54
This is how I read a 16 matrix membrane switch. All horizonal rows connected to PORTC 1,2,3,4 outputs. All vertical columns connected to PORTB 1,2,3,4 inputs held high by resistor network. This example just shows eight readings:

PORTC = 255 'MAKE SURE ALL OUTPUTS ARE HIGH

START:
LOW PORTC.1
PAUSE 1
IF PORTB.1 = 0 THEN ONE
IF PORTB.2 = 0 THEN TWO
IF PORTB.3 = 0 THEN THREE
IF PORTB.4 = 0 THEN FOUR
HIGH PORTC.1
PAUSE 1

LOW PORTC.2
PAUSE 1
IF PORTB.1 = 0 THEN FIVE
IF PORTB.2 = 0 THEN SIX
IF PORTB.3 = 0 THEN SEVEN
IF PORTB.4 = 0 THEN EIGHT
HIGH PORTC.2

Pauses are added to slow down the process. Without them we experienced intermittant problems (probably from capacitance in the membrane switch). Hope this helps.

mister_e
- 13th April 2007, 01:45
http://www.picbasic.co.uk/forum/showthread.php?t=3250