MM74C922 16-Key Encoder

used products:

1. Arduino UNO
2. MM74C922N

content:

Çeşme: http://embedded-lab.com/blog/mm74c922n-based-encoded-matrix-keypad/

Arduino:

#define PINA 7 #define PINB 6 #define PINC 5 #define PIND 4 int output; char str[16] = {'1', '2', '3', 'А', '4', '5', '6', 'B', '7', '8', '9', 'C', '*', '0', '#', 'D' }; void setup() { pinMode(PINA, INPUT); pinMode(PINB, INPUT); pinMode(PINC, INPUT); pinMode(PIND, INPUT); Serial.begin(9600); } void loop() { output = 0; output = output | digitalRead(PIND); output = output << 1; output = output | digitalRead(PINC); output = output << 1; output = output | digitalRead(PINB); output = output << 1; output = output | digitalRead(PINA); Serial.print("KEY = "); Serial.print(str[output]); Serial.println(); delay(50); }

C:

#include <avr/io.h> #include <util/delay.h> #include <Arduino.h> int output; char str[16] = {'1', '2', '3', 'А', '4', '5', '6', 'B', '7', '8', '9', 'C', '*', '0', '#', 'D' }; int main(void) { Serial.begin(9600); DDRD &= ~(1<<PD4); DDRD &= ~(1<<PD5); DDRD &= ~(1<<PD6); DDRD &= ~(1<<PD7); while (1) { output = 0; output = output | ((PIND & (1<<PD4)) == 0 ? 0 : 1); output = output << 1; output = output | ((PIND & (1<<PD5)) == 0 ? 0 : 1); output = output << 1; output = output | ((PIND & (1<<PD6)) == 0 ? 0 : 1); output = output << 1; output = output | ((PIND & (1<<PD7)) == 0 ? 0 : 1); Serial.print("KEY = "); Serial.print(str[output]); Serial.println(); _delay_ms(50); } return 0; }