#include
#include
#define uchar unsigned char
#define uint unsigned int
unsigned long num=0,tt=0;
uchar j,k;
sbit shuru=P1^0;
sbit shuchu=P1^1;
uchar a0,b0,c0,d0,e0,f0;
sbit dula=P2^6;
sbit wela=P2^7;
sbit beep=P2^3;
unsigned char pwm_left_val = 0;//
unsigned char pwm_t;//周期
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
int flag=0;
void delay(uchar i)
{
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void displayw(uint a,uint b,uint c,uint d,uint e,uint f)
{
dula=0;
P0=table[a];
dula=1;
dula=0;
wela=0;
P0=0xfe;
wela=1;
wela=0;
delay(5);
P0=table[b];
dula=1;
dula=0;
P0=0xfd;
wela=1;
wela=0;
delay(5);
P0=table[c];
dula=1;
dula=0;
P0=0xfb;
wela=1;
wela=0;
delay(5);
P0=table[d];
dula=1;
dula=0;
P0=0xf7;
wela=1;
wela=0;
delay(5);
P0=table[e];
dula=1;
dula=0;
P0=0xef;
wela=1;
wela=0;
delay(5);
P0=table[f];
dula=1;
dula=0;
P0=0xdf;
wela=1;
wela=0;
delay(5);
}
void display0(num)
{
if(num<10)
{
a0=num;b0=16;c0=16;d0=16;e0=16;f0=16;
}
else
{
if(num<100)
{a0=num/10;b0=num%10;c0=16;d0=16;e0=16;f0=16;}
else
{
if(num<1000)
{a0=num/100;b0=num%100/10;c0=num%10;d0=16;e0=16;f0=16;}
else
{
if(num<10000)
{a0=num/1000;b0=num%1000/100;c0=num%100/10;d0=num%10;e0=16;f0=16;}
else
{
if(num<100000)
{a0=num/10000;b0=num%10000/1000;c0=num%1000/100;d0=num%100/10;e0=num%10;f0=16;}
else
{
if(num<1000000)
{a0=num/100000;b0=num%100000/10000;c0=num%10000/1000;d0=num%1000/100;e0=num%100/10;f0=num%10;}
}
}
}
}
}
displayw(a0,b0,c0,d0,e0,f0);
}
void main()
{
TMOD=0x51;
TR0=1;
TR1=1;
TH1=0x4c;// 5*10^-2s
TL1=0x00;
ET0=1;
ET1=1;
EA=1;
while(1)
{
display0(num/2);
if(TL1==1)
{
shuchu=~shuchu;
num++;
TL1=0;
}
if (flag==1)
{
if ((num/2)<10)
{
beep=0;
delay(8);
beep=1;
delay(2);
}
if ((num/2)>40)
{
beep=0;
delay(20);
display0(num/2);
delay(20);
beep=1;
}
}
}
}
/*void timer0() interrupt 1
{
pwm_t++;
if(pwm_t == 200)
pwm_t = P1 = 0;
if(pwm_left_val == pwm_t)
P1 = 0XFF;
} */
void time0() interrupt 3
{
TH1=0x4c;
TL1=0x00;
tt++;
shuru=~shuru; //定时器每隔50ms发起一次中断,shuru电平变换一次,故模拟输入方波的周期为100ms
if(tt==200)
{
EA=0;
flag=1;
}
}