www.pudn.com > PICTCPIP.rar > FrigWndw.c
//***********************************************************//
// Frigidaire窗机控制 //
// cpu: NEC uPD789104A clock: 4MHz //
// Main, C Program V2.6 //
// by ZhangZhihua 2003.06.15 //
//***********************************************************//
//#pragma PC(9104A)
#ifdef __K0S__
#pragma sfr
#endif
#pragma asm
// CPU管脚使用分布及定义
//
// 78F9116
// __________________ __________________
// | U |
// REMOTE——— 1|P23/INTP0/CPT20/^SS20 P22/SI20/RXD20|28 ———BUTTON COM1
// BUZZER——— 2|P24/INTP1/TO80/TO20 P21/SO20/TXD20|27 ———Filter Plus
// ZERO CROSS——— 3|P25/INTP2/TI80 P20/^SCK20/ASCK20|26 ———LED COM2
// ——— 4|AVDD P11|25 ———FAN
// ROOM TEMP——— 5|P60/ANI0 P10|24 ———COMPRESSOR
// DEFROST TEMP——— 6|P61/ANI1 VDD|23 ———
// LINE VOLTAGE——— 7|P62/ANI2 VSS|22 ———
// BUTTON COM2——— 8|P63/ANI3 CL1|21 ———
// GND——— 9|AVSS CL2|20 ———
// 7-SEG COM2——— 10|P50 IC(Vpp)|19 ———
// 7-SEG COM1——— 11|P51 ~RESET|18 ———
// LED COM1——— 12|P52 P03|17 ———EEPROM SDA(DATA)
// FILTER CHECK LED——— 13|P53 P02|16 ———EEPROM SCL(CLOCK)
// 164 CLOCK——— 14|P00 P01|15 ———164 DATA
// |_____________________________________|
//
// I/O port address define
#define PIO_LEDSensor P5.3 //
#define PIO_FiltPlus P2.1 //
// constant define
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define P0IOMODE 0b11111000 // P00~P02 -- (out), P03 -- (input)
#define P0INIT 0b11111100 //
#define P0PULLUP 0b00000000 // no pullup
#define P1IOMODE 0b11111100 // P10~P11 -- (out)
#define P1INIT 0b11111100 //
#define P2IOMODE 0b11101100 // P20~P21 -- (out), P22~P23 -- (input), P24 -- (output), P25 -- (input)
//#define P2IOMODE 0b11101110 // P20 -- (out), P21~P23 -- (input), P24 -- (output), P25 -- (input)
#define P2PULLUP 0b00101000 // P23, P25 -- (pullup)
#define P2INIT 0b00101100 //
//#define P2INIT 0b00101110 //
#define P5IOMODE 0b11110000 // P50~P53 -- (out)
#define P5INIT 0b00001111 //
#define T80MODE 0b00000010 // clock:Fx/8 -- 2.0US (Fx = 4MHz)
#define T80TM125US 63 // 125US/2.0US = 62.5 ---> 63,126US
#define T20MODE 0b00000000 // clock:Fx/4 -- 1.0US (Fx = 4MHz), no capture, no output, no convert
#define INTWDTEN 0x01 // MK0.0
#define INTP0EN 0x02 // MK0.1
#define INTP1EN 0x04 // MK0.2
#define INTP2EN 0x08 // MK0.3
#define INTSR20EN 0x10 // MK0.4
#define INTST20EN 0x20 // MK0.5
#define INTTM80EN 0x40 // MK0.6
#define INTTM20EN 0x80 // MK0.7
#define INTAD0EN 0x01 // MK1.0
// LED通道值 0 ~ 7
#define LEDSLOW 0
#define LEDFAST 1
#define LEDPWRSAV 2
#define LEDCOOL 3
#define LEDAUTO 4
#define LEDSLEEP 5
#define LEDFAN 6
#define LEDTIMER 7
#define LEDPLUS 6
#define LEDCHECK 5
// 按键通道值 0 ~ 15
#define BTNCDOWN 0
#define BTNCUP 1
#define BTNCSLOW 2
#define BTNCFAST 3
#define BTNCNODEF 4
#define BTNCMODE 5
#define BTNCAUTO 6
#define BTNCSLEEP 7
#define BTNCPLUS 8
#define BTNCTIMER 9
#define BTNCCHECK 10
#define BTNCPWR 11
#define BTNCSEL1 12
#define BTNCSEL2 13
#define BTNCSEL3 14
#define BTNCSEL4 15
// 按键值 0 ~ 15
#define BTNPWR 0x88
#define BTNSLOW 0x20
#define BTNFAST 0x80
#define BTNAUTO 0x0f0
#define BTNCHECK 0x4
#define BTNCOOL 0x90
#define BTNPWRSAV 0x40
#define BTNSLEEP 0x0
#define BTNFAN 0x0e0
#define BTNTIMER 0x60
#define BTNDOWN 0x0b0
#define BTNUP 0x70
#define BTNPLUS 0x0f1
#define BTNMODE 0x0f2
#define BTNNODEF 0x0f3
#define BTNIFON 0x0f5
#define BTNIFTP 0x0f6
#define BTNIFOFF 0x0f7
#define BTNSEL1 0x0ff
#define BTNSEL2 0x0ff
#define BTNSEL3 0x0ff
#define BTNSEL4 0x0ff
#define KEYDEPRESS 0b00100000
#define KEYPRESSED 0b01000000
#define KEYANSWER 0b10000000
// 风机速度常数
#define FANLOW 10
#define FANMID 50
#define FANHIGH 99
#define TRIGWIDE 1500 // 1500uS
#define TRIGNARROW 600 // 600uS
#define TRIGW2N 1500 // 1500uS
#define TRIGFAST 340 // 340uS
#define RATEVOL1 0x0AF // 230V/115V
#define RATEVOL2 0x09C // 230V/115V
#define RATEVOL3 0x091 // 230V/115V
#define RATEVOL4 0x085 // 230V/115V
// 设定温度限值,摄氏16 ~ 32,华氏60 ~ 90
#define CTEMPSETL 16
#define CTEMPSETH 32
#define FTEMPSETL 60
#define FTEMPSETH 90
// 化霜温度,华氏温度->摄氏
#define TEMP30F 60 // 30F = -1℃
#define TEMP55F 110 // 55F = 12.8℃
#define TEMP60F 71 // 15.6℃
#define TEMP62F5 74 // 16.9℃
#define TEMP61F5 73 // 16.4℃
#define TEMP59F 70 // 15℃
#define TEMP2F5 5 //
#define TEMP1F5 3 //
#define TEMPN1F 2 //
#define TEMP0F5 1 //
#define TEMP2F 4 //
#define TEMP4F 8 //
// 数码管特殊显示信息
#define T1ERRCODEH 0x6D // 室温传感器故障代码显示,高位 --- 5
#define T1ERRCODEL 0x3F // 室温传感器故障代码显示,低位 --- 0
#define T2ERRCODEH 0x7D // 管温传感器故障代码显示,高位 --- 6
#define T2ERRCODEL 0x80 // 管温传感器故障代码显示,低位 --- .
#define BYPASSH 0x73 // bypass模式显示,高位 --- P
#define BYPASSL 0x7C // bypass模式显示,低位 --- b
#define PWRERRH 0x79 // 电源故障显示,高位 --- E
#define PWRERRL 0x50 // 电源故障显示,低位 --- r
#define MEMERRH 0x79 // EEPROM故障显示,高位 --- E
#define MEMERRL 0x5C // EEPROM故障模式显示,低位 --- o
#define DBYPASS 0x80
#define DFANSET 0x40
#define DTEMPSET 0x20
#define DTIMESET 0x10
// 时间常数
#define MAXWAIT 0x0ff // 255*125us = 31.875ms
#define ZCROSSMIN 80 // 50Hz--100, 60Hz--120
#define BEEPTIME 30 // 300Ms/10ms
#define TIM100MS 10 // 100ms/10ms
#define TIM160MS 25//16 // 160ms/10ms
#define TIM200MS 20 // 200ms/10ms
#define TIM150MS 15 // 150ms/10ms
#define TIM330MS 33 // 330ms/10ms
#define TIM350MS 35 // 350ms/10ms
#define TIM1S 100 // 1S/10ms
#define TIM2S5 250 // 2.5S/10ms
#define TIMK1S 10 // 1S/100ms
#define TIMK2S 20 // 2S/100ms
#define TIM2S 20 // 2S/100ms
#define TIMK4S 40 // 4S/100ms
#define TIMD2S5 16 // 2.5S/xxxms
#define TIMD5S 35 // 5S/xxxms
#define TIM3S 3 // 3S/1S
#define TIM5S 5 // 5S/1S
#define TIM10S 10 // 10S/1S
#define TIM30S 30 // 30S/1S
#define TIM60S 60 // 60S/1S
#define TIM1MIN 60 // 1M/1S
#define TIM200S 200 // 200S/1S
#define TIM3MIN 18 // 3M/10S
#define TIM5MIN 30 // 5M/10S
#define TIM2MIN 12 // 2M/10S
#define TIM10MIN 60 // 10M/10S
#define TIM30MIN 180 // 30M/10S
#define TIM60MIN 360 // 60M/10S
#define TIM8H 2880 // 8H/10S
#define TIM250H 250
extern bit b_BT10MS;
extern bit b_ErrEeprom, b_SysRestore;
extern bit b_ErrT1Sensor, b_ErrT2Sensor, b_T2Open;
extern bit b_RTDataOk, b_RTSameCode, b_RTRepeat;
bit b_TestRun;
bit b_FanCycle;
bit b_FanOut;
bit b_CompOut;
bit b_CompPort;
bit b_FiltOut;
bit b_Defrost;
bit b_AutoFan;
bit b_ModeCool;
bit b_ModePwrSav;
bit b_ModeSleep;
bit b_ModeFan;
bit b_Bypass;
bit b_Runing;
bit b_IFeel;
bit b_F2C2F;
bit b_DispCgrade;
bit b_RunTimer;
bit b_TimerTemp;
bit b_TimerTempA;
bit b_KeyRepeatA;
bit b_KeyRepeatB;
bit b_NewKey;
bit b_TempSetChg;
bit b_RTKeyHold;
bit b_IsRepeatA;
bit b_IsRepeatB;
bit b_SysBack;
bit b_ErrSysData;
bit b_ErrSystem;
bit b_BTimer02S;
bit b_BTimer1S;
bit b_BTimer10S;
bit b_BTimer60S;
extern unsigned char n_ADMin;
extern unsigned char n_ADMax;
extern unsigned char n_ADData[2];
extern unsigned char n_Button[16];
extern unsigned char n_RTLast[6];
extern unsigned char n_LEDDisp[2];
extern unsigned char n_NumDisp[2];
extern unsigned char n_SysData[];
extern unsigned char n_SysBack[];
extern unsigned char n_ZCrossCnt;
extern unsigned n_TrigDelay;
extern unsigned n_TrigDurat;
unsigned char n_GenBuf;
unsigned char n_BT01SCnt;
unsigned char n_BT02SCnt;
unsigned char n_BT1SCnt;
unsigned char n_BT10SCnt;
//unsigned char n_BT60SCnt;
unsigned char n_TempSet;
unsigned char n_TempSetD;
unsigned char n_IFTemp;
unsigned char n_FanSpeed;
unsigned char n_FanSel;
unsigned char n_FanSelAdj;
unsigned char n_VolLast;
unsigned char n_TimerSet;
unsigned char n_KeyInput;
unsigned char n_RTKeyLast;
unsigned char n_DispMode;
unsigned char n_DispTime;
unsigned char n_BeepTime;
unsigned char n_LEDIFDelay;
unsigned char n_LEDIFFlash;
unsigned char n_IFeelTime;
unsigned char n_TestStep1S;
unsigned char n_TempChg3S;
unsigned char n_TempDisp2S;
unsigned char n_SysBack10S;
unsigned char n_Restore1S;
unsigned char n_Frost1S;
unsigned char n_Defrost1S;
unsigned char n_CompWaitCnt;
unsigned char n_Comp1Min;
unsigned char n_Comp3Min;
unsigned char n_Comp5Min;
unsigned char n_FanFst035S;
unsigned char n_Fan30SCnt;
unsigned char n_FanStop3S;
unsigned char n_FanCycleCnt;
unsigned char n_Fan30Min;
unsigned char n_VolAdj5S;
unsigned char n_Fan1MinCnt;
unsigned char n_KeyRepeatA;
unsigned char n_KeyRepeatB;
unsigned char n_KeyRT200MS;
unsigned char n_KeyHold2S;
unsigned char n_KeyHold4S;
unsigned char n_KeyUPWait;
unsigned char n_KeyDNWait;
unsigned char n_Timer30Min;
unsigned n_SleepTime;
unsigned n_LEDIFLight;
static const unsigned char TBL_Button[16];
static const unsigned char TBL_FanSelAdj[4][13];
static const unsigned char TBL_PwrVolAdj[4][18];
static const unsigned TBL_PwrAdjTrig[18];
static const unsigned TBL_LEDBright[36];
static const unsigned TBL_TrigD[27];
static const unsigned char TBL_Trig[27][18];
extern void BtnDisp(void);
extern void IF_LED(void);
extern void ADSample(void);
extern void TempToDisp(void);
extern void TpSetToDisp(void);
extern void SpeedToDisp(void);
extern void TimeToDisp(void);
extern void TempF2C(void);
extern void TempD2S(void);
extern void TpSetDC2F2C(void);
extern void ReadEeprom(void);
extern void WriteEeprom(void);
extern void RTSignWait(void);
void DeviceInit(void);
void DataInit(void);
void TimerProc(void);
void Display(void);
void LEDIFStart(void);
void GetIFTemp(void);
void IFTempProc(void);
void TempDisp(void);
void SysDataBack(void);
void FanOut(void);
void CompOut(void);
void FiltOut(void);
void Defrost(void);
void FanVolAdj(void);
void FanSpeed(void);
void KeyDeal(void);
void ModeDeal(void);
void IsRepeat(void);
void main()
{
__asm("\tdi");
#asm
movw hl, #0FE00H ; RAM start, SADDR RAM start #0FE20H
?LRamClr: ; RAM memory clear
xor a, a
mov [hl], a
incw hl
movw ax, hl
cmpw ax, #0FF00H ; SADDR RAM end #0FEFFH
bc $?LRamClr
movw ax, #0FEFFH
movw sp, ax
#endasm
DeviceInit();
DataInit();
__asm("\tei");
for(;;){
RUN = 1;
RTSignWait();
TimerProc();
ADSample();
IFTempProc();
KeyDeal();
ModeDeal();
Display();
BtnDisp();
IF_LED();
if(!n_VolAdj5S){
n_VolAdj5S = TIM60S;
FanVolAdj();
}
FanSpeed();
FanOut();
Defrost();
CompOut();
FiltOut();
SysDataBack();
// IF_LED();
}
}
void DeviceInit()
{
PCC = 0;
// CSS = 0;
// SCKM = 0;
// Watchdog timer
// TCL2 = 0x02; // Time Interval:2^13/Fx = 1.6384mS (Fx=5MHz)
TCL2 = 0x06; // Time Interval:2^17/Fx = 32.8mS (Fx=4MHz)
TMIF4 = 0;
WDTM = 0b00011000; // reset when overflow
// 通用端口
P0 = P0INIT;
PM0 = P0IOMODE;
P1 = P1INIT;
PM1 = P1IOMODE;
P2 = P2INIT;
PUB2 = P2PULLUP;
PM2 = P2IOMODE;
P5 = P5INIT;
PM5 = P5IOMODE;
/*
// UART通讯
PORT_REDE = 1; // receive mode
CSIM20 = 0x0;
ASIM20 = 0b00001000; // 8 bit data 1 stop bit
BRGC20 = 0x60; // 2046 Bauds
TXS20 = 0xff;
*/
// AD转换
ADM0 = 0b00000000; // STOP, Convert time:144/Fx = 34.37uS
ADS0 = 0; // select channel 0
TMC80 = T80MODE;
CR80 = T80TM125US;
TCE80 = 1;
TMC20 = T20MODE;
// INTM0 = INTM0P1F;
IF0 = 0;
IF1 = 0;
INTM0 = 0;
MK0 = ~(/*INTWDTEN+*/INTP0EN/*+INTP1EN*/+INTP2EN/*+INTSR20EN+INTST20EN*/+INTTM80EN/*+INTTM20EN*/);
MK1 = 0xFF; /*INTAD0EN*/
}
void DataInit(void)
{
n_ADMax = 0;
n_ADMin = 0xff;
ADCS0 = TRUE; // ADM0.7, start AD convert
n_Comp3Min = TIM3MIN;
n_Fan30Min = TIM30MIN;
n_Timer30Min = TIM30MIN;
n_RTKeyLast = n_KeyInput = 0x0ff;
n_VolAdj5S = TIM10S;
Display();
for(n_GenBuf=100; n_GenBuf>0; n_GenBuf--){
BtnDisp();
ADSample();
}
if(n_Button[BTNCSEL1] & KEYPRESSED) n_FanSel |= 0x01;
if(n_Button[BTNCSEL2] & KEYPRESSED) n_FanSel |= 0x02;
if(n_Button[BTNCSEL3] & KEYPRESSED) n_FanSel |= 0x04;
if(n_Button[BTNCSEL4] & KEYPRESSED) n_FanSel |= 0x08;
// b_SysRestore = 0;
ReadEeprom();
if(b_ErrEeprom) ReadEeprom();
if(b_ErrEeprom){
b_ErrSysData = 1;
n_SysData[0] =RATEVOL1;
n_SysData[1] =RATEVOL2;
n_SysData[2] =RATEVOL3;
n_SysData[3] =RATEVOL4;
n_SysData[4] =0;
// n_SysData[5] =0;
}
n_VolLast = n_SysData[0];
n_FanSelAdj = 5;
b_SysRestore = 1;
ReadEeprom();
if(b_ErrEeprom) ReadEeprom();
if(!b_ErrEeprom){
n_TempSetD = n_SysBack[0];
n_FanSpeed = n_SysBack[1];
if(n_SysBack[2] & 0x01) b_ModeFan = 1;
if(n_SysBack[2] & 0x02) b_ModeCool = 1;
if(n_SysBack[2] & 0x04){ b_ModePwrSav = 1; /*n_FanCycleCnt = TIM10MIN;*/}
if(n_SysBack[2] & 0x08) b_ModeSleep = 1;
if(n_SysBack[3] & 0x01) b_AutoFan = 1;
if(n_SysBack[3] & 0x02) b_DispCgrade = 1;
if(n_SysBack[3] & 0x04){ b_RunTimer = 1; n_TimerSet = n_SysBack[4];}
if(n_SysBack[3] & 0x08){ n_Restore1S = TIM1S+1;}//b_Runing = 1; n_BeepTime = BEEPTIME;}
if(n_SysBack[3] & 0x10) b_FiltOut = 1;
// if(n_SysBack[3] & 0x80) b_Filt30Min = 1;
// n_CheckTime = n_SysBack[5];
TempD2S();
}
else{
n_TempSet = 120;
n_TempSetD = 60;
n_FanSpeed = FANHIGH; //
b_ModeCool = 1;
b_DispCgrade = 0;
n_SysBack[3] &= ~0x80;
n_SysBack[5] = 0;
SysDataBack();
}
}
void SysDataBack()
{
if(!b_SysBack) return;
b_SysBack = 0;
n_SysBack[0] = n_TempSetD;
n_SysBack[1] = n_FanSpeed;
n_SysBack[2] = 0;
if(b_ModeFan) n_SysBack[2] |= 0x01;
if(b_ModeCool) n_SysBack[2] |= 0x02;
if(b_ModePwrSav) n_SysBack[2] |= 0x04;
if(b_ModeSleep) n_SysBack[2] |= 0x08;
n_SysBack[3] &= 0x80; // Filter 30分钟计时
if(b_AutoFan) n_SysBack[3] |= 0x01;
if(b_DispCgrade) n_SysBack[3] |= 0x02;
if(n_TimerSet) n_SysBack[3] |= 0x04;
if(b_Runing) n_SysBack[3] |= 0x08;
if(b_FiltOut) n_SysBack[3] |= 0x10;
n_SysBack[4] = n_TimerSet;
#asm
mov c, #6 ; total 8bytes
movw ax, #_n_SysBack
movw hl, ax
xor a, a
mov x, a
?LSysBk01:
add a, [hl]
bnc $?LSysBk02
inc x
?LSysBk02:
incw hl
dbnz c, $?LSysBk01
add a, #2eh
bnc $?LSysBk03
inc x
?LSysBk03:
mov [hl], a
xch a, x
mov [hl+1], a
#endasm
b_SysRestore = 1;
WriteEeprom();
// if(b_ErrEeprom) WriteEeprom();
}
void Display()
{
if(!b_Runing){
if(b_RunTimer){
n_LEDDisp[0] = (1<= TIM250H) n_LEDDisp[1] |= 1<= 20){ b_BTimer02S = 1; n_BT02SCnt = 0;}
n_BT1SCnt++;
if(n_BT1SCnt >= 98){
b_BTimer1S = 1;
n_BT1SCnt = 0;
n_BT10SCnt++;
if(n_BT10SCnt >= 10){ b_BTimer10S = 1; n_BT10SCnt = 0;}
}
n_BT01SCnt++;
if(n_BT01SCnt >= 10){
n_BT01SCnt = 0;
// 2003-05-22
if(!b_F2C2F){
if(n_KeyHold2S < TIMK2S) n_KeyHold2S++;
if(n_KeyHold4S < TIMK4S) n_KeyHold4S++;
}
if(n_TempDisp2S) n_TempDisp2S--;
}
if(n_FanFst035S) n_FanFst035S--;
// 2003-05-22
if(n_KeyRepeatA){
if(!b_F2C2F) n_KeyRepeatA--;
}
else{
b_KeyRepeatA = 1;
n_KeyRepeatA = TIM330MS;
if(n_KeyHold2S < TIMK2S) n_KeyRepeatA = TIM1S;
}
if(n_KeyRepeatB){
if(!b_F2C2F) n_KeyRepeatB--;
}
else{
b_KeyRepeatB = 1;
if(n_KeyHold4S < TIMK1S) n_KeyRepeatB = TIM1S;
else if(n_KeyHold4S < TIMK4S) n_KeyRepeatB = TIM200MS;
else n_KeyRepeatB = TIM100MS;
}
if(n_KeyRT200MS) n_KeyRT200MS--;
// 2003-05-22
if(n_Button[BTNCUP] & KEYPRESSED){if(n_KeyUPWait) n_KeyUPWait--;}
else n_KeyUPWait = TIM100MS;
if(n_Button[BTNCDOWN] & KEYPRESSED){if(n_KeyDNWait) n_KeyDNWait--;}
else n_KeyDNWait = TIM100MS;
if(n_BeepTime){ n_BeepTime--; TOE80 = 1;}
else TOE80 = 0;
if(n_TestStep1S) n_TestStep1S--;
if(n_Restore1S){
n_Restore1S--;
if(n_Restore1S == 1){ b_Runing = 1; n_BeepTime = BEEPTIME;}
}
if((n_ADData[1] <= TEMP30F) && !b_T2Open){
if(n_Frost1S < TIM2S5+1) n_Frost1S++;
}
else n_Frost1S = 0;
if(n_ADData[1] >= TEMP55F){
if(n_Defrost1S < TIM2S5+1) n_Defrost1S++;
}
else n_Defrost1S = 0;
if(n_LEDIFFlash > 0) n_LEDIFFlash--;
else{
if(n_LEDIFDelay > 0){
n_LEDIFDelay--;
n_LEDIFFlash = TIM150MS;
__asm("mov a, _n_LEDIFDelay");
__asm("rol a, 1 ");
__asm("clr1 a.0 ");
__asm("mov x, a ");
__asm("xor a, a ");
__asm("addw ax, #_TBL_LEDBright");
__asm("movw hl, ax ");
__asm("mov a, [hl] ");
__asm("mov x, a ");
__asm("mov a, [hl+1] ");
__asm("movw _n_LEDIFLight, ax");
// n_LEDIFLight = TBL_LEDBright[n_LEDIFDelay];
}
else{
n_LEDIFLight = 0;
n_LEDIFFlash = 0;
}
}
}
if(b_BTimer1S){
b_BTimer1S = 0;
if(n_Fan1MinCnt) n_Fan1MinCnt--;
if(b_F2C2F){
if(n_TempChg3S < TIM3S + 1) n_TempChg3S++;
if(n_TempChg3S == TIM3S){
TpSetDC2F2C();
n_DispTime = 0;
n_SysBack10S = TIM10S;
}
}
else n_TempChg3S = 0;
if(b_CompOut && n_Fan30SCnt) n_Fan30SCnt--;
n_GenBuf = n_TempSet - TEMPN1F;
if((n_ADData[0] <= n_GenBuf) && (!b_ErrT1Sensor)){ if(n_Comp1Min) n_Comp1Min--;}
else n_Comp1Min = TIM1MIN;
if(n_DispTime) n_DispTime--;
else{
n_DispMode = 0;
// b_TimerTempA = FALSE;
}
if(n_SysBack10S){
n_SysBack10S--;
if(n_SysBack10S == 1) b_SysBack = 1;
}
if(n_ZCrossCnt < ZCROSSMIN) b_Bypass = 0;
n_ZCrossCnt = 0;
if(!b_FanOut && n_FanStop3S) n_FanStop3S--;
if(n_VolAdj5S) n_VolAdj5S--;
if(n_IFeelTime) n_IFeelTime--;
else if(b_IFeel){
n_BeepTime = BEEPTIME;
b_IFeel = 0;
n_LEDIFDelay = 0;
}
}
if(b_BTimer10S){
b_BTimer10S = 0;
if(n_FanCycleCnt){ if(!n_Comp3Min && !b_CompOut) n_FanCycleCnt--;}
else{
if(b_FanCycle){ b_FanCycle = 0; n_FanCycleCnt = TIM10MIN;}
else{ b_FanCycle = 1; n_FanCycleCnt = TIM2MIN;}
}
if(n_Comp3Min) n_Comp3Min--;
if(n_Comp5Min) n_Comp5Min--;
if(b_FanOut){
if(n_Fan30Min) n_Fan30Min--;
else if(n_SysBack[5] < TIM250H){
n_Fan30Min = TIM30MIN;
if(n_SysBack[3] & 0x80){ n_SysBack[3] &= ~0x80; n_SysBack[5]++;}
else n_SysBack[3] |= 0x80;
b_SysBack = 1;
n_SysBack10S = 0;
}
}
if(b_RunTimer){
if(n_Timer30Min) n_Timer30Min--;
else{
n_Timer30Min = TIM30MIN;
if(n_TimerSet){
n_TimerSet--;
if(!n_TimerSet){
if(b_Runing){
b_Runing = 0;
// b_ModeSleep = 0;
TempD2S();
}
else{
b_Runing = 1;
n_TempDisp2S = 0;
// 定时开机改为高风制冷
b_ModeFan = FALSE;
b_ModePwrSav = FALSE;
b_ModeCool = TRUE;
b_AutoFan = FALSE;
n_FanSpeed = FANHIGH;
}
b_ModeSleep = 0;
b_RunTimer = 0;
}
b_SysBack = 1;
n_SysBack10S = 0;
}
}
}
if(b_ModeSleep){
n_SleepTime++;
if((n_SleepTime == TIM30MIN) || (n_SleepTime == TIM60MIN)){
n_TempSetD++;
if(b_DispCgrade) TempD2S();
else{
n_TempSetD++;
n_TempSet += TEMP2F;
}
n_Comp1Min = 1;
n_Comp5Min = 0;
n_Fan30SCnt = 0;
}
else if(n_SleepTime == TIM8H){
b_ModeSleep = 0;
n_TempSetD--;
n_TempSetD--;
if(b_DispCgrade) TempD2S();
else{
n_TempSetD--;
n_TempSetD--;
n_TempSet -= TEMP4F;
}
n_Comp1Min = 1;
n_Comp5Min = 0;
n_Fan30SCnt = 0;
}
}
}
if(!b_ModeSleep) n_SleepTime = 0;
}
void KeyDeal()
{
if(!b_Runing){
if((n_Button[BTNCPWR] & KEYPRESSED) && !(n_Button[BTNCPWR] & KEYANSWER)){
n_Button[BTNCPWR] |= KEYANSWER;
n_BeepTime = BEEPTIME;
n_KeyInput = BTNPWR;
if((n_Button[BTNCCHECK] & KEYPRESSED) && (n_Button[BTNCMODE] & KEYPRESSED)){
n_Button[BTNCCHECK] |= KEYANSWER;
n_Button[BTNCMODE] |= KEYANSWER;
b_TestRun = TRUE;
n_TestStep1S = TIM1S;
}
else if((n_Button[BTNCAUTO] & KEYPRESSED) && (n_Button[BTNCMODE] & KEYPRESSED)){
n_Button[BTNCAUTO] |= KEYANSWER;
n_Button[BTNCMODE] |= KEYANSWER;
b_Bypass = TRUE;
n_DispMode = DBYPASS;
n_DispTime = TIM5S;
}
return;
}
}
b_F2C2F = FALSE;
/* // 2003-05-22
if(b_Runing){
if((n_Button[BTNCSLOW] & KEYPRESSED) && (n_Button[BTNCCHECK] & KEYPRESSED)){
n_Button[BTNCSLOW] |= KEYANSWER;
n_Button[BTNCCHECK] |= KEYANSWER;
b_F2C2F = TRUE;
return;
}
}
*/
if(b_Runing){
if((n_Button[BTNCUP] & KEYPRESSED) && (n_Button[BTNCDOWN] & KEYPRESSED)){
n_Button[BTNCUP] |= KEYANSWER;
n_Button[BTNCDOWN] |= KEYANSWER;
b_F2C2F = TRUE;
// n_RTKeyLast = 0x0ff;
return;
}
}
if(!n_KeyRT200MS){
b_RTKeyHold = 0;
n_RTKeyLast = 0x0ff;
if((n_Button[BTNCUP] & KEYDEPRESS) && (n_Button[BTNCDOWN] & KEYDEPRESS)) n_KeyHold2S = 0;
if((n_Button[BTNCSLOW] & KEYDEPRESS) && (n_Button[BTNCFAST] & KEYDEPRESS)) n_KeyHold4S = 0;
}
if(b_RTDataOk){
b_RTDataOk = 0;
n_KeyRT200MS = TIM160MS;
if(!b_RTRepeat){
n_KeyInput = n_RTLast[2];
if((n_KeyInput == BTNIFON) || (n_KeyInput == BTNIFTP)) GetIFTemp();
n_RTKeyLast = n_KeyInput;
IsRepeat();
if(b_IsRepeatA){ n_KeyHold2S = 0; n_KeyRepeatA = TIM1S;}
if(b_IsRepeatB){ n_KeyHold4S = 0; n_KeyRepeatB = TIM1S;}
b_RTKeyHold = 1;
if((n_KeyInput != BTNIFTP) && (n_KeyInput != 0x0ff)) b_NewKey = 1;
if(n_KeyInput == BTNPWR) n_BeepTime = BEEPTIME;
}
}
else{
for(n_GenBuf = 0; n_GenBuf < 12/*16*/; n_GenBuf++){
if((n_Button[n_GenBuf] & KEYPRESSED) && !(n_Button[n_GenBuf] & KEYANSWER)){
// 2003-05-22
if((n_GenBuf == BTNCUP) && (n_KeyUPWait)) continue;
if((n_GenBuf == BTNCDOWN) && (n_KeyDNWait)) continue;
n_KeyInput = TBL_Button[n_GenBuf];
n_Button[n_GenBuf] |= KEYANSWER;
b_NewKey = 1;
IsRepeat();
if(b_IsRepeatA){ n_KeyHold2S = 0; n_KeyRepeatA = TIM1S;}
if(b_IsRepeatB){ n_KeyHold4S = 0; n_KeyRepeatB = TIM1S;}
n_TestStep1S = TIM1S;
break;
}
}
}
if(b_NewKey){
b_NewKey = 0;
if(b_Runing ||/* (n_KeyInput == BTNPWR) ||*/ (n_KeyInput == BTNTIMER)) n_BeepTime = BEEPTIME;
else if(b_RunTimer){
if((n_KeyInput == BTNUP) || (n_KeyInput == BTNDOWN) || (n_KeyInput == BTNMODE) || (n_KeyInput == BTNCOOL)) n_BeepTime = BEEPTIME;
}
}
else{
if(b_KeyRepeatA){
b_KeyRepeatA = 0;
if(b_RTKeyHold){
if((n_RTKeyLast == BTNUP) || (n_RTKeyLast == BTNDOWN)) n_KeyInput = n_RTKeyLast;
}
if(n_Button[BTNCUP] & KEYPRESSED)/* && (n_Button[BTNUP] & KEYANSWER))*/ n_KeyInput = BTNUP;
if(n_Button[BTNCDOWN] & KEYPRESSED)/* && (n_Button[BTNDOWN] & KEYANSWER))*/ n_KeyInput = BTNDOWN;
}
if(b_KeyRepeatB){
b_KeyRepeatB = 0;
if(b_RTKeyHold){
if((n_RTKeyLast == BTNSLOW) || (n_RTKeyLast == BTNFAST)) n_KeyInput = n_RTKeyLast;
}
if(n_Button[BTNCSLOW] & KEYPRESSED)/* && (n_Button[BTNSLOW] & KEYANSWER))*/ n_KeyInput = BTNSLOW;
if(n_Button[BTNCFAST] & KEYPRESSED)/* && (n_Button[BTNFAST] & KEYANSWER))*/ n_KeyInput = BTNFAST;
}
}
}
void IsRepeat()
{
b_IsRepeatA = 0;
b_IsRepeatB = 0;
if(b_Runing || b_RunTimer){
if((n_KeyInput == BTNUP) || (n_KeyInput == BTNDOWN)) b_IsRepeatA = 1;
}
if(b_Runing){
if((n_KeyInput == BTNFAST) || (n_KeyInput == BTNSLOW)) b_IsRepeatB = 1;
}
}
void ModeDeal()
{
if(b_ErrT2Sensor && (n_KeyInput != BTNPWR) && (n_KeyInput != BTNDOWN) && (n_KeyInput != BTNUP)){ n_KeyInput = 0x0ff; return;}
if(b_TestRun && (n_KeyInput != BTNPWR) && (n_KeyInput != BTNPLUS)){ n_KeyInput = 0x0ff; return;}
switch(n_KeyInput){
case BTNPWR:
b_ModeSleep = FALSE;
TempD2S();
if(b_Runing){
b_Runing = FALSE;
b_Bypass = 0;
b_TestRun = 0;
}
else if(!b_RunTimer){ b_Runing = TRUE; n_TempDisp2S = 0;}
b_RunTimer = FALSE;
b_TimerTemp = FALSE;
// b_TimerTempA = FALSE;
n_TimerSet = 0;
n_SysBack10S = TIM10S;
n_Restore1S = 0;
break;
case BTNTIMER:
if(!b_RunTimer){ b_RunTimer = TRUE; n_TimerSet = 1; n_Timer30Min = TIM30MIN; b_TimerTemp = FALSE;} // 0.5hour
else{
if(!b_Runing) b_TimerTemp = FALSE;
else { b_RunTimer = FALSE; n_TimerSet = 0; n_TempDisp2S = 0; /*b_TimerTempA = FALSE;*/}
}
n_SysBack10S = TIM10S;
break;
case BTNDOWN:
if(b_RunTimer && (!b_TimerTemp) && (!b_TimerTempA)){
if(b_ErrT2Sensor) break;
if(n_TimerSet > 1){ n_TimerSet--; n_SysBack10S = TIM10S;} // 0.5h min.
if(n_TimerSet > 10*2) n_TimerSet--;
n_Timer30Min = TIM30MIN;
n_DispMode = DTIMESET;
n_DispTime = TIM5S;
}
else if((b_Runing && (!b_ModeFan)) || ((!b_Runing) && b_TimerTemp)){
if(b_ErrT1Sensor) break;
b_ModeSleep = FALSE;
if(b_DispCgrade){
if(n_TempSetD > CTEMPSETL){ n_TempSetD--; b_TempSetChg = TRUE;}
}
else if(n_TempSetD > FTEMPSETL){ n_TempSetD--; b_TempSetChg = TRUE;}
n_DispMode = DTEMPSET;
n_DispTime = TIM5S;
}
break;
case BTNUP:
if(b_RunTimer && (!b_TimerTemp) && (!b_TimerTempA)){
if(b_ErrT2Sensor) break;
if(n_TimerSet < 24*2){
n_TimerSet++;
if(n_TimerSet > 10*2) n_TimerSet++;
n_SysBack10S = TIM10S;
}
n_Timer30Min = TIM30MIN;
n_DispMode = DTIMESET;
n_DispTime = TIM5S;
}
else if((b_Runing && (!b_ModeFan)) || ((!b_Runing) && b_TimerTemp)){
if(b_ErrT1Sensor) break;
b_ModeSleep = FALSE;
if(b_DispCgrade){
if(n_TempSetD < CTEMPSETH){ n_TempSetD++; b_TempSetChg = TRUE;}
}
else if(n_TempSetD < FTEMPSETH){ n_TempSetD++; b_TempSetChg = TRUE;}
n_DispMode = DTEMPSET;
n_DispTime = TIM5S;
}
break;
case BTNMODE:
if(!b_Runing){
if(b_RunTimer) b_TimerTemp = TRUE;
break;
}
n_DispTime = TIM5S;
n_DispMode = DTEMPSET;
if((!b_ModeFan) && (!b_TimerTempA) && b_RunTimer){ b_TimerTempA =TRUE; break;}
// b_ModeSleep = FALSE;
if(!b_ModePwrSav){
b_TimerTempA = TRUE;
n_Comp5Min = 0;
}
if(b_ModeCool){
b_ModeCool = FALSE;
b_ModeFan = FALSE;
b_ModePwrSav = TRUE;
b_FanCycle = 0;
n_FanCycleCnt = TIM10MIN;
}
else if(b_ModePwrSav && (!b_IFeel)){
b_ModeSleep = FALSE;
b_ModeCool = FALSE;
b_ModePwrSav = FALSE;
b_ModeFan = TRUE;
n_TempDisp2S = 0;
if(b_AutoFan){ b_AutoFan = FALSE; n_FanSpeed = FANLOW;}
}
else{
b_ModeFan = FALSE;
b_ModePwrSav = FALSE;
b_ModeCool = TRUE;
}
TempD2S();
n_SysBack10S = TIM10S;
break;
case BTNCOOL:
if(!b_Runing){
if(b_RunTimer) b_TimerTemp = TRUE;
break;
}
// b_ModeSleep = FALSE;
b_ModePwrSav = FALSE;
b_ModeFan = FALSE;
if(!b_ModeCool){
b_ModeCool = TRUE;
n_Comp5Min = 0;
n_SysBack10S = TIM10S;
}
n_DispMode = DTEMPSET;
n_DispTime = TIM5S;
b_TimerTempA = TRUE;
TempD2S();
break;
case BTNIFTP:
n_IFeelTime = TIM200S;
if(!b_Runing) break;
if(b_ModeFan){
n_BeepTime = BEEPTIME;
break;
}
if(!b_IFeel){
n_BeepTime = BEEPTIME;
b_IFeel = 1;
}
LEDIFStart();
break;
case BTNIFOFF:
b_IFeel = 0;
n_LEDIFDelay = 0;
break;
default:
break;
}
if(b_Runing){
switch(n_KeyInput){
case BTNSLOW:
b_AutoFan = FALSE;
if(n_FanSpeed > FANLOW){ n_FanSpeed--; n_SysBack10S = TIM10S;}
n_DispMode = DFANSET;
n_DispTime = TIM5S;
n_LEDDisp[0] &= ~(1<= TIM250H){
n_SysBack[5] = 0;
n_SysBack[3] &= ~0x80;
n_Fan30Min = TIM30MIN;
n_SysBack10S = TIM10S;
}
break;
case BTNPWRSAV:
// b_ModeSleep = FALSE;
b_ModeCool = FALSE;
b_ModeFan = FALSE;
if(!b_ModePwrSav){
b_ModePwrSav = TRUE;
b_FanCycle = 0;
n_FanCycleCnt = TIM10MIN;
n_Comp5Min = 0;
n_SysBack10S = TIM10S;
}
n_DispMode = DTEMPSET;
n_DispTime = TIM5S;
b_TimerTempA = TRUE;
TempD2S();
break;
case BTNFAN:
if(b_IFeel) break;
b_ModeSleep = FALSE;
b_ModePwrSav = FALSE;
b_ModeCool = FALSE;
if(!b_ModeFan){
b_ModeFan = TRUE;
n_TempDisp2S = 0;
if(b_AutoFan){ b_AutoFan = FALSE; n_FanSpeed = FANLOW;}
n_SysBack10S = TIM10S;
}
TempD2S();
break;
case BTNSLEEP:
if(b_ModeCool || b_ModePwrSav){
b_ModeSleep ^= 1;
TempD2S();
n_Comp5Min = 0;
n_SysBack10S = TIM10S;
}
break;
case BTNPLUS:
b_FiltOut ^= 1;
n_SysBack10S = TIM10S;
break;
case BTNIFON:
if(!b_ModeFan){
b_IFeel = 1;
if(!n_LEDIFDelay) LEDIFStart();
else n_LEDIFDelay = TIMD2S5;
}
n_IFeelTime = TIM200S;
break;
default:
break;
}
}
n_KeyInput = 0x0ff;
if(b_TempSetChg){
b_TempSetChg = FALSE;
n_Comp1Min = 1;
n_Comp5Min = 0;
n_Fan30SCnt = 0;
TempD2S();
n_SysBack10S = TIM10S;
}
if(!n_DispTime || !b_RunTimer || !b_Runing || b_ModeFan) b_TimerTempA = FALSE;
if(!b_RunTimer) n_DispMode &= ~DTIMESET;
}
void FanOut()
{
if(b_Runing){
if(b_ModeFan || b_ModeCool || b_TestRun) b_FanOut = 1;
else if(b_ModePwrSav){
if(b_Defrost){
b_FanOut = 1;
b_FanCycle = 1;
n_FanCycleCnt = TIM2MIN;
}
else if(b_CompOut || n_Comp3Min) b_FanOut = 1;
else b_FanOut = b_FanCycle;
}
else b_FanOut = 0;
}
else b_FanOut = 0;
if(b_FanOut) n_FanStop3S = TIM3S;
if(!n_FanStop3S) n_FanFst035S = TIM350MS;
if(b_CompOut){ n_FanCycleCnt = TIM10MIN; b_FanCycle = 0;}
}
void CompOut()
{
if(!b_Runing || b_ModeFan) b_CompOut = 0;
else{
if(b_Bypass) b_CompOut = 1;
else{
if(((!n_Comp1Min) || b_Defrost)){
if(!n_Comp5Min){
b_CompOut = 0;
if(b_ModePwrSav) n_Fan30SCnt = TIM30S;
}
}
else{
n_GenBuf = n_TempSet + TEMP0F5;
if((n_ADData[0] >= n_GenBuf) || b_ErrT1Sensor){
if(!n_Comp3Min) b_CompOut = 1;
}
}
}
}
if(!b_ModePwrSav) n_Fan30SCnt = 0;
if(b_CompOut){
if(!n_Fan30SCnt){
if(!b_CompPort){ n_VolAdj5S = TIM60S; n_CompWaitCnt = MAXWAIT;}
b_CompPort = 1;
n_Comp3Min = TIM3MIN;
}
}
else{
if(b_CompPort){ n_VolAdj5S = TIM60S; n_CompWaitCnt = MAXWAIT;}
b_CompPort = 0;
n_Comp5Min = TIM5MIN;
}
}
void FiltOut()
{
if(b_FiltOut && b_Runing && b_FanOut){
if(!PIO_FiltPlus) n_VolAdj5S = TIM60S;
PIO_FiltPlus = 1;
}
else{
if(PIO_FiltPlus) n_VolAdj5S = TIM60S;
PIO_FiltPlus = 0;
}
}
void LEDIFStart()
{
n_LEDIFDelay = TIMD5S;
// n_LEDIFLight = 0;
n_LEDIFFlash = 0;
}
void Defrost()
{
if(b_Runing){
if(n_Frost1S > TIM2S5) b_Defrost = 1;
if(n_Defrost1S > TIM2S5) b_Defrost = 0;
if(b_T2Open) b_Defrost = 0;
}
else b_Defrost = 0;
}
void GetIFTemp()
{
#asm
mov a, _n_RTLast+3
mov x, #0
mov c, #7
?LGetIFTp00:
ror a, 1
bnc $?LGetIFTp01
inc x
?LGetIFTp01:
dbnz c, $?LGetIFTp00
xor a, x
bf a.0, $?LGetIFTp02
mov a, _n_RTLast+3
clr1 a.7
add a, #100
mov _n_IFTemp, a
ret
?LGetIFTp02:
mov _n_KeyInput, #0ffh
ret
#endasm
}
void IFTempProc()
{
if(!b_IFeel) return;
b_ErrT1Sensor = 0;
if(b_Runing && (!b_ModeFan)) n_ADData[0] = n_IFTemp;
}
void FanVolAdj()
{
if(n_SysData[4] & 0x01) { n_FanSelAdj = 5; return;}
#asm
mov a, _n_ADData+2
sub a, _n_VolLast
bnc $?LFanVolAdj01
xor a, #0ffh
inc a
?LFanVolAdj01:
cmp a, #2
bnc $?LFanVolAdj02
ret
?LFanVolAdj02:
#endasm
if(b_CompPort) n_GenBuf = (PIO_FiltPlus)? 3:2;
else n_GenBuf = (PIO_FiltPlus)? 1:0;
#asm
; 保留本次调节的电源电压值
mov a, _n_ADData+2
mov _n_VolLast, a
; 计算当前的额定电压标准值
movw hl, #_TBL_PwrAdjTrig
mov c, #0
mov b, #18-1
movw ax, _n_TrigDelay
addw ax, #550
?LFanVolAdj03:
cmp a, [hl+1]
bc $?LFanVolAdj08
bnz $?LFanVolAdj04
xch a, x
cmp a, [hl]
xch a, x
bc $?LFanVolAdj08
?LFanVolAdj04:
cmp _n_GenBuf, #0
bz $?LFanVolAdj06
mov a, _n_GenBuf
mov b, a
movw ax, #_TBL_PwrVolAdj
?LFanVolAdj05:
addw ax, #18
dbnz b, $?LFanVolAdj05
br $?LFanVolAdj07
?LFanVolAdj06:
movw ax, #_TBL_PwrVolAdj
?LFanVolAdj07:
xch a, x
add a, c
xch a, x
addc a, #0
movw hl, ax
mov a, [hl]
mov c, a
mov a, _n_GenBuf
mov x, a
xor a, a
addw ax, #_n_SysData
movw hl, ax
mov a, [hl]
sub a, c
br $?LFanVolAdj10
?LFanVolAdj08:
inc c
incw hl
incw hl
dbnz b, $?LFanVolAdj03
br $?LFanVolAdj04
?LFanVolAdj10:
mov c, a
movw ax, #_TBL_FanSelAdj
?LFanVolAdj11:
cmp _n_GenBuf, #0
bz $?LFanVolAdj12
addw ax, #13
dec _n_GenBuf
br $?LFanVolAdj11
?LFanVolAdj12:
movw hl, ax
mov a, c
add a, #20 ; shift the adj. value by 5
bnc $?LFanVolAdj13
mov a, #0ffh
?LFanVolAdj13:
mov x, #0
sub a, _n_ADData+2
bc $?LFanVolAdj15
mov c, #13
?LFanVolAdj14:
cmp a, [hl]
bc $?LFanVolAdj15
incw hl
inc x
dbnz c, $?LFanVolAdj14
?LFanVolAdj15:
mov a, x
mov _n_FanSelAdj, a
#endasm
}
void FanSpeed()
{
if(b_TestRun){
if(!n_TestStep1S) n_FanSpeed = FANLOW;
else n_FanSpeed = FANHIGH;
}
else if(b_AutoFan){
n_GenBuf = n_TempSet + TEMP2F5;
if(n_ADData[0] >= n_GenBuf){
if(n_FanSpeed == FANMID){
if(!n_Fan1MinCnt){ n_FanSpeed = FANHIGH; n_Fan1MinCnt = TIM1MIN;}
}
else if(n_FanSpeed != FANHIGH){ n_FanSpeed = FANMID; n_Fan1MinCnt = TIM1MIN;}
}
else{
n_GenBuf = n_TempSet - TEMPN1F;
if(n_ADData[0] <= n_GenBuf){
if(!n_Fan1MinCnt) n_FanSpeed = FANLOW;
}
else{
if((n_ADData[0] <= n_TempSet) && (n_FanSpeed == FANHIGH) && (!n_Fan1MinCnt)){
n_FanSpeed = FANMID;
n_Fan1MinCnt = TIM1MIN;
}
}
if((n_FanSpeed != FANMID) && (n_FanSpeed != FANHIGH)) { n_FanSpeed = FANLOW; n_Fan1MinCnt = 0;}
}
}
n_TrigDurat = TRIGWIDE;
if(n_FanFst035S){ n_TrigDelay = TRIGFAST; return;}
#asm
mov a, _n_FanSel
cmp _n_FanSelAdj, #5
bnc $?LFanSpeed00
mov _n_GenBuf, a
add a, _n_FanSelAdj
add _n_GenBuf, #5
br $?LFanSpeed02
?LFanSpeed00:
add a, _n_FanSelAdj
cmp a, #27
bc $?LFanSpeed01
mov a, #27-1
?LFanSpeed01:
mov _n_GenBuf, a
?LFanSpeed02:
rol a, 1
mov x, a
xor a, a
addw ax, #_TBL_TrigD
movw hl, ax
mov a, [hl+1]
mov x, a
mov a, [hl]
movw bc, ax
movw ax, #_TBL_Trig
?LFanSpeed03:
cmp _n_GenBuf, #0
bz $?LFanSpeed04
addw ax, #18
dec _n_GenBuf
br $?LFanSpeed03
?LFanSpeed04:
movw hl, ax
mov a, _n_FanSpeed
sub a, #10 ; FANLOW
mov _n_GenBuf, a
movw ax, bc
mov c, #5
?LFanSpeed05:
cmp _n_GenBuf, #0
bz $?LFanSpeed08
sub a, [hl]
bnc $?LFanSpeed06
dec x
?LFanSpeed06:
dbnz c, $?LFanSpeed07
incw hl
mov c, #5
?LFanSpeed07:
dec _n_GenBuf
br $?LFanSpeed05
?LFanSpeed08:
xch a, x
subw ax, #550 ; death of zerocross
movw _n_TrigDelay, ax
#endasm
if(n_TrigDelay > TRIGW2N) n_TrigDurat = TRIGNARROW;
}
// 按键代码
static const unsigned char TBL_Button[]=
{
// No.1 No.2 No.3 No.4 No.5 No.6 No.7 No.8
BTNDOWN, BTNUP, BTNSLOW, BTNFAST, BTNNODEF, BTNMODE, BTNAUTO, BTNSLEEP,
// No.9 No.10 No.11 No.12 No.13 No.14 No.15 No.16
BTNPLUS, BTNTIMER, BTNCHECK, BTNPWR, BTNSEL1, BTNSEL2, BTNSEL3, BTNSEL4
};
static const unsigned char TBL_FanSelAdj[4][]=
{
// 最多下调5档,上调8档,共13档。中心偏移值 20 <-> 0(5)
// -5 -4 -3 -2 -1 0 +1 +2 +3 +4 +5 +6 +7 +8
{
0, 4, 9, 13, 18, 23, 28, 32, 37, 41, 46, 50, 55
},
{
1, 5, 10, 14, 18, 23, 27, 32, 36, 40, 45, 49, 53
},
{
3, 7, 11, 15, 19, 22, 26, 30, 34, 38, 42, 46, 49
},
{
5, 8, 12, 15, 19, 22, 26, 29, 33, 36, 40, 43, 46
},
};
static const unsigned char TBL_PwrVolAdj[4][]=
{
{
0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 6, 5, 4
}, // all off
{
0, 0, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 4, 4
}, // flz on
{
0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2
}, // comp on
{
0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1
}, // all on
};
static const unsigned TBL_PwrAdjTrig[]=
{
/*4530,*/ 4420, 4310, 4190, 4070, 3950, 3830, 3700, 3560, 3420, 3270, 3110, 2940, 2750, 2540, 2290, 2000, 1600, 780,
};
/*
static const unsigned char TBL_LEDBright[]=
{
0x00, 0x10, 0x40, 0xa4, 0xaa, 0xb5, 0xbb, 0xef, 0xff,
0xff, 0xef, 0xbb, 0xb5, 0xaa, 0xa4, 0x40, 0x10, 0x00, 0x00
};
*/
static const unsigned TBL_LEDBright[]=
{
0x0000, 0x0000, 0x0100, 0x1010, 0x4208, 0x8888, 0x9124, 0x924a, 0xa4a9,
0x5555, 0xab55, 0xadb6, 0x6db6, 0xedb6, 0x7777, 0xfbfb, 0xff7f, 0xffff,
0xffff, 0xff7f, 0xfbfb, 0x7777, 0xedb6, 0x6db6, 0xadb6, 0xab55, 0x5555,
0xa4a9, 0x924a, 0x9124, 0x8888, 0x4208, 0x1010, 0x0100, 0x0000, 0x0000
};
static const unsigned TBL_TrigD[]=
{
/*5161, 5074, */4986, 4897, 4805,
4714, 4621, 4527, 4431, 4334, 4234, 4132, 4027, 3920, 3808, 3693, 3573, 3449, 3319, 3180, 3034,
2876, 2702, 2512, 2294, 2018, 1690, 1167, 700
};
static const unsigned char TBL_Trig[27][]=
{
/* {
27, 27, 28, 29, 29, 29, 31, 32, 33, 35, 38, 40, 43, 48, 56, 67, 91,195
}, // 60V
{
26, 27, 27, 28, 29, 29, 30, 31, 33, 34, 37, 39, 42, 48, 55, 66, 89,191
}, // 62V
*/
{
25, 26, 26, 27, 28, 28, 30, 30, 32, 34, 36, 38, 42, 47, 53, 65, 88,187
}, // 64V
{
25, 25, 25, 26, 27, 28, 29, 30, 31, 33, 35, 38, 41, 46, 52, 64, 86,183
}, // 66V
{
24, 24, 25, 26, 26, 27, 28, 29, 31, 32, 35, 36, 41, 45, 51, 63, 85,178
}, // 68V
{
23, 23, 25, 25, 25, 26, 28, 28, 30, 32, 33, 36, 40, 44, 51, 61, 83,174
}, // 70V
{
23, 23, 23, 24, 25, 26, 27, 28, 29, 31, 32, 36, 38, 44, 49, 61, 81,169
}, // 72V
// ↓SEL = 0 (OFF OFF OFF OFF)
{
22, 22, 23, 24, 24, 25, 26, 27, 28, 31, 32, 34, 38, 42, 49, 59, 80,164
}, // 74V
{
21, 22, 22, 23, 24, 24, 25, 27, 28, 29, 31, 34, 37, 41, 48, 58, 78,159
}, // 76V
{
21, 21, 21, 22, 23, 24, 24, 26, 27, 29, 30, 33, 36, 41, 46, 56, 77,154
}, // 78V
{
20, 20, 21, 22, 22, 23, 24, 25, 26, 28, 29, 33, 35, 39, 45, 56, 74,149
}, // 80V
{
19, 20, 20, 20, 22, 22, 23, 25, 25, 27, 29, 31, 35, 38, 44, 54, 72,144
}, // 82V
{
18, 19, 20, 20, 21, 21, 23, 23, 25, 26, 28, 30, 34, 37, 43, 52, 71,138
}, // 84V
{
17, 18, 19, 20, 20, 21, 21, 23, 24, 25, 28, 29, 32, 37, 41, 51, 68,133
}, // 86V
{
17, 18, 18, 18, 20, 20, 21, 22, 23, 24, 27, 28, 32, 35, 40, 49, 66,127
}, // 88V
{
16, 17, 18, 18, 18, 19, 21, 21, 22, 24, 25, 28, 30, 34, 39, 48, 64,120
}, // 90V
{
16, 16, 17, 17, 18, 18, 20, 20, 21, 23, 25, 26, 29, 33, 38, 46, 61,114
}, // 92V
{
15, 15, 16, 17, 17, 18, 18, 20, 20, 22, 24, 25, 28, 32, 36, 44, 59,107
}, // 94V
{
14, 15, 15, 16, 16, 17, 18, 19, 19, 21, 23, 24, 27, 30, 35, 42, 56,100
}, // 96V
{
14, 14, 14, 15, 15, 16, 17, 18, 19, 20, 21, 23, 26, 28, 33, 40, 53, 93
}, // 98V
{
12, 13, 14, 14, 15, 15, 16, 16, 18, 19, 20, 22, 24, 28, 31, 37, 50, 85
}, // 100V
{
11, 12, 13, 13, 14, 14, 15, 16, 17, 17, 19, 21, 23, 25, 29, 35, 47, 76
}, // 102V
{
11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 18, 19, 21, 24, 27, 32, 43, 67
}, // 104V
// ↑ SEL = 15 (ON ON ON ON)
{
10, 10, 11, 11, 11, 12, 13, 13, 14, 15, 17, 17, 19, 22, 24, 30, 37, 58
}, // 106V
{
9, 9, 10, 10, 10, 11, 11, 12, 13, 13, 15, 15, 17, 19, 22, 26, 32, 47
}, // 108V
{
7, 8, 8, 9, 9, 9, 9, 10, 11, 12, 12, 13, 15, 16, 18, 21, 26, 35
},
{
6, 6, 6, 7, 7, 7, 7, 8, 8, 9, 10, 10, 11, 12, 13, 15, 17, 22
},
{
3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6
},
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
},
};
// THE END