|
#include<reg51.h>
unsigned char table[]="666666";
sbit RS=P2^6;
sbit RW=P2^5;
sbit E=P2^7;
void delay(unsigned char ms)//延時(shí)函數(shù)
{
unsigned i,j;
for(i=ms;i>0;i--)
for(j=110;j>0;j--);
}
void writeinstruction(unsigned char dictate)//寫(xiě)命令
{
RS=0;
RW=0;
P0=dictate;
delay(5);
E=1;
delay(5);
E=0;
}
void writedate(unsigned char y)//寫(xiě)數(shù)據(jù)
{
RS=1;
RW=0;
P0=y;
delay(5);
E=1;
delay(5);
E=0;
}
void chushihua() //1602初始化
{
writeinstruction(0x38); //顯示設(shè)置
writeinstruction(0x0f); //0000 01DCB D為顯示開(kāi)關(guān),B為光標(biāo)開(kāi)關(guān),C為光標(biāo)閃爍開(kāi)關(guān)
writeinstruction(0x06); // 寫(xiě)一個(gè)字符后地址指針加一
/writeinstruction(0x01); //清屏
}
void main()
{ int a;
chushihua();
writeinstruction(0x80); for(a=0;a<6;a--)
writedate(table[a]);
delay(5);
while(1);
}
|
|