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?
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?
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
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 ... #
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
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.
Last edited by Archangel; - 10th July 2009 at 09:11.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
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
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
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
Why don't you use the universal keypad project? See it @ http://www.picbasic.co.uk/forum/showthread.php?t=10420Do you have other examples of management programs 4x3 keypad.
Al.
All progress began with an idea
Bookmarks