#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit D1 = P1^3;
uchar sum=0,times = 0;
sbit k1 = P3^4;
sbit k2 = P3^5;
void delay(unsigned char i)
{
unsigned char k;
for(;i>0;i--)
for(k=110;k>0;k--);
}
void init_int0()
{
TMOD = 0X01;
TH0 = 64536/256;
TL0 = 65536%256;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main()
{
init_int0();
while(1)
{
if(k1==0)
{
delay(10);
if(k1==0)
{
if(sum<19)
sum++;
while(!k1);
}
}
else if(k2==0)
{
delay(10);
if(k2==0)
{
if(sum>0)
sum--;
while(!k2);
}
}
}
}
void int0() interrupt 1
{
TH0 = 64536/256;
TL0 = 65536%256;
if(times>sum)
D1=0;
else
D1=1;
times++;
if(times==19)
times =0;
}