菜鸟求大神啊LED数码管万年历
#include<reg52.h> //头文件
#define uint unsigned int
#define uchar unsigned char
sbit wela=P2^7; //位选
sbit dula=P2^6; //段选
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
uchar s1,s2,s3,s4,s5,s6;
uchar day=6,month=6,year=14,days,k,h,min,s;
uint t;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //不带小数点
uchar code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef}; //带小数点
//初始化
void init()
{
TMOD=0x01; //定时器0定时方式1
TH0=(65536-50000)/256; //装初值高八位
TL0=(65536-50000)%256; //低八位
EA=1; //开总中断
ET0=1; //定时器0中断
TR0=1; //启动定时器
}
//延时
void delay(uint x)
{
uint i,j;
for(i=x;i--;i>0);
for(j=110;j--;j>0);
}
//显示时间
void display1()
{
wela=1; //打开位选
P0=0xfe;
wela=0; //锁存
dula=1; //打开段选
P0=table[s6];
dula=0; //锁存
delay(5); //延时5ms,消隐
wela=1;
P0=0xfd;
wela=0;
dula=1;
P0=table1[s5];
dula=0;
delay(5);
wela=1;
P0=0xfb;
wela=0;
dula=1;
P0=table[s4];
dula=0;
delay(5);
wela=1;
P0=0xf7;
wela=0;
dula=1;
P0=table1[s3];
dula=0;
delay(5);
wela=1;
P0=0xef;
wela=0;
dula=1;
P0=table[s2];
dula=0;
delay(5);
wela=1;
P0=0xdf;
wela=0;
dula=1;
P0=table[s1];
dula=0;
delay(5);
}
//显示年月日
void display2()
{
switch(month)
{
case 1:case 3:case 5:case 7:case 8:case 10:case 12: days=31; break;
case 2:days=28+k; break;
case 4:case 6:case 9:case 11: days=30;break;
}
if(day>days)
{
day=1;month++;
}
if(month==13)
{
month=1;year++;
}
if(year%4==0)
k=1;
else
k=0;
wela=1; //打开位选
P0=0xfe;
wela=0; //锁存
dula=1; //打开段选
P0=table[year/10];
dula=0; //锁存
delay(5);
wela=1;
P0=0xfd;
wela=0;
dula=1;
P0=table1[year%10];
dula=0;
delay(5);
wela=1;
P0=0xfb;
wela=0;
dula=1;
P0=table[month/10];
dula=0;
delay(5);
wela=1;
P0=0xf7;
wela=0;
dula=1;
P0=table1[month%10];
dula=0;
delay(5);
wela=1;
P0=0xef;
wela=0;
dula=1;
P0=table[day/10];
dula=0;
delay(5);
wela=1;
P0=0xdf;
wela=0;
dula=1;
P0=table[day%10];
dula=0;
delay(5);
}
void display3()
{
s1=s/10;
s2=s%10;
s3=min/10;
s4=min%10;
s5=h/10;
s6=h%10;
}
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
while(!key1)
{
display1();
display3();
}
}
}
else
{
display1();
display2();
}
if(key2==0)
{
delay(10);
if(key2==0)
{
s1++;
}
}
if(key3==0)
{
delay(10);
if(key2==0)
{
s3++;
}
}
if(key3==0)
{
delay(10);
if(key2==0)
{
s5++;
}
}
}
void main()
{
init(); //初始化
keysan();
}
void time0() interrupt 1 //定时器中断
{
TH0=(65536-50000)/256; //装初值高八位
TL0=(65536-50000)%256; //低八位
t++;
if(t==20)
{
t=0;
s++;
if(s==60)
{
s=0;
min++;
if(min==60)
{
min=0;
h++;
if(h==24)
{
h=0;
day++;
}
}
}
}
}
求修改!谢谢啊