#include<reg51.h>
unsigned char table[]="666666";
sbit RS=P2^6;
sbit RW=P2^5;
sbit E=P2^7;
void delay(unsigned char ms)//延时函数
{
unsigned i,j;
for(i=ms;i>0;i--)
for(j=110;j>0;j--);
}
void writeinstruction(unsigned char dictate)//写命令
{
RS=0;
RW=0;
P0=dictate;
delay(5);
E=1;
delay(5);
E=0;
}
void writedate(unsigned char y)//写数据
{
RS=1;
RW=0;
P0=y;
delay(5);
E=1;
delay(5);
E=0;
}
void chushihua() //1602初始化
{
writeinstruction(0x38); //显示设置
writeinstruction(0x0f); //0000 01DCB D为显示开关,B为光标开关,C为光标闪烁开关
writeinstruction(0x06); // 写一个字符后地址指针加一
/writeinstruction(0x01); //清屏
}
void main()
{ int a;
chushihua();
writeinstruction(0x80); for(a=0;a<6;a--)
writedate(table[a]);
delay(5);
while(1);
}
|