当前位置:网站首页>17.[STM32]仅用三根线带你驱动LCD1602液晶
17.[STM32]仅用三根线带你驱动LCD1602液晶
2022-07-05 15:18:00 【依点_DW】
作者简介:大家好啊,我叫DW,每天分享一些我新学到的知识,期待和大家一起进步
系列专栏:STM32
小实验目标:三线驱动LCD1602液晶
如有写得不好的地方欢迎大家指正开发板:正点原子STM32F103Mini版
创作时间:2022年6月4日
不管是串行方式驱动LCD1602液晶还是并行方式驱动LCD1602液晶,都会占用STM32过多的IO口,那么有没有什么方式可以减少单片机IO口的使用呢?答案是有的。
我们可以把两片74HC595芯片以级联的方式驱动LCD1602,该方式只用到单片机的3个IO口就可以驱动LCD1602了。
在四位数码管的文章中已经详细介绍了74HC595这块芯片的使用方法,详细介绍见文章:15.[STM32]一篇文章教会你使用75HC595芯片驱动四位数码管
在该文章的基础上添加上一个写字节的函数。
写字节函数
//写字节函数
void LCD1602_Write_Byte(u8 dat,u8 dat1){
for(u8 i=0;i<8;i++){
((dat<<i)&0x80) ? DIO_High:DIO_Low;
SCK_High;
SCK_Low;
}
for(u8 i=0;i<8;i++){
((dat1<<i)&0x80) ? DIO_High:DIO_Low;
SCK_High;
SCK_Low;
}
RCK_High;
RCK_Low;
}
提示:两块74HC595采取级联方式,故需要发送两次数据。
接下来编写一个写指令和写数据的函数,该函数是本次例程的重点。我们需要写的是8位数据,但是我们只用到位:RS、RW、EN(对应位0~2),位3~7为0。
当我们需要写数据时E、RW、RS为:001,故需要写的指令为0000 0001(0x01)接下来需要将数据写到总线上,当E为高电平时数据会送到液晶内部,故需要写的指令为:0000 0101(0x05),之后需要释放EN,故需要重新写0x01;
当我们需要写指令时E、RW、RS为:000,故需要写的指令为0000 0000(0x00),接下来需要将指令写到总线上,当E为高电平时数据会送到液晶内部,故需要写的指令为:0000 0100(0x04),之后需要释放EN,故需要重新写0x00;
写指令和写数据的函数
void LCD1602_Write_Cmd_Data(u8 cmd,u8 data){
if(cmd){ //1 数据
LCD1602_Write_Byte(data,0x01); //0000 0001 // E = 0 RW = 0 RS = 1
delay_ms(3);
LCD1602_Write_Byte(data,0x05); //0000 0101 // E = 1 RW = 0 RS = 1
delay_ms(3);
LCD1602_Write_Byte(data,0x01); //0000 0001 // E = 0 RW = 0 RS = 1
}
else{ //0 指令
LCD1602_Write_Byte(data,0x00); //0000 0000 // E = 0 RW = 0 RS = 0
delay_ms(3);
LCD1602_Write_Byte(data,0x04); //0000 0100 // E = 1 RW = 0 RS = 0
delay_ms(3);
LCD1602_Write_Byte(data,0x00); //0000 0000 // E = 0 RW = 0 RS = 0
}
}
提示:
RS = 1:写数据 RS = 0:写指令
RW = 1:读操作 RW = 1:写操作
EN:读操作高有效 EN:高有效
接下来看硬件连接图吧。
第一片74HC595芯片的11、12、14引脚分别与单片机的PB0~PB2相连,74HC595的15、1、2引脚和LCD1602的RS、R/W、E引脚相连 。
第二片74HC595芯片的QA~QH引脚与LCD1602的D0~D7相连。
提示:
第一块芯片的9引脚和第二块芯片的14引脚相互连接
两块芯片的RCK、SCK相互连接
我们把上一篇DS18B20的文章的例程添加进去,就可以在LCD1602上显示温度了,大家一起来看看实验结果图吧。
今天的分享就到这里,谢谢大家的耐心阅读,如果觉得有用的话给个
本章结束,我们下一章见
参考资料:
1.STM32固件库手册
2.正点原子STM32不完全手册_库函数版本
3.参考视频
4.数字电子技术基础
资料已上传,需要自取
边栏推荐
- Advanced level of static and extern
- MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
- Summary of the second lesson
- Data communication foundation NAT network address translation
- Information collection of penetration test
- Creation and use of thymeleaf template
- I'm fat, huh
- Noi / 1.3 01: a+b problem
- 一文搞定vscode编写go程序
- Noi / 1.5 06: element maximum span value of integer sequence
猜你喜欢
Bugku easy_ nbt
Misc Basic test method and knowledge points of CTF
Common MySQL interview questions
Bugku alert
Number protection AXB function! (essence)
CSRF, XSS science popularization and defense
Thymeleaf uses background custom tool classes to process text
Optional parameters in the for loop
Redis' transaction mechanism
First PR notes
随机推荐
Ctfshow web entry explosion
Cartoon: programmers don't repair computers!
修改pyunit_time使得其支持‘xx~xx月’的时间文本
CODING DevSecOps 助力金融企业跑出数字加速度
String modification problem solving Report
Bugku telnet
[brief notes] solve the problem of IDE golang code red and error reporting
Advanced level of static and extern
Reasons and solutions for redis cache penetration and cache avalanche
Detailed explanation of QT creator breakpoint debugger
Magic methods and usage in PHP (PHP interview theory questions)
go学习 ------jwt的相关知识
Usage and usage instructions of JDBC connection pool
PHP high concurrency and large traffic solution (PHP interview theory question)
Data communication foundation - dynamic routing protocol rip
Appium自动化测试基础 — APPium基础操作API(二)
ICML 2022 | 探索语言模型的最佳架构和训练方法
First PR notes
复现Thinkphp 2.x 任意代码执行漏洞
Noi / 1.5 37: mercenaries