ATMEGA328PB-AU外设中带外围触摸控制器(PTC)电容式触摸按钮、滑块和轮子24个自帽通道和144个互帽通道。
为了访问PTC,用户必须使用Atmel Start QTouch®配置器来配置QTouch Library固件并将其与应用软件链接QTouch Library可用于在单个界面上以多种组合方式实现按钮、滑块和滚轮.
#include
#include "touch.h"
extern volatile uint8_t measurement_done_touch;
int main(void)
{
uint8_t key_status0 = 0;
uint8_t key_status1 = 0;
/* Initializes MCU, drivers and middleware */
atmel_start_init();
/* Enable interrupts */
cpu_irq_enable();
/** If any of the two self-capacitance buttons is touched, the LED is turned ON
* When touch is released, the LED is turned OFF
*/
while (1) {
/* Does acquisition and post-processing */
touch_process();
if (measurement_done_touch == 1) {
measurement_done_touch = 0;
key_status0 = get_sensor_state(0) & 0x80;
key_status1 = get_sensor_state(1) & 0x80;
if ((0u != key_status0) || (0u != key_status1))
LED_set_level(true);
else
LED_set_level(false);
}
}
}
✨在具体使用触摸功能进行测试过程中发现,如果启用了串口打印调试信息,会发现触摸相应后,如果打印调试信息会出现乱码,目前解决的办法就是,在需要通过串口打印调试信息的时候,开启串口,在不需要打印串口调试信息的时候,关闭串口功能。
#include
#include "touch.h"
#include
extern volatile uint8_t measurement_done_touch;
int main(void)
{
uint8_t key_status0 = 0;
uint8_t key_status1 = 0;
uint8_t key_status2 = 0;
uint8_t key_status3 = 0;
/* Initializes MCU, drivers and middleware */
atmel_start_init();
/* Enable interrupts */
cpu_irq_enable();
//USART_disable();
/** If any of the two self-capacitance buttons is touched, the LED is turned ON
* When touch is released, the LED is turned OFF
*/
while (1) {
/* Does acquisition and post-processing */
touch_process();
if (measurement_done_touch == 1) {
measurement_done_touch = 0;
key_status0 = get_sensor_state(0) & 0x80;
key_status1 = get_sensor_state(1) & 0x80;
key_status2 = get_sensor_state(2) & 0x80;
key_status3 = get_sensor_state(3) & 0x80;
if ((0u != key_status0) || (0u != key_status1) || (0u != key_status2) || (0u != key_status3)){
LED_set_level(true);
USART_enable_tx();
printf("********\r\n");
printf("PE2:%d,PE3:%d,PE0:%d,PE1:%d\r\n",key_status0,key_status1,key_status2,key_status3);
printf("Touch Press PE0 - PE3\r\n");
USART_disable();
}
else
{
LED_set_level(false);
USART_disable();
}
}
}
}