#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit lcdrs=P2^0;
sbit lcden=P2^1;
uchar shi,ge,count;
char year,month,day,week,hour,min,s;
void delay_ms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void write_com(uchar com) //液晶命令
{
lcdrs=0;
P0=com;
delay_ms(5);
lcden=1;
delay_ms(5);
lcden=0;
}
void write_data(uchar wdata) //液晶数据
{
lcdrs=1;
P0=wdata;
delay_ms(5);
lcden=1;
delay_ms(5);
lcden=0;
}
void _fenqu() //"AM"、"PM"函数
{
write_com(0x80+0x41);
write_date('M');
if(hour>=12)
{
write_com(0x80+0x40);
write_date('P');
}
else
{
write_com(0x80+0x40);
write_date('A');
}
}
void write_ymd(uchar add1,uchar date1)//年月日函数
{
uchar shi,ge;
shi=date1/10;
ge=date1%10;
write_com(0x80+add1);
write_date(0x30+shi);
write_date(0x30+ge);
}
void write_hms(uchar add,uchar date)//写时分秒函数
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);//
write_date(0x30+ge); //
}
void write_week(char week) //液晶星期
{
write_com(0x80+12);
switch(week)
{
case 1:write_date('M');
delay(5);
write_date('O');
delay(5);
write_date('N');
break;
case 2:write_date('T');
delay(5);
write_date('U');
delay(5);
write_date('E');
break;
case 3:write_date('W');
delay(5);
write_date('E');
delay(5);
write_date('D');
break;
case 4:write_date('T');
delay(5);
write_date('H');
delay(5);
write_date('U');
break;
case 5:write_date('F');
delay(5);
write_date('R');
delay(5);
write_date('I');
break;
case 6:write_date('S');
delay(5);
write_date('A');
delay(5);
write_date('T');
break;
case 7:write_date('S');
delay(5);
write_date('U');
delay(5);
write_date('N');
break;
}
}
void writeym()
{
day=1;
month++;
if(month==13)
{
month=1;
year++;
if(year==100)
year=0;
}
}
void init()
{
uchar num;
lcden=0;
year=19; //TIME初始化
month=10;
day=18;
week=5;
shi=18;
fen=59;
miao=59;
count=0;
s1num=0;
s4num=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)
{
write_date(table[num]);
delay(5);
}
delay(5);
write_com(0x80+0x46);
write_date(':');
delay(5);
write_com(0x80+0x49);
write_date(':');
delay(5);
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void main()
{
init();
while(1)
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
s++;
if(s==60)
{
s=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
week++;
if(week==8)
{
week=1;
}
day++;
if(year%4==0&&month==2)//判断是否为闰年的2月
{
if(day==29)
{
writeym();
}
}
if(year%4!=0&&month==2)//判断是否为平年的2月
{
if(day==28)
{
writeym();
}
}
if(month!=2&&month!=4&&month!=6&&month!=9&&month!=11)
{
if(day==31)
{
writeym();
}
}
if(month==4||month==6||month==9||month==11)
{
if(day==30)
{
writeym();
}
}
}
}
}
}
}
//AWSL
|