我们需要的函数很简单,只有2个
1、bool MTOUCH_Service_Mainloop(void),运行主函数
2、bool MTOUCH_Button_isPressed(enum mtouch_button_names name) 获取触摸状态函数
主函数设计如下:
注意:最上面的2个箭头的中断必须打开。之后就是调用主函数,调用触摸状态,2个中文注释就是相应功能触发时,你需要的处理,比如你可以点灯之类的,而我这里选择发送数据到PC上显示触发状态。
本人的代码如下,即触摸触发时,发出触发的端口标号,否则发出0x00;代码如下
#include "mcc_generated_files/mcc.h"
/*
Main application
*/
static unsigned int xx = 2000;
static unsigned int y = 5;
void main(void)
{
// initialize the device
SYSTEM_Initialize();
// When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
// Use the following macros to:
// Enable the Global Interrupts
INTERRUPT_GlobalInterruptEnable();
// Enable the Peripheral Interrupts
INTERRUPT_PeripheralInterruptEnable();
// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
while (1)
{
MTOUCH_Service_Mainloop();
xx--;
if(xx==0)
{
y--;
xx=2000;
}
if(y==0)
{
xx=2000;
y=5;
{
unsigned char i;
for(i=0;i<=7;i++)
{
if(MTOUCH_Button_isPressed(i)==true)
{
//触摸触发处理
EUSART_Write(0xaa);
EUSART_Write(i);
EUSART_Write(0xaa);
}
else
{
//触摸未触发处理
EUSART_Write(0x00);
}
}
}
}
// Add your application code
}
}
/**
End of File
*/