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!
<p>Where can I get the Eagle schematic?</p>
<p>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.</p><p>Cheers! </p>
If anyone else is interested in using the MM74C922 IC, I have to warn you:<br><br>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.<br><br>Just a friendly reminder to others :)
<p>Heyas,</p><p>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 <em>semantic</em> 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).</p><p>Hope I understood your question and this helps to clear things up.</p>
Hello, Nice project and code I think : was just looking for something like this for making a code lock. My question: for what type of AVR have you written the C-code ? Can I use it without changes for my ATMega88 ?
Hi,<br/>Thanks. I've written it for an ATmega328P. You will need to edit the Makefile and change MCU to atmega88 and F_CPU to whatever speed at which you have your '88 running. You may need to change the AVRDUDE settings in the Makefile to reflect your programmer and port. Further, note which pins I have things on and either match those in your setup or change them in the code to match yours.<br/><br/>Also, if you're going to read the key value, you will need to make some sort of translation table or compare how the values are sent when checking a keycode. That's because the actual value of the key (ie 1 or 3 or B) doesn't get sent, but instead a number (hex) starting from 0 at key 1 and ending at F at key D. Make sense? The keypad values vs the value sent from a keypress is like this:<br/><pre>[ 1 2 3 A ] [ 0 1 2 3 ][ 4 5 6 B ] [ 4 5 6 7 ][ 7 8 9 C ] [ 8 9 A B ][ * 0 # D ] [ C D E F ]</pre>So you'll need to make sure you're translating/comparing the right maps.<br/>Good luck!<br/>
Please, do you have some of these IC 74C922 yet?<br>Could sell some to me?
Sorry, I wish I could. I found just a couple at a local electronics shop. They've gotten pretty scarce recently. I don't know of a replacement part for it.<br><br>Good luck!
Hey Nevdull <br>- cool name by the way! :)<br><br>I am starting out a project tomorrow, using the 74C922 IC.<br>Would it be possible to use this IC on a 12 keypad-setup?<br>And is it difficult to translate your code to arduino-readable code?<br><br>I really could like to use this IC, as I need as many I/O ports as possible.

About This Instructable




Bio: Gian is a computational biologist and is the Managing Director at Open Design Strategies, LLC. He holds a BA in Molecular/Cellular Biology and an ... More »
More by nevdull:Create A Custom Medieval-/Fantasy-Style Calligraphy Quill Practical DACs Using Enumerated Types as Bitflags 
Add instructable to: