今天捣鼓EBS003按键触控。
原理图:
代码:主程序:
#include "SC_Init.h" //MCU Init header,Include all IC resource headers
#include "SC_it.h"
#include "..\Drivers\SCDriver_list.h"
#include "HeadFiles\SysFunVarDefine.h"
/**************************************Generated by EasyCodeCube*************************************/
/*************************************.Generated by EasyCodeCube.************************************/
/*****************************************************************************************************
* Function Name: main
* Description : This function implements main function.
* Arguments : None
* Return Value : None
******************************************************************************************************/
void main(void)
{
/*** MCU init***/
SC_Init();
/*<Generated by EasyCodeCube begin>*/
/*<UserCodeStart>*//*<SinOne-Tag><9>*/
TouchKeyInit();
/*<UserCodeEnd>*//*<SinOne-Tag><9>*/
/*<UserCodeStart>*//*<SinOne-Tag><10>*/
while(1)
{
/*<UserCodeStart>*//*<SinOne-Tag><14>*/
if(SOCAPI_TouchKeyStatus & 0x80)
{
/*<UserCodeStart>*//*<SinOne-Tag><22>*/
SOCAPI_TouchKeyStatus &= 0x7f;
/*<UserCodeEnd>*//*<SinOne-Tag><22>*/
/*<UserCodeStart>*//*<SinOne-Tag><18>*/
exKeyValueFlag = TouchKeyScan();
/*<UserCodeEnd>*//*<SinOne-Tag><18>*/
/*<UserCodeStart>*//*<SinOne-Tag><35>*/
UserCode();
/*<UserCodeEnd>*//*<SinOne-Tag><35>*/
/*<UserCodeStart>*//*<SinOne-Tag><36>*/
TouchKeyRestart();
/*<UserCodeEnd>*//*<SinOne-Tag><36>*/
}
/*<UserCodeEnd>*//*<SinOne-Tag><14>*/
}
/*<UserCodeEnd>*//*<SinOne-Tag><10>*/
/*<Generated by EasyCodeCube end>*/
}
用户代码:
#include "SC_Init.h"
#include "SC_it.h"
#include "..\Drivers\SCDriver_list.h"
#include "HeadFiles\SysFunVarDefine.h"
/**************************************Generated by EasyCodeCube*************************************/
/******************************************************************************************************
*用于存放键值的变量(32bit长度的变量)1.该变量0-30bit对应TK键值TK0-TK30的状态:有
*键值则对应bit会置1,无键则对应bit为0
******************************************************************************************************/
unsigned long exKeyValueFlag = 0;
////用户应用层函数编写(可修改)1.键值处理逻辑2.应用层逻辑实现
void UserCode()
{
/*<UserCodeStart>*//*<SinOne-Tag><23>*/
if((exKeyValueFlag&0x00000004)==0x00000004)
GPIO_WriteHigh(GPIO1,GPIO_PIN_4);
else
GPIO_WriteLow(GPIO1, GPIO_PIN_4);
if((exKeyValueFlag&0x00000008)==0x00000008)
GPIO_WriteHigh(GPIO1,GPIO_PIN_5);
else
GPIO_WriteLow(GPIO1, GPIO_PIN_5);
/*<UserCodeEnd>*//*<SinOne-Tag><23>*/
}
两个触控按键。按下左边的触控按键,L1灯亮,释放灯灭。按下右边的触控按键,L2灯亮,释放灯灭。
效果图:
|