【Proteus仿真】Arduino UNO+PCF8574+LCD1602矩阵按键

【Proteus仿真】Arduino UNO+PCF8574+LCD1602矩阵按键


  • 🎬Proteus仿真
    在这里插入图片描述
  • 📜PCF8574地址:
    在这里插入图片描述

📑程序说明

本例程使用了2片PCF8574,共用I2C总线,通过配置不同的地址,实现对不同外设的控制。

📝程序代码

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
57
58
#include <Wire.h>
#include <LiquidCrystal\_I2C.h>//点击这里会自动打开管理库页面: http://librarymanager/All#LiquidCrystal\_I2C
#include <Key.h>
#include <Keypad.h>
#include <Keypad\_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);//Address PCF8574 :A0 A1 A2-->VCC
#define I2CADDR 0x26 // Set the Address of the PCF8574 :A1 A2-->VCC;A0-->GND

const byte ROWS = 4; // Set the number of Rows
const byte COLS = 4; // Set the number of Columns

// 4×4矩阵键盘
char keys [ROWS] [COLS] = {
{'7', '8', '9', 'C'},
{'4', '5', '6', 'B'},
{'1', '2', '3', 'A'},
{'\*', '0', '#', 'D'}
};

// define active Pin (4x4)
byte rowPins [ROWS] = {0, 1, 2, 3}; // Connect to Keyboard Row Pin
byte colPins [COLS] = {4, 5, 6, 7}; // Connect to Pin column of keypad.

// makeKeymap (keys): Define Keymap
// rowPins:Set Pin to Keyboard Row
// colPins: Set Pin Column of Keypad
// ROWS: Set Number of Rows.
// COLS: Set the number of Columns
// I2CADDR: Set the Address for i2C
// PCF8574: Set the number IC
Keypad_I2C keypad (makeKeymap (keys), rowPins, colPins, ROWS, COLS, I2CADDR, PCF8574);

//void LCD\_display(void);
void setup () {

lcd.init();
lcd.backlight();
Wire .begin (); // Call the connection Wire
keypad.begin (makeKeymap (keys)); // Call the connection
Serial.begin (9600);
lcd.setCursor(2,0);
lcd.print("Key BUTTON");

}
void loop () {

char key = keypad.getKey (); // 获取按键
if (key) {
// Serial.println (key); // 串口输出
lcd.setCursor(0,1);//显示位置
lcd.print(key);
}
}




  • 📓编译信息
1
2
3
4
5
6
7
8
使用 1.0  版本的库 Wire 在文件夹: C:\Users\Administrator\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire 
使用 1.1.2 版本的库 LiquidCrystal_I2C 在文件夹: C:\Users\Administrator\Documents\Arduino\libraries\LiquidCrystal_I2C
使用 3.1.1 版本的库 Keypad 在文件夹: C:\Program Files (x86)\Arduino\libraries\Keypad
使用 3.0.0 版本的库 Keypad_I2C 在文件夹: C:\Program Files (x86)\Arduino\libraries\Keypad_I2C
"C:\\Users\\Administrator\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "d:\\arduino\\MyHexDir/pcf8574\_KEYPAD.ino.elf"
项目使用了 6466 字节,占用了 (20%) 程序存储空间。最大为 32256 字节。
全局变量使用了595字节,(29%)的动态内存,余留1453字节局部变量。最大为2048字节。

  • 🚩仿真时所调用的是pcf8574_KEYPAD.ino.with_bootloader.standard.HEX文件:
    在这里插入图片描述

📚程序和仿真文件

  • 🔖基于Proteus8.12平台,包含所需库。
1
2
3
4
5


链接: https://pan.baidu.com/s/151pXV9FFsGibMZ0j2kS3sw
提取码: 7126