STM32 底层按键驱动

作者:fly 发布于:2014-3-14 8:53 分类:嵌入式

版权声明:本文系www.forwhat.cn 原创 ,尊重作者劳动,转载请标明出处。本文转载自www.forwhat.cn 谢谢

以下是独立按键完整的C文件。如有需要可联系我。
#include "..\Global\World.h"

#if(System_PanelKey==Module_USED)

SYS_RES_HWTimer * paneltmr=TQ_NULL;
HW_Panelkey_TYPEDEF HW_PanelKey[5];

TQ_U8 HW_Panelkey_Callback()
{//10ms一次//循环检查所有按键。
	TQ_U8 i=0;
	for(i=0;i<5;i++)
	{
		if(HW_PanelKey[i].keypin!=TQ_NULL)
		{
			if(HW_PanelKey[i].keypin->GetStatus()!=HW_PanelKey[i].CurrentStatus)
			{
				if(HW_PanelKey[i].KeepTimes++ > 5)
				{
					HW_PanelKey[i].KeepTimes=0;
					HW_PanelKey[i].CurrentStatus=HW_PanelKey[i].keypin->GetStatus();
					if(HW_PanelKey[i].CurrentStatus==0)
					{
						SYS_KEYBOARD_UploadAKey(HW_PanelKey[i].Key_Code,0);
					}
				}
			}
			else
			{
				HW_PanelKey[i].KeepTimes=0;
			}
		}
	}
	return Err_none;
}

TQ_U8 HW_Panelkey_init()
{
	if(SysRegisterGPIO("PE11",&HW_PanelKey[0].keypin)==Err_none)
	{
		HW_PanelKey[0].keypin->Setmode(GPIO_Mode_IPU);
		HW_PanelKey[0].CurrentStatus=0;
		HW_PanelKey[0].KeepTimes=0;
		HW_PanelKey[0].Key_Code=KEY_CODE_PRINT_RETURN;
	}
	if(SysRegisterGPIO("PE12",&HW_PanelKey[1].keypin)==Err_none)
	{
		HW_PanelKey[1].keypin->Setmode(GPIO_Mode_IPU);
		HW_PanelKey[1].CurrentStatus=0;
		HW_PanelKey[1].KeepTimes=0;
		HW_PanelKey[1].Key_Code=KEY_CODE_ENSURE;
	}
	if(SysRegisterGPIO("PE13",&HW_PanelKey[2].keypin)==Err_none)
	{
		HW_PanelKey[2].keypin->Setmode(GPIO_Mode_IPU);
		HW_PanelKey[2].CurrentStatus=0;
		HW_PanelKey[2].KeepTimes=0;
		HW_PanelKey[2].Key_Code=KEY_CODE_DOWN;
	}
	if(SysRegisterGPIO("PE14",&HW_PanelKey[3].keypin)==Err_none)
	{
		HW_PanelKey[3].keypin->Setmode(GPIO_Mode_IPU);
		HW_PanelKey[3].CurrentStatus=0;
		HW_PanelKey[3].KeepTimes=0;
		HW_PanelKey[3].Key_Code=KEY_CODE_UP;
	}
	if(SysRegisterGPIO("PE15",&HW_PanelKey[4].keypin)==Err_none)
	{
		HW_PanelKey[4].keypin->Setmode(GPIO_Mode_IPU);
		HW_PanelKey[4].CurrentStatus=0;
		HW_PanelKey[4].KeepTimes=0;
		HW_PanelKey[4].Key_Code=KEY_CODE_MENU;
	}
	if(SysRegistVirsualTimer(&paneltmr)==Err_none)
	{
		paneltmr->Irq_Timer=HW_Panelkey_Callback;
		paneltmr->SetIntvalue(10);//10ms一次中断
		paneltmr->Enable();//使能定时亲
	}
	return Err_none;
}


#endif

发表评论:

 
Powered by emlog sitemap