Step 4: Using 74C922 to Reduce I/O Requirements

The MM74C922N is a 16-key encoder that includes all the internals to take the output of a 16-key switch that we just saw from the previous step, and encode it onto only four outputs using a truth table. This is a boon, as it gives you more I/O to control or monitor other things without having to go buy a bigger (in the sense of more pinouts for I/O) microcontroller.

The 74C922 16-Key Encoder

From the datasheet, the MM74C922 can use an external clock for synchronous keypad scanning, has internal pull-ups, and has an internal debounce circuit! Both the scan rate and debounce time is configurable via an external clock or capacitor. It also keeps the last key pressed on the outputs even after they key has been depressed, in case your MCU has a moment and needs to retrieve the value again (at least before the next keypress). It also operates from 3V to 15V so it integrates well into TTL and CMOS designs.

The rows of the keypad are connected through its internal pull-up resistors when no key has been pressed. When a key is pressed the chip goes through it's debounce mechanism and when that times out, the encoded data is latched and the DA pin (Data Available) goes high. The DA pin stays high (logical 1) until the key is released, then it drops to a logical 0. There is also an OE pin (Output Enabled) which is the inverse of the DA pin.

The 74C922N pinout is shown in a schematic I've included below that only shows this IC. I've also included an Eagle schematic, although the keypad device's rows and columns made the circuit difficult to interpret, so I also include my hand written schematic that I made when I first started toying with the keypad and the 74C922. Hopefully one of those will clear up any connectivity issues, if you get any.

Build the Circuit

Put in your 74C922 into your breadboard, somewhere close but where you're not too cramped. If you're not familiar with IC's, take a moment to wonder at your new shiny chip and notice that the legs are splayed out when they come out of the factory. It can help getting it into the breadboard if you lay it on its side with its legs flat on the table, and with a gentle rolling motion slightly bend them inward. When placing your IC note that there is a stripe or divot on one side. That indicates where pin one is.

Connect the 0.1uF capacitors to pins 6 and 7 and take them to ground. See below. If you're using tantalum capacitors remember they're polarized so put the positive side (usually the longer leg) closest to the pin and the short leg in the ground terminal.
You may have to play around with the capacitors for your setup. I've found 1uF on the oscillator and 10uF to 15uF (I had 3 in parallel) gives me the best responsive scan with the least debounce. Figuring it out for your setup can be fun.

Next connect your power components. At this stage I don't have my board powered. It's just easier to do these now than after you're connected all the inputs and outputs. Connect Vcc (top right pin) to 5V, the bottom left pin to ground, as well as the OE pin to ground. We won't be caring about it this time. See below.

Now connect your data outputs to your AVR. In the picture below I've connected Data Out (DO) A to PD2, DOB to PD3, DOC to PD4 and DOD to PD5. Now would be a good time to connect the Data Available pin (the one right below the OE you ran to ground on the right) to your microcontroller. I chose PD6. Nice contiguous block of I/O. If we could know that the same two numbers weren't entered consecutively we could leave off the Data Available and just poll the data out pins. That would reduce our previously needed eight I/O lines to only four! For completeness, I'm including it because that's the pin I'll service with a pin change interrupt. It's nicer than polling and lets your computer do other stuff instead of wait in loops polling the pin state.

Finally, connect your input wires. The top left four pins go to rows one, two, three, and four. The two pins between the capacitor and ground on the bottom left connect to column four and three. On the other side, reading from the bottom right, the pins connect to column two and one. Mind the order! Connect your keypad if you made a cable for it and fire your microcontroller!
vpontis6 months ago

Where can I get the Eagle schematic?

nevdull (author)  vpontis1 month ago

I didn't realize I only included a PDF of the schematic and not the eagle sch/brd. If you're still wanting them drop me an email and I'll look for them and send them to you.


If anyone else is interested in using the MM74C922 IC, I have to warn you:

The diagram shown above confuses more than it helps, as the IC is setup differently - at least the datasheet tells me this: Column X1 + X2 is NOT on the left side. Or in general: the layout of the IC is not comparable to the layout above.

Just a friendly reminder to others :)
nevdull (author)  mbroesby-olsen1 month ago


I think there is some confusion here. The diagram (technically, the schematic symbol I use for the 74C922 is only that: a schematic diagram. Just as a logic diagram does not map one-to-one with the physical pinout of the IC, many schematic symbols also choose to place the pins where it makes the most semantic difference and not how they are physically setup. This is done to help alleviate the rats nest some schematics become when attaching passives and such. The 555 timer is a great example; the physical pinout and the symbol are totally different and this is to allow engineers the ability to follow a common design pattern on the schematic that would otherwise be ugly and messy (as mine looks above).

Hope I understood your question and this helps to clear things up.