#include<reg51.h>
#define ulong unsigned long
char tab[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳数码管数字码
char tab_dp[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x70,0x10};//共阳数码管数字码(带小数点
sbit change=P3^0; //P3^0为“调时”按键
ulong t;
ulong sec,min,hour,sec_ge,sec_shi,min_ge,min_shi,hour_ge,hour_shi; //定义秒,分,时,秒的个位,十位,分的个位,十位,时的个位,十位
//--------------------------------延时函数------------------------------------//
void delay(int x)
{
int i,j;
for(i=x;i>0l;i--)
for(j=255;j>0;j--);
}
//-------------------------------显示函数---------------------------------------//
void display()
{
int i=0;
if(TF0==1) //如果定时器溢出
{
TF0=0; //清中断标志位
t++;
if(t==10)
{
t=0;
sec++; //秒加1
if(sec==60) //如果秒为60,则清零,分加1
{
sec=0;
min++;
}
if(min==60) //如果分为60,则清零,时加1
{
min=0;
hour++;
}
if(hour==24) //如果时为24,则清零
{
hour=0;
}
}
}
sec_ge=sec%10; //秒的个位和十位
sec_shi=sec/10;
min_ge=min%10; //分的个位和十位
min_shi=min/10;
hour_ge=hour%10; //时的个位和十位
hour_shi=hour/10;
//----------------------------调时程序-------------------------------//
void main()
{
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
IE=0x82;
while(1)
{
while(change==1)
display();
TR0=1;
EA=1;
while(change==0)
display();
while(change==1)
display();
EA=0;
while(change==0);
display();
while(change==1)
display();
sec=min=hour=0;
while(change==0)
display();
}
}
}
//---------------------------------------------------------------------//
void init()
{
TMOD=0x01; //定义定时器0工作与方式1
TH0=(65536-5536)/256; //定时器赋初值
TL0=(65536-5536)%256;
EA=1; //开总中断和T0中断
ET0=1;
}

#define ulong unsigned long
char tab[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳数码管数字码
char tab_dp[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x70,0x10};//共阳数码管数字码(带小数点
sbit change=P3^0; //P3^0为“调时”按键
ulong t;
ulong sec,min,hour,sec_ge,sec_shi,min_ge,min_shi,hour_ge,hour_shi; //定义秒,分,时,秒的个位,十位,分的个位,十位,时的个位,十位
//--------------------------------延时函数------------------------------------//
void delay(int x)
{
int i,j;
for(i=x;i>0l;i--)
for(j=255;j>0;j--);
}
//-------------------------------显示函数---------------------------------------//
void display()
{
int i=0;
if(TF0==1) //如果定时器溢出
{
TF0=0; //清中断标志位
t++;
if(t==10)
{
t=0;
sec++; //秒加1
if(sec==60) //如果秒为60,则清零,分加1
{
sec=0;
min++;
}
if(min==60) //如果分为60,则清零,时加1
{
min=0;
hour++;
}
if(hour==24) //如果时为24,则清零
{
hour=0;
}
}
}
sec_ge=sec%10; //秒的个位和十位
sec_shi=sec/10;
min_ge=min%10; //分的个位和十位
min_shi=min/10;
hour_ge=hour%10; //时的个位和十位
hour_shi=hour/10;
//----------------------------调时程序-------------------------------//
void main()
{
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
IE=0x82;
while(1)
{
while(change==1)
display();
TR0=1;
EA=1;
while(change==0)
display();
while(change==1)
display();
EA=0;
while(change==0);
display();
while(change==1)
display();
sec=min=hour=0;
while(change==0)
display();
}
}
}
//---------------------------------------------------------------------//
void init()
{
TMOD=0x01; //定义定时器0工作与方式1
TH0=(65536-5536)/256; //定时器赋初值
TL0=(65536-5536)%256;
EA=1; //开总中断和T0中断
ET0=1;
}
