ATtiny44A,求技术支持
ATMEL 芯片型号ATtiny44A
#include <avr/io.h>
#include <avr/interrupt.h>
#define __delay_cycles(n) __builtin_avr_delay_cycles(n)
#define __enable_interrupt() sei()
#include "touch_api.h"
#include "touch.h"
#define GET_SENSOR_STATE(SENSOR_NUMBER) qt_measure_data.qt_touch_status.sensor_states[(SENSOR_NUMBER/8)] & (1 << (SENSOR_NUMBER % 8))
#define GET_ROTOR_SLIDER_POSITION(ROTOR_SLIDER_NUMBER) qt_measure_data.qt_touch_status.rotor_slider_values[ROTOR_SLIDER_NUMBER]
extern void touch_measure();
extern void touch_init( void );
extern void init_system( void );
extern void init_timer_isr(void);
extern void set_timer_period(uint16_t);
uint16_t qt_measurement_period_msec = QT_MEASUREMENT_PERIOD_MS;
uint16_t time_ms_inc=0;
/* flagset by timer ISR when it's time to measure touch */
volatile uint8_t time_to_measure_touch =0u;
/*current time, set by timer ISR */
volatile uint16_t current_time_ms_touch =0u;
int main( void )
{
/* initialise host app, pins, watchdog, etc */
init_system();
/* configure timer ISR to fire regularly */
init_timer_isr();
/* Initialize Touch sensors */
touch_init();
/* Set pin PA4/PA5/PA6 direction as output,and initial output value as HI */
DDRA |= (0x07u << PORTA4);
PORTA |= (0x07u << PORTA4);
/* loop forever */
for(; ; )
{
touch_measure();
/* Time Non-critical hostapplication code goes here */
if((GET_SENSOR_STATE(0)) != 0)
PORTA &= ~(1 << PORTA4);
else
PORTA |= (1 << PORTA4);
if((GET_SENSOR_STATE(1)) != 0)
PORTA &= ~(1 << PORTA5);
else
PORTA |= (1 << PORTA5);
if((GET_SENSOR_STATE(2)) != 0)
PORTA &= ~(1 << PORTA6);
else
PORTA |= (1 << PORTA6);
}
}
file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtml1/01/clip_image002.jpg
上面程序提供,三个按键(PA0 PA1 PA2),三个输出口(PA4 PA5 PA6)。
现在想将三个按键改成两个按键(PA0 PA1),输出还是三个输出(PA4 PA5 PA6)。
具体方式如下:
1. 假设PA1和PA0连接的按键是音量加减键,加减方式为上下滑动。即先接触PA0(减)后接触PA1(加)滑动,在PA4输出一个低电平信号,音量增大,;反之,先接触PA1(加)后接触PA0(减)滑动,在PA5输出一个低电平信号,音量减小。
2. 常时间接触PA0(减){具体是长按PA0还是长按PA1,可具体再设置},即长按此键,大概五秒左右(时间可具体在设置),切换到程序切换功能。切换到此功能,正常触摸PA0键,可在PA6输出一个低电平信号,为程序切换信号。要返回第一个音量加减功能,可常时间触摸PA0(减),大概五秒左右(时间可具体在设置),就切换到上一步的音量加减功能。