|
发表于 2010-2-6 18:04:52
|
显示全部楼层
#include<avr\io.h>
#include<avr\interrupt.h>
#include<touch_api.h>
#include"_QTOUCH_.h"
//unsigned char key_test_flag1=0;
//unsigned char key_test_flag2=0;
unsigned int hw_time_ms;
volatile unsigned char qt_measure_flag;//检测标志,全局变量
volatile qt_touch_status_t qt_touch_status;
//unsigned char test_time;
void delay(unsigned char m)
{
static unsigned char i,j,k;
for(i=0;i<m;i++)
{
for(j=0;j<200;j++)
{
for(k=0;k<200;k++);
}
}
}
SIGNAL(SIG_OVERFLOW1)
{
TCNT1H=0xFF;
TCNT1L=0xaa;//0x83
hw_time_ms++;
qt_measure_flag=1;
// test_time++;
}
void port_init(void)
{
MCUCR|=(1<<PUD);
DDRC=0xFF;
PORTC=0xFF;
// PORTC&=~(1<<PC0);
// PORTC&=~(1<<PC1);
// PORTC&=~(1<<PC5);
PORTC&=~(1<<PC2);
}
void timer1_init(void)
{
TCNT1H=0xFF;
TCNT1L=0xaa;//0x83
TCCR1B|=(1<<CS11)|(1<<CS10);
}
void int_ctrl(void)
{
sei();
TIMSK1|=(1<<TOIE1);
}
void sys_init(void)
{
port_init();
timer1_init();
int_ctrl();
hw_time_ms=0;
}
void channel_1()
{
if(qt_measure_data.qt_touch_status.sensor_states[0]&0x01)
{
PORTC|=(1<<PC2);
//PORTC|=(1<<PC0);
}
}
void channel_2()
{
if(qt_measure_data.qt_touch_status.sensor_states[0]&0x02)
{
PORTC&=~(1<<PC2);
//PORTC|=(1<<PC2);
//PORTC|=(1<<PC1);
}
}
void channel_3()
{
if(qt_measure_data.qt_touch_status.sensor_states[0]&0x04)
{
PORTC&=~(1<<PC2);
//PORTC|=(1<<PC2);
//PORTC|=(1<<PC5);
}
}
int main(void)
{
sys_init();
qt_reset_sensing();
qt_enable_key(CHANNEL_0, NO_AKS_GROUP, 10, HYST_25);
// qt_enable_key(CHANNEL_2, AKS_GROUP_1, RECAL_12_5, HYST_6_25);
qt_enable_key(CHANNEL_4, NO_AKS_GROUP, 10, HYST_25);
qt_enable_key(CHANNEL_2, NO_AKS_GROUP, 10, HYST_25);//HYST_25
qt_init_sensing();
while(1)
{
if(qt_measure_flag)
{
qt_measure_flag=0;
qt_measure_sensors(hw_time_ms);
//hw_time_ms=0;
channel_1();
channel_2();
channel_3();
//delay(100);
}
}
} |
|