#How to do it
**Schematic**
Code
******************************************************************
* 【Course 17】 ****LCD1602 Experiment***********
* 【illustrate】 ****
* 【Description】 ****Display characters on LCD1602
******************************************************************
---------------------------------------------------------
Basic operations:
Read status: RS=0,RW=1,EN=1
Output: D0~D7=status word;
Write instruction: RS=0, RW=0, EN=falling edge pulse
D0~D7=instruction code;
Read data: RS=1, RW=1, EN=1
Output: D0~D7=data;
Write data: RS=1, RW=1, EN=falling edge pulse
D0~D7=data;
*********************************************************/
#include //---------Two commonly used macro definitions-------------- #define uint8 unsigned char #define uint16 unsigned int //--------1602 control pin definition------------- sbit RS = P2^5; sbit RW = P2^6; sbit EN = P2^7; //----------Displayed data------------ uint8 Data1[7]="welcom!"; uint8 Data2[13]="www.yxarm.net"; //-----------Function declaration------------------ void DelayMS(uint16 dly); //----------Declaration of LCD module--------------- bit BUSY(void); void Write_cmd(uint8 cmd); void Write_dat(uint8 dat); void LCD_Init(void); //---------Main Task--------------------- void main(void) { uint8 i; LCD_Init(); while(1) { Write_cmd(0x85); //First line for(i=0;i<7;i++) Write_dat(Data1[i]); Write_cmd(0xc2); //The second line for(i=0;i<13;i++) Write_dat(Data2[i]); } } /******************************************************** ** Name: void DelayMS(uint16 dly) ** Function: millisecond delay (12M crystal oscillator) ** Entry parameter: dly user's delay parameter ** Export parameters: None *********************************************************/ void DelayMS(uint16 dly) { uint16 x,y; for(x=dly;x>0;x--) for(y=124;y>0;y--); } /******************************************************** ** Name: bit BUSY(void) ** Function: Check whether LCD1602 is in busy state; ** Input parameters: None ** Export parameter: bit Bit Returns 1, then BUSY Return 0, then OK *********************************************************/ bit BUSY(void) { bit Bit; RS = 0; RW = 1; EN = 1; DelayMS(1); Bit = (bit)(P0 & 0x80); //The highest bit is the busy signal bit EN = 0; return Bit; } /******************************************************** ** Name: void Write_cmd(uint8 cmd) ** Function: Write command ** Input parameter: cmd control command ** Export parameters: None *********************************************************/ void Write_cmd(uint8 cmd) { while(BUSY()); //测忙 RS = 0; RW = 0; EN = 0; P0 = cmd; EN = 1; DelayMS(1); EN = 0; } /******************************************************** ** Required: void Write_dat(uint8 dat) ** Function: write data ** Input parameter: dat data to be displayed ** Export parameters: None *********************************************************/ void Write_dat(uint8 dat) { while(BUSY()); //测忙 RS = 1; RW = 0; EN = 0; P0 = that; EN = 1; DelayMS(1); EN = 0; } /******************************************************** ** Name: void LCD_Init(void) ** Function: LCD initialization ** Input parameters: None ** Export parameters: None *********************************************************/ void LCD_Init(void) { Write_cmd(0x38); //Function setting DelayMS(1); Write_cmd(0x0c); //Display switch control DelayMS(1); Write_cmd(0x06); //Input mode setting DelayMS(1); Write_cmd(0x01); //Clear the LCD display content DelayMS(1); }
Previous article:15: Lighting up the LED matrix
Next article:107: Operation of DS1302
- Popular Resources
- Popular amplifiers
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
- 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
- A brief introduction to the internal structure of photoelectric sensors
- Geek Black Technology, Shopping Carnival | Here are the deals you can’t miss!
- I need help from an expert. "When designing a microcontroller hardware circuit using STC89C51, should I design the EEPROM circuit part?"
- Claiming that software is open source when it is not is false advertising
- Zigbee 3.0 universal gateway coordinator based on CC2652R
- Ask a question about the LM35CZ temperature sensor
- MSP430FR2311 LaunchPad Development Kit
- What chips can use pwm to control the brightness of leds
- 【NUCLEO-L552ZE Review】- 6: After the summary, start again...
- A simple chopper circuit drawn by myself