当前位置:网站首页>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--);
}
边栏推荐
- An article was uncovered to test the truth of outsourcing companies
- Digital triangle model acwing 1015 Picking flowers
- php使用redis实现分布式锁
- Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
- Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
- Database isolation level
- Luogu p2141 abacus mental arithmetic test
- [mqtt from getting started to improving series | 01] quickly build an mqtt test environment from 0 to 1
- Online and offline problems
- Oscp raven2 target penetration process
猜你喜欢
![[C language] string left rotation](/img/5f/66bcc8f992108bf3b7e455709d3174.png)
[C language] string left rotation

Private cloud disk deployment

On weak network test of special test

Selenium source code read through · 9 | desiredcapabilities class analysis

Postman核心功能解析-参数化和测试报告

Basic knowledge of MySQL

数据库-当前读与快照读

MySQL之基础知识

F - True Liars (种类并查集+DP)

MFC关于长字符串unsigned char与CString转换及显示问题
随机推荐
模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
Past and present lives of QR code and sorting out six test points
Black cat takes you to learn UFS Protocol Part 8: UFS initialization (boot operation)
[postman] dynamic variable (also known as mock function)
Simulation volume leetcode [general] 1143 Longest common subsequence
E - food chain
MySQL之数据类型
数据库-当前读与快照读
基于JEECG-BOOT的list页面的地址栏参数传递
leetcode 24. Exchange the nodes in the linked list in pairs
Customize the gateway filter factory on the specified route
LeetCode 739. Daily temperature
Esp32 esp-idf watchdog twdt
这些年用Keil遇到的坑
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
Cannot create poolableconnectionfactory (could not create connection to database server. error
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
B - The Suspects
[postman] test script writing and assertion details
D - How Many Answers Are Wrong