LCD operation:
1602 LCD can only display ASCI. Today, I will drive 1602 LCD. LCD operation is simpler than digital tube.
Basic operation sequence of LCD:
1.1 Read state: Input: RS = L, RW = H, E = H Output D0~D7
1.2 Write instruction: Input: RS = L, RW = L, D0~D7 instruction code, E = high pulse, output: none;
RS is the data command selection terminal (H/L);
1.3 Read data: input RS= H, RW=H, E=H
1.4 Write instruction: output, RS = L, RW = L, D0~D7 = data, E = high pulse
Note: Before each read and write operation on the controller, a read and write test must be performed to ensure that STA7 is 0. A simple delay can be used instead.
Initial Setup
Display Mode Settings
Instruction code: 00111000 Function 16*2 display, 5*7 dot matrix, 8 is the instruction of data interface 0x38
Display on/off cursor setting
So left and right are set by N and S
Data pointer instruction code
80H+address code (0-27H, 40H to 67H)
other settings
The function of instruction code 01H is to clear the screen: 1 data pointer cleared, 2 all displays cleared
02H displays carriage return: 1 data pointer cleared
The circuit diagram is shown in the figure:
Sample code: Dynamic display
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit lcden = P2^6; //These ports need to be connected to the hardware circuit first
sbit lcdrw = P2^5;
sbit lcdrs = P2^4;
sbit dula = P3^1;
sbit wela = P3^2;
uchar num;
uchar code table[]="I LIke MCU!";
uchar code table1[]="I LIke HULeiHao";
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 command function
{
lcdrs = 0; // Enable the terminal to 0. Low pulse writes the instruction, high pulse writes the data
_nop_(); // postpone one machine cycle
lcdrw = 0; //Low level to write data
P0=com;
delay(5);
lcden = 1; // Enable the terminal to give a high level to read data
delay(5);
lcden = 0; // Enable the terminal to return to a low level
}
void write_date(uchar date) // write data function
{
lcdrs = 1; // Enable the terminal to 0. Low pulse writes the instruction, high pulse writes the data
_nop_(); // postpone one machine cycle
lcdrw = 0;
P0= date;
delay(5);
lcden = 1;
delay(5);
lcden = 0;
}
void init()
{
dula = 0;
wela = 0; // turn off the digital tube
lcden = 0;
write_com(0x38); //Display mode setting
write_com(0x0e); //Display switch and cursor setting
write_com(0x06);
write_com(0x80+0x10);
}
void main()
{
init();
for(num=0;num<11; num++)
{
write_date(table[num]);
delay(20);
}
// write_com = 1; // clear screen operation
write_com(0x80+0x53); //Set data pointer
for(num=0;num<15; num++)
{
write_date(table1[num]);
delay(20);
}
for(num = 0 ;num<16;num++)
{
write_com(0x18); //The entire screen moves left
delay(20);
}
while(1);
}
Previous article:I2C serial bus composition and working principle
Next article:Application of single chip keyboard
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
- Difference between LOG_printf() and printf() in DSP
- What is the principle of this circuit?
- I want to know if this method is correct to predict the change in capacitance of chip capacitors due to temperature drift?
- [NXP Rapid IoT Review] Analysis of Rapid-Iot boot process (K64 part)
- Serial port baud rate selection
- STM32 interrupt priority grouping setting
- FreeRtos blocking issue discussion
- Received the X-NUCLEO-IKS01A3 sensor kit
- MSP430 MCU Development Record (20)
- Burning problem