求助:时钟程序,执行出错
问题:到了09月01后,自动跳到12月02,然后一直执行到年份加一年,可到了下一年的2月01,又跳到12月了。请大家帮帮忙,看看究竟哪里出问题了?谢谢!程序:
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit lcdrw=P2^5;
sbit lcdrs=P2^6;
sbit lcden=P2^7;
uchar code table1[]="2012-07-26";
uchar year=12,month=07,day=26,gnsz,num,snum;
void delayms(uchar ms)
{
uint i,j;
for(i=ms;i>0;i--)
for(j=110;j>0;j--);
}
void write_com(uchar com)
{
lcdrw=0;
lcdrs=0;
P0=com;
delayms(2);
lcden=1;
delayms(5);
lcden=0;
}
void write_date(uchar date)
{
lcdrw=0;
lcdrs=1;
P0=date;
delayms(2);
lcden=1;
delayms(5);
lcden=0;
}
void init()
{
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
TMOD=0X01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
write_com(0x80+0x03);
for(num=0;num<10;num++)
{
write_date(table1[num]);
delayms(5);
}
}
void write_ymd(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void main()
{
init();
while(1);
{
}
}
void T0_time() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
snum++;
if(snum==20)
{
snum=0;
day++;
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month=12))
{
if(day>31)
{
day=1;
month++;
}
}
if((month==4)||(month==6)||(month==9)||(month==11))
{
if(day>30)
{
day=1;
month++;
}
}
if(month==2)
{
if(year%4==0)
{
if(day>29)
{
day=1;
month++;
}
}
else
{
if(day>28)
{
day=1;
month++;
}
}
}
if(month>12)
{
month=1;
year++;
}
write_ymd(0x0b,day);
write_com(0x80+0x0b);
write_ymd(0x08,month);
write_com(0x80+0x08);
write_ymd(0x05,year);
write_com(0x80+0x05);
}
}