if (ADCON & 0x10)//ADC1
{
if (adc_cnt & 0xc0)//adc_cnt>63
{
ADCON = 0x01;
adc_cnt = 0;
sen_val = adc_val_buf;
//delay wait for A/D channel to be stable
cur_temp=(int)tar_temp+(int)(adc_val_buf>>6)-(int)(tar_adv>>6);
if (flag.t_stb==0 && tmr_delay==0)
{
if (cur_temp42)cur_temp++;
else if (cur_temp>cur_temp && (sen_val&63)<21)cur_temp--;
DispValue(cur_temp);
if (tar_temp==cur_temp)flag.t_stb=1;
}
else if (cur_temp>tar_temp+5 || cur_temp
{
flag.t_stb=0;
}
//Calculate the P of PID
p_pid=(int)(tar_adv>>4)-(int)(sen_val>>4);
adc_val_buf=0;
}
else ADCON |= 0x01;//Start A/D Convert
}
else//ADC0
{
if (adc_cnt & 0xf0)//adc_cnt>15
{
uint buf16;
ADCON=0x11;//ADCON ^= 0x10;
adc_cnt = 0;
buf16 = adc_val_buf>>4;
//delay wait for A/D channel to be stable
if (vr_val>buf16+2 || vr_val+2
{
vr_val=buf16;
buf16=( (buf16<<4)+(buf16<<3)+buf16+(buf16>>3)>>6 )+100;//( (vr_val>>1)+(vr_val>>2)+(vr_val>>4)>>1 )
if (buf16>500)buf16=500;
tar_temp=buf16;
DispValue(buf16);
buf16-=100;
if ( (buf16&31)<16 )tar_adv=temp_tab[buf16>>5]+((buf16&31)<<6);
else tar_adv=temp_tab[buf16+32>>5]-(32-(buf16&31)<<6);
tmr_delay=4;
flag.t_stb=0;
}
adc_val_buf=0;
}
else ADCON |= 0x01;//Start A/D Convert
}
//=================================================
if (sw_power!=0 && sen_val<0x21E5)
{
union a period;uchar p2_buf=0x20;
P0=0;P2=0x20;
Relay_off;
while (sw_power)
{
wdt_feed;
if (++period.u16r==0)p2_buf ^= 0x20;
if (period.u8r.l
else P2 = p2_buf^0x20;
}
flag.t_stb=0;
Relay_on;
}
}
}
//======================
#pragma vector=0x00
__interrupt void int_9454()//T0 10ms/cycle
{
int Heat_duty,s16buf,d_pid;//
signed char s8buf,i_pid;
//中断服务程序
T0CON = T0CON & 0xfe;
//BTCON = 0x2;
if (++tmr>4)//50ms
{
tmr=0;
tmr_sec++;
if (tmr_sec>9)//0.5s
{
tmr_sec=0;
if (tmr_delay>0)tmr_delay--;
if ((P2&1)==0)
{
if (flag.t_stb!=0 && ++delay_sleep>119)//60/0.5=120
{
flag.d_slp=1;
flag.t_stb=0;
}
}
else {delay_sleep=0;flag.d_slp=0;}
//Calculate the I of PID
s8buf = ip_sum>>3;
if (s8buf+p_pid>100)s8buf=100;
else if (s8buf+p_pid<0)s8buf=0;
else s8buf += p_pid;
ip_sum = ip_sum + s8buf - ip_tab[ip_cnt];
ip_tab[ip_cnt++]=s8buf;
ip_cnt &= 7;
}
//Calculate the D of PID
if (last_sev
else {s16buf=last_sev-sen_val;s8buf=0;}
if (s16buf>127)s16buf=127;
if (s8buf)s8buf = -(signed char)s16buf;
else s8buf = (signed char)s16buf;
if (sw_power)Heat_duty=0;//
else Heat_duty=p_pid+i_pid+d_pid;//
if (Heat_duty>100)Heat_duty=100;
else if (Heat_duty<0)Heat_duty=0;
Heat_duty>>=2;
Periods_cnt++;
if (Periods_cnt>24)Periods_cnt=0;
if (Periods_cnt
else Power_off;
}