|
发表于 2011-9-24 17:17:40
|
显示全部楼层
回复【182楼】zhu555
-----------------------------------------------------------------------
/****************************************************
This program was produced by the
CodeWizardAVR V1.24.1d Standard
Automatic Program Generator
?Copyright 1998-2004 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.ro
e-mail:office@hpinfotech.ro
Chip type : ATmega8L
Program type : Application
Clock frequency : 1.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega8.h>
void SaveSetPara(void);
void ShowSetPara(void);
void ShowSetTemp(void);
void CheckReceive(void);
void ClosePowerProc(void);
void TempAdj(void);
unsigned char cReadTime;
unsigned char b40ms,c40ms,b500ms,c500ms,bHeatEn,bHeatDisable,cZphOld, cZphNew;
unsigned char bt10ms = 0,b10ms = 0,c10ms = 0,b100ms,bUpLimit = 0;
unsigned char c200ms = 0,cDispBit = 0,cSetBit,cBlinkTime;
unsigned char cDispBuf[3],cKeyTime = 0,cKeyShiftTime = 0;
unsigned char bSetTemp = 0,bShowType,cKeyInputTime = 0;
unsigned char bInputAdjust = 0,bSetPara = 0,cSetParaNo = 0;
unsigned char cOldPINB,cDataPINB,cSpeakTime,bHeatOK = 0;
unsigned char bAlarm,bCloseCount,bClosePower = 0,bDownLimit = 0;
unsigned char cSpeakOnTimer = 0,bSleep = 0,bHeatError = 0;
unsigned char bShowAdjust = 0,cShowAdjustTime = 0;
unsigned char cFirstOpen, bFirstOpen,cDownLimit,bTempDown;
unsigned int cSlpTimer = 0,cOldTemp;
unsigned int cMidleTime = 200;
unsigned int cSetPara[10],cControlTemp,cCloseTime = 0;
unsigned int cControlVal,cSampleVal;
unsigned int eeprom *ptr_to_eeprom;
// '0' '1' '2' '3' '4' '5' '6' '7'
const char cDispTab[21] = {0x81,0xdd,0x13,0x19,0x4d,0x29,0x21,0x9d,
// '8' '9' '-' '-1' 'C' 'F' 'S'
0x1,0x9,0x7f,0x5d,0xa3,0x27,0x29,
// 'L' 'P' 'H' 'E' ' '
0xe3,0x7,0x45,0x23,0xff,0x00};
#define RunLedBlink() PORTB ^= 0x20
#define HeatDisable() PORTB &= ~0x10
#define HeatEnable() PORTB |= 0x10
#define SpeakOn() PORTB &= ~ 0x80
#define SpeakOff() PORTB |= 0x80
#define SpeakBlink() PORTB ^= 0x80
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
HeatDisable();
bHeatDisable = 1;
}
// Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer 1 value
TCNT1H = 0xfc;
TCNT1L = 0x17;
// Place your code here
if(++c10ms >= 10)
{
c10ms = 0;
bt10ms = 1;
/*
if(--cMidleTime == 0)
{
cMidleTime = 200;
if(cSlpTimer >= 50)
{
bCloseCount = 0;
cCloseTime = 0;
}
else
bCloseCount = 1;
cSlpTimer = 0;
} */
}
// Led display
PORTD = 0xff;
PORTB |= 0x7;
if(bSetTemp)
{
if(cSetBit == cDispBit)
{
if(cBlinkTime & 0x80)
PORTD = cDispTab[cDispBuf[cDispBit]];
}
else
PORTD = cDispTab[cDispBuf[cDispBit]];
}
else
PORTD = cDispTab[cDispBuf[cDispBit]];
if(cDispBit == 0) //1
{
if(PORTB & 0x10)
PORTD &= 0xfe;
PORTB &= ~0x1;
}
else if(cDispBit == 1) //10
PORTB &= ~0x2;
else if(cDispBit == 2) //100
PORTB &= ~0x4;
if(++cDispBit >= 3)
cDispBit = 0;
}
#define ADC_VREF_TYPE 0xc0
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
void TimeProc(void)
{
b10ms = 0;
b100ms = 0;
b40ms = 0;
if(bt10ms)
{
bt10ms = 0;
b10ms = 1;
if( ++c40ms > 4 )
{
c40ms = 0;
b40ms = 1;
}
if(++c500ms > 12)
{
c500ms = 0;
b500ms = 1;
if((bHeatOK == 1)&&(bTempDown == 0)&&(bDownLimit == 0))
{
if(bHeatEn == 0)
bHeatEn = 1;
else
bHeatEn = 0;
}
else
bHeatEn = 1;
}
if(++c200ms > 20)
{
b100ms = 1;
if(cFirstOpen > 0)
{
cFirstOpen--;
if(cFirstOpen == 0)
{
bFirstOpen = 0;
}
}
cBlinkTime = ~ cBlinkTime;
c200ms = 0;
RunLedBlink();
//if(bAlarm || bHeatError)
if(bHeatError)
SpeakBlink();
else if((!(bAlarm || bHeatError)) && (cSpeakTime == 0))
SpeakOff();
if(cShowAdjustTime > 0)
{
if((--cShowAdjustTime) == 0)
bShowAdjust = 0;
}
}
if(cSpeakTime > 0)
{
cSpeakTime--;
if(cSpeakTime == 0)
{
SpeakOff();
if(cSpeakOnTimer > 0)
{
cSpeakOnTimer--;
cSpeakTime = 20;
if((cSpeakOnTimer % 2) == 1)
SpeakOn();
}
}
}
}
}
void KeyUpProc(void)
{
if(bSetTemp)
{
if((cSetBit == 2) && (bSetPara == 0))
{
if(bShowType == 1)
{
if(bInputAdjust == 1)
{
if(cDispBuf[cSetBit] == 0)
cDispBuf[cSetBit] = 10 ; // display '-'
else if(cDispBuf[cSetBit] == 10)
cDispBuf[cSetBit] = 11 ;
else if(cDispBuf[cSetBit] == 11)
cDispBuf[cSetBit] = 1 ;
else if(cDispBuf[cSetBit] == 1)
cDispBuf[cSetBit] = 0 ;
}
else
{
cDispBuf[cSetBit]++;
if(cDispBuf[cSetBit] > 8)
cDispBuf[cSetBit] = 3;
}
}
else
{
if(bInputAdjust == 1)
{
if(cDispBuf[cSetBit] == 0)
cDispBuf[cSetBit] = 10 ; // display '-1'
else
cDispBuf[cSetBit] = 0 ;
}
else
{
cDispBuf[cSetBit]++;
if(cDispBuf[cSetBit] >= 5)
cDispBuf[cSetBit] = 2 ;
}
}
}
else
{
cDispBuf[cSetBit]++;
if(cDispBuf[cSetBit] >= 10)
cDispBuf[cSetBit] = 0;
}
}
else if(bSetPara == 1)
{
switch(cSetParaNo)
{
case 0:
cSetPara[2 + cSetParaNo]++;
cSetPara[2 + cSetParaNo] &= 0x1;
break;
case 3:
cSetPara[2 + cSetParaNo]++;
cSetPara[2 + cSetParaNo] &= 0x1;
break;
case 1:
cSetPara[2 + cSetParaNo]++;
if(cSetPara[2 + cSetParaNo] >= 3)
cSetPara[2 + cSetParaNo] = 0;
break;
default :
break;
}
ShowSetPara();
}
}
void KeyDownProc(void)
{
if(bSetTemp)
{
if((cSetBit == 2) && (bSetPara == 0))
{
if(bShowType == 1)
{
if(bInputAdjust == 1)
{
if(cDispBuf[cSetBit] == 0)
cDispBuf[cSetBit] = 1 ; // display '1'
else if(cDispBuf[cSetBit] == 1)
cDispBuf[cSetBit] = 11 ;// display '-1'
else if(cDispBuf[cSetBit] == 11)
cDispBuf[cSetBit] = 10 ;
else if(cDispBuf[cSetBit] == 10)
cDispBuf[cSetBit] = 0 ;
}
else
{
cDispBuf[cSetBit]--;
if(cDispBuf[cSetBit] < 3)
cDispBuf[cSetBit] = 8 ;
}
}
else
{
if(bInputAdjust == 1)
{
if(cDispBuf[cSetBit] == 0)
cDispBuf[cSetBit] = 10 ; // display '-'
else
cDispBuf[cSetBit] = 0 ;
}
else
{
cDispBuf[cSetBit]--;
if(cDispBuf[cSetBit] <= 1)
cDispBuf[cSetBit] = 4 ;
}
}
}
else
{
cDispBuf[cSetBit]--;
if(cDispBuf[cSetBit] == 255)
cDispBuf[cSetBit] = 9;
}
}
else if(bSetPara == 1)
{
switch(cSetParaNo)
{
case 0:
cSetPara[2 + cSetParaNo]--;
cSetPara[2 + cSetParaNo] &= 0x1;
break;
case 3:
cSetPara[2 + cSetParaNo]--;
cSetPara[2 + cSetParaNo] &= 0x1;
break;
case 1:
cSetPara[2 + cSetParaNo]--;
if(cSetPara[2 + cSetParaNo] >= 3)
cSetPara[2 + cSetParaNo] = 2;
break;
default :
break;
}
ShowSetPara();
}
}
void KeyShiftProc(void)
{
unsigned int i;
if(bSetTemp)
{
cSetBit--;
if(cSetBit == 255)
{
cSetBit = 2;
if(bInputAdjust == 1)
{
// bHeatOK = 0;
if(cDispBuf[2] == 10)
i = 1000;
else if(cDispBuf[2] == 11)
i = 1100;
else if(cDispBuf[2] == 1)
i = 100;
else
i = 0;
cSetPara[1] = cDispBuf[0] + (unsigned int)cDispBuf[1] * 10;
if(((cDispBuf[2] & 0x1) == 0) || (((cDispBuf[2] & 0x1) == 1) && (cSetPara[1] <= 78)))
{
cSetPara[1] += i;
bSetTemp = 0;
bInputAdjust = 0;
ptr_to_eeprom = 2;
*ptr_to_eeprom = cSetPara[1];
bHeatOK = 0;
}
}
else if(bSetPara == 1)
{
cSetPara[4] = cDispBuf[0] + (unsigned int)cDispBuf[1] * 10
+ (unsigned int)cDispBuf[2] * 100;
if(((cSetPara[4] <= 150) && (cSetPara[4] >= 30) && (bShowType == 0))
|| ((cSetPara[4] <= 300) && (cSetPara[4] >= 50) && (bShowType == 1)))
{
bSetTemp = 0;
cSetParaNo++;
ptr_to_eeprom = 8;
*ptr_to_eeprom = cSetPara[4];
ShowSetPara();
}
}
else
{
cSetPara[0] = cDispBuf[0] + (unsigned int)cDispBuf[1] * 10
+ (unsigned int)cDispBuf[2] * 100;
if((cSetPara[2] == 0) && (cSetPara[0] >= 200) && (cSetPara[0] <= 450)
|| ((cSetPara[2] == 1) && (cSetPara[0] >= 392) && (cSetPara[0] <= 842)))
{
bSetTemp = 0;
bHeatOK = 0;
ptr_to_eeprom = 0;
*ptr_to_eeprom = cSetPara[0];
}
}
}
}
else if(bSetPara == 1)
{
if(bShowType != cSetPara[2])
{
//bHeatOK = 0;
if(cSetPara[2] == 0)
{
i = (cSetPara[0] - 32)*5 / 9;
cSetPara[0] = i;
i = cSetPara[4]*5 / 9;
cSetPara[4] = i;
if(cSetPara[1] >= 1000)
{
cSetPara[1] -= 1000;
i = cSetPara[1]*5 / 9;
cSetPara[1] = i + 1000;
}
else
{
i = cSetPara[1]*5 / 9;
cSetPara[1] = i;
}
}
else
{
i = (cSetPara[0] *9)/5 + 32;
cSetPara[0] = i;
i = cSetPara[4]*9 / 5;
cSetPara[4] = i;
if(cSetPara[1] >= 1000)
{
cSetPara[1] -= 1000;
i = cSetPara[1]*9 / 5;
cSetPara[1] = i + 1000;
}
else
{
i = cSetPara[1]*9 / 5;
cSetPara[1] = i;
}
}
ptr_to_eeprom = 0;
*ptr_to_eeprom = cSetPara[0];
ptr_to_eeprom = 2;
*ptr_to_eeprom = cSetPara[1];
}
SaveSetPara();
bShowType = cSetPara[2];
cSetParaNo++;
if(cSetParaNo == 2)
{
cSetBit = 2;
bSetTemp = 1;
}
if(cSetParaNo >= 4)
{
cSetParaNo = 0;
bSetPara = 0;
ShowSetTemp();
}
else
ShowSetPara();
}
else
cKeyShiftTime = 0;
}
void KeyInputProc(void)
{
unsigned int i;
if((bSetTemp == 0) && (bSetPara == 0)&&(bHeatDisable == 0))
{
cShowAdjustTime = 10;
bShowAdjust = 1;
if(cSetPara[1] >= 1100)
{
i = cSetPara[1] - 1100;
cDispBuf[2] = 11;
}
else if(cSetPara[1] >= 1000)
{
i = cSetPara[1] - 1000;
cDispBuf[2] = 10;
}
else if(cSetPara[1] >= 100)
{
i = cSetPara[1] - 100;
cDispBuf[2] = 1;
}
else
{
cDispBuf[2] = 0;
i = cSetPara[1];
}
if(i != 0)
{
cDispBuf[0] = i % 10;
cDispBuf[1] = i / 10;
}
else
{
cDispBuf[0] = 0;
cDispBuf[1] = 0;
}
}
}
void SaveSetPara(void)
{
ptr_to_eeprom = 4 + 2 * cSetParaNo;
*ptr_to_eeprom = cSetPara[cSetParaNo + 2];
}
void ShowSetPara(void)
{
switch(cSetParaNo)
{
case 0:
cDispBuf[2] = 1;
cDispBuf[1] = 19;
if((cSetPara[cSetParaNo + 2]) == 0)
cDispBuf[0] = 12;
else
cDispBuf[0] = 13;
break;
case 1:
cDispBuf[2] = 2;
if((cSetPara[cSetParaNo + 2]) == 2)
{
cDispBuf[1] = 3;
cDispBuf[0] = 0;
}
else if((cSetPara[cSetParaNo + 2]) == 1)
{
cDispBuf[1] = 1;
cDispBuf[0] = 0;
}
else
{
cDispBuf[1] = 19;
cDispBuf[0] = 0;
}
break;
case 2:
cDispBuf[2] = cSetPara[2+ cSetParaNo] / 100;
cDispBuf[1] = (cSetPara[2+ cSetParaNo] % 100) / 10;
cDispBuf[0] = cSetPara[2+ cSetParaNo] % 10;
break;
case 3:
cDispBuf[2] = 4;
cDispBuf[1] = 19;
if((cSetPara[cSetParaNo + 2]) == 0)
cDispBuf[0] = 0;
else
cDispBuf[0] = 1;
break;
default :
break;
}
}
void CheckReceive(void)
{
if(b10ms)
{
cOldPINB = cDataPINB;
cDataPINB = PINB;
/*if((bSetTemp == 0) && (cOldPINB & 0x8) && (!(cDataPINB & 0x8))
&& (bSetPara == 0))
{
// bHeatOK = 0;
bSetTemp = 1;
cSetBit = 2;
ShowSetTemp();
}*/
if((bSetTemp == 0) && (cOldPINB & 0x8) && (!(cDataPINB & 0x8))
&& (bSetPara == 0))
//if(((bSetTemp == 0) && ((PINB & 0x8) == 0 )&&(cOldPINB != cDataPINB)
// && (bSetPara == 0)))
{
bHeatOK = 0;
bSetTemp = 1;
cSetBit = 2;
//cCheckTimeA = 0;
//SpeakOn();
//cSpeakTime = 20;
ShowSetTemp();
// return;
}
/* if(((bSetTemp == 1)&& (cOldPINB & 0x8)&&(!(cDataPINB & 0x8)))||((bSetPara ==1)
&&(cOldPINB & 0x8)&&(!(cDataPINB & 0x8))))
{
bSetTemp = 0;
bSetPara = 0;
cSetParaNo = 0;
bInputAdjust = 0;
//cCheckTimeB = 0;
SpeakOn();
cSpeakTime =20;
ShowSetTemp();
}*/
}
}
void CheckKey(void)
{
unsigned char key;
unsigned int i;
key = ~PINC;
key &= 0x3c;
if(key != 0)
{
if(cKeyTime == 0x80)
{
if((bSetTemp == 1) || (bSetPara == 1) || (bInputAdjust == 1))
return;
if((key == 0x10) && (bSetTemp == 0)&& ((PINB & 0x8) == 0))
{
if(b10ms)
if(++cKeyShiftTime > 100)
{
// bHeatOK = 0;
bSetTemp = 1;
cSetBit = 2;
ShowSetTemp();
}
}
if((key == 0x20) && (bInputAdjust != 1))
{
if(b10ms)
if(++cKeyInputTime > 100)
{
if((cSetPara[5] == 0) && ((PINB & 0x8) == 0) ||
(cSetPara[5] == 1))
{
// bHeatOK = 0;
bSetTemp = 1;
cSetBit = 2;
bInputAdjust = 1;
if(cSetPara[1] >= 1100)
{
i = cSetPara[1] - 1100;
cDispBuf[2] = 11;
}
else if(cSetPara[1] >= 1000)
{
i = cSetPara[1] - 1000;
cDispBuf[2] = 10;
}
else if(cSetPara[1] >= 100)
{
i = cSetPara[1] - 100;
cDispBuf[2] = 1;
}
else
{
cDispBuf[2] = 0;
i = cSetPara[1];
}
if(i != 0)
{
cDispBuf[0] = i % 10;
cDispBuf[1] = i / 10;
}
else
{
cDispBuf[0] = 0;
cDispBuf[1] = 0;
}
}
}
}
return;
}
if(b10ms)
{
if(++cKeyTime >= 8)
{
cKeyTime = 0x80;
if(bSleep == 1)
{
bSleep = 0;
cCloseTime = 0;
bHeatOK = 0;
return;
}
if(key == 0x4)
KeyUpProc();
else if(key == 0x8)
KeyDownProc();
else if(key == 0x10)
KeyShiftProc();
else if(key == 0x20)
KeyInputProc();
else
cKeyTime = 0;
}
}
}
else
{
cKeyTime = 0;
cKeyShiftTime = 0;
cKeyInputTime = 0;
}
} // unsigned char CheckKey(void)
void WatchDog(void)
{
// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/2048k
WDTCR = 0x1F;
WDTCR = 0x0F;
}
void ShowSetTemp(void)
{
cDispBuf[0] = cSetPara[0] % 10;
cDispBuf[1] = (cSetPara[0] %100) / 10;
cDispBuf[2] = cSetPara[0] / 100;
}
void ClosePowerProc(void)
{
static unsigned char cHeatTime = 0;
if((bCloseCount == 1) && (b100ms == 1) && (cSetPara[3] != 0))
{
cCloseTime++;
if(cSetPara[3] == 2)
{
if((cCloseTime >= 8500) && (bClosePower == 0))
{
HeatDisable();
bClosePower = 1;
SpeakOn();
cSpeakTime = 20;
cSpeakOnTimer = 6;
}
}
else if(((cSetPara[0] >= 300) && (cSetPara[2] == 0))
|| ((cSetPara[0] >= 600) && (cSetPara[2] == 1)))
{
if((cCloseTime >= 4300) && (bSleep == 0))
{
bSleep = 1;
SpeakOn();
cSpeakTime = 20;
cCloseTime = 0;
}
}
}
}
void InitEEPROM(void)
{
unsigned int m,k;
for(m = 0; m++;m < 1000)
for(k = 0; k++;k < 1000);
ptr_to_eeprom = 30;
m = *ptr_to_eeprom;
ptr_to_eeprom = 32;
k = *ptr_to_eeprom;
ptr_to_eeprom = 30;
m = *ptr_to_eeprom;
ptr_to_eeprom = 32;
k = *ptr_to_eeprom;
if((m != 0x11) && (k != 0x22))
{
ptr_to_eeprom = 30;
*ptr_to_eeprom = 0x11;
ptr_to_eeprom = 32;
*ptr_to_eeprom = 0x22;
ptr_to_eeprom = 0;
*ptr_to_eeprom = 350;
ptr_to_eeprom = 2;
*ptr_to_eeprom = 0;
ptr_to_eeprom = 4;
*ptr_to_eeprom = 0;
ptr_to_eeprom = 6;
*ptr_to_eeprom = 0;
ptr_to_eeprom = 8;
*ptr_to_eeprom = 150;
ptr_to_eeprom = 10;
*ptr_to_eeprom = 0;
}
}
void TempAdj(void)
{
switch( cSetPara[0]/10)
{
case 20:
cSampleVal -= 209;
break;
case 21:
cSampleVal -= 201;
break;
case 22:
cSampleVal -= 197;
break;
case 23:
cSampleVal -= 190;
break;
case 24:
cSampleVal -= 182;
break;
case 25:
cSampleVal -= 170;
break;
case 26:
cSampleVal -= 162;
break;
case 27:
cSampleVal -= 159;
break;
case 28:
cSampleVal -= 150;
break;
case 29:
cSampleVal -= 141;
break;
case 30:
cSampleVal -= 132;
break;
case 31:
cSampleVal -= 121;
break;
case 32:
cSampleVal -= 112;
break;
case 33:
cSampleVal -= 101;
break;
case 34:
cSampleVal -= 91;
break;
case 35:
cSampleVal -= 82;
break;
case 36:
cSampleVal -= 75;
break;
case 37:
cSampleVal -= 68;
break;
case 38:
cSampleVal -= 60;
break;
case 39:
cSampleVal -= 50;
break;
case 40:
cSampleVal -= 40 ;
break;
case 41:
cSampleVal -= 37;
break;
case 42:
cSampleVal -= 25;
break;
case 43:
cSampleVal -= 18;
break;
case 44:
cSampleVal -= 11;
break;
case 45:
cSampleVal += 1;
break;
default:
break;
}
}
void ReadADCSample(void)
{
unsigned int i,adc_data;
// cOldTemp = cSampleVal;
if(bHeatOK == 0)
{
if(b100ms == 1)
{
HeatDisable();
adc_data = read_adc(0);
adc_data = 0;
for(i = 0;i < 2; i++)
adc_data += read_adc(0) + 190;
cSampleVal = (adc_data >> 1);
if(bHeatDisable == 0)
HeatEnable();
}
else
return;
}
else
{
if(b40ms == 1)
{
HeatDisable();
adc_data += read_adc(0);
adc_data = 0;
for(i = 0;i < 2; i++)
adc_data += read_adc(0);
cSampleVal = (adc_data >> 1) + 190;
if(cSampleVal > 190)
TempAdj();
}
else
return;
}
if(cSampleVal > 720)
{ bAlarm = 1;
HeatDisable();
}
else
bAlarm = 0;
//if(cSetPara[2] == 0)
if(bShowType == 0)
{
cSampleVal *= 5;
cSampleVal /= 7;
cControlVal = 1;
}
else
{
cSampleVal *= 9;
cSampleVal /= 7;
cSampleVal += 32;
cControlVal = 2;
}
if(cSampleVal <= (cControlTemp - 32))
{
bTempDown = 1;
}
if(bTempDown == 1)
{
cControlTemp = cControlTemp + 10;
// cControlTemp = cControlTemp ;
if(cSampleVal > cControlTemp)
{
bTempDown = 0;
}
}
if((cSampleVal <= (cControlTemp - cControlVal)) && (bClosePower == 0)
&& ((bSetTemp == 0) ||
((bSetTemp == 1)&& (bSetPara ==1))||
((bSetTemp == 1)&& (bInputAdjust == 1))))
{
if((!(PORTB & 0x10)) && (bAlarm == 0)&&(bHeatEn == 1)&&(bHeatDisable == 0))
{
cSlpTimer++;
HeatEnable();
}
}
if(((bSetTemp == 1)&&(bSetPara == 0)&&(bInputAdjust == 0))||(cSampleVal >= cControlTemp))
HeatDisable();
if(cSampleVal <= (cControlTemp - 30))
{
bCloseCount = 0;
cCloseTime = 0;
}
else
bCloseCount = 1;
if((bHeatOK == 1) && (bSleep == 0) && (bClosePower == 0))
{
if((cSampleVal < (cControlTemp - cSetPara[4])))
{ bHeatError = 1;
HeatEnable();
}
else
bHeatError = 0;
}
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
unsigned char i;
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=In Func2=Out Func1=Out Func0=Out
// State7=P State6=P State5=1 State4=1 State3=P State2=1 State1=1 State0=1
PORTB = 0xF7;
DDRB = 0xb7;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=Out Func0=In
// State6=P State5=P State4=P State3=P State2=P State1=1 State0=P
PORTC = 0x7F;
DDRC = 0x0;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=1 State6=1 State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
PORTD = 0xFF;
DDRD = 0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0 = 0x00;
TCNT0 = 0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x01;
TCNT1H = 0xFC;
TCNT1L = 0x17;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR = 0x00;
TCCR2 = 0x00;
TCNT2 = 0x00;
OCR2 = 0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR = 0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK = 0x04;
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 62.500 kHz
// ADC Voltage Reference: AREF pin
// ADC High Speed Mode: Off
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x87;
SFIOR&=0xEF;
/*
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 62.500 kHz
// ADC Voltage Reference: AREF pin
// ADC High Speed Mode: Off
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x84;
SFIOR&=0xEF;
*/
WatchDog();
InitEEPROM();
#asm("WDR");
for(i = 0; i < 10; i++)
{
ptr_to_eeprom = (i << 1);
cSetPara = *ptr_to_eeprom;
}
cZphOld = cZphNew;
cZphNew = PINC.1;
if(PINC.1 == 0)
{
HeatDisable();
bHeatDisable = 1;
}
if(cSetPara[2] >1)
cSetPara[2] = 0;
if((cSetPara[0] > 450) && (cSetPara[2] == 0))
{
cSetPara[0] = 350;
cSetPara[1] = 0;
}
else if((cSetPara[0] > 842) && (cSetPara[2] == 1))
{
cSetPara[0] = 700;
cSetPara[1] = 0;
}
if(((PINB & 0x8) == 0)&&(PINC.2 == 0)&&(PINC.3 == 0))
// if((~PINC) & 0xc)
{
cSetParaNo = 0;
bSetPara = 1;
ShowSetPara();
}
else
ShowSetTemp();
bShowType = cSetPara[2];
HeatDisable();
cSampleVal = 25;
cFirstOpen = 7;
bFirstOpen = 1;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
#asm("WDR");
TimeProc();
ClosePowerProc();
CheckKey();
CheckReceive();
if(cSetPara[1] >= 1000)
cControlTemp = 1000 + cSetPara[0] - cSetPara[1];
else
cControlTemp = cSetPara[0] + cSetPara[1];
if(bSleep == 1)
{
if(cSetPara[2] == 0)
cControlTemp = 200;
else
cControlTemp = 400;
}
ReadADCSample();
if((bSetTemp == 0) && (bSetPara == 0) && (bShowAdjust == 0)
&& (b100ms == 1))
{
if(bClosePower == 1)
{
// display "- - -"
cDispBuf[2] = 10;
cDispBuf[1] = 10;
cDispBuf[0] = 10;
}
else if(bFirstOpen == 1)
{
//display"8.8.8."
cDispBuf[2] = 20;
cDispBuf[1] = 20;
cDispBuf[0] = 20;
}
else if (PINC.1 == 0)
{
bHeatDisable = 1;
SpeakOn();
//display"H.S.E."
if(cBlinkTime & 0x80)
{
cDispBuf[2] = 17;
cDispBuf[1] = 14;
cDispBuf[0] = 18;
}
else
{
cDispBuf[2] = 19;
cDispBuf[1] = 19;
cDispBuf[0] = 19;
}
}
else if (PINB.6 == 1)
// display"C-E"
{
SpeakOn();
if(cBlinkTime & 0x80)
{
cDispBuf[2] = 12;
cDispBuf[1] = 10;
cDispBuf[0] = 18;
}
else
{
cDispBuf[2] = 19;
cDispBuf[1] = 19;
cDispBuf[0] = 19;
}
}
else if(bAlarm == 1)
{
SpeakOff();
if(cBlinkTime & 0x80)
{
// display "S - E"
cDispBuf[2] = 14;
cDispBuf[1] = 10;
cDispBuf[0] = 18;
}
else
{
cDispBuf[2] = 19;
cDispBuf[1] = 19;
cDispBuf[0] = 19;
}
}
else if(bHeatError == 1)
{
if(cBlinkTime & 0x80)
{
// display "H - E"
cDispBuf[2] = 17;
cDispBuf[1] = 10;
cDispBuf[0] = 18;
}
else
{
cDispBuf[2] = 19;
cDispBuf[1] = 19;
cDispBuf[0] = 19;
}
}
else if(bSleep == 1)
{
// display "S L P"
cDispBuf[2] = 14;
cDispBuf[1] = 15;
cDispBuf[0] = 16;
}
else if((bHeatOK == 0) || (bDownLimit == 1) || (bUpLimit == 1))
{
cDispBuf[2] = cSampleVal / 100;
cDispBuf[1] = cSampleVal % 100/10;
cDispBuf[0] = cSampleVal % 10;
}
else
{
ShowSetTemp();
//cDispBuf[2] = cSampleVal / 100;
//cDispBuf[1] = cSampleVal % 100/10;
//cDispBuf[0] = cSampleVal % 10;
}
}
if(cSampleVal < (cControlTemp - 30*(cSetPara[2]+1)))
{
if(b100ms)
{
if(++cDownLimit >= 2)
{
bDownLimit = 1;
cDownLimit = 0;
}
}
}
else
bDownLimit = 0;
if(cSampleVal > (cControlTemp + 30*(cSetPara[2]+1)))
bUpLimit = 1;
else
bUpLimit = 0;
if((bHeatOK == 0) && (bSetTemp == 0) && (bAlarm == 0)
&& (cSampleVal >= cControlTemp))
{
bDownLimit = 0;
bHeatOK = 1;
SpeakOn();
cSpeakTime = 20;
ShowSetTemp();
}
}
} |
|