#include
sbit RS=P3^7;
sbit RW=P3^6;
sbit E=P3^5;
sbit BF=P2^7;
void delay(unsigned char n) //about n(ms) delay
{
unsigned char i,j,k;
for(k=0;k
for(j=0;j<10;j++) //about 1ms delay
{
for(i=0;i<32;i++) //about 0.1ms delay
{;}
}
}
}
unsigned char test(void) //Busy check, test=1, busy. test=0, data and command operations are possible
{
bit busy;
RS=0;
RW=1;
E=1;
_nop_();
_nop_()
; _nop_();
_nop_();
busy=BF;
E=0;
return busy;
}
void WriteInstruction(unsigned char dictate) //写指令、地址
{
while(test()==1);
RS=0;
RW=0;
E=0;
_nop_();
_nop_();
_nop_();
P2=dictate;
_nop_();
_nop_();
_nop_();
_nop_();
E=1;
_nop_();
_nop_();
_nop_();
_nop_();
E=0;
}
void wData(unsigned char dat) //写数据
{
while(test()==1);
RS=1;
RW=0;
E=0;
_nop_();
_nop_();
_nop_(); _nop_();
P2=dat;
_nop_(); _nop_(
);
_nop_();
_nop_();
E=1;
_nop_();
_nop_();
_nop_();
_nop_();
E=0;
}
void WriteAddress(unsigned char x) //write address
{
unsigned char x1;
x1=x+0x80;
WriteInstruction(x1);
// WriteInstruction(x|0x80); // another way to calculate address
}
void LcdInitiate(void) //LCD initialization
{
delay(15);
WriteInstruction(0x38);
delay(5);
WriteInstruction(0x38);
delay(5);
WriteInstruction(0x38);
delay(5);
WriteInstruction(0x0f); //Display setting
delay(5);
WriteInstruction(0x06); //Input mode
delay(5);
WriteInstruction(0x01); //清屏
delay(5);
}
main()
{
unsigned char string[]={"my Computer"};
unsigned char i=0;
while(1)
{
LcdInitiate(); //Initialize
WriteAddress(0x02); //Write address, character display position
i=0;
while(string[i]!='\0') //Write string from write address
{
wData(string[i]); //Write a character
i++;
delay(200);
}
WriteAddress(0x42); //Write address
delay(15);
i=0;
while(string[i]!='\0') //Write string from write address
{
wData(string[i]);
i++;
delay(200);
}
for(i=0;i<10;i++)
{
delay(200);
}
}
}
Previous article:C51 Timer/Counter
Next article:c51: Function
- 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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Thank you for having you +EE @【chat, laugh, make noise】
- Op amp basics: DC biasing of active circuits
- How to write C/C++ code in DSP? + Data types in c6000
- What role does power supply potting glue play in power supplies, and why do power supplies need potting?
- 37 "Ten Thousand Miles" Raspberry Pi Car——ROS Learning (VSCode Debugging ROS)
- How to pack .mpy files into esp8266 micro python firmware package?
- Beidou short message development board based on STM32F103RET6
- Want to know more about UWB? Just read this article.
- When downloading a program to a PCB board in SWD mode, what will happen if the PCB board's own power is not disconnected?
- I would like to ask you guys, what is the value of the bypass capacitor for the LT1763 chip?