4X3 Matrix 12-key keypad(STM32F0) to 74c922 Encoder Ic to Arduino UNO Interface

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):

Here is a link to some interfacing instructions :
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.

Enjoy !

74C922 TO 12-KEY KEYPAD WIRING LIST.docx (16.4 KB)

keypad_4x3_Program_Working_CORRECTLY_ISR_and_setflag_test_5.ino (5.74 KB)

Here are some software upgrades.
The attached file with just the word ARRAY in it is a BCD-weighting scheme with an array.
The other one with PIND and ARRAY is the array code with the BCD weighting method replaced by a
port -D read shifted 4-bits to the right. I had to use bits 4-7 for my input because pin-1 (serial tx pin)
was always HIGH and I couldn’t figure out why and I was using pins 8,11 & 12 for I/O already.
95% of the code in these two examples came from GrayNomad, who was kind enough to help me
out of a hole.

Matrix_4x3_12_key_kypd_to_74c922_encoder_ic_ARRAY_code.ino (1.28 KB)

Matrix_4x3_12_key_kypd_to_74c922_encoder_ic_PIND_ARRAY_code.ino (1.17 KB)

ARRAY_TEST_capture.txt (38 Bytes)

PIND_ARRAY_TEST_capture.txt (475 Bytes)

Latest software upgrade.
I finally got the Interrupt Service Routine working.

Matrix_4x3_12_key_keypad_to_74c922_encoder_ic_ISR__WORKING.ino (854 Bytes)

Matrix_4x3_12_key_keypad_to_74c922_encoder_ic_ISR__WORKING.txt (899 Bytes)

Matrix_4x3_12_key_kypd_to_74c922_encoder_ic_ISR_test_Terminal_Capture.txt (220 Bytes)

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.

Please disregard the above. This ic is a TONE encoder , and generated the telephone tones , NOT BCD output
codes. My oversite.