#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^2;/*定义端口,根据自己单片上按键端口定义*/
sbit led=P2^1;
uint i,j=0;
delay(uchar x);
/*主程序*/
void main()
{
while(1)
{
if(key1==0)
{
delay(50);
while(!key1);
delay(50);
j++;
if(j==5)
led=0;
if(j==10)
led=1;
}
}
}
/*延时程序*/
delay(uchar x)
{
uchar a,b;
for(a=x;a>0;a--)
for(b=200;b>0;b--);
} |