当前位置:网站首页>Lecture 8: 1602 LCD (Guo Tianxiang)
Lecture 8: 1602 LCD (Guo Tianxiang)
2022-07-06 06:25:00 【Lin Jiazhan】
explain : This article is just some records of my learning process , If there is any infringement , Please contact me to delete , There are inevitably omissions and mistakes in the article , Welcome to point out .
One 、1602 Liquid crystal introduction
LCD belongs to extended content , however , It's used a lot of times , After all, you need a visual result to provide to users , So we need to master the use of LCD .
1602 Model LCD , among 16 Express 1 Rows can show 16 Characters ,02 Expressing common ownership 2 That's ok .
Allied , also 1601、0801、0802...
Some models are 12864、12232 This kind of graphic liquid crystal , for example 12864 It's horizontal 128 A little bit , Vertical yes 64 A little bit , These points form a graph . And the character LCD mentioned above , Only characters can be displayed . These can be learned in the description document .
notes : The teacher said , Now that you have learned liquid crystal , Then try not to use digital tubes if you can use LCD , Because by comparison , LCD is simpler , And more interesting .
Two 、 Learn how to operate through documents 1602 liquid crystal
1. There is a Chinese document in the material sent by the teacher , First look at the LCD pin function :
Look at the connection diagram of the development board :
You can see the 5 The pin is directly connected to the ground , Because here we only need to write data into the LCD , There is no need to read data . So just manipulate the 4 And the 6 Pin can be .
2. Next, let's look at the detailed interface description :
The reason to make sure STA7 = 0, Because STA7 It is the read-write operation enable , Only in the allowed position , To read and write . Because the frequency of crystal oscillator is not very high in MCU , Therefore, there is no need to think too much . It mainly takes time for LCD to write data , But in the use of DSP、 When embedded chips are running at high speed , Sometimes the LCD didn't display completely last time , The next display request is coming , And if the read / write operation is enabled , It may cause the loss of display data . Therefore, we should carry out corresponding processing through read-write detection .
notes :
High pulse : From low to high to low is a high pulse .
Low pulse : In turn, , High and low is a low pulse .
3. Next, let's look at the sequence of write operations in detail :
We know from the previous documentation ,RS The difference of represents the difference between writing instructions and writing data .
and R/W We have defaulted to grounding . So by right RS、E The operation of can realize the writing of instructions or data .
So we write two functions , Used to write instructions and write data respectively :
The write instruction function is as follows :
void write_com(uchar com)// Write instructions / command
{
lcdrs = 0;
//RW = 0;// The development board has been grounded by default
P0 = com;//com For instructions
delay(5);
lcden = 1;
delay(5);
lcden = 0;
}
The function of writing data is as follows :
void write_data(uchar date)// Writing data
{
lcdrs = 1;
//RW = 0;// The development board has been grounded by default
P0 = date;//date For data
delay(5);
lcden = 1;
delay(5);
lcden = 0;
}
Because the requirement of real-time is not high , So the timing parameters are only simple delay Function substitution , The actual development process may need attention .
There is also the read-write detection mentioned above , In a simple single-chip program, it can also be omitted , We just need simple delay Function delay , The delay time is greater than the speed of LCD writing .
4.RAM Address map
Each box represents an address , Write data content to the address , Then the content will be displayed in this place . And the first line in the back 10 To 27 And the second line 50 To 67 Not part of the display , But we can choose to write the content behind this first , Then move the whole screen , Move the content behind this to the screen .
5. Instructions :
Send instructions before you start , To set the display mode . There is only one mode in Chinese documents , There should be other instructions in the detailed English document , In actual development, we should try to write the program according to the original file .
Then there is the display switch and cursor setting .
Notice the top N=1 When reading or writing a character, add one to the address pointer , Because of the data pointer that will be mentioned later , We need to set the data pointer , Then the content will be displayed at the position pointed by the data pointer , When we want to write a row of data , We need to set multiple data pointers , And if the address pointer will automatically add 1, We don't need to set , Just write the data .
Setting of data pointer , Preparation before writing data .
Other settings , There are many, many settings , You can find... In the documentation .
3、 ... and 、 Use 1602 liquid crystal , First line display “I AM hong!”, The second line shows “I LIKE MCU!”
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit lcden = P3^4;
sbit lcdrs = P3^5;
sbit dula = P2^6;
sbit wela = P2^7;
void delay(uint z);
uchar num;
uchar code table[]="I AM hong!";
uchar code table1[]="I LIKE MCU!";
void write_com(uchar com)// Write instructions / command
{
lcdrs = 0;
//RW = 0;// The development board has been grounded by default
P0 = com;
delay(5);
lcden = 1;
delay(5);
lcden = 0;
}
void write_data(uchar date)// Writing data
{
lcdrs = 1;
//RW = 0;// The development board has been grounded by default
P0 = date;
delay(5);
lcden = 1;
delay(5);
lcden = 0;
}
void init()
{
dula = 0;
wela = 0;// Turn off the nixie tube
lcden = 0;
write_com(0x38);// Display mode settings
write_com(0x0c);// Show on / Turn off cursor setting
write_com(0x06);// Address pointer plus 1,N=1,S=0
write_com(0x01);// The display is clear , Because there is a data in it by default , There is a black block on the screen
write_com(0x80);// Data pointer setting
}
void main()
{
init();
for(num = 0;num < 10;num++)
{
write_data(table[num]);
delay(200);
}
write_com(0x80+0x40);// The second line
for(num = 0;num < 11;num++)
{
write_data(table1[num]);
delay(200);
}
while(1);
}
void delay(uint z) // The time delay function ,z The value of is the delay of this function ms Count , Such as delay(200); About time delay 200ms.
{ //delay(500); About time delay 500ms.
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
边栏推荐
- Error getting a new connection Cause: org. apache. commons. dbcp. SQLNestedException
- Career advancement Guide: recommended books for people in big factories
- selenium源码通读·9 |DesiredCapabilities类分析
- Customize the gateway filter factory on the specified route
- sourceInsight中文乱码
- Luogu p2141 abacus mental arithmetic test
- Past and present lives of QR code and sorting out six test points
- 使用Nacos管理配置
- LeetCode 732. My schedule III
- F - True Liars (种类并查集+DP)
猜你喜欢
Delete the variables added to watch1 in keil MDK
[postman] collections - run the imported data file of the configuration
联合索引的左匹配原则
Manage configuration using Nacos
B - The Suspects
记一个基于JEECG-BOOT的比较复杂的增删改功能的实现
E - food chain
sourceInsight中文乱码
Play video with Tencent video plug-in in uni app
Digital triangle model acwing 1015 Picking flowers
随机推荐
Digital triangle model acwing 1015 Picking flowers
Postman核心功能解析-参数化和测试报告
Past and present lives of QR code and sorting out six test points
Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
B - The Suspects
基于JEECG-BOOT的list页面的地址栏参数传递
Cannot create poolableconnectionfactory (could not create connection to database server. error
On weak network test of special test
通过修改style设置打印页样式
技术分享 | 常见接口协议解析
模拟卷Leetcode【普通】1218. 最长定差子序列
模拟卷Leetcode【普通】1414. 和为 K 的最少斐波那契数字数目
G - Supermarket
JDBC Requset 对应内容及功能介绍
Simulation volume leetcode [general] 1091 The shortest path in binary matrix
Database - current read and snapshot read
[eolink] PC client installation
Manage configuration using Nacos
selenium源码通读·9 |DesiredCapabilities类分析
Left matching principle of joint index