For components like this that contain chips, the most important thing is to learn how to understand the pin functions of the chip, rather than to memorize the statements of the chip. The same components from different manufacturers have slight differences, so when purchasing such things, ask the manufacturer for a chip manual and design the program or circuit according to the manual.
1602 LCD
1602: 16 means that 16 characters can be displayed in one line, and 02 means there are two lines in total
Only numbers and characters can be displayed
Write data timing diagram
RS low level selects data, high level selects instruction
RW High level means read, low level means write
E is the enable signal, which sends high and low pulses
According to the timing diagram, write the instruction (data) first, delay, and give the pulse
Write command (data)
First select the write instruction, then assign the value to port P0, and then write the program according to the instructions of the timing diagram. Writing data is the same, so I won't go into details.
void write_com(uchar com) //
{
lcdrs=0; // set write com
P0=com; // give value data
delay(5);
lcden=1;// Âö³å
delay(5);
lcden=0;
}
Initialization Procedure
What is displayed here is the RAM address of each bit of the matrix, only 00-0F, 40-4F are displayed. Although there are addresses on the right side of these two rows, they are not displayed. They can be used to shift the full screen to the left to achieve a dynamic effect.
void init()
{
dula=0; //Because the digital tube will divide the voltage, turn it off to prevent insufficient voltage
wela=0;
lcden=0;
write_com(0x38); //Initialize 5*7 matrix
//0000 1DCB D displays C cursor B flashes
write_com(0x0f);
//0000 01NS
write_com(0x06); //The cursor moves, but the data does not move
write_com(0x80); //Initialize pointer position, 80H is the first position
}
Character Manual
We can write data using matrices, according to the following table
If you want to write directly, separate them with '
write_data('A');
If you want to write a string of characters
Just use the matrix
uchar code table[]=" I Love U";
But here the matrix is no longer surrounded by {} curly braces, but double quotes.
move
According to the chip manual, assigning P0 = 0x18 means moving left once, and the cursor will also move left.
other settings
0x01 is to clear the screen 0x02 is to enter
Code Sample
Does not include movement, includes clearing the screen, and code examples on a new page
#include #define uchar unsigned char #define uint unsigned int sbit lcden=P3^4; sbit lcdrs=P3^5; sbit dula=P2^6; sbit wela=P2^7; uchar code table[]=" I Love U"; uchar code table1[]=" FOREVER"; uchar code table2[]="Just a joking"; void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void write_com(uchar com) //write instruction { lcdrs=0; // set writing com P0=com; // input value data delay(5); lcden=1; // give pulse delay(5); lcden=0; } void write_data(uchar date) //write data { lcdrs=1; //Select data P0=date; delay(5); lcden=1; delay(5); lcden=0; } void init() { dula=0; wela=0; lcden=0; write_com(0x38); write_com(0x0f); write_com(0x06); write_com(0x80); } void main() { uint time; init(); for(time=0;time<12;time++) { write_data(table[time]); delay(300); } write_com(0x80+0x40); for(time=0;time<11;time++) { write_data(table1[time]); delay(300); } delay(300); write_com(1); delay(300); delay(300); delay(300); write_com(0x80+0x00); for(time=0;time<13;time++) { write_data(table2[time]); delay(300); } while(1); } Full screen mobile code #include #define uchar unsigned char #define uint unsigned int sbit lcden=P3^4; sbit lcdrs=P3^5; sbit dula=P2^6; sbit wela=P2^7; uchar code table[]="I Love U"; uchar code table1[]="FOREVER"; uchar code table2[]="Just a joking"; void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void write_com(uchar com) //дÃüÁî { lcdrs=0; // set write com P0=com; // give value data delay(5); lcden=1;// Âö³å delay(5); lcden=0; } void write_data(uchar date) // { lcdrs=1; // set write com P0=date; // give value data delay(5); lcden=1;// Âö³å delay(5); lcden=0; } void init() { dula=0; wela=0; lcden=0; write_com(0x38); write_com(0x0f); write_com(0x06); write_com(0x80+0x10); void main() { uint time; init(); for(time=0;time<8;time++) { write_data(table[time]); delay(20); } write_com(0x80+0x50);//»»ÐÐ for(time=0;time<7;time++) { write_data(table1[time]); delay(20); } for(time=0;time<16;time++) { write_com(0x18); delay(200); } while(1); }
Previous article:Step-by-step teaching of 51 MCU Lesson 7 | AT24C02 I²C bus data transmission
Next article:Hands-on teaching of 51 single-chip microcomputer | Section 4 Dynamic digital tube, use 6-bit digital tube to make a clock
Recommended posts
- Millimeter wave radar IWR1443
- IhaveanES3.0versionofIWR1443radarboard.TItechnicianssaidthatitcanonlybeusedforvitalsignexperiments.Iwanttodoagesturerecognitionexperiment,whichcanonlybedonewiththeES2.0version.HowcanIbuyanES2.0version
- ifif RF/Wirelessly
- In a battery-powered microcontroller product, when a pin is used for falling edge interrupt, how should this pin be set to achieve the most energy-efficient
- Inabattery-poweredSTM32microcontrollerproduct,whenapinisusedforfallingedgeinterrupt,howshouldthispinbesettoachievethemostenergy-efficient Readthemanualandapplicationnotes TheinterruptisusedtoindicatethattheS
- 一沙一世 stm32/stm8
- [Digi-Key Follow Me Issue 1] + Task 1: Familiarize yourself with the basic syntax of MicroPython
- RaspberryPiPicoWisanewproductlaunchedbytheRaspberryPiFoundationin2022.Itaddsacertified2.4GHz802.11nwirelessmoduletotheRaspberryPiPico,makingitanidealsolutionforprojectsrequiringwirelesscommunication. Featur
- ID.LODA DigiKey Technology Zone
- [Renesas RA8D1 development board, graphics MCU based on M85 core] USB development environment construction takes CDC as an example
- Preface ThisvideosharestheconstructionofUSBdevelopmentenvironment,takingCDCasanexample. Createaproject Opene2studio Menubarclick File-New-RenesasC/C++Project-RenesasRA SelectC/C++-RenesasRAC/C++Project
- qinyunti Renesas Electronics MCUs
- How to ensure that DA has no output when downloading the program
- Projectrequirements:DAhasnooutputwhendownloadingtheprogram,howtoensurethis?WhatshouldIconsider?
- sudongpo2018 Motor Drive Control(Motor Control)
- Looking for a book host computer to develop a pass
- Lookingforabookhostcomputertodevelopapass Isthereabookcover?Ithinktherearemanyhostcomputerlanguages,soitismoreappropriatetochooseagoodone. Iguessit'snotpossibletopassitthroughthisbook. Youcantakea
- spwongks Download Centre
- 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
- 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
- Experience using the bootloader of TMS320VC33
- Is the CS+ for CACX development environment free to use now?
- Please help me. When the circuit board motor is working, the LED light controlled by the IO port of the main control IC will flash.
- Motor rotor position detection
- How do we distinguish the difference between bypass capacitors and decoupling capacitors?
- [Distributed temperature and humidity acquisition system] + WIFI module expansion board V2
- Basic knowledge of power amplifiers - the original feedforward - is still in use today
- How to use WatchDog in RTOS?
- Last day! Double 11 discount of 1,000 yuan for Tektronix oscilloscopes!
- [FM33LG0 series development board evaluation] 02. Basic engineering (LED, KEY, LPUART, LPTIM, SHELL)