搜索
bottom↓
回复: 15

新手qtouch问题

[复制链接]

出0入0汤圆

发表于 2012-5-5 21:11:47 | 显示全部楼层
Gorgon_Meducer 发表于 2011-8-23 13:10
官方用户手册下载了么?
官方用户手册有一步一步来的设置介绍。感觉你是没有正确配置阿。 ...

能不能教教我,AVR和Qtouch,点亮一个灯的程序,我用的是ATmega16A
初学者,见谅

出0入0汤圆

发表于 2012-5-7 10:53:20 | 显示全部楼层

#include <avr/io.h>
#include <avr/interrupt.h>
#define __delay_cycles(10)     __builtin_avr_delay_cycles(10)
#define __enable_interrupt()  sei()

/*  now include touch api.h with the localization defined above */
#include "touch_api.h"

/*----------------------------------------------------------------------------
                            manifest constants
----------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------
                            type definitions
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
                                prototypes
----------------------------------------------------------------------------*/

/*  initialise host app, pins, watchdog, etc    */
static void init_system( void );
/*  configure timer ISR to fire regularly   */
static void init_timer_isr( void );
/*  Assign the parameters values to global configuration parameter structure    */
static void qt_set_parameters( void );
/*  Configure the sensors */
static void config_sensors(void);

/*  Configure the sensors for  Keys configuration */
    static void config_keys(void);





/*----------------------------------------------------------------------------
                            Structure Declarations
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
                                    macros
----------------------------------------------------------------------------*/


#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]

/*----------------------------------------------------------------------------
                                global variables
----------------------------------------------------------------------------*/
/* Timer period in msec. */
uint16_t qt_measurement_period_msec = 25u;

/*----------------------------------------------------------------------------
                                extern variables
----------------------------------------------------------------------------*/
/* 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;
/* touch output - measurement data */
extern qt_touch_lib_measure_data_t qt_measure_data;
/* Get sensor delta values */
extern int16_t qt_get_sensor_delta( uint8_t sensor);



/*----------------------------------------------------------------------------
                                static variables
----------------------------------------------------------------------------*/

/* flag set by timer ISR when it's time to measure touch */
static volatile uint8_t time_to_measure_touch = 0u;

/* current time, set by timer ISR */
static volatile uint16_t current_time_ms_touch = 0u;

/*============================================================================
Name    :   main
------------------------------------------------------------------------------
Purpose :   main code entry point
Input   :   n/a
Output  :   n/a
Notes   :
============================================================================*/

int main( void )
{
    /*status flags to indicate the re-burst for library*/
    uint16_t status_flag = 0u;
    uint16_t burst_flag = 0u;

/* initialise host app, pins, watchdog, etc */
    init_system();

    /* Configure the Sensors as keys or Keys With Rotor/Sliders in this function */
    config_sensors();

    /* initialise touch sensing */
    qt_init_sensing();

    /*  Set the parameters like recalibration threshold, Max_On_Duration etc in this function by the user */
    qt_set_parameters( );

    /* configure timer ISR to fire regularly */
    init_timer_isr();


    /*  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 interrupts */
    __enable_interrupt();

// /* loop forever */
//    for( ; ; )
//   {
//        if( time_to_measure_touch )
//        {

            /*  clear flag: it's time to measure touch  */
//            time_to_measure_touch = 0u;

//            do {
                /*  one time measure touch sensors    */
//                status_flag = qt_measure_sensors( current_time_ms_touch );
               
//               burst_flag = status_flag & QTLIB_BURST_AGAIN;

  /* Time-critical host application code goes here */

//                   }while (burst_flag) ;
            


  /*  Time Non-critical host application code goes here  */
//               }
//        }


         while(1)
         {
               if( time_to_measure_touch )
                                   {
                                    time_to_measure_touch = 0u;

                                        qt_measure_sensors( current_time_ms_touch) ;
                                 }       

                if(qt_measure_data.qt_touch_status.sensor_states[0]&0x01)
                         PORTC&=~(1<<PC0);//A灯亮
                 else
                         PORTC|=(1<<PC0);//A灯灭
         }




}




/*============================================================================
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, AKS_GROUP_1, 10u, HYST_6_25 );
    qt_enable_key( CHANNEL_1, AKS_GROUP_1, 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 );
    /*  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 );


}




/*============================================================================
Name    :   init_system
------------------------------------------------------------------------------
Purpose :   initialise host app, pins, watchdog, etc
Input   :   n/a
Output  :   n/a
Notes   :
============================================================================*/

static void init_system( void )
{
    /*  disable pull-ups    */
    MCUCR |= (1u << PUD);

}

/*============================================================================
Name    :   timer_isr
------------------------------------------------------------------------------
Purpose :   timer 1 compare ISR
Input   :   n/a
Output  :   n/a
Notes   :
============================================================================*/

ISR(TIMER1_COMPA_vect)
{
    /*  set flag: it's time to measure touch    */
    time_to_measure_touch = 1u;

    /*  update the current time */
    current_time_ms_touch += qt_measurement_period_msec;
}


/*============================================================================
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;
    qt_config_data.qt_pos_recal_delay = DEF_QT_POS_RECAL_DELAY;
}
编译之后是:
Build started 7.5.2012 at 10:50:08
avr-gcc -I"C:\Program Files\Atmel\Atmel_QTouch_Libraries_4.4\Generic_QTouch_Libraries\include" -I"C:\Program Files\Atmel\Atmel_QTouch_Libraries_4.4\Generic_QTouch_Libraries\debug" -I"C:\Program Files\Atmel\Atmel_QTouch_Libraries_4.4\Generic_QTouch_Librarie
s\AVR_Tiny_Mega_XMega\QTouch\common_files" -I"C:\Program Files\Atmel\Atmel_QTouch_Libraries_4.4\Generic_QTouch_Libraries\AVR_Tiny_Mega_XMega\QTouch\library_files"  -mmcu=atmega16 -Wall -gdwarf-2 -std=gnu99 -DQT_DELAY_CYCLES=1 -D_QTOUCH_ -DSNSK1=A -DQT_NUM_
CHANNELS=8 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums  -DSNS1=A -Wp,-M,-MP,-MT,11111.o,-MF,dep/11111.o.d  -c   ../11111.c -o 11111.o

../11111.c:45:24: "10" may not appear in macro parameter list
../11111.c: In function `main':
../11111.c:133: warning: unused variable `status_flag'
../11111.c:134: warning: unused variable `burst_flag'
../11111.c: At top level:
../11111.c:282: warning: return type defaults to `int'
../11111.c: In function `ISR':
../11111.c:282: warning: type of "TIMER1_COMPA_vect" defaults to "int"
../11111.c:288: warning: control reaches end of non-void function
../11111.c: At top level:
../11111.c:67: warning: 'init_timer_isr' used but never defined
make: *** [11111.o] Error 1
Build failed with 1 errors and 6 warnings...
不知道哪儿错了,怎么改?
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-2 19:09

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表