#include <at89x52.h>
char P0table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
char P2table[]={0xfe,0xfd};
char bdata flag;
sbit up_flag=flag^0;
sbit down_flag=flag^1;
char bcd[]={0,0};
int count=0;
int time=20;
int j;
sbit btn1=P3^0;
void delay_1ms(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<114;j++)
;
}
main()
{
IE=0x8A;
TMOD=0x10;
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR0=1;
TR1=1;
up_flag=1;
down_flag=0;
while(1)
{
if(btn1==0)
{
up_flag=~up_flag;down_flag=~down_flag;delay_1ms(20);while(btn1!=1);delay_1ms(20);
}
}
}
void t0_int0(void) interrupt 1
{
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
P0=P0table[bcd[j]];
P2=P2table[j];
j++;
if(j==2)
j=0;
}
void t1_int0(void) interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
time--;
if(time==0)
{
time=20;
if(up_flag==1)
{
count++;
if(count>99)
count=0;
}
else if(down_flag==1)
{
count--;
if(count<0)
count=99;
}
bcd[0]=count%10;
bcd[1]=count/10;
}
}
沒有留言:
張貼留言