现在按你的意㽖这样整了一下,还是不行
#include <reg52.h>
#define ufloat unsigned float
#define uchar unsigned char
#define uint unsigned int
uchar Flash_Delay, LedOnCount, m, CONT, JJ;
sbit SW = P1^0;
sbit LED = P2^0; //输出口;
bit key_In;
static uchar f_SW=1; //按键松开标志
static uchar f_long_SW=0; //长按动作标志,为1时,长按已动作,为0时长按未动作
int main (void)
{
P2 = 0; P1 = 0; SW = 1;key_In = 1;
while (1)
{
if(SW == 0)
{
f_SW=0; //按键按下标志
m++;
}
else f_SW=1; //按键松开标志
if((f_SW==1)&&(m>10)&&(m<500)) //按键松开,并且m值处于10~500之间,为短按
{
m=0;
CONT++;
if(CONT == 2)CONT = 0 ;
if(CONT == 1)
{
if(key_In == 1) //按键标置位bit
{
if(++Flash_Delay>1000) //闪灯延时int
{
Flash_Delay = 0;
if(LED == 1) //闪灯脚sbit
{
LedOnCount++;//闪灯次数char
LED = 0;
}else
{
LED = 1;
}
if(LedOnCount == 2)
{
key_In = 0;
LedOnCount = 0;
}
}
}
}
if(CONT == 0) LED = 0;
}
if((m>=500)&&(f_long_SW==0))
{
f_long_SW=1;
{
f_long_SW=0;
m=0;
}
}
}
}
|