This time I will share my LCD1602 programming experience:
Let me first explain that the chip driver of the LCD1602 I am going to talk about below is HD44780. If your LCD1602 driver chip is not HD44780, then the following content is not applicable.
My overall understanding of LCD1602
Here I will talk about my overall understanding of LCD1602. LCD1602 is an LCD display that can display two lines of characters. Each line can have 40 characters. However, only the first 16 characters of each line can be displayed. The last 24 characters of each line cannot be displayed immediately. It is not easy to understand just by saying it. Let's take a look at the schematic diagram below:
In addition, LCD1602 can only display characters, numbers and some simple symbols, but cannot display Chinese characters, so remember this.
LCD1602 Pinout:
Then let's talk about the pins. Whenever you learn a chip or module, the first thing you need to understand is the pins:
Since we are only learning how to program now, I will not talk about the circuit connection. Here are the pins related to programming:
1. RS pin: data/command selection terminal (H/L)
When you want to send a command to the LCD, give this pin a low level;
When you want to exchange data with the LCD, give this pin a high level.
2.R/W pin: read/write selection terminal (H/L)
When you want to write data to the LCD, give this pin a low level;
When you want to read the data in the LCD, give this pin a high level.
3. E pin: enable terminal (Here to take care of those who like to nitpick: Why is E called "enable"? What does "enable" mean? How come I have never heard of it?)
Answer 1: The full English name of the E pin is Enable pin. En is a prefix in English, which means "enable...", and the "able" behind it is translated as "can be", so together it is called the "enable" pin.
Answer 2: What does enable mean? I won't talk about professional terms here. You can think of the enable terminal as a switch. When this pin is high/low level, the device can be used. When it is the opposite level, the device is useless. No matter what you do, it will not work. Of course, is it a low-level device that is effective, or a high-level device that is effective? This depends on the data sheet of the specific device or some pins will be directly marked, such as E is high level effective, and E(——) is low level effective.
4.D0~D7 pins: There is nothing much to say about this. They are the pins for transmitting data or commands.
5. I won’t talk about other power pins, backlight power supply and so on, as they have been explained very clearly in the table, and we are only learning programming now, so I won’t talk about circuit connections.
Now that we have discussed the pins, let's talk about the programming part of LCD1602:
By convention, the dividing line:
From "Sword Art Online" Klein
I think there are only two parts that you need to remember about LCD1602, timing and instructions (you don’t have to remember them all. After learning, you can write a function library by yourself and call it directly when you need it in future development)
Let's talk about the timing and initialization process first:
LCD1602 read timing:
I didn't write the source code of the reading function, after all, it is almost never used.
As can be seen from the figure:
The RS pin depends on what you read. If you read data, it is high level, and if you read a command, it is low level.
The RW pin is naturally high level, because we want to read;
Then the E pin is next. When we read commands or data, we must enable the device first, so the E pin must be set to a high level;
Finally, D0 to D7 are the read data, and we just need to find a variable array to save them.
Although the reading timing has been explained, we almost do not need to perform a reading operation in actual development. I think someone will say at this time: Don’t we need to read the busy flag? Then don’t we need to perform a reading operation? That is indeed the case, but the speed of LCD1602 is in the nanosecond level, while the speed of 51 single-chip microcomputer is in the millisecond level, so there is basically no need to read the busy flag, just a slight delay will do.
As shown in the figure:
LCD1602 write timing:
I wrote this function, here is the code:
[Note] I used two methods in the function, paralleling 4 ports and paralleling 8 ports;
Let's talk about the most important write operation timing, as can be seen from the figure:
The RS pin depends on what you read. If you read data, it is high level, and if you read a command, it is low level.
The RW pin is naturally at a low level, because we are going to write this time;
Then the E pin is next. When we read commands or data, we must enable the device first, so the E pin must be set to a high level;
Finally, D0 to D7 are the data or commands to be written.
LCD1602 initialization process:
I also wrote this, here is the code:
The initialization of LCD1602, that is, the initialization process of HD44780 chip, there are too many versions of this initialization process, most of which can be successfully initialized, but I am writing an article here, so I can't talk about a messy initialization process, so I checked the original English data sheet of HD44780 chip, as shown below:
If you want to understand it, just read it step by step from top to bottom, and then you will understand why the initialization should be written as above.
[Note] Many initialization versions can be initialized successfully. The one I mentioned is just the most formal one. It is a personal preference. As long as the initialization can be successful, it will be fine.
Finally, write the header file of LCD1602, and then the function library of LCD1602 is ready. Of course, we did not write the read function, if you want to write these, just add them yourself. With this function library, you can directly call it when using LCD1602 in the future, which is very convenient.
Previous article:MCU Project: 51 MCU Bluetooth Control Fan
Next article:51 Single Chip Microcomputer--Memorize the knowledge related to stepper motor
- Popular Resources
- Popular amplifiers
- 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
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- ADI Think Tank Secrets New Release丨High Speed Circuit Design Guide is now available for download
- 【LAUNCHXL-CC1350-4】- 1: Install CCS on Ubuntu 20.04
- Review summary: RTT & Renesas high-performance CPK-RA6M4 development board
- Two methods of chip unpacking
- MSP430FR25x2 Capacitive Touch Sensing Mixed-Signal Microcontrollers
- Analog circuit basics: from system level to circuit level
- HyperLynx High-Speed Circuit Design and Simulation (II) Reflection due to unequal transmission line impedance and power supply impedance
- OS_STM32F103 V2.0 version project source code.
- I feel that the STM32H750XB is useless.
- Urgent!!! How to get download points?