📄 main.c
字号:
nop_instruction();
nop_instruction();
nop_instruction();
K=0;
for(i=0;i<3;i++)//total for pan
{
nop_instruction();
}
PAN=1;
P0D.0=0;//change to input
IR_INT0=0;//clear ir requre
IR_INT1=0;
enable_interrupt();
for(i=0;i<70;i++)//delay 116us?? to detect pan
{
nop_instruction();
}
//counterInt_pan_check=3; //for test
if((counterInt_pan_check>=1)&(counterInt_pan_check<=4))
{
FlagPan=1;
FlagErrorDisplayPan=0;
}
else if(counterInt_pan_check>4)
{
FlagPan=0;
InitialErrorDisplayPan=0;
FlagErrorDisplayPan=1;
K=0;
}
else if(counterInt_pan_check==0)//E0
{
FlagPan=0;
FlagSeriousError=1;
FlagHardwareError=1;
}
}
//end check pan
//start Ti Guo detect
if(InitialCheckPan==1)//have been check pan,then start tiguo detect
{
CountTiguo++;
if(CountTiguo==60)//for detect
{
if((ADdata_curn<=0xf6)&(K==1))//412 not isolator
{
InitialCheckPan=0;
CountineCheckPan=0;
InitialCountineCheckPan=0;
InitialErrorDisplayPan=0;
}
}
}
//end Ti Guo detect
if(FlagErrorDisplayPan==1)
{
if((InitialErrorDisplayPan==0)&(CountineCheckPan==0))
{
count_1s=0;
count_2s=0;
Flag2s=1;//frist beep
Flag1s=0;
count_30s=0;
Flag30s=0;
count_500ms=0;
Flag500msTwinkle=0;
InitialErrorDisplayPan=1;
}
//display error code E1
if(Flag30s==0)
{
if(Flag500msTwinkle==0)
{
InitialCountineCheckPan=0;//initial countine check pan
Disp[0]=0xff;
Disp[1]=0xc2;// "E"
Disp[2]=LEDDisp[1];// "1"
Disp[3]=0xff;
}
else
{
if(InitialCountineCheckPan==0)
{
InitialCheckPan=0;//every 1s check pan
CountineCheckPan=1;//
InitialCountineCheckPan=1;
}
Disp[0]=0xff;//turn off all led
Disp[1]=0xff;
Disp[2]=0xff;
Disp[3]=0xff;
}
if(FlagFunc_ShaoShui)
{
Disp[4]=0x00;
Disp[5]=DispLed_ShaoShui+DispLed_Power;
}
if(FlagFunc_ZhengDun)
{
Disp[4]=0x00;
Disp[5]=DispLed_ZhenDun+DispLed_Power;
}
if(FlagFunc_BaoTang)
{
Disp[4]=DispLed_BaoTang;
Disp[5]=DispLed_Power;
}
if(FlagFunc_Zhufan)
{
Disp[4]=DispLed_ZhuFan;
Disp[5]=DispLed_Power;
}
if(FlagFunc_AoZhou)
{
Disp[4]=DispLed_AoZhou;
Disp[5]=DispLed_Power;
}
if(Flag2s==1)
{
buzzer_on_flag=1;
Flag2s=0;
}
}
else//diplay over turn to start status
{
FlagErrorDisplayPan=0;
Func.ubyte=0x00;//close all func
FlagFuncEnable=0;
FlagFunc_YuYueDingShi=0;
FlagSetOver_SetupYuYueDingShi=0;
//Initial1s=0;//display start twinkle
Flag40s=0;
Flag1Min=0;
count_1min=0;
CountineCheckPan=0;
}
}
}
}
}
void CheckIGBT_Panel_PowerVolt(void)
{ if(FlagFuncEnable==1)
{
#if testIsolator==1// for isolator test
if(FlagSeriousError==0)//serious error poriay than power volt dectect
{
if(ADdata_volt>=0x2E0)//power volt dectect 412 not isolator
{
FlagPowerVoltHigh=1;
FlagFun_CheckPan=0;//disable fun checkpan,check igbt priority higher than chankpan
}
else if(ADdata_volt<=0xc1)//412 not isolator
{
FlagPowerVoltLow=1;
FlagFun_CheckPan=0;//disable fun checkpan,check igbt priority higher than chankpan
}
else
{
FlagPowerVoltHigh=0;
FlagPowerVoltLow=0;
if(FlagSeriousError==0)
{
FlagFun_CheckPan=1;//disable fun checkpan,check igbt priority higher than chankpan
InitialErrorDisplayIGBT=0;
}
}
Temp2FlagPowerVoltHigh=Temp1FlagPowerVoltHigh;
Temp1FlagPowerVoltHigh=FlagPowerVoltHigh;
Temp2FlagPowerVoltLow=Temp1FlagPowerVoltLow;
Temp1FlagPowerVoltLow=FlagPowerVoltLow;
if(((Temp2FlagPowerVoltHigh)&(Temp1FlagPowerVoltHigh==0)
||(Temp2FlagPowerVoltLow)&(Temp1FlagPowerVoltLow==0))&(K==0))
{
InitialK=0;
}
}
if((ADdata_main<=0x03)||(ADdata_main>=0x3e0))//panel temperature alarm 0v 5v 412 not isolator
{
if(InitialCheckIGBT==0)
{
FlagPanelError=1;
FlagFun_CheckPan=0;//disable fun checkpan,check igbt priority higher than chankpan
InitialCheckIGBT=1;
FlagSeriousError=1;
}
}
else if(ADdata_main>=0x3d3)//exceed 300 0C 412 not isolator
{
if(InitialCheckIGBT==0)
{
FlagPanelOverHeat=1;
FlagFun_CheckPan=0;//disable fun checkpan
InitialCheckIGBT=1;
FlagSeriousError=1;
}
}
if((ADdata_igbt<=0x03)||(ADdata_igbt>=0x3e0))//igbt temperature alarm 412 not isolator
{
if(InitialCheckIGBT==0)
{
FlagIGBTError=1;
FlagFun_CheckPan=0;//disable fun checkpan,check igbt priority higher than chankpan
InitialCheckIGBT=1;
FlagSeriousError=1;
}
}
else if(ADdata_igbt>=0x2b0)//exceed 110 0C 412 not isolator
{
if(InitialCheckIGBT==0)
{
FlagIGBTOverHeat=1;
FlagFun_CheckPan=0;//disable fun checkpan
InitialCheckIGBT=1;
FlagSeriousError=1;
}
}
if(FlagSeriousError)//close all func display error code and wait restart
{
Func.ubyte=0x00;//close all func
}
if((FlagIGBTError)||(FlagIGBTOverHeat)||(FlagPanelError)
||(FlagPanelOverHeat)||(FlagPowerVoltHigh)||(FlagPowerVoltLow)||(FlagHardwareError))
{
K=0;//close IGBT
if(InitialErrorDisplayIGBT==0)
{
count_1s=0;
Flag2s=0;
Flag1s=0;
Flag30s=0;
count_500ms=0;
Flag500msTwinkle=0;
InitialErrorDisplayIGBT=1;
buzzer_on_flag=1;
//close all func
}
//display error code
if(Flag500msTwinkle==0)
{
//InitialCountineCheckPan=0;//initial countine check pan
Disp[0]=0xff;
Disp[1]=0xc2;// "E"
if(FlagPowerVoltHigh)
{
Disp[2]=LEDDisp[4];// "4" power volt high
}
if(FlagPowerVoltLow)
{
Disp[2]=LEDDisp[3];// "3" power volt low
}
if(FlagPanelError)
{
Disp[2]=LEDDisp[5];// "5" panel sensor short or open
}
if(FlagPanelOverHeat)
{
Disp[2]=LEDDisp[7];// "7" panel temperature over 300 oc
}
if(FlagIGBTError)
{
Disp[2]=LEDDisp[6];// "6" IGBT sensor short or open
}
if(FlagIGBTOverHeat)
{
Disp[2]=LEDDisp[2];// "2"IGBT temperature over 110oc
}
if(FlagHardwareError)
{
Disp[2]=LEDDisp[0];// "0"hardware error E0
}
Disp[3]=0xff;
Disp[4]=0x00;
Disp[5]=0x00;//close all led
}
else
{
Disp[0]=0xff;//turn off all led
Disp[1]=0xff;
Disp[2]=0xff;
Disp[3]=0xff;
Disp[4]=0x00;
Disp[5]=0X00;
}
}
}
}
/*************************************************************************
Name : surge protection
Parameters : None
Returns : None
Description: surge protection function
**************************************************************************/
void surge_protection(void)
{
if(FlagSurgeProtect==1)
{
K=0;
if(Flag2s==1)
{
FlagSurgeProtect = 0;
InitialK=0;
}
}
}
/*************************************************************************
Name : vol_cur_sample
Parameters : None
Returns : None
Description: voltage & current collect using A/D
**************************************************************************/
void vol_cur_sample(void)
{
if(signal_512us_end)
{
signal_512us_end = 0;
/* V-AD sample */
ADCON=ADChannelSerialSetup[CountADchannel]; /* restart A/D */
while(ADSTP==0){}
ad_data.AD_BYTE.dataH=ADH;
ad_data.AD_BYTE.dataL=ADL;
ADarray_volt[CountTempertureCur_Sample]=ad_data.a; /* read A/D value */
CountTempertureCur_Sample++;
if(CountTempertureCur_Sample==5) /* volt sample frequency is 0.512ms ,every 4 times*/
{
for(Ad_a=1;Ad_a<4;Ad_a++)
for(Ad_b=4-1;Ad_b>=Ad_a;Ad_b--)
{
if(ADarray_volt[Ad_b-1]>ADarray_volt[Ad_b])
{
AD_t=ADarray_volt[Ad_b-1];
ADarray_volt[Ad_b-1] = ADarray_volt[Ad_b];
ADarray_volt[Ad_b] = AD_t;
}
}
ADValue[CountADchannel]=(ADarray_volt[1]+ADarray_volt[2])>>1;
CountADchannel++;
if(CountADchannel==4)
{
CountADchannel=0;
}
CountTempertureCur_Sample=0;
}
}
/*
ADdata_volt=0x180;//for test
ADdata_main=0xe8;
ADdata_main=0xe9;
ADdata_igbt=0x100;
ADdata_curn=0x100;*/
}
void Func_YuYueDingShi(void)
{
if((FlagFunc_YuYueDingShi)&(FlagErrorDisplayPan==0))
{
if((FlagFunc_AoZhou)||(FlagFunc_BaoTang)||(FlagFunc_ShaoShui)
||(FlagFunc_ZhengDun)||(FlagFunc_Zhufan))
{
FAN=0;//close fan
K=0;//close IGBT
}
//calculate four 8-seg led display
Temp3=countMin%10;//minite
Temp2=(countMin-Temp3)/10;
TempDisp3=LEDDisp[Temp3];
TempDisp2=LEDDisp[Temp2];
Temp1=countHour%10;//hour
Temp0=(countHour-Temp1)/10;
TempDisp1=LEDDisp[Temp1]+DispLed_Dp;
TempDisp0=LEDDisp[Temp0];
if(Temp0==0)
TempDisp0=0xff;
//end calculate four 8-seg led display
if((Flag5s==1)&(FlagSetOver_SetupYuYueDingShi==0))//set yuyue 5s has been over
{
FlagSetOver_SetupYuYueDingShi=1;
Flag5s=0;
Flag5sTwinkle=0;//when finish set, frist display time
count_1s=0;//initial timers
Flag1s=0;
count_1min=0;
Flag1Min=0;
if((FlagYuYueDingShiTimeVaid==0)&((FlagFunc_HuoGuo)||(FlagFunc_JianChao)||(FlagFunc_ShaoKao)))
{
FlagFunc_YuYueDingShi=0;
FlagSetOver_SetupYuYueDingShi=0;
EnableYuYueCounter=1;
}
}
if(FlagSetOver_SetupYuYueDingShi==1)//yuyuedingshi timer running
{
if((countHour==0)&(countMin==0))//deriect to o
{
if((FlagFunc_AoZhou)||(FlagFunc_BaoTang)||(FlagFunc_ShaoShui)
||(FlagFunc_ZhengDun)||(FlagFunc_Zhufan))//maunal func
{
FlagFunc_YuYueDingShi=0;
FlagSetOver_SetupYuYueDingShi=0;//need?
EnableYuYueCounter=1;
InitialK=0;
}
else if((FlagYuYueDingShiTimeVaid)&((FlagFunc_HuoGuo)||(FlagFunc_JianChao)||(FlagFunc_ShaoKao)))//auto func
{
K=0;//close IGBT
CCRP = 0x01; /* Selecte Latch 01 */
CRAL = CMP01_L_800W; /* Write low-order of compare 01 */
CRAH = CMP01_H_800W; /* Write high-order of compare 01 */
CMPR = 0x01; /* Compare latch 00,01 reload at next underflow *///close pwm//close pwm
Func.ubyte=0x00;//close all func
FlagFuncEnable=0;
FlagFunc_YuYueDingShi=0;
FlagSetOver_SetupYuYueDingShi=0;
Flag40s=0;
Flag1Min=0;
count_1min=0;
FlagFuncEndProssTimer=0;
FlagYuYueDingShiTimeVaid=0;
}
}
if(Flag1Min==1)//timer to o
{
Flag1Min=0;
//calculate
if(countMin==0)
{
if(countHour==0)
{
;
}
else
{
countHour--;
countMin=59;
}
}
else
{
countMin--;
}
}
}
if(FlagSetOver_SetupYuYueDingShi==1)//when setvoer in yuyuemode, yuyue run now
{
//setup pwm only for autofunc in yuyue running mode
if((FlagFunc_ShaoKao)||(FlagFunc_HuoGuo)||(FlagFunc_JianChao))
{
CCRP = 0x01; /* Selecte Latch 01 */
CRAL = AutoPowerSerial[PowerSerial]; /* Write low-order of compare 01 */
CRAH = 0x00; /* Write high-order of compare 01 */
CMPR = 0x01; /* Compare latch 00,01 reload at next underflow */
}
//end of pwm only for autofunc in yuyue running mode
if(Flag5sTwinkle==0)
{
Disp[0]=TempDisp0;
if(Flag500msTwinkle==0)
{
Disp[1]=TempDisp1;
}
else
{
Disp[1]=TempDisp1+DispLed_Dp;
}
Disp[2]=TempDisp2;
Disp[3]=TempDisp3;
}
else//5s twinkle
{
if(FlagFunc_ShaoShui)
{
Disp[0]=LEDDisp[1];
Disp[1]=LEDDisp[8];
Disp[2]=LEDDisp[0];
Disp[3]=LEDDisp[0];
}
if(FlagFunc_AoZhou)
{
if(FlagAutoFunc800W)
{
Disp[0]=0xff;
Disp[1]=LEDDisp[8];
Disp[2]=LEDDisp[0];
Disp[3]=LEDDisp[0];
}
else
{
Disp[0]=LEDDisp[1];
Disp[1]=LEDDisp[4];
Disp[2]=LEDDisp[0];
Disp[3]=LEDDisp[0];
}
}
if(FlagFunc_Zhufan)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -