用pic12f675,发现程序进入到else if(result1<=982)执行完后,需要很长时间才能再进来。
求大神看看程序哪里有问题。。。。
void main()
{
set_tris_a (0x1d); //01 1101 A1 A5输出口
setup_wdt(WDT_72MS);
//ADC初始化
setup_adc_ports(sAN0|sAN2|sAN3|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2|RTCC_8_BIT);
setup_timer_1 (T1_INTERNAL|T1_DIV_BY_2);
//enable_interrupts(INT_TIMER1); //启动定时器1
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
while(1)
{
//SW1_H();
//delay_ms(10);
SW1_L();
//OUT_H();
SET_ADC_CHANNEL(0);
//delay_ms(500);
//result1=(READ_ADC(ADC_START_AND_READ)+READ_ADC(ADC_START_AND_READ)+READ_ADC(ADC_START_AND_READ)+READ_ADC(ADC_START_AND_READ))>>2;
//delay_ms(50);
result1=READ_ADC(ADC_START_AND_READ);
if(result1>982)//BT 14.4V
//if(result1<982)
{
SW1_L();
result1=(READ_ADC(ADC_START_AND_READ)+READ_ADC(ADC_START_AND_READ)+READ_ADC(ADC_START_AND_READ)+READ_ADC(ADC_START_AND_READ))>>2;
if(result1>982)
{
SW1_L();
}
}
else if(result1<=982)
{
enable_interrupts(INT_TIMER1);
while(time2<jishu)
{
SW1_H();
//OUT_L();
//delay_ms(100);
//enable_interrupts(INT_TIMER1);
}
time2=0;
}
}
} |