/**************************
Resources used by the file
1. Port: P0.0, P0.1
2. Call delay_ms function
******************************/
#define TIME 1
#define display_TIME 1000
sbit CS=P1^0; //Chip select
sbit SCLK=P0^0; //Clock
sbit STD=P0^1; //Data
//sbit LCD_ON=P0^2; //Backlight switch
uchar code AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //The first line of Chinese characters
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //The second line of Chinese characters
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, //The third line of Chinese characters
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, //The fourth line of Chinese characters
};
/******************************
Serial transmission of one byte of data
******************************/
void SendByte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
SCLK=0; //SCLK=0;
if(dat&0x80)
STD=1; //STD=1;
else STD=0; //STD=0;
SCLK=1; //SCLK=1;
dat=dat<<1;
}
}
/***************************
Write control command
***************************/
void SendCMD(uchar dat)
{
CS=1; //CS=1;
SendByte(0xF8); //11111,00,0 RW=0,RS=0 synchronization flag, send instruction from CPU to LCD
SendByte(dat&0xF0); //high four bits
SendByte((dat&0x0F)<<4);//low four bits
CS=0; //CS=0;
}
/***************************
Write display data or single-byte character
***************************/
void SendDat(uchar dat)
{
CS=1; //CS=1;
SendByte(0xFA); //11111,01,0 RW=0,RS=1
SendByte(dat&0xF0); //High four bits
SendByte((dat&0x0F)<<4);//Low four bits
CS=0; //CS=0;
}
/***************************
Clear the Chinese characters displayed on the screen
***************************/
void clear_LCD(void)
{
SendCMD(0x01); //0000,0001 Clear DDRAM
delay_ms(TIME);
SendCMD(0x34); //Extended instruction, allow graphic displaySendCMD
(0x30); //Basic instruction set bit2, bit1, bit0 in bit2 control
}
/***************************
Initialize LCM
*******************************/
void init_lcm(void)
{
CS=0; //CS=0;
delay_ms(TIME);
SendCMD(0x30); //Basic instruction set//bit2, bit1, bit0 in bit2 controlSendCMD
(0x0C); //0000,1100 Overall display, cursor off, cursor position off
SendCMD(0x01); //0000,0001 Clear DDRAM
delay_ms(TIME);
}
/****************************
Display picture 128*64
****************************/
void display_picture(uchar *biao)
{
uchar x,y,i,j,k;
x=0x80;
SendCMD(0x34); //Turn off the image display
for(k=0;k<2;k++)
{
y=0x80;
for(j=0;j<32;j++)
{
SendCMD(y);
SendCMD(x);
for(i=0;i<16;i++)
{
SendDat(*biao++);
}
y++;
}
x=0x88;
}
SendCMD(0x36); //Turn on the image display
}
/****************************
Display the string on the entire screen
****************************/
void display(uchar *str)
{
uchar i,k=0;
while(*str!='\0')
{
if(k==0)SendCMD(0x80);
else if(k==16)SendCMD(0x90);
else if(k==32)SendCMD(0x88);
else if(k==48)SendCMD(0x98);
k++;
if(k==65)
{
k=0;
for (i=0;i<49;i++)
{
str--;
}
delay_ms(display_TIME);
clear_LCD();
}
SendDat(*str++);
}
}
/****************************
Display the string at the specified position
****************************/
void display_char(uchar row,uchar col,uchar *puts)
{
bit flag=0;
SendCMD(0x30); //8BitMCU, basic instruction setwhile
(*puts != '\0') //Judge whether the string is displayed
{
if(col==8) //Judge line break
{ //If not judged, automatically from the first row to the third rowcol
=0;
row++;
}
if(row==4)
{
row=0; //One screen is displayed and returns to the upper left corner of the screen
}
if(!flag)SendCMD(AC_TABLE[8*row+col]); //Send position commandSendDat
(*puts++); //A Chinese character needs to be written twiceif
(flag)col++;
flag=~flag;
}
}
Previous article:DS18B20 multi-point temperature detection C51 program
Next article:PS/2 Keyboard Interface C51 Driver
Recommended ReadingLatest update time:2024-11-16 13:03
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- A Complete Illustrated Guide to Operational Amplifier Applications (Written by Wang Zhenhong)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
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
- Recruiting part-time lecturers in motor control related majors
- It is recommended to merge the ATMEL and PIC microcontroller sections
- TI TMS320C6678 Evaluation Module
- IoT wireless communication data transmission module: multi-host gateway working mode, understand it in one article
- [RT-Thread reading notes]——The definition of threads and the implementation of thread switching
- How to read and write attributes through the characteristic uuid in sdk!
- MSP430FR5994 Hardware SPI Exception
- In what fields can power amplifiers be used?
- [Runhe Neptune Review] Five PWM
- How to use the wireless transceiver module