- //简单的1602测试程序
- //rs,rw,en根据自己的实际情况进行修改
- #include<reg52.h>
- typedef unsigned char uchar;
- typedef unsigned int uint;
- sbit RS = P3^5;//数据/命令选择端
- sbit RW = P3^6;//读/写数据端
- sbit EN = P3^4;//使能端
- //检测液晶是否繁忙
- void Read_Busy()
- {
- uchar busy;
- P0 = 0XFF;
- RS = 0;
- RW = 1;
- do
- {
- EN = 1;
- busy = P0;
- EN=0;
- }while(busy & 0X80);
- }
- //写指令
- void Write_Cmd(uchar cmd)
- {
- Read_Busy();
- RS = 0;
- RW = 0;
- P0 = cmd;
- EN = 1;
- EN = 0;
- }
- //写入数据
- void Write_Dat(uchar dat)
- {
- Read_Busy();
- RS = 1;
- RW = 0;
- P0=dat;
- EN=1;
- EN=0;
- }
- //主函数
- void main()
- {
- uchar *p;
- uchar a[] = {"Hello Worldi"};
-
- Write_Cmd(0X38);//显示设置
- Write_Cmd(0x0f);//开显示
- Write_Cmd(0X01);//清屏
-
- Write_Cmd(0x06);
- Write_Cmd(0x80 | 0x00);
- p=a;
- while(*p != '\0')
- {
- Write_Dat( *p++);
- }
-
- while(1);
- }
复制代码
|