#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define dtime 5
uchar code table[]="abcdefghijkl";
uchar code table1[]="1234567890";
sbit EN=P2^7;
sbit RS=P2^6;
sbit RW=P2^5;
int num;
void delayms(uint t)
{
uint i,j;
for(i=t;i>0;i++)
for(j=110;j>0;j++)
{}
}
//写命令
void write_com(uchar com)
{
RS=0;
RW=0;
P0=com;
delayms(dtime);
EN=1;
delayms(dtime);
EN=0;
}
//写数据
void write_data(uchar dat)
{
RS=1;
RW=0;
P0=dat;
delayms(dtime);
EN=1;
delayms(dtime);
EN=0;
}
//初始化
void init()
{
EN=0;
write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
delayms(dtime);
write_com(0x0c);//设置开显示,不显示光标
write_com(0x06);//写一个字符后地址指针加一
write_com(0x01);//显示清零。数据指针清零
}
void main()
{
init();
write_com(0x80);
for(num=0;num<12;num++)
{
write_data(table[num]);
delayms(dtime);
}
write_com(0x80+0x40);
for(num=0;num<10;num++)
{
write_data(table1[num]);
delayms(dtime);
}
while(1);
}