This is a 16-key matrix keypad project using the 74c922 16-key encoder ic (circa 1995) .
The wiring is straightforward.
The 74c922 datasheet shows the Truth Table on pg-4 and the layout and wiring on pgs. 6 & 7.
Rows 1 ,2,3 & 4 are ic pins -1,2,3 & 4 respectively.
Columns 1,2,3 & 4 are ic pins -11, 10,8, & 7 respectively.
OSC cap is 0.01 uF on pin-5 of ic.
KeyBounce Mask (KBM) (debounce cap) is 0.1 uF on ic pin-6.
Vcc is pin 18.
Gnd is pin-9
DATA_AV (Data Available) is ic pin-12 and goes to Arduino INT0 input on pin-2.
OE-NOT (Output Enable) is ic pin 13. (not used because if left unconnected the ic outputs are always available)
DCBA OUTPUTS
OUTA: ic pin-17 goes to Arduiino Port-B bit-0 at pin-8 (D8)
OUTB: ic pin-16 goes to Arduiino Port-B bit-1 at pin-9 (D9)
OUTC: ic pin-15 goes to Arduiino Port-B bit-2 at pin-10 (D10)
OUTD: ic pin-14 goes to Arduiino Port-B bit-3 at pin-11 (D11)
The PORTB bits 0-5 include pin 13 (PB5, bit-5) which although it is not used by the program , seemed to alway
read as HIGH so it was MASKED using the following AND operation:
total = PINB & B011111 ;
Here is the code for the program running on a SainSmart Arduino UNO-R3
const int intISR = 0; // Interrupt0 on pin 2
volatile boolean newKey = false;
volatile int Flagpin=6;
volatile int total=0;
volatile int Key=0;
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int totVals [] = { 1, 2, 3, 10, 4, 5, 6, 11, 7, 8, 9, 12, 14, 0, 15, 13};
void setup()
{
attachInterrupt(intISR,readEncoder , CHANGE);
DDRB = B00000000; // set PORTD (digital 7~0)=INPUTS
pinMode(Flagpin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
delay(300);
digitalWrite(Flagpin,LOW);
delay(300);
total=0;
newKey = false;
}
void readEncoder()
{
digitalWrite(Flagpin,HIGH);
total = PINB & B011111 ;
Serial.print("PORTB= ");
Serial.println(total,BIN);
Key = totVals[total];
Serial.print("key= ");
Serial.println(Key);
newKey = true;
}
Attached :
A terminal capture of the serial output showing the binary code read and the Key mapped to that value by the ARRAY.
The IDE source code program "*.ino" file.
A photo of the 16-key keypad used.
A WORD file with the keypad MAPPING info.