現在按你的意㽖這樣整了一下,還是不行
#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;
}
}
}
}
|