#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);
}
|