【触摸按键识别】触摸验证(五)

 

我们需要的函数很简单,只有2

1bool MTOUCH_Service_Mainloop(void),运行主函数

 

2bool 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
*/

串口打印数据:

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值