当前位置:网站首页>(十八)LCD1602实验
(十八)LCD1602实验
2022-07-06 14:29:00 【我爱笔记】
本节我们来完成另一种在单片机上的显示的编程,使用LCD1602液晶显示器来显示我们想要输出的字符,输出"I LOVE MCU"和“MCU LOVE I”这两个短字符串。完成我们51单片机的最后一个简单实验,之后可能就会直接放几个简单项目在上面,加深对于51单片机的理解。
关于LCD1602
1602液晶也叫LCD1602字符型液晶,它能显示2行字符信息,每行又能显示16个字符,它是一种专门用来显示字母、数字、符号的点阵型液晶模块,我们每个人的LCD1602模块可能不相同,但是他们的用法基本都是相同的,在LCD1602的内部含有80个字节的DDRAM,它们是用来显示字符的。其地址和屏幕的对应关系如下所示:

其中只有0x00到0x0f和0x40到0x4f是用来显示的,其他的都只能用来存储,而关于LCD1602我们在写地址的时候每个地址是对应加上0x80才能达到对应的地址的,比如你要在0x00这个地址写入值,那么我们是需要在0x80写入值的,意思就是每个地址都有一个0x80的偏移,而关于LCD1602我们有一些常用的指令来控制它,
其中(1)清屏指令:0x01, (2)模式设置指令,指令格式如下所示:

其中DB1的含义是:
0:写入数据后光标左移 1:写入数据后光标右移
其中DB0的含义是:
0:写入数据后显示屏不移动 1:写入数据后显示屏整体右移一个单位
(3)显示开关控制指令,指令格式如下所示:

其中DB2的含义是:
0:显示功能关 1:显示功能开
其中DB1的含义是:
0:无光标 1:有光标
其中DB0的含义是:
0:光标闪烁 1:光标不闪烁
(4)显示模式,我们默认设置16*2显示,5*7点阵,8位数接口,那么我们默认的指令就是0x38
关于硬件

其中与单片机相连的控制接口分别有三个RS,WR,EN,其余D0到D7是数据端口,用来传输数据的,其中的基本时序如下所示
读状态:输入:RS=L,R/W=H, EN = H 输出:D0~D7状态字
我们是不能读对应的数据
写指令:输入:RS=L, R/W=L, D0~D7=指令码,E=高脉冲 输出:D0~D7=数据
写数据:输入:RS=H,R/W=L,D0~D7=数据,E=高脉冲 输出:无
而关于每次读写之后我们都有可能会延时,其实我们不用那么准确,因为液晶显示的大多数为纳秒级,而我们单片机没有那么快,但是为了稳定延时,我们还是会做简短延时。
关于软件:
ds1602的主要函数如下所示:
#include "reg52.h"
sbit lcd_en = P2^7;
sbit lcd_rs = P2^6;
sbit lcd_rw = P2^5;
void delay_us(unsigned int xus){
while(xus--);
}
void lcd1602_write(unsigned char dat, int flag){
lcd_en = 0;
lcd_rs = flag;
lcd_rw = 0;
P0 = dat;
delay_us(500);
lcd_en = 1;
delay_us(100);
lcd_en = 0;
}
void lcd1602_init(){
lcd1602_write(0x38, 0);
lcd1602_write(0x0c, 0);
lcd1602_write(0x06, 0);
lcd1602_write(0x01, 0);
lcd1602_write(0x80, 0);
}而它的头文件如下所示:
#ifndef _LCD1602_H_
#define _LCD1602_H_
#include "reg52.h"
void delay_us(unsigned int xus);
void lcd1602_write(unsigned char dat, int flag);
void lcd1602_init();
#endif而它的主函数如下所示:
#include <reg52.h>
#include "ds1602.h"
unsigned char table0[] = {"I LOVE MCU"};
unsigned char table1[] = {"MCU LOVE I"};
void main(){
int i;
lcd1602_init();
lcd1602_write(0x80 + 0x03 , 0);
for(i = 0; i < 10;i++){
lcd1602_write(table0[i], 1);
delay_us(100);
}
lcd1602_write(0x80 + 0x40 + 0x03, 0);
for(i = 0;i < 10;i++){
lcd1602_write(table1[i], 1);
delay_us(100);
}
while(1){
}
} 边栏推荐
- GPS从入门到放弃(十三)、接收机自主完好性监测(RAIM)
- Shell product written examination related
- LeetCode刷题(十一)——顺序刷题51至55
- Management background --3, modify classification
- PVL EDI project case
- [10:00 public class]: basis and practice of video quality evaluation
- Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings
- PVL EDI 项目案例
- What is the difference between animators and animators- What is the difference between an Animator and an Animation?
- Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
猜你喜欢

Embedded common computing artifact excel, welcome to recommend skills to keep the document constantly updated and provide convenience for others
Learn the principle of database kernel from Oracle log parsing

How does the uni admin basic framework close the creation of super administrator entries?

Adjustable DC power supply based on LM317

第4章:再谈类的加载器

3DMAX assign face map

GNN, please deepen your network layer~

GPS from getting started to giving up (XIII), receiver autonomous integrity monitoring (RAIM)

嵌入式常用计算神器EXCEL,欢迎各位推荐技巧,以保持文档持续更新,为其他人提供便利

Bat script learning (I)
随机推荐
Powerful domestic API management tool
China 1,4-cyclohexanedimethanol (CHDM) industry research and investment decision-making report (2022 Edition)
Some problems about the use of char[] array assignment through scanf..
MariaDb数据库管理系统的学习(一)安装示意图
Chapter 4: talk about class loader again
2022年6月国产数据库大事记-墨天轮
Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution
About the professional ethics of programmers, let's talk about it from the way of craftsmanship and neatness
Management background --1 Create classification
The nearest common ancestor of binary (search) tree ●●
小满网络模型&http1-http2 &浏览器缓存
How does the uni admin basic framework close the creation of super administrator entries?
Leetcode learning records (starting from the novice village, you can't kill out of the novice Village) ---1
HDU 2008 digital statistics
ZABBIX proxy server and ZABBIX SNMP monitoring
[linear algebra] determinant of order 1.3 n
墨西哥一架飞往美国的客机起飞后遭雷击 随后安全返航
【10点公开课】:视频质量评价基础与实践
Barcodex (ActiveX print control) v5.3.0.80 free version
2021 geometry deep learning master Michael Bronstein long article analysis