[mw_shl_code=c,true] /**** KEY--PD5
****************************************************************************************/
#include "key.h"
extern void Delay(u32 nCount);
extern void Delays(unsigned int S);
u16 num=0;
void KEY_Init(void)
{
// GPIO_Init(GPIOD,GPIO_PIN_5,GPIO_MODE_IN_PU_NO_IT);
GPIO_Init(GPIOD, GPIO_PIN_5, GPIO_MODE_IN_FL_NO_IT);
}
u16 Key_Scan(void)
{
u16 key_press_num=0;
if(GPIO_ReadInputPin(GPIOD,GPIO_PIN_5))
{
Delay(0x3ff);/* 消抖 */
if(GPIO_ReadInputPin(GPIOD,GPIO_PIN_5))
{
while(GPIO_ReadInputPin(GPIOD,GPIO_PIN_5))
{
key_press_num++;
Delay(0x3ff); //10x200=2000ms=2s
//while(GPIO_ReadInputPin(GPIOD,GPIO_PIN_5));//这里用于识别是否按键还在按下执行相关动作,否则退出
}
}
}
return key_press_num; //按键按下 key_press_num计数松手后返回
}
void Hand_key(void)
{
u16 a,key_press_num=0;
key_press_num=Key_Scan();
if(key_press_num>405) //大约2s
{
key_press_num=0; //如果达到长按键标准 //则进入长按键动作
while(GPIO_ReadInputPin(GPIOD,GPIO_PIN_5));//这里用于识别是否按键还在按下执行相关动作,否则退出
TIM2_SetCompare2(0);
Delays(1);
TIM2_SetCompare2(100);
Delays(1);
TIM2_SetCompare2(0);
Delays(1);
TIM2_SetCompare2(100);
Delays(10);
for(a=100;a>0;a--)
{
Delay(0xfff);
TIM2_SetCompare2(a);
}
TIM2_SetCompare2(0);
}
else if(key_press_num>0&&key_press_num<400)
{
key_press_num=0; //如果达到短按键标准 //则进入短按键动作
while(GPIO_ReadInputPin(GPIOD,GPIO_PIN_5));//这里用于识别是否按键还在按下执行相关动作,否则退出
num++;
// TIM2_SetCompare2(90);
if(num==1)
{
Delay(0xfff);
for(a=0;a<=99;a++)
{
Delay(0xfff);
Delay(0xfff);
TIM2_SetCompare2(a);
}
TIM2_SetCompare2(100);
}
if(num==2)
{
Delay(0xfff);
for(a=100;a>70;a--)
{
Delay(0xfff);
Delay(0xfff);
TIM2_SetCompare2(a);
}
TIM2_SetCompare2(70);
}
if(num==3)
{
num=0;
Delay(0xfff);
for(a=70;a>10;a--)
{
Delay(0xfff);
Delay(0xfff);
TIM2_SetCompare2(a);
}
TIM2_SetCompare2(10);
}
}
}[/mw_shl_code]
产品使用有效。。 |