Today I reviewed the content of LCD1602 liquid crystal display and did an experiment to display a string of characters "First Try" in 8-bus mode.
The simulation diagram is as follows:
code show as below:
LCD1602.h
#ifndef _LCD1602_H_
#define _LCD1602_H_
#include //Redefine keywords #ifndef uchar #define uchar unsigned char #endif #ifndef uint #define uint unsigned int #endif /********************************** PIN port definition **********************************/ #define Lcd1602DataPin P0 sbit LCD1602_E=P2^7; sbit LCD1602_RW=P2^5; sbit LCD1602_RS=P2^6; /********************************** Function declaration **********************************/ /*Delay function under 12MHZ clock of 51 MCU*/ void Lcd1602_Delay1ms(uint c); //Error 0us /*LCD1602 write 8-bit command subfunction*/ void LcdWriteCom(uchar com); /*LCD1602 write 8-bit data sub-function*/ void LcdWriteData(uchar dat); /*LCD1602 initialization subroutine*/ void Lcd1602Init(); #endif LCD1602.c #include "lcd1602.h" /*********************************************************************************** * Function name: Lcd1602_Delay1ms * Function: Delay function * Input: c * Output: None ***********************************************************************************/ void Lcd1602_Delay1ms(uint c){//delay function uchar a,b; for (; c>0; c--){ for (b=199;b>0;b--){ for(a=1;a>0;a--); } } } /*********************************************************************************** * Function name: LcdWriteCom * Function: Write a byte command to LCD * Input: com * Output: None ***********************************************************************************/ void LcdWriteCom(uchar com) //Write command { LCD1602_E = 0; // Enable LCD1602_RS = 0; /*Select to send command*/ LCD1602_RW = 0; //Select write Lcd1602DataPin = com; //Insert command Lcd1602_Delay1ms(1); //Wait for data to stabilize LCD1602_E = 1; //According to the write data timing diagram, pull up the write timing (data) Lcd1602_Delay1ms(5); //hold time LCD1602_E = 0; //Pull low again to finish writing data, release } /*********************************************************************************** * Function name: LcdWriteData * Function: Write one byte of data to the LCD * Input: dat * Output: None ***********************************************************************************/ void LcdWriteData(uchar dat) //Write data { LCD1602_E = 0; //Enable clear LCD1602_RS = 1; /*Select input data*/ LCD1602_RW = 0; //Select write Lcd1602DataPin = dat; //Write data Lcd1602_Delay1ms(1); LCD1602_E = 1; //Write timing Lcd1602_Delay1ms(5); //hold time LCD1602_E = 0; } /*********************************************************************************** * Function name: Lcd1602Init() * Function: Initialize LCD screen * Input: None * Output: None ***********************************************************************************/ void Lcd1602Init() //LCD initialization subroutine { LcdWriteCom(0x38); //Turn on the display, set to 8 buses, 2 lines of display, 5*7 dot matrix, this is the "function setting command" LcdWriteCom(0x0c); //Turn on the display without displaying the cursor, "display switch control command" LcdWriteCom(0x06); //Write a pointer plus 1, "enter mode setting instruction" LcdWriteCom(0x01); //Clear screen, "clear screen command" LcdWriteCom(0x80); //Set the starting point of the data pointer. The first character is at 0x00, but the address format of the data to be written must be 0x**+0x80, so add the address plus 0x80 in advance; it is okay not to write it here, but the address to be written must be + 0x80 before calling the main function } main.c #include #include "lcd1602.h" #define uint unsigned int #define uchar unsigned char uchar DisplayData[]=" First Try "; //Define the string to be displayed, and the space is also counted as a character void main(void){ uchar i; Lcd1602Init(); //Call the initialization function of LCD1602, which uses the call of the write command function for(i=0;i<11;i++){ //Loop calling LCD1602 write data function to write characters respectively LcdWriteData(DisplayData[i]); } while(1); //The infinite loop is here so that the data can be displayed statically all the time: because after the data is input into LCD1602, it will be stored in DDRAM until it changes. } Experimental results: Summarize the method of using LCD1602: 1. Initialize LCD1602 first, that is, initialize the function Lcd1602Init(); The content that needs to be initialized is (1): (2): (3): (4): These must be set during initialization, and these function command bytes are written into LCD1602 through the write command function written by yourself In our program, we also set the cursor position, that is, at which dot matrix the data starts to be displayed. Of course, you can not write the command to determine the display address in the initialization, and just determine the display address before displaying in the main.c file. (5): Confirm the display address command: 2. After initialization, you can write the characters to be displayed to the LCD's DDRAM through the data write function you wrote. question: 1. They all write data, and they all write one byte. Why do we need a write command function "" and a "write data function"? Answer: The reason is that the high and low level requirements for the LCD1602_RS pin are different when writing commands and writing data. Write command: LCD1602_RS=0; Write data: LCD1602_RS=1; Therefore, we need to write two functions separately to implement the functionality. 2. Determine the displayed address, why is it at address +0x80 Answer: The fixed format of the command to write the display address in Figure (5) above is: 0x80+display address 3. Write timing: 4. How to display a character alone uchar dat=1; dat=dat+0x30; LcdWriteData(dat); //This is it, in the form of ASCII code 5. How to display in the second line // Display in the second line: LcdWriteCom(0x40+0x80); //Re-confirm the cursor position through the write command function for(i=0;i<11;i++){ //Recycle and call the LCD1602 write data function to write characters respectively LcdWriteData(DisplayData[i]); } 5. RAM address mapping of LCD1602 Conclusion: Only by studying with a calm mind can you gain something. There is no such thing as overnight success.
Previous article:51 single chip microcomputer series - LCD1602 displays the characters on the calculator keys
Next article:51 MCU Series - How to use timers T0 and T1
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- FPGA and Digital Image Processing
- Score points! Tell us how you have prepared for the eSports tournament so far and what you think.
- Prize live broadcast opens up IoT society Nichicon's new power storage device
- SensorTile.box_--Unicleo-GUI debugging tutorial
- What are the main parameters for selecting magnetic beads?
- Learn embedded development from engineers——Based on STM32 and μC/OS-III
- What is the output/input impedance value of CC2xxx?
- EEWORLD University Hall----Live Replay: Infineon & Intron Explanation- How to Choose a Suitable Automotive MOSFET
- Amway uses LT768 to realize TFT industrial serial port screen solution
- Neopixel Christmas Tree