标题:
汽车空调控制器单片机程序
[打印本页]
作者:
sedation588
时间:
2018-3-14 16:00
标题:
汽车空调控制器单片机程序
汽车空调程序
单片机源程序如下:
//
#include "gw801.h"
void interrupt timer1(void)//中断服务程序
{
if(TMR1IF)//timer
{
wdcheck=wdcheck|0x80;
TMR1IF=0;
TMR1H=0xf6;
TMR1L=0x3b;
T1CON=T1CON|0x30;
kbit=1;
// LED_RDEF=!LED_RDEF;
if(tmr_delay>0) tmr_delay--;
if(tmr_ccpr>0) tmr_ccpr--;
if(tempdtmr>0) tempdtmr--;
if(tempsttmr>0) tempsttmr--;
if(modedtmr>0) modedtmr--;
if(modesttmr>0) modesttmr--;
if(intakesttmr>0) intakesttmr--;
if(mem_tmr>0) mem_tmr--;
if(tmr_test>0) tmr_test--;
if(((amb<30)||(amb>1000))&&(tmr_amb_error<1000)) tmr_amb_error++;
else if(((amb>30)&&(amb<1000))&&(tmr_amb_error>0)) tmr_amb_error--;
if(((incar<30)||(incar>1000))&&(tmr_incar_error<1000)) tmr_incar_error++;
else if(((incar>30)&&(incar<1000))&&(tmr_incar_error>0)) tmr_incar_error--;
if(((evap<30)||(evap>1000))&&(tmr_evap_error<1000)) tmr_evap_error++;
else if(((evap>30)&&(evap<1000))&&(tmr_evap_error>0)) tmr_evap_error--;
if(((tempfb<5)||(tempfb>250))&&(tmr_temp_error<1000)) tmr_temp_error++;
else if(((tempfb>5)&&(tempfb<250))&&(tmr_temp_error>0)) tmr_temp_error--;
if(((modefb<5)||(modefb>250))&&(tmr_mode_error<1000)) tmr_mode_error++;
else if(((modefb>5)&&(modefb<250))&&(tmr_mode_error>0)) tmr_mode_error--;
if(tmr_system>0) tmr_system--;
else
{
tmr_system=500;
adj|=0x3f;
}
if(sensor_adtimer!=0) sensor_adtimer--;
else
{
sensor_adtimer=50;
adj|=0x20;
}
}
}
//==========================
void port_init(void)
{
__CONFIG(0x0f7c);
__CONFIG(0xcaff);
OSCCON=0x73; //IRCF2-0:101=2M 110=4M 111=8M SCS=1 由内部时钟作为震荡器
LCDREF=0x00;
T0CS=0;
CM1CON0=0X00; //关闭比较寄存器
CM2CON0=0X00; //关闭比较寄存器
WDTCON=0x12; //1024分平 2*10/2*5=2*5=32ms
PSA=0; //将欲分频 分配给定时器0
SWDTEN=1; //启动WDT ???
TRISA=0xb3;
PORTA=0x4c;
TRISB=0xfe;
PORTB=0x01;
TRISC=0xbb;
PORTC=0x00;
TRISD=0x00;
PORTD=0xfe;
TRISE=0x00;
PORTE=0x03;
TRISF=0xe2;
PORTF=0xed;
TRISG=0xf0;
PORTG=0x00;
}
//==========================
void pwm_init(void)
{
CCPTMRS0=0x3c; //ccp1:tmr2,ccp3:tmr2
CCPTMRS1=0x03; //ccp1:tmr2,ccp3:tmr2
PR2=0x80;//====PWM周期:2M/64=31.25K
CCPR1L=126;
blowernow=126;
blowertg=126;
CCPR4L=10;
T2CON=0x6;//T2 ON ,PRESCALE 16,POSTSCALE 1
CCP1CON=0x0f;//设定CCP1为pwm mode
CCP4CON=0x0f;//设定CCP3为pwm mode
CCP2CON=0x05;//设定CCP3为capture mode
TMR2IE=0;//定时器2中断:不允许
}
//==========================
void ad_init(void)
{ //由ADCON1.ADCS2和ADCON0.ADCS0,ADCON0.ADCS1确定分频=FOSC/16
ANSELA=0x03; //配置模拟输入口
ANSELE=0x00;
ANSELF=0xe2; //配置模拟输入口
ANSELG=0x10; //配置模拟输入口
ADCON0=0x01; //ADFM=1(right),Vref-=Vss,Vref+=Vdd,GO/DOWN=0,ADON=0
ADCON1=0xa0;
}
//==========================
void int_init(void)
{
INTCON=0x0; //全局中断、外部设备禁止
TMR1H=0xf6;
TMR1L=0x3b;
T1CON=0x10;
TMR1IF=0; //清TMR1溢出标志
TMR1IE=1; //允许TMR1中断
TMR1ON=1; //star TMR1
CCP1IE=0; //不允许捕获 比较
PEIE=1; //允许外设中断
GIE=1; //全局中断、外部设备允许
}
//===================================
void comm_init (void)
{
TRISC7=1;
TRISC6=0;
TX1STA=0x20;
SP1BRGL=0x33;//2400bpr
RC1STA=0x90;
RCIE=0;//接收中断允许
PEIE=1;//
GIE=1; //
}
//==========================
void ad_sample(void)
{
switch(channel)
{
case 0:
ADCON0=0x01;//channel=0
nop();
nop();
nop();
nop();
GO_nDONE=1;
while(GO_nDONE) continue;
amb=((ADRESH*256)+ADRESL)&0x03ff;
channel=1;
break;
case 1:
ADCON0=0x05;//channel=1
nop();
nop();
nop();
nop();
GO_nDONE=1;
while(GO_nDONE) continue;
modefb=(((ADRESH*256)+ADRESL)&0x03ff)>>2;
channel=2;
break;
case 2:
ADCON0=0x15;//channel=5
nop();
nop();
nop();
nop();
GO_nDONE=1;
while(GO_nDONE) continue;
incar=(((ADRESH*256)+ADRESL)&0x03ff);
channel=3;
break;
case 3:
ADCON0=0x19;//channel=6
nop();
nop();
nop();
nop();
GO_nDONE=1;
while(GO_nDONE) continue;
ig=((((ADRESH*256)+ADRESL)&0x03ff));
channel=4;
break;
case 4:
ADCON0=0x29;//channel=10
nop();
nop();
nop();
nop();
GO_nDONE=1;
while(GO_nDONE) continue;
blowerfb=((ADRESH*256)+ADRESL)&0x03ff;
channel=5;
break;
case 5:
ADCON0=0x2d;//channel=11
nop();
nop();
nop();
nop();
GO_nDONE=1;
while(GO_nDONE) continue;
evap=((ADRESH*256)+ADRESL)&0x03ff;
channel=6;
break;
case 6:
ADCON0=0x31;//channel=12
nop();
nop();
nop();
nop();
GO_nDONE=1;
while(GO_nDONE) continue;
tempfb=(((ADRESH*256)+ADRESL)&0x03ff)>>2;
channel=0;
break;
default:
channel=0;
break;
}
}
//==========================
void tavgw_CONVERT(void)
{
signed char dif;
signed int i;
i=tavg_wstable-tavg;
if(i>40)
dif=tavgw_table[80];
else if(i<-40)
dif=tavgw_table[0];
else
dif=tavgw_table[i+40];
tavg_w=tavg_wstable+dif;
}
//==========================
void tavg_CONVERT(void)
{
signed char i;
if(tamb>30) i=-1;
else if(tamb>20) i=-1;
else if(tamb>10) i=-1;
else if(tamb>-0) i=-2;
else if(tamb>-10) i=-3;
else if(tamb>-20) i=-3;
else i=-3;
tavg=(tinc+i)*2;
}
//==========================
signed int evapSENSOR_CONVERT(unsigned int vol)
{
unsigned int i;
signed int thermo;
if(vol>910) thermo=-30;
else if(vol<229) thermo=60;
else
{
i=90;
do
{
i--;
} while(vol>=evapsensor_table[i]);
thermo=i-30;
}
return thermo;
}
//==========================
signed int ambSENSOR_CONVERT(unsigned int vol)
{
unsigned int i;
signed int thermo;
if(vol>958) thermo=-30;
else if(vol<252) thermo=60;
else
{
i=90;
do
{
i--;
} while(vol>=ambsensor_table[i]);
thermo=i-30;
}
return thermo;
}
//==========================
signed int incarSENSOR_CONVERT(unsigned int vol)
{
unsigned int i;
signed int thermo;
if(vol>956) thermo=-30;
else if(vol<254) thermo=60;
else
{
i=90;
do
{
i--;
} while(vol>=incarsensor_table[i]);
thermo=i-30;
}
return thermo;
}
//==========================
signed int tout_CONVERT(signed int vol1,unsigned char vol2,signed int vol3)//tout(tamb,tidef_effect,tavg_w)
{
signed int thermo;
signed long int k;
signed long int b;
k=((vol1*7)/10)+190;
b=-(95*vol1)-850;
thermo=(signed long int)(k*(vol3-vol2)+(b*2))/20;
return thermo;
}
//==========================
void sensor_init(void)
{
unsigned char i;
for(i=0;i<4;i++)
{amb_table[i]=amb;}
tamb=ambSENSOR_CONVERT(amb);
for(i=0;i<4;i++)
{incar_table[i]=incar;}
tinc=incarSENSOR_CONVERT(incar);
for(i=0;i<4;i++)
{evap_table[i]=evap;}
tevap=evapSENSOR_CONVERT(evap);
tavg_CONVERT();
tavg_wstable=tset*2;
tavgw_CONVERT();
tout=tout_CONVERT(tamb,tidef_effect,tavg_w);
spi_data|=SENSOR_ON;
adj|=0x3f;
}
//================================
void error_test(void)
{
if(tmr_incar_error>500) {tinc=20;error_mode|=0x01;}
else error_mode&=0xfe;
if(tmr_amb_error>500) {tamb=20;error_mode|=0x02;}
else error_mode&=0xfd;
if(tmr_evap_error>500) {tevap=-2;error_mode|=0x04;}
else error_mode&=0xfd;
if(tmr_mode_error>500)error_mode|=0x08;
else error_mode&=0xfb;
if(tmr_temp_error>500)error_mode|=0x10;
else error_mode&=0xf7;
}
//================================
void sensor_process(void)
{
unsigned char i=0;
signed int sum;
spi_data|=SENSOR_ON;
if(adj&0x20)
{
for(i=0;i<3;i++) //amb
{amb_table[i]=amb_table[i+1];}
amb_table[3]=amb;
sum=0;
for(i=0;i<4;i++)
{sum=sum+amb_table[i];}
sum=sum/4;
tamb=ambSENSOR_CONVERT(sum);
for(i=0;i<3;i++) //incar
{evap_table[i]=evap_table[i+1];}
evap_table[3]=evap;
sum=0;
for(i=0;i<4;i++)
{sum=sum+evap_table[i];}
sum=sum/4;
tevap=evapSENSOR_CONVERT(sum);
for(i=0;i<3;i++) //incar
{incar_table[i]=incar_table[i+1];}
incar_table[3]=incar;
sum=0;
for(i=0;i<4;i++)
{sum=sum+incar_table[i];}
sum=sum/4;
tinc=incarSENSOR_CONVERT(sum);
error_test();
tavg_CONVERT();
tavg_wstable=tset*2;
tavgw_CONVERT();
tout=tout_CONVERT(tamb,tidef_effect,tavg_w);
adj&=0xdf;
}
}
//==========================
unsigned int LOOP_LS166(void)
{
unsigned char jjj;
jjj=0xff;
if(KEY_OFF==0) jjj&=KOFF;
if(KEY_AUTO==0) jjj&=KAUTO;
if(KEY_REC==0) jjj&=KREC;
if(KEY_AC==0) jjj&=KAC;
if(KEY_DEF==0) jjj&=KDEF;
return jjj;
}
//====================================================
void key_scan(void)
{
keynew=LOOP_LS166();
if(kbit>0)
{
if(keynew!=0xff)
{
if(keyold==keynew)
{
keyyear++;
if(!response)
{
if(keynew==KTEST)
{
if(keyyear>=KEY_TIMELONG)
{
keyyear=0;
response=1;
keycom=keyold;
}
}
else if(keyyear>=KEY_TIME)
{
keyyear=0;
response=1;
keycom=keyold;
}
}
else
{
keyyear=0;
keycom=0xff;
}
}
else
{
response=0;
keyold=keynew;
keyyear=0;
}
}
else
{
keyold=keynew;
response=0;
keyyear=0;
}
kbit=0;
}
}
//==========================
void key_process (void)
{
if(keycom!=0xff)
{
mem_tmr=20;
memflag=1;
adj|=0x3f;
if(test_mode)
{
switch(keycom)
{
case KAUTO:
test_mode=0;
break;
default:
break;
}
}
else
{
switch(keycom)
{
case KAC:
if(sys_mode&0x80)
{
sys_mode&=0x77;
ac_func&=0x7f;
ac_func|=0x08;
ac_old=ac_func;
}
else
{
sys_mode&=0xf7;
ac_func&=0x7f;
if(ac_func&0x08) ac_func&=0xf7;
else ac_func|=0x08;
ac_old=ac_func;
}
break;
case KDEF:
if(sys_mode&0x80)
{
sys_mode&=0x7f;
if(mode_func!=0x04)
{
mode_old=mode_func;
ac_old=ac_func;
blower_old=blower_func;
intake_old=intake_func;
}
mode_func=0x4;
blower_func=0x07;
intake_func=0x01;
ac_func=0x08;
break;
}
else
{
if(mode_func!=4)
{
mode_old=mode_func;
ac_old=ac_func;
blower_old=blower_func;
intake_old=intake_func;
mode_func=0x4;
blower_func=0x07;
intake_func=0x01;
ac_func=0x08;
}
else
{
mode_func=mode_old;
blower_func=blower_old;
intake_func=intake_old;
ac_func=ac_old;
}
}
break;
case KREC:
sys_mode&=0xf7;
if((intake_func&0x7f)==0x00) intake_func=0x01;
else intake_func=0x00;
intake_old=intake_func;
break;
case KOFF:
sys_mode|=0X80;
break;
case KAUTO:
sys_mode=0x08;
mode_func|=0x80;
blower_func|=0x80;
ac_func|=0x80;
intake_func|=0x80;
break;
case KTEST:
test_mode=1;
tmr_test=0;
break;
default:
keycom=0xff;
break;
}
}
}
keycom=0xffff;
}
//==========================
void temp_scan(void)
{
KEY_TUP=1;
if(KEY_TUP==1)
{temp_scan1=1;tmr_tup=0;}
if((KEY_TUP==0)&&(temp_scan1==1))
{
tmr_tup++;
if(tup==0)
{
if((tmr_tup>KEYT_TIME)&&(keycom1==0xff))
{
tmr_tup=0;
keycom1=0;
tup=1;
}
}
else
{
tmr_tup=0;
keycom1=0xff;
}
}
else
{
tmr_tup=0;
tup=0;
}
KEY_TDN=1;
if(KEY_TDN==1)
{temp_scan2=1;tmr_tdn=0;}
if((KEY_TDN==0)&&(temp_scan2==1))
{
tmr_tdn++;
if(tdn==0)
{
if((tmr_tdn>KEYT_TIME)&&(keycom2==0xff))
{
tmr_tdn=0;
keycom2=0;
tdn=1;
}
}
else
{
tmr_tdn=0;
keycom2=0xff;
}
}
else
{
tmr_tdn=0;
tdn=0;
}
KEY_MUP=1;
if(KEY_MUP==1)
{mode_scan1=1;tmr_mup=0;}
if((KEY_MUP==0)&&(mode_scan1==1))
{
tmr_mup++;
if(mup==0)
{
if((tmr_mup>KEYT_TIME)&&(keycom5==0xff))
{
tmr_mup=0;
keycom5=0;
mup=1;
}
}
else
{
tmr_mup=0;
keycom5=0xff;
}
}
else
{
tmr_mup=0;
mup=0;
}
KEY_MDN=1;
if(KEY_MDN==1)
{mode_scan2=1;tmr_mdn=0;}
if((KEY_MDN==0)&&(mode_scan2==1))
{
tmr_mdn++;
if(mdn==0)
{
if((tmr_mdn>KEYT_TIME)&&(keycom6==0xff))
{
tmr_mdn=0;
keycom6=0;
mdn=1;
}
}
else
{
tmr_mdn=0;
keycom6=0xff;
}
}
else
{
tmr_mdn=0;
mdn=0;
}
KEY_BUP=1;
if(KEY_BUP==1)
{blow_scan1=1;tmr_bup=0;}
if((KEY_BUP==0)&&(blow_scan1==1))
{
tmr_bup++;
if(bup==0)
{
if((tmr_bup>KEYT_TIME)&&(keycom3==0xff))
{
tmr_bup=0;
keycom3=0;
bup=1;
}
}
else
{
tmr_bup=0;
keycom3=0xff;
}
}
else
{
tmr_bup=0;
bup=0;
}
KEY_BDN=1;
if(KEY_BDN==1)
{blow_scan2=1;tmr_bdn=0;}
if((KEY_BDN==0)&&(blow_scan2==1))
{
tmr_bdn++;
if(bdn==0)
{
if((tmr_bdn>KEYT_TIME)&&(keycom4==0xff))
{
tmr_bdn=0;
keycom4=0;
bdn=1;
}
}
else
{
tmr_bdn=0;
keycom4=0xff;
}
}
else
{
tmr_bdn=0;
bdn=0;
}
if((keycom1==0)&&(test_mode==0))
{
if(!(sys_mode&0x80))
{
if((sys_mode&0x03)==0x01)
{
if(mode_func!=0x04)
{
mode_func=mode_old;
blower_func=blower_old;
intake_func=intake_old;
ac_func=ac_old;
}
tset=20;
sys_mode&=0xfc;
}
else if(tset<30) tset=tset+2;
else if((sys_mode&0x03)==0x02);
else //hi
{
sys_mode=(sys_mode&0xfc)|0x02;
if(mode_func!=0x04)
{
mode_old=mode_func;
ac_old=ac_func;
blower_old=blower_func;
intake_old=intake_func;
mode_func=0x2;
blower_func=0x07;
intake_func=0x01;
ac_func=0x00;
}
}
adj|=0x3f;
}
mem_tmr=20;
memflag=1;
}
keycom1=0xff;
if((keycom2==0)&&(test_mode==0))
{
if(!(sys_mode&0x80))
{
if((sys_mode&0x03)==0x02)
{
if(mode_func!=0x04)
{
mode_func=mode_old;
blower_func=blower_old;
intake_func=intake_old;
ac_func=ac_old;
}
tset=30;
sys_mode&=0xfc;
}
else if(tset>20) tset=tset-2;
else if((sys_mode&0x03)==0x01);
else //lo
{
sys_mode=(sys_mode&0xfc)|0x01;
if(mode_func!=0x04)
{
mode_old=mode_func;
ac_old=ac_func;
blower_old=blower_func;
intake_old=intake_func;
mode_func=0x0;
blower_func=0x07;
intake_func=0x00;
ac_func=0x08;
}
}
adj|=0x3f;
}
mem_tmr=20;
memflag=1;
}
keycom2=0xff;
if((keycom3==0)&&(test_mode==0))
{
if(!(sys_mode&0x80))
{
sys_mode&=0xf7;
blower_func&=0x7f;
if(blower_func<8) blower_func++;
blower_old=blower_func;
adj|=0x3f;
}
else sys_mode&=0x7f;
mem_tmr=20;
memflag=1;
}
keycom3=0xff;
if((keycom4==0)&&(test_mode==0))
{
if(!(sys_mode&0x80))
{
sys_mode&=0xf7;
blower_func&=0x7f;
if(blower_func>1) blower_func--;
blower_old=blower_func;
adj|=0x3f;
}
else sys_mode&=0x7f;
mem_tmr=20;
memflag=1;
}
keycom4=0xff;
if((keycom5==0)&&(test_mode==0))
{
if(sys_mode&0x80)
{
sys_mode&=0x7f;
}
else
{
if(mode_func==0x04)
{
mode_func=mode_old;
blower_func=blower_old;
intake_func=intake_old;
ac_func=ac_old;
}
else
{
sys_mode&=0xf7;
mode_func&=0x7f;
if(mode_func<3) mode_func++;
mode_old=mode_func;
}
}
mem_tmr=20;
memflag=1;
}
keycom5=0xff;
if((keycom6==0)&&(test_mode==0))
{
if(sys_mode&0x80)
{
sys_mode&=0x7f;
}
else
{
if(mode_func==0x04)
{
mode_func=mode_old;
blower_func=blower_old;
intake_func=intake_old;
ac_func=ac_old;
}
else
{
sys_mode&=0xf7;
mode_func&=0x7f;
if(mode_func>0) mode_func--;
mode_old=mode_func;
}
}
mem_tmr=20;
memflag=1;
}
keycom6=0xff;
}
//==========================
void ac_drv(void)
{
if((sys_mode&0x80)==0x00)
{
if((ac_func&0x80)&&(!(sys_mode&0x03)))
{
if(adj&0x01)
{
if(tamb>=((tout-20)/10)) ac_func|=0x08;
if(tamb<((tout-40)/10)) ac_func&=0xf7;
adj&=0xfe;
}
}
if(tamb<0) ac_func&=0xf7;
if(ac_func&0x08)
{
ac_func|=0x01;
}
else ac_func&=0xfe;
}
else ac_func&=0xfe;
if(ac_func&0x01)
{
spi_data|=AC_ON;
}
else
{
spi_data&=AC_OFF;
}
}
//==========================
void intake_proc(void)
{
if(!(sys_mode&0x80))
{
if((intake_func&0x80)&&(!(sys_mode&0x03)))
{
if((adj&0x08)&&(!(sys_mode&0x20)))
{
if(ac_func&0x08) intake_func=0x80; //内循环
else intake_func=0x81;
adj&=0xf7;
}
}
}
}
//==========================
void mode_proc(void) //tout<29vent,tout>31mix
{
if(!(sys_mode&0x80))
{
if((mode_func&0x80)&&(!(sys_mode&0x03)))
{
if(adj&0x02)
{
if(tout<=290) mode_func=0x80;//vent
if((tout>=310)&&(tout<=360)) mode_func=0x81;//bi
if(tout>=380) mode_func=0x82;//foot
if((tout<310)&&(tout>290))
{if((mode_func!=0x80)&&(mode_func!=0x81))
mode_func=0x80;}
if((tout<380)&&(tout>360))
{if((mode_func!=0x82)&&(mode_func!=0x81))
mode_func=0x82;}
adj&=0xfd;
}
}
modetg=mode_table[mode_func&0x7];
}
}
//==========================
unsigned char Angle_convet(signed int t1,signed int t2,unsigned char a1,unsigned char a2,signed int t3)
{
signed long int k;
signed long int b;
signed char a3;
signed long int i;
//k=((a2-a1)*1000)/(t2-t1);
k=(signed long int)a2-a1;
k=k*100;
i=t2-t1;
k=k/i;
b=(signed long int)a1*100;
i=(signed long int)k*t1;
b=b-i;
a3=((k*t3)+b)/100;
return a3;
}
//==========================
void temp_proc(void)
{
unsigned char i;
signed char j;
signed int tout1;
signed int tout2;
signed int tout3;
signed int tout4;
signed int tout5;
signed int tout6;
if(ac_func&0x01)
{
tevap=5;
}
else if(intake_func&0x7f)
{
tevap=tamb+2;
}
else
{
tevap=tinc+2;
}
if(!(sys_mode&0x80))
{
if((sys_mode&0x03)==0x01) temptg=TEMP_MAX; //cool
else if((sys_mode&0x03)==0x02) temptg=TEMP_MIN; //heat
else if(adj&0x10)
{
if(tevap<=-20)
{i=0;j=-30;}
else if(tevap<=-10)
{i=6;j=-20;}
else if(tevap<=0)
{i=12;j=-10;}
else if(tevap<=10)
{i=18;j=0;}
else if(tevap<=20)
{i=24;j=10;}
else if(tevap<=30)
{i=30;j=20;}
else
{i=36;j=30;}
if((mode_func&0xf)<=1)
{
tout1=((atempvent_table[i+6]-atempvent_table[i])*(tevap-j))/10+atempvent_table[i];
tout2=((atempvent_table[i+7]-atempvent_table[i+1])*(tevap-j))/10+atempvent_table[i+1];
tout3=((atempvent_table[i+8]-atempvent_table[i+2])*(tevap-j))/10+atempvent_table[i+2];
tout4=((atempvent_table[i+9]-atempvent_table[i+3])*(tevap-j))/10+atempvent_table[i+3];
tout5=((atempvent_table[i+10]-atempvent_table[i+4])*(tevap-j))/10+atempvent_table[i+4];
tout6=((atempvent_table[i+11]-atempvent_table[i+5])*(tevap-j))/10+atempvent_table[i+5];
}
else
{
tout1=((atempfoot_table[i+6]-atempfoot_table[i])*(tevap-j))/10+atempfoot_table[i];
tout2=((atempfoot_table[i+7]-atempfoot_table[i+1])*(tevap-j))/10+atempfoot_table[i+1];
tout3=((atempfoot_table[i+8]-atempfoot_table[i+2])*(tevap-j))/10+atempfoot_table[i+2];
tout4=((atempfoot_table[i+9]-atempfoot_table[i+3])*(tevap-j))/10+atempfoot_table[i+3];
tout5=((atempfoot_table[i+10]-atempfoot_table[i+4])*(tevap-j))/10+atempfoot_table[i+4];
tout6=((atempfoot_table[i+11]-atempfoot_table[i+5])*(tevap-j))/10+atempfoot_table[i+5];
}
if(tout<=tout1) temptg=TEMP_MAX;//coo
else if(tout<=tout2)temptg=Angle_convet(tout1,tout2,ATEMP1,ATEMP2,tout);
else if(tout<=tout3)temptg=Angle_convet(tout2,tout3,ATEMP2,ATEMP3,tout);
else if(tout<=tout4)temptg=Angle_convet(tout3,tout4,ATEMP3,ATEMP4,tout);
else if(tout<=tout5)temptg=Angle_convet(tout4,tout5,ATEMP4,ATEMP5,tout);
else if(tout<=tout6)temptg=Angle_convet(tout5,tout6,ATEMP5,ATEMP6,tout);
else temptg=TEMP_MIN;//hot
adj&=0xef;
}
}
}
//==========================
void blower_proc(void)
{
signed char i;
signed char j;
unsigned char l;
unsigned char blowertg1;
unsigned char blowertg2;
if(!(sys_mode&0x80))
{
if((blower_func&0x80)&&(!(sys_mode&0x03)))
{
if(adj&0x04)
{
l=(((tset*2)-tidef_effect)/2)-10;
if(tamb>=40)
{
blowertg1=blow_autotable40[l];
blowertg2=blow_autotable40[l];
i=40;
j=40;
}
else if(tamb>=30)
{
blowertg1=blow_autotable40[l];
blowertg2=blow_autotable30[l];
i=30;
j=40;
}
else if(tamb>=20)
{
blowertg1=blow_autotable30[l];
blowertg2=blow_autotable20[l];
i=20;
j=30;
}
else if(tamb>=10)
{
blowertg1=blow_autotable20[l];
blowertg2=blow_autotable10[l];
i=10;
j=20;
}
else if(tamb>=0)
{
blowertg1=blow_autotable10[l];
blowertg2=blow_autotable0[l];
i=0;
j=10;
}
else if(tamb>=-10)
{
blowertg1=blow_autotable0[l];
blowertg2=blow_autotablen10[l];
i=-10;
j=0;
}
else if(tamb>=-20)
{
blowertg1=blow_autotablen10[l];
blowertg2=blow_autotablen20[l];
i=-20;
j=-10;
}
else
{
blowertg1=blow_autotablen20[l];
blowertg2=blow_autotablen30[l];
i=-30;
j=-20;
}
if(blowertg1>=blowertg2)
blowertg=blowertg2+((abs_delta(blowertg1,blowertg2)*(tamb-i))/10);
else
blowertg=blowertg1+((abs_delta(blowertg1,blowertg2)*(j-tamb))/10);
adj&=0xfb;
}
i=6;
do
{
i--;
} while(blowertg>blow_table[i]);
blower_func=(i+2)|0x80;
if(blower_func>=0x87) blower_func=0x86;
}
}
}
//==========================
void blower_drv(void)
{
if(sys_mode&0x80)
{
CCPR1L=110;
blowernow=110;
blowertg=110;
BLC=0;
spi_data&=HS_OFF;
}
else if(blower_func&0x80)
{
BLC=1;
spi_data&=HS_OFF;
}
else if((blower_func&0x7f)==8)
{
blowertg=0;
BLC=1;
if(CCPR1L==0)
spi_data|=HS_ON;
else spi_data&=HS_OFF;
}
else
{
blowertg=blow_table[(blower_func&0x7f)-1];
BLC=1;
spi_data&=HS_OFF;
}
if (tmr_ccpr==0)
{
if(blowernow<blowertg) blowernow++;
else if(blowernow>blowertg) blowernow--;
if(CCPR1L!=blowernow) CCPR1L=blowernow;
tmr_ccpr=5;
}
}
//==========================
void temp_drv(void)
{
unsigned char tempmin;
unsigned char tempmax;
if((TEMP_MAX-temptg)>30) tempmax=temptg+30;
else tempmax=TEMP_MAX;
if((temptg-TEMP_MIN)>30) tempmin=temptg-30;
else tempmin=TEMP_MIN;
switch (tempws_mode)
{
case 0:
temptgn=temptg;
if (temptgn>temptgo)
{
tempsttmr=STALLTMR;
tempws_mode=1;
spi_data&=TOFF;
spi_data|=TUP;
temptgo=temptgn;
}
else if (temptgn<temptgo)
{
tempsttmr=STALLTMR;
tempws_mode=2;
spi_data&=TOFF;
spi_data|=TDN;
temptgo=temptgn;
}
else
{
spi_data&=TOFF;
spi_data|=TSTOP;
}
break;
case 1:
if(tempfb>tempmax)
{
tempws_mode=0;
spi_data&=TOFF;
spi_data|=TSTOP;
temptgo=tempfb;
}
else if(tempsttmr==0)
{
spi_data&=TOFF;
spi_data|=TSTOP;
tempws_mode=0;
temptgo=temptgn;
}
else if(temptg!=temptgn) tempws_mode=0;
else if (temptgn==tempfb)
{
spi_data&=TOFF;
spi_data|=TSTOP;
tempws_mode=0;
temptgo=tempfb;
}
break;
case 2:
if(tempfb<tempmin)
{
tempws_mode=0;
spi_data&=TOFF;
spi_data|=TSTOP;
temptgo=tempfb;
}
else if(tempsttmr==0)
{
spi_data&=TOFF;
spi_data|=TSTOP;
tempws_mode=0;
temptgo=temptgn;
}
else if(temptg!=temptgn) tempws_mode=0;
else if (temptgn==tempfb)
{
spi_data&=TOFF;
spi_data|=TSTOP;
tempws_mode=0;
}
break;
default:
tempws_mode=0;
break;
}
}
//==========================
void mode_drv(void)
{
unsigned char modemin;
unsigned char modemax;
if((MODE_MAX-modetg)>30) modemax=modetg+30;
else modemax=MODE_MAX;
if((modetg-MODE_MIN)>30) modemin=modetg-30;
else modemin=MODE_MIN;
switch (modews_mode)
{
case 0:
modetgn=modetg;
if (modetgn>modetgo)
{
modesttmr=STALLTMR;
modews_mode=1;
spi_data&=MOFF;
spi_data|=MUP;
modetgo=modetgn;
}
else if (modetgn<modetgo)
{
modesttmr=STALLTMR;
modews_mode=2;
spi_data&=MOFF;
spi_data|=MDN;
modetgo=modetgn;
}
else
{
spi_data&=MOFF;
spi_data|=MSTOP;
}
break;
case 1:
if(modefb>modemax)
{
modews_mode=0;
spi_data&=MOFF;
spi_data|=MSTOP;
modetgo=modefb;
}
else if(modesttmr==0)
{
spi_data&=MOFF;
spi_data|=MSTOP;
modews_mode=0;
modetgo=modetgn;
}
else if(modetg!=modetgn) modews_mode=0;
else if (modetgn==modefb)
{
spi_data&=MOFF;
spi_data|=MSTOP;
modews_mode=0;
modetgo=modefb;
}
break;
case 2:
if(modefb<modemin)
{
modews_mode=0;
spi_data&=MOFF;
spi_data|=MSTOP;
modetgo=modefb;
}
else if(modesttmr==0)
{
spi_data&=MOFF;
spi_data|=MSTOP;
modews_mode=0;
modetgo=modetgn;
}
else if(modetg!=modetgn) modews_mode=0;
else if (modetgn==modefb)
{
spi_data&=MOFF;
spi_data|=MSTOP;
modews_mode=0;
}
break;
default:
modews_mode=0;
break;
}
}
//==========================
void intake_drv(void)
{
if(intake_func!=intake_old2)
{
intakesttmr=STALLTMR;
intake_old2=intake_func;
}
/* if(intakesttmr)
{
if(intake_func)
{
spi_data&=IOFF;
spi_data|=IFRE;
}
else
{
spi_data&=IOFF;
spi_data|=IREC;
}
}
else
{
spi_data&=IOFF;
}
*/
}
//==========================
void act_drv(void)
{
}
//==========================
void EEROM_proc (void)
{
if ((memflag!=0)&&(mem_tmr==0))
{
switch (memflag)
{
case 1: {EEPROM_WRITE(0x20,tset);memflag=2;} break;
case 2: {EEPROM_WRITE(0x21,mode_func); memflag=3;} break;
case 3: {EEPROM_WRITE(0x22,intake_func); memflag=4;} break;
case 4: {EEPROM_WRITE(0x23,ac_func);memflag=5;}break;
case 5: {EEPROM_WRITE(0x24,blower_func);memflag=6;}break;
case 6: {EEPROM_WRITE(0x25,sys_mode); memflag=7;}break;
case 7: {EEPROM_WRITE(0x26,mode_old); memflag=0;}break;
default :
{memflag=0; } break;
}
}
}
//==========================
void EEPROM_init(void)
{
tset=EEPROM_READ(0x20);
if((tset<20)||(tset>30))
{
tset=24;
sys_mode=0x80;
mode_func=0;
ac_func=0;
blower_func=0x01;
intake_func=0x01;
}
else
{
mode_func=EEPROM_READ(0x21);
intake_func=EEPROM_READ(0x22);
ac_func=EEPROM_READ(0x23);
blower_func=EEPROM_READ(0x24);
sys_mode=EEPROM_READ(0x25);
}
mode_old=0x0;
ac_old=0x0;
blower_old=0x01;
intake_old=0x01;
}
//==========================
void led_drv(void)
{
if((sys_mode&0x80)==0)
{
if(ac_func&0x08)
{
LED_AC=0;
}
else LED_AC=1;
if((sys_mode&0x08)&&(mode_func!=4)) LED_AUTO=0;
else LED_AUTO=1;
if((sys_mode&0x03)==0x01) t_show=0x01;
else if((sys_mode&0x03)==0x02) t_show=0x08;
else if(tset==20) t_show=0x02;
else if(tset==22) t_show=0x03;
else if(tset==24) t_show=0x04;
else if(tset==26) t_show=0x05;
else if(tset==28) t_show=0x06;
else if(tset==30) t_show=0x07;
switch(t_show)
{
case 1:
LEDT18=0;
LEDT20=1;
LEDT22=1;
LEDT24=1;
LEDT26=1;
LEDT28=1;
LEDT30=1;
LEDT32=1;
break;
case 2:
LEDT18=1;
LEDT20=0;
LEDT22=1;
LEDT24=1;
LEDT26=1;
LEDT28=1;
LEDT30=1;
LEDT32=1;
break;
case 3:
LEDT18=1;
LEDT20=1;
LEDT22=0;
LEDT24=1;
LEDT26=1;
LEDT28=1;
LEDT30=1;
LEDT32=1;
break;
case 4:
LEDT18=1;
LEDT20=1;
LEDT22=1;
LEDT24=0;
LEDT26=1;
LEDT28=1;
LEDT30=1;
LEDT32=1;
break;
case 5:
LEDT18=1;
LEDT20=1;
LEDT22=1;
LEDT24=1;
LEDT26=0;
LEDT28=1;
LEDT30=1;
LEDT32=1;
break;
case 6:
LEDT18=1;
LEDT20=1;
LEDT22=1;
LEDT24=1;
LEDT26=1;
LEDT28=0;
LEDT30=1;
LEDT32=1;
break;
case 7:
LEDT18=1;
LEDT20=1;
LEDT22=1;
LEDT24=1;
LEDT26=1;
LEDT28=1;
LEDT30=0;
LEDT32=1;
break;
case 8:
LEDT18=1;
LEDT20=1;
LEDT22=1;
LEDT24=1;
LEDT26=1;
LEDT28=1;
LEDT30=1;
LEDT32=0;
break;
default:break;
}
switch(mode_func&0x7f)
{
case 0:
LEDVENT=0;
LEDBL=1;
LEDFOOT=1;
LEDMIX=1;
LEDDEF=1;
break;
case 1:
LEDVENT=1;
LEDBL=0;
LEDFOOT=1;
LEDMIX=1;
LEDDEF=1;
break;
case 2:
LEDVENT=1;
LEDBL=1;
LEDFOOT=0;
LEDMIX=1;
LEDDEF=1;
break;
case 3:
LEDVENT=1;
LEDBL=1;
LEDFOOT=1;
LEDMIX=0;
LEDDEF=1;
break;
case 4:
LEDVENT=1;
LEDBL=1;
LEDFOOT=1;
LEDMIX=1;
LEDDEF=0;
break;
default:break;
}
switch(blower_func&0x7f)
{
case 1:
LEDB1=1;
LEDB2=0;
LEDB3=0;
LEDB4=0;
LEDB5=0;
LEDB6=0;
LEDB7=0;
break;
case 2:
LEDB1=1;
LEDB2=1;
LEDB3=0;
LEDB4=0;
LEDB5=0;
LEDB6=0;
LEDB7=0;
break;
case 3:
LEDB1=1;
LEDB2=1;
LEDB3=1;
LEDB4=0;
LEDB5=0;
LEDB6=0;
LEDB7=0;
break;
case 4:
LEDB1=1;
LEDB2=1;
LEDB3=1;
LEDB4=1;
LEDB5=0;
LEDB6=0;
LEDB7=0;
break;
case 5:
LEDB1=1;
LEDB2=1;
LEDB3=1;
LEDB4=1;
LEDB5=1;
LEDB6=0;
LEDB7=0;
break;
case 6:
LEDB1=1;
LEDB2=1;
LEDB3=1;
LEDB4=1;
LEDB5=1;
LEDB6=1;
LEDB7=0;
break;
case 7:
LEDB1=1;
LEDB2=1;
LEDB3=1;
LEDB4=1;
LEDB5=1;
LEDB6=1;
LEDB7=1;
break;
default:break;
}
}
else
{
LED_AC=1;
LED_AUTO=1;
LEDT18=1;
LEDT20=1;
LEDT22=1;
LEDT24=1;
LEDT26=1;
LEDT28=1;
LEDT30=1;
LEDT32=1;
LEDVENT=1;
LEDBL=1;
LEDFOOT=1;
LEDMIX=1;
LEDDEF=1;
LEDB1=0;
LEDB2=0;
LEDB3=0;
LEDB4=0;
LEDB5=0;
LEDB6=0;
LEDB7=0;
}
if(intake_func&0x7f) LED_REC=1;
else LED_REC=0;
}
//==========================
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
汽车空调程序.rar
(9.62 KB, 下载次数: 68)
2018-3-14 15:59 上传
点击文件名下载附件
pic 汽车空调程序
下载积分: 黑币 -5
作者:
huolong1988
时间:
2018-4-1 23:22
楼主你好,毫不犹豫的冲了20元的800黑币就为下载你的资料【捂脸】
有些细节问题想和楼主交流一下,留个wx:Royalfun88,求带求带
作者:
lgc961104
时间:
2019-5-13 00:49
没有硬件图??这咋去连线,
作者:
yinxh722
时间:
2022-12-1 11:02
对车用空调控制器程序非常感兴趣。想学习了解一下。
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1