#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit k1=P3^4;
sbit led=P1^0;
sbit D=P2^3;
uint temp,temp1,qian,bai,shi,ge,si,san,er,yi;
uchar t0,t2,num;
uchar code shuma[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,};
void delay(uint z) //延时子程序
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void chushihua() //设置定时器1为工作方式1?
{
temp=900;
TMOD=0x01;
dula=1;
wela=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void zhongduan() interrupt 1 //中断函数子程序不需要声明
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
}
void daojishi(temp) //显示子程序
{
uint qian,bai,shi,ge;
qian=temp/1000;
bai=temp%1000/100;
shi=temp%100/10;
ge=temp%10;
P0=shuma[qian];
dula=1;
dula=0;
P0=0xfe;
wela=1;
wela=0;
delay(2);
P0=shuma[bai];
dula=1;
dula=0;
P0=0xfd;
wela=1;
wela=0;
delay(2);
P0=shuma[shi];
dula=1;
dula=0;
P0=0xfb;
wela=1;
wela=0;
delay(2);
P0=shuma[ge];
dula=1;
dula=0;
P0=0xf7;
wela=1;
wela=0;
delay(2);
}
void daojishipaoma()
{
if(t0==1)
{
t0=0;
if(temp<=0)
{
led=1;
D=0;
delay(5000);
D=1;
temp=1;
}
temp--;
}
daojishi(temp);
}
void kaiguankongzhi()
{
switch(num)
{
case 1:daojishipaoma();break;
}
if(k1==0)
{
delay(10);
if(k1==0)
{
num++;
if(num==3)
num=0;
led=1;
}
while(!k1);
delay(10);
while(!k1);
}
}
void main()
{
led=0;
chushihua();
while(1)
{
kaiguankongzhi();
}
}