We will not go into details about the pointer and 1602 LCD screen. The document "Teaching You to Learn 51 Single-Chip Microcomputers" has very detailed explanations in Chapters 12 and 13. We do not need to create unique driver codes ourselves. There is no need to "reinvent the wheel". We can just transplant and use the code written by Mr. Song. Mr. Song also explained the principle of the LCD screen code in detail in the document. You can master it by reading it repeatedly. Here, I will only explain some of the codes. Open Mr. Song's code lesson12_4.
1. Display the execution operation of characters
If we need to display the following content on the LCD screen
Then you need to operate step by step on the code to complete it.
First, set the usage indicators of the LCD screen, such as "16*2 display, 5*7 dot matrix", "display on, cursor off", "text does not move, address automatically +1". These are called LCD screen initialization, which means that these tasks need to be configured in advance for the LCD screen to display content normally.
For example, if we want to set the LCD screen to "display on, cursor off" function, we need to write the command byte to the LCD screen as 0x0C. Before writing, we need to read whether the LCD screen is busy, that is, "sta = LCD1602_DB;" reads the 8-bit state of the entire P0 port, and "while (sta & 0x80);" means that as long as P0.7 is in a high level state, it proves that the LCD screen is busy, and the byte 0x0C cannot be written to the LCD screen. After the LCD screen outputs a low level and pulls the pin low, it proves that the LCD screen is not busy, and the command byte can be written. The analysis of the "void LcdWaitReady()" function is completed.
"void LcdWriteCmd (unsigned char cmd)" is the byte to be written into the command.
LCD1602_RS = 0;
LCD1602_RW = 0;
It prepares the LCD screen to receive commands, and then makes "P0= cmd;" output relevant high and low levels, and then makes LCD1602_E complete a high pulse. In this way, when "cmd=0x0C;", the LCD screen receives the command and makes the display function "display on, cursor off".
Then let's talk about how to implement the code to display the content from which grid. If you want to display a character in the first grid of the second line, the cursor should be set at this position, that is, the byte written to the LCD screen is "0x80|0x40", and the highest bit of the command byte for setting the coordinates should be 1. Write the address where you want to display.
Finally, let’s explain the “void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str)” function.
The function for setting the address to be displayed has been mentioned. We see "LcdWriteDat(*str++);", which means to write the character data in an array or a string into the address of the display position in the above figure so that the characters can be displayed in the corresponding place.
In the initialization function, the setting of "LcdWriteCmd(0x06);" is to automatically increase the address by 1. If data is continuously written at the first position of the second row of the LCD screen (that is, the address is 0x40), then after writing one data, the next data will be written at the address 0x41, and the subsequent data will be written at the address 0x41.
We have briefly talked about the LCD screen code. If you still have doubts in understanding, we may lack theoretical knowledge, which needs to be digested slowly.
Of course, we don't need to go into every detail. We will teach you how to use these functions later.
Previous article:51 MCU-Serial port printf series function
Next article:51 MCU - pointer to array
- 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
- Intelligently Connected World—Application of Internet of Vehicles and Future Development of Digitalization
- Motor drive circuit design 1
- Free Review - Topmicro Intelligent Display Module (5) Touch Screen
- How to deal with the acidic wastewater from acid salt spray testing of metal electronic products and devices?
- Summary: annysky2012's practical journey of motor development based on "STM32F746ZG+IHM07M1"
- Engineer, if you don't develop from the perspective of engineering or product, how can you be worthy of the word "engineering"...
- Understand the past and present of NFC in one article!
- When power saving is required, how should the LCD screen's SEG pin, COM pin, VLVD1-3, and VLCDH related configurations be configured?
- [New version of Bluesun AB32VG1 RISC-V development board] - 1: From "New" to "0 errors, 0 warnings."
- 1- Design of vending machine based on 51 single chip microcomputer (schematic diagram + PCB + paper + program)