Jonas2
And it still does not work?
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
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
Hello EarlyBird2
Thank you for your help and it works well.
Bookmarks