#include
#define uc unsigned char
#define ui unsigned int
sbit RS=P3^5;
sbit RW=P3^6;
sbit E=P3^4;
void read_busy()//判斷忙不忙;
{
uc busy;
P0=0xff;//
RS=0;
RW=1;
do
{
E=1;
busy=P0;
E=0;
}
while(busy&0x80);//若忙,則一直循環(huán)(0x10000000的1為禁止狀態(tài))
}
void write_cmd(uc cmd)//命令函數(shù)
{
read_busy();//執(zhí)行上個語言,判斷忙不忙
RS=0;
RW=0;
P0=cmd;
E=1;
E=0;
}
void write_dat(uc dat)//寫命令
{
read_busy();
RS=1;
RW=0;
P0=dat;
E=1;
E=0;
}
void main()
{
write_cmd(0x38);//顯示模式
write_cmd(0x0f);//開顯示,顯示光標,并閃爍
write_cmd(0x06);//指針加一,光標加一
write_cmd(0x01);//清0
write_cmd(0x80|0x03);//第一行第四個開始
write_dat(0+'0');//輸入的字符
write_dat(0+'1');
write_dat(0+'2');
}