- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit rs=P1^1;
- sbit wr=P1^2;
- sbit lcden=P1^3;
- sbit dula=P2^6;
- sbit wela=P2^7;
- uchar num;
- uchar code table1[]="lcd1026";
- uchar code table2[]="test";
- uint i,j;
- void delay(uint x)
- {
- for (i=x;i>0;i--)
- {
- for(j=125;j>0;j--);
- }
- }
- void write_com(uchar com) //写命令函数
- {
- rs=0;
- wr=0;
- lcden=0;
- P0=com;
- lcden=1;
- delay(5);
- lcden=0;
- }
- void write_data(uchar dat) //写数据函数
- {
- rs=1;
- wr=0;
- lcden=0;
- P0=dat;
- lcden=1;
- delay(5);
- lcden=0;
- }
- void init() //初始化函数
- {
- write_com(0x38);
- write_com(0x08);
- write_com(0x01);
- write_com(0x06);
- write_com(0x0f);
- }
- void main()
- {
- P0=0;
- dula=0;
- wela=0;
- init();
- for(num=0;num<7;num++)
- {
- write_data(table1[num]);
- delay(5);
- }
- write_com(0x80+0x40);
- for(num=0;num<4;num++)
- {
- write_data(table2[num]);
- delay(5);
- }
- while(1);
- }
复制代码 lcd1602驱动程序,包含初始化、写命令、写数据,供新人参考。
|