#include <reg52.h>
#include <function.h>
#define TIMES 1000 //死循环里的代码量少,所以把阈值调大点
sbit KEY4 = P2^7;
u8 KEY4_Scan()
{
static
u8 key_up=1;
static
u16 times;
if
(key_up==0)
{
times++;
if
(times>=TIMES&&KEY4==1)
{
times=0;
return
1;
}
}
key_up=KEY4;
return
0;
}
void
main()
{
u8 key;
LED_Init();
P2=0xF7;
while
(1)
{
key=KEY4_Scan();
if
(key==1)LED2=!LED2;
}
}