I thought I ordered a 16-key keypad when I ordered the 74c922 Encoder ic but actually I ordered a
4x3 instead of 4x4 and the 74c922 was released in 1993 for 16 key keypads (the rugged ones) were
used for many things. So the problem was the BCD CODE (8,4,2,1) was for a different layout ,hence
the codes didn't match up with the key labels. I ordered the correct keypad and the correct
encoder Ic TCM5089 12-KEY encoder ic but thought I would try to write a program to make the
keypad work while I'm waiting for parts. The keypad is available online cheap. They're sold all over
the world. Here is the best price I could find ($1.77):http://www.ebay.com/itm/New-4x3-12-Key-Matrix-Membrane-Super-Slim-Switch-Keypad-Keyboard-General-Use-/140891821818
Here is a link to some interfacing instructions :http://www.aiscube.com/main/resources/78.html
After many hours of testing and writing code I came up with a program that works and obtains a corrected
code (int total) that represents the key pressed. The program uses serial output to the monitor to report
BCD weights, the ORIGINAL code and then the key pressed. Forexample , key '0' generates the value '13' but
is reported as '0'. This is accomplished using a boolean flag (setflag) to lock out all the other comparisons
once a match is found. When you see the code (attached) you'll see why. The program says 'If total=0,
then total=1. This is because the '1' key generates '0'. The flag is necessary because the very next test says
'If total= 1, then total=2. (because the '2' key generates '1'. You can see how this could get out of control
with one statement changing right after another and so forth. The flag is set to 'true' after the change
and the 'if' statement can only be entered when it is 'false'.
The original (the encoder output) code was/is this:
1: L,L,L,L=> 0
2: L,L,L,H=> 1
3 : L,L,H,L=> 2
4: L,H,L,L=> 4
5: L,H,L,H=> 5
6: L,H,H,L=> 6
7: H,L,L,L=> 8
8: H,L,L,H=> 9
9: H,L,H,L=> 10
0: H,H,L,H=> 13
*: H,H,L,L=> 12
#: H,H,H,L=> 14
These values are reported to the serial port along with the correct key, so '0' reports '13' and 'KEY=0'
The '*' (asterisk) and '#' have been given the values '10' & '11' respectively but you can change them
to whatever you want. In fact you can change any key to any integer value whatsoever within the
contrains of unsigned 8-bit int (53 thous or is it 32 thou) whatever. The code includes a flag status
ledpin output (pin-6) that is turned on when the flag is SET ! and turned off when at the beginning
of each loop. If you wanted to you could add serial output like "FLAG SET !"/"FLAG CLEARED" but
I thought that would be overkill. When you start the program there is no serial output until you
press a key. A key press generates all four BCD weighted values , the encoder output code (sum)
and the name of the key, once and only once until the next keypress.
If you want to use the * & # you need to use int 10 & 11 for execution
(changed from the original 12 & 14) . The serial reporting is after all ASCII. The wiring list is attached.
(sorry, no CAD). I know how to draw a schematic but it would look like crap.
If you decide to go with the TCM5089 they are very hard to find but I found one in China for $1.00.
Also, it requires a 3.58 Mhz Color-Burst crystal that is even harder to find but I found one for
$2.00. (30pF caps too).
Obviously, those of you who are experienced programmers are saying to yourself:
"What's all this code ? That could have done with one ISR. True , but my ISR program is not working
and I don't know why. If you're one of those wizards then you can take a look at it and tell
me what's wrong. http://forum.arduino.cc/index.php?topic=203396.new;topicseen