|
想试试看QTOUCH,选M48的CPU 4.0的库,修改IAR样例程序(初次学用IAR,有错误请批评)。修改后程序编译通过,但是用示波器测量IO,居然连波形都没有。下面是我的程序,如有错误请不吝赐教。
#include <ioavr.h>
#include <intrinsics.h>
#include "touch_api.h"
static void init_system( void ); //initialise host app, pins, watchdog, etc
static void init_timer_isr( void ); //configure timer ISR to fire regularly
static void qt_set_parameters( void ); //Assign the parameters values to global configuration parameter structure
static void config_sensors(void);
static void config_keys(void);
#pragma vector=TIMER1_COMPA_vect
__interrupt static void timer_isr( void );
/* The timing information for timer to fire periodically to measure touch */
#define TICKS_PER_MS 1381u
#define MEASUREMENT_PERIOD_MS 25u
#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]
/* This configuration data structure parameters if needs to be changed will be
changed in the qt_set_parameters function */
extern qt_touch_lib_config_data_t qt_config_data;
extern qt_touch_lib_measure_data_t qt_measure_data; //touch output - measurement data
extern int16_t qt_get_sensor_delta( uint8_t sensor);//Get sensor delta values
static volatile uint8_t time_to_measure_touch = 0u; //flag set by timer ISR when it's time to measure touch
static volatile uint16_t current_time_ms_touch = 0u; // current time, set by timer ISR
int main( void )
{
/*status flags to indicate the re-burst for library*/
uint16_t status_flag = 0u;
uint8_t burst_flag = 0u;
/* initialise host app, pins, watchdog, etc */
init_system(); DDRD = 0xFF;
config_sensors();
qt_init_sensing(); //initialise touch sensing
qt_set_parameters( ); //Set the parameters like recalibration threshold, Max_On_Duration etc in this function by the user
init_timer_isr(); //configure timer ISR to fire regularly
/* Address to pass address of user functions */
/* This function is called after the library has made capacitive measurements,
* but before it has processed them. The user can use this hook to apply filter
* functions to the measured signal values.(Possibly to fix sensor layout faults) */
qt_filter_callback = 0;
__enable_interrupt();//enable interrupts
for( ; ; ) //loop forever
{
if( time_to_measure_touch )
{
PORTD|=(1u<<PORTD6);
time_to_measure_touch = 0u; // clear flag: it's time to measure touch
do{
status_flag = qt_measure_sensors( current_time_ms_touch ); //one time measure touch sensors
if(GET_SENSOR_STATE(1)!=0)PORTD|=(1u<<PORTD5);
else PORTD&=~(1u<<PORTD5);
burst_flag = status_flag & QTLIB_BURST_AGAIN;
if (burst_flag!= 0u)
{
/*Time critical host application code goes here*/
}
}while ( burst_flag) ;
}
else PORTD&=~(1u<<PORTD6);
/* Time Non-critical host application code goes here */
}
}
/*============================================================================
Name : init_timer_isr
------------------------------------------------------------------------------
Purpose : configure timer ISR to fire regularly
Input : n/a
Output : n/a
Notes :
============================================================================*/
static void init_timer_isr( void )
{
OCR1A = ( TICKS_PER_MS * MEASUREMENT_PERIOD_MS); //set timer compare value (how often timer ISR will fire)
TIMSK1 |= (1u << OCIE1A);//enable timer ISR
TCCR1B |= (1u << CS11); //timer prescaler = system clock / 8
TCCR1B |= (1u << WGM12);//timer mode = CTC (count up to compare value, then reset)
}
/*============================================================================
Name : init_system
------------------------------------------------------------------------------
Purpose : initialise host app, pins, watchdog, etc
Input : n/a
Output : n/a
Notes :
============================================================================*/
static void init_system( void )
{
/* run at 4MHz (assuming internal clock is set to 8MHz)*/
// CLKPR = 0x80u;
// CLKPR = 0x01u;
MCUCR |= (1u << PUD); //disable pull-ups
}
/*============================================================================
Name : timer_isr
------------------------------------------------------------------------------
Purpose : timer 1 compare ISR
Input : n/a
Output : n/a
Notes :
============================================================================*/
#pragma vector=TIMER1_COMPA_vect
__interrupt static void timer_isr( void )
{
time_to_measure_touch = 1u; // set flag: it's time to measure touch
current_time_ms_touch += MEASUREMENT_PERIOD_MS; //update the current time
}
/*============================================================================
Name : qt_set_parameters
------------------------------------------------------------------------------
Purpose : This will fill the default threshold values in the configuration
data structure.But User can change the values of these parameters .
Input : n/a
Output : n/a
Notes : initialize configuration data for processing
============================================================================*/
static void qt_set_parameters( void )
{
/* This will be modified by the user to different values */
qt_config_data.qt_di = DEF_QT_DI;
qt_config_data.qt_neg_drift_rate = DEF_QT_NEG_DRIFT_RATE;
qt_config_data.qt_pos_drift_rate = DEF_QT_POS_DRIFT_RATE;
qt_config_data.qt_max_on_duration = DEF_QT_MAX_ON_DURATION;
qt_config_data.qt_drift_hold_time = DEF_QT_DRIFT_HOLD_TIME;
qt_config_data.qt_recal_threshold = DEF_QT_RECAL_THRESHOLD;
}
/*============================================================================
Name : config_sensors
------------------------------------------------------------------------------
Purpose : Configure the sensors
Input : n/a
Output : n/a
Notes : n/a
============================================================================*/
static void config_sensors(void)
{
config_keys();
}
/*============================================================================
Name : config_keys
------------------------------------------------------------------------------
Purpose : Configure the sensors as keys only
Input : n/a
Output : n/a
Notes : n/a
============================================================================*/
static void config_keys(void)
{
/* enable sensors 0..3: keys on channels 0..3 */
qt_enable_key( CHANNEL_0, NO_AKS_GROUP, 10u, HYST_6_25 );
qt_enable_key( CHANNEL_1, NO_AKS_GROUP, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_2, AKS_GROUP_1, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_3, AKS_GROUP_1, 10u, HYST_6_25 );
#if(QT_NUM_CHANNELS >= 8u)
/* enable sensors 4..7: keys on channels 4..7 */
// qt_enable_key( CHANNEL_4, AKS_GROUP_1, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_5, AKS_GROUP_1, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_6, AKS_GROUP_1, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_7, AKS_GROUP_1, 10u, HYST_6_25 );
#endif
#if(QT_NUM_CHANNELS >= 12u)
/* enable sensors 8..11: keys on channels 4..7 */
// qt_enable_key( CHANNEL_8, AKS_GROUP_1, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_9, AKS_GROUP_1, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_10, AKS_GROUP_1, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_11, AKS_GROUP_1, 10u, HYST_6_25 );
#endif
#if (QT_NUM_CHANNELS >= 16u)
/* enable sensors 12..15: keys on channels 8..15 */
// qt_enable_key( CHANNEL_12, AKS_GROUP_1, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_13, AKS_GROUP_1, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_14, AKS_GROUP_1, 10u, HYST_6_25 );
// qt_enable_key( CHANNEL_15, AKS_GROUP_1, 10u, HYST_6_25 );
#endif
}
IAR (原文件名:p1.jpg)
IAR配置 (原文件名:p2.jpg) |
阿莫论坛20周年了!感谢大家的支持与爱护!!
如果天空是黑暗的,那就摸黑生存;
如果发出声音是危险的,那就保持沉默;
如果自觉无力发光,那就蜷伏于牆角。
但是,不要习惯了黑暗就为黑暗辩护;
也不要为自己的苟且而得意;
不要嘲讽那些比自己更勇敢的人。
我们可以卑微如尘土,但不可扭曲如蛆虫。
|