LCD1602
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1602 means that each line displays 16 characters, and a total of two lines can be displayed. If it is a 12232 liquid crystal (graphic liquid crystal), it means that it is composed of 122 columns and 32 rows, that is, a total of 122*32 dots
ps. Pay attention to the usage temperature. Usually the working range of liquid crystal is 0~+55℃, and the storage temperature range is -22~+60℃.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Pin conditions:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Basic operation sequence:
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
state | enter | output |
read status | RS=0R/W=1E=1 | D0~D7=status word |
Read data | RS=1R/W=1E=1 | D0~D7=data |
write command | RS=0R/W=0E=1D0~D7=command code E=1 | none |
write data | RS=1R/W=0E=1D0~D7=Data E=1 | none |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RAM internal mapping: 80 bytes
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Status word description: //The status word reflects the current situation of the LCD screen. When STA7 is 1, it means that the display is busy. , cannot be operated
STA0~STA6 represent the value of the current address pointer
STA7 indicates read/write enable, =1 indicates base, =0 indicates permission
ps In principle, read and write detection must be performed before each read and write operation on the controller to ensure that STA7=0. In actual operation, since the operating speed of the microcontroller is slower than the response speed of the liquid crystal control, read and write detection may not be performed but only a brief Delay.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Data pointer setting:
Users can access the internal 80-byte RAM through the following data address pointer to set the data address
80H+address code (0~27H, 40~67H)
Example: operate on the first address, 0x80+0x01
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-other Script code:
01H | The display is cleared (the data pointer is cleared and all displays are cleared) |
02H | Display carriage return (data pointer cleared) |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Initialization:
Display mode setting: 38H
Display on/off and cursor settings
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Read and write operation timing:
Read operation
write operation
Operating time parameters
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Operation method:
Operations on the LCD can be divided into two parts: data and instructions.
By operating RS, R/W, and E, four operations are performed: read status, read data, write instructions, and write data.
D0~D7 are used to input and output instruction codes and data
————————————————————————————————————————————
LCD1602 usage examples:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Design requirements:
Use LCD1602 to display two lines of characters, display two lines of words, and two buttons to control the display or clear the screen
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Design ideas:
Initialize LCD display //Refer to "Initialization" above
Open enable
Script operation
Set 16*2 display, 5*7 dot matrix, 8-bit data structure
Turn on the display, display the cursor without flashing
After reading and writing characters, the address pointer +1, the cursor +1, and the entire screen display does not move.
clear screen
Set the first character of the address display
initialization interrupt
Turn on interrupts
External interrupts 0 and 1
Infinite loop waiting for interrupt
key interrupt
"Display" button
Loop to write data (character array)
Command "newline"
Write the second row of data in a loop
Button "clear screen"
Command "clear screen"
Subfunction //Refer to the "Read and Write Operation Timing Table" above
write data
write command
1 #include
2 typedef unsigned char uchar;
3 sbit en = P3 ^ 4;
4 sbit rs = P3 ^ 5;
5 uchar code table1[] =
6 {
7 "SMC1602 0x01..."
8 };
9 uchar code table2[] =
10 {
11 "Hugh Dong."
12};
13 void Delay(uchar m)
14 {
15 uchar i, j;
16 for (i = m; i > 0; --i)
17 for (j = 110; j > 0; --j);
18}
19 /*Write data*/
20 void write_date(uchar date)
twenty one {
22 //Reference write operation timing diagram
23 rs = 1; //RS high level, write data
24 P2 = date; //Write data, corresponding to the timing diagram t_SP2 data establishment
25Delay(5);
26 en = 1; //Turn on the enable, give E a high pulse, and start writing data
27Delay(5);
28 en = 0; //Close enable and write data is completed
29 }
30 /* Write command*/
31 void write_com(uchar com)
32 {
33 //Basic principles are the same as writing data
34 rs = 0; //RS low level, write instruction
35 P2 = com;
36Delay(5);
37 en = 1;
38Delay(5);
39 en = 0;
40}
41 /* Initialize LCD */
42 voidInit()
43 {
44 en = 1;
45 write_com(0x38); //00111000 Set 16*2 display, 5*7 dot matrix, 8-bit data interface
46 write_com(0x0E); //00001110 Turn on display, display cursor, do not flash
47 write_com(0x06); //00000110 After reading and writing characters, the address pointer +1, the cursor +1, and the screen does not move
Previous article:MCS-51 microcontroller storage address space division
Next article:51 microcontroller interrupt mechanism (timer/counter)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Bear Pie Huawei IoT operating system LiteOS bare metal driver transplantation 01-Explain driver transplantation using LED as an example
- 【GD32450I-EVAL】Simple oscilloscope demonstration
- [GD32E231 DIY Contest] 05. Automatic Fish Feeding Robot - PWM
- Shenzhen becomes the "world's first 5G city": challenges and business opportunities for the PCB industry
- 【Ended】 R&S Live 【PCI Express Gen 3 Conformance Test】
- Live broadcast at 10 am today [Renesas Electronics Secure IoT Suite provides you with secure cloud connection solutions
- Xun developed Qt for Android for i.MX6ULL Terminator QT application
- Applications of RF Transformers
- RF FilterRF knowledge classics to understand
- 【NXP Rapid IoT Review】+Hello world!