Arduino与Proteus仿真实例-74C922键盘解码驱动仿真

74C922键盘解码驱动仿真

矩阵键盘是向基于微控制器的系统提供用户输入数据的绝佳方式。键盘在远程控制、独立数据记录器、安全系统、门禁系统、计算器、微波炉等中找到应用。它们通常被实现为按行和列矩阵格式排列的按钮开关,以减少 I/O 连接的数量.例如,一个 16 开关键盘以 4 X 4 矩阵格式排列,需要 8 个 I/O 连接。通过扫描键盘以查找行和列线之间的短路情况来检测和识别按下的键。键盘扫描可以通过轮询或中断程序来完成。在轮询方式中,扫描过程在一个连续的循环中重复进行,导致CPU时间的浪费。中断方法更有效,它会在有击键时通知处理器。将键盘连接到微控制器的另一种方法是使用专用键盘编码器 IC,这进一步减少了 I/O 连接并使接口更加简单。

MM74C922 芯片提供 18 引脚 DIP 和 20 引脚 SOIC 封装。

74C922 编码器实现了将 16 键开关矩阵连接到数字系统所需的所有逻辑。编码器芯片连续扫描键盘等待按键。当按下开关时,它会在其输出引脚 D、B、C 和 A (14-17) 上提供与按下的开关相对应的 4 位半字节。该芯片具有内置去抖电路,需要将单个外部电容器连接到 Keybounce Mask 引脚 (6) 才能运行。电容器的值取决于所需的去抖动时间。当检测到有效按键且按键弹跳电路超时时,编码数据被锁存到输出端口,数据可用 (DAV) 引脚 (11) 变为高电平。当按下的键被释放时,DAV 引脚回落到低电平。因此,DAV 输出可以在有击键时用作处理器的中断信号。即使在按键被弹起后,锁存输出在引脚 A 到 D 上仍保持活动状态。新的数据将在新的击键时可用。该芯片还具有双键翻转功能,在主动击键期间忽略任何第二次按键。键盘扫描速率也可通过连接到振荡器引脚 (5) 的外部电容器进行配置。

将74C922的16 个开关分别命名为 0-9、*、# 和 A-D。 下表显示了对应于每个按键的输出半字节的十六进制值。

在这里插入图片描述

1、仿真电路原理图

在这里插入图片描述

2、仿真代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

#define PINA 3
#define PINB 4
#define PINC 5
#define PIND 6
#define PIN\_DAV 2
int output, key_code, press_status = 0;
/\*char str[16] = {'1','2','3','A',
'4','5','6','B',
'7','8','9','C',
'\*','0','#','D'};\*/
char str[16] = {'1', 'A', '3', '2', '4', 'B', '6', '5', '7', 'C', '9',
'8', '\*', 'D', '#', '0'};
void setup()
{
pinMode(PINA, INPUT);
pinMode(PINB, INPUT);
pinMode(PINC, INPUT);
pinMode(PIND, INPUT);
pinMode(PIN_DAV,INPUT);
Serial.begin(9600);
Serial.println("MM74C22N Demo!");
attachInterrupt(digitalPinToInterrupt(PIN_DAV), Read_Data, RISING);
}

void loop()
{
if(press_status){
//Serial.println("Key press detected.");
Serial.print("Pressed Key (code) = ");
Serial.print(str[output]);
Serial.print(" HEX=(");
Serial.print(output, HEX);
Serial.println(')');
press_status = 0;
}
}

void Read\_Data()
{
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);
press_status = 1;
//Serial.print("read:output=");
//Serial.print(output);
//Serial.println();

}


3、仿真结果

在这里插入图片描述

文章来源: https://iotsmart.blog.csdn.net/article/details/121163424