PDA

View Full Version : keypad 4x3



jonas2
- 8th July 2009, 09:37
Hello


Currently I use the program by Bruce, a 4x3 keypad and wire
this way:
RB6 RB5 RB4
RBO 1 2 3
RB1 4 5 6
RB2 7 8 9
RB3 * # 0

But when I visualize the data received on my computer, the figures are
step in the right order.

An example:

RB0 RB7 4
RB0 RB6 3
RB0 RB5 2
RB0 RB4 1

I do not know how, thank you for your help

Archangel
- 8th July 2009, 17:01
...and wire
this way:
RB6 RB5 RB4
RBO 1 2 3
RB1 4 5 6
RB2 7 8 9
RB3 * # 0

RB7 not used here . . .


But when I visualize the data received on my computer, the figures are
step in the right order.

An example:

RB0 RB7 4
RB0 RB6 3
RB0 RB5 2
RB0 RB4 1


But it is used in this example . . . . BTW Hi Jonas2 . . .



I do not know how, thank you for your help

OK, What is it you do not know how to do ?
The "little secret" of this code is when it scans the keypad each button = a number from zero to 12 or 16 depending upon which keypad you use, and the lookup table then makes it have the number <b>YOU</b> want those keys to represent.

jonas2
- 9th July 2009, 09:22
Hello

Even with instruction lockup figures are reversed.
RB7 on I put a led, for columns RB6 RB5 RB4 for
lines rb0 RB1 RB2 RB3.

I really do not understand this program and how to edit?

EarlyBird2
- 9th July 2009, 11:05
This is the line to edit

LOOKUP Key,["147*2580369#"],sKey

But it looks like you have you rows and columns wired wrong. Swap your RB4 and RB6 wires over.

Steve

jonas2
- 9th July 2009, 11:26
hello

I already tested this way, but without success.

.......RB6... RB5... RB4

RB0... 1... 2 ... 3

RB1... 4 ... 5... 6

RB2... 7... 8 ... 9

RB3... * ... 0 ... #

Ioannis
- 9th July 2009, 21:33
If you won't post your code I think it is difficult to get help...

Ioannis

EarlyBird2
- 10th July 2009, 07:14
This is becoming very confusing. For a 4x3 keypad RB0 to RB6 should be used RB7 is not used. So why are you talking about RB7 of course if you are using a 4x4 keypad you would use all of the pins.

Can you send a photograph of your set up?

Steve

Archangel
- 10th July 2009, 08:06
RB7 on I put a led, for columns RB6 RB5 RB4 for
lines rb0 RB1 RB2 RB3.


OK, I think your problem is here, you set the TrisB to $F0 which in binary is 11110000, which sets the lower ports as outputs and the upper ports as inputs, so then you hang an LED on this PortB.7 input and it pulls it low. Change the Tris To $70 or %01110000, which will set the PortB.7 as an output. Better yet, put it back the way Bruce wrote it and move the LED to PortA otherwise, (although I am not sure), I think the keypad will not go over 7, I think if you want to "rob" portB of a port you must use one of the outputs not inputs.

jonas2
- 10th July 2009, 09:41
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

EarlyBird2
- 10th July 2009, 09:59
Jonas2

And it still does not work?

jonas2
- 10th July 2009, 10:05
not yet, and the keys are shifted

EarlyBird2
- 10th July 2009, 11:00
You are using pull up resistors for the inputs so col will be 1111 when no key pressed. If you press number 1 then it will be 1011 so at ****2 1011 xor 1111 will become 0100 and key=(0*3)+(NCD(0100))

which is 3 and on your lookup the third number is 7 so change the 7 to 1 and that one will be correct.

If you wire

'------RB4--RB5--RB6--
' | | |
'RB0----1----2----3---row1
' | | |
'RB1----4----5----6---row2
' | | |
'RB2----7----8----9---row3
' | | |
'RB3----*----0----#---row4
' | | |
'-----col1--col2--col3

then

the lookup table is

LOOKUP key,["123456789*0#"],skey which is a bit neater.

If you press number 1 then it will be 1110 so at ***2 1110 xor 1111 will become 0001 and key=(0*3)+(NCD(0001))which is 1 and on your lookup the first number is 1 so that one is correct.


Lets try again with number 8 now we have 1101 which becomes 0010 and key=(2*3)+(NCD(0010))which is 8 and on your lookup the eighth number is 8that one is correct.

so these are the changes to make

col = PORTB >> 4 ' Read columns ****** ************** 1
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)) ******************** 2




'------RB4--RB5--RB6--
' | | |
'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,["123456789*0#"],skey ******************** 3

Do you understand the maths and logic now? XOR always intrigued me along with bitwise operators. Why did anyone even think of this was my first thought. After a while I have found them useful.

Steve

jonas2
- 11th July 2009, 10:19
Hello

I still have not solved my problem, I tried different configuration
and impossible to get what I want?

Do you have other examples of management programs 4x3 keypad.

Thank you

aratti
- 11th July 2009, 11:04
Do you have other examples of management programs 4x3 keypad.

Why don't you use the universal keypad project? See it @ http://www.picbasic.co.uk/forum/showthread.php?t=10420

Al.

EarlyBird2
- 11th July 2009, 12:25
In your program you have the rows and columns the wrong way round and also can we resolve wether it is a 3x4 or 4x4 keypad because in your program you have 16 digits in your lookup table.

It looks to me as if you have not read my last post?

Steve

jonas2
- 14th July 2009, 09:29
Hello EarlyBird2

Thank you for your help and it works well.

EarlyBird2
- 15th July 2009, 06:34
You are most welcome.

Steve