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. N.B.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!