代码
#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={"2018:08:07"};
sbit lcdrs=P1^5;
sbit lcdrw=P1^6;
sbit lcden=P1^7;
uchar num;
void delay(uint z)
{ uint x,y;
for(x=z;x>0;x--)
for(100;y>0;y--);
}
void lcdwritecom(uchar com)
{
lcdrw=0;
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void lcdwritedate(uchar date)
{
lcdrw=0;
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
lcdrs=0;
}
void init()
{
lcden=0;
lcdwritecom(0x38);
lcdwritecom(0x08);
lcdwritecom(0x06);
lcdwritecom(0x01);
lcdwritecom(0x80);
}
void main()
{
init();
for(num=0;num<16;num++)
{
lcdwritedate(table[num]);
delay(5);
}
while(1);
}
/*void writecom(uchar com) //写入命令
{
lcdrs=0;
P0=com;
delay(10);
lcden=1;
delay(10);
lcden=0;
}
void writedate(uchar date) //写入数据
{
lcdrs=1;
P0=date;
delay(10);
lcden=1;
delay(10);
lcden=0;
}
void init()
{
lcden=0;
writecom(0x38); //设置16*2 初始显示
writecom(0x0e);
writecom(0x06);
writecom(0x01);
writecom(0x80);
}
void main()
{
init();
for(num=0;num<10;num++)
{
writedate(table[num]);
delay();
}
while(1);
} |