LCD EN 用P3.4;LCD RS用P3.5;
LCD R/W在仿真的硬件电路上接地;
仿真电路参考图片;
单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- sbit lcden=P3^4;
- sbit lcdrs=P3^5;
- unsigned int const ad1=0x80;
- unsigned int const ad2=0x80+0x40;
- void delay(unsigned char j)
- {
- unsigned char i=60;
- for(;j>0;j--)
- {
- while(--i); i=59;
- while(--i); i=60;
- }
-
- }
- void w_date(unsigned char date)
- {
- lcden=0;
- lcdrs=1;
- P0=date;
- delay(5);
- lcden=1;
- _nop_();
- lcden=0;
- delay(1);
- }
- void w_com(unsigned char com)
- {
- lcden=0;
- lcdrs=0;
- P0=com;
- delay(5);
- lcden=1;
- _nop_();
- lcden=0;
- delay(1);
- }
- void string(unsigned char ad,unsigned char *s)
- {
- w_com(ad);
- while(*s>0)
- {
- w_date(*s++);delay(100);
- }
- }
- void lcd_ini()
- {
- w_com(0x38);//16*2显示;5*7点阵;8位数据口
- w_com(0x0c);//开显示,不显示光标
- w_com(0x06);//写一个字符后地址加1;
- w_com(0x01);//clear screen
- delay(1);
- }
- unsigned char code table1[]={"hellow "};
- unsigned char code table2[]={"hellow word"};
- int main()
- {
- lcd_ini();
- while(1)
- {
- string(0x80,table1);
- string(0x80+0x40,table2);
- delay(100);
- }
- }
复制代码
|