#include"reg52.h"
sbit LED =P2^0;
sbit KEY =P2^3;
void delay2s(void);
void delay30ms(void);
void keyscan(void)
unsingned char flag =0;
int main(void)
{
while(1)
{
keyscan();
}
}
void keyscan(void)
{
if ((KEY==1)&&(flag==0)) 液春锋
{
delay30ms();
if (KEY==1)
{
LED=0;
delay2s();
flag=1;
}
}
if ((KEY==0)&&(flag==1))
{
delay30ms();
if (KEY==0)
闹晌 flag=0;
}
森孙
}
//注释就不写了,相信你能看懂
写一个keyscan的子函数放while里面