Arduino与Proteus仿真实例-PCF8574驱动4x4矩阵键盘仿真

PCF8574驱动4x4矩阵键盘仿真

PCF8574/74A 通过两线双向 I2C 总线(串行时钟 (SCL)、串行数据 (SDA))提供通用远程 I/O 扩展。

PCF8574/74A包括八个准双向端口、100 kHz I2C 总线接口、三个硬件地址输入和中断输出在 2.5 V 和 6 V 之间运行。准双向端口可以独立指定为输入以监控中断状态或键盘,或作为输出以激活 LED 等指示设备。 系统主机可以通过单个寄存器从输入端口读取或写入输出端口。

PCF8574/74A具有2.5 uA(典型值,静态)的低电流消耗非常适合移动应用,并且锁存输出端口可直接驱动 LED。

在前面的实例中,对PCF8574已经做了详细的描述,请参考:

键盘是广泛用于各种电子和嵌入式项目的输入设备。 它们用于以数字和字母的形式获取输入,并将其输入系统以进行进一步处理。

矩阵键盘由一组相互连接的按钮组成。 在本次实例中使用 4X4 矩阵键盘,其中四行中的每一行都有 4 个按钮。 按钮端子按下图所示示连接。 在第一行,所有4个按钮的一个端子连接在一起,4个按钮的另一个端子代表4列中的每一列,每行也是如此。 所以一共有 8 根线来连接一个微控制器。

在前面的实例中,对矩阵键盘驱动做了详细的介绍,请参考:

2、仿真电路原理图

在这里插入图片描述

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
#include <Keypad\_I2C.h>
#include <Keypad.h>
#include <Wire.h>
#define I2CADDR 0x20

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'\*','0','#','D'}
};
// Digitran keypad, bit numbers of PCF8574 i/o port
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad

TwoWire \*jwire = &Wire; //test passing pointer to keypad lib
Keypad_I2C kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS, I2CADDR, PCF8574, jwire );
//Keypad\_I2C kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS, I2CADDR );

void setup(){
Serial.begin(9600);
while( !Serial ){ /\*wait\*/ }
// Wire.begin( );
jwire->begin( );
// kpd.begin( makeKeymap(keys) );
kpd.begin( );
Serial.print( "start with pinState = " );
Serial.println( kpd.pinState\_set( ), HEX );
}
void loop(){

char key = kpd.getKey();

if (key){
Serial.println(key);
}
}


3、仿真结果

在这里插入图片描述

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