cc2541 周期性事件performPeriodicTask方法中写的处理,发现定时不准,是什么原因

static void performPeriodicTask(void) {
// Read Adc Value
HalAdcSetReference(HAL_ADC_REF_AVDD);
lux = HalAdcRead(HAL_ADC_CHN_AIN7, HAL_ADC_RESOLUTION_12) & 0x07ff;
timevr = HalAdcRead(HAL_ADC_CHN_AIN4, HAL_ADC_RESOLUTION_12) & 0x07ff;
luxvr = HalAdcRead(HAL_ADC_CHN_AIN5, HAL_ADC_RESOLUTION_12) & 0x07ff;
tmrcnt++;

/***************************************************************
*tmrcnt=1s
*if (tmrcnt == 10) {
*ON_OFF = 1;
*} else if (tmrcnt == 20) {
*ON_OFF = 0;
*}
*/

if (load_state == ON) {
RelayONOff(1);
} else if (load_state == OFF) {
RelayONOff(0);
}

if(worhing_state==OFF)
{
//LED_ON;
if(tmrcnt==5)
{
load_state_OFF;
worhing_state_ON;
//LED_OFF;
check_pir_ON;
}
}
if(worhing_state==NC)
{
if(tmrcnt==1) worhing_state_ON;
}
if(worhing_state==ON)
{
if(load_state==OFF)
{
if(P0_0==ON)
{
if(lux>=luxvr){
settime=Read_ADC_temp_level(timevr);
//LED_ON;
load_state_ON;
check_pir_OFF;
tmrcnt=0;
}
}
else tmrcnt=0;
}
else
{
if(check_pir==OFF)
{
if(tmrcnt==2)
{
//LED_OFF;
}
else if(tmrcnt==4)
{
check_pir_ON;
}
}
else
{
if(P0_0==ON)
{
//LED_ON;
check_pir_OFF;
tmrcnt=0;
}
}
if((tmrcnt==settime)&&(tmrcnt!=0))
{
load_state_OFF;
check_pir_OFF;
worhing_state_NC;
tmrcnt=0;
}
}
}
}

10 个回复