#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define led P0
sbit key=P1^0;
unsigned int i=0,num=0;
void Delayms(unsigned int c);
void init();
void key_Scan();
void key_Scan()
{
if(!key)
{
Delayms(1);
if(!key)
{
while(!key)
{
P0=0x01;
i++;
}
}
}
}
void Delayms(unsigned int c)
{
unsigned char a, b;
while(c--)
{
for (b=38;b>0;b--)
{
for (a=130;a>0;a--);
}
}
}
void main()
{
init();
key=1;
P0=0x00;
while(1)
{
key_Scan();
}
}
void init()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
}
void T_time() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num++;
if(i==1&&num==20)
{
P0=0x00;}
} |