⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frigwndw.c

📁 pic单片机实现的TCP/IP协议
💻 C
📖 第 1 页 / 共 3 页
字号:

		n_LEDDisp[1] = 0x0;
		return;
	}

	if(b_TestRun){
		n_NumDisp[0] = 0x7F;	// "88"
		n_NumDisp[1] = 0x7F;
		if(!n_TestStep1S) n_LEDDisp[0] = ~(1<<LEDSLOW) ;
		else n_LEDDisp[0] = ~(1<<LEDFAST) ;
		n_LEDDisp[1] = 0x0ff;
		if(!n_LEDIFDelay) LEDIFStart();
		return;
	}

	if(b_FiltOut) n_LEDDisp[1] |= 1<<LEDPLUS;
	else n_LEDDisp[1] &= ~(1<<LEDPLUS);

	if(n_SysBack[5] >= TIM250H) n_LEDDisp[1] |= 1<<LEDCHECK;
	else n_LEDDisp[1] &= ~(1<<LEDCHECK);

	if(b_AutoFan){
		n_LEDDisp[0] |= 1<<LEDAUTO;
		n_LEDDisp[0] &= ~(1<<LEDSLOW | 1<<LEDFAST);
	}
	else n_LEDDisp[0] &= ~(1<<LEDAUTO);
	if(b_ModeCool) n_LEDDisp[0] |= 1<<LEDCOOL;
	else n_LEDDisp[0] &= ~(1<<LEDCOOL);
	if(b_ModePwrSav) n_LEDDisp[0] |= 1<<LEDPWRSAV;
	else n_LEDDisp[0] &= ~(1<<LEDPWRSAV);
	if(b_ModeSleep) n_LEDDisp[0] |= 1<<LEDSLEEP;
	else n_LEDDisp[0] &= ~(1<<LEDSLEEP);
	if(b_ModeFan) n_LEDDisp[0] |= 1<<LEDFAN;
	else n_LEDDisp[0] &= ~(1<<LEDFAN);
	if(b_RunTimer) n_LEDDisp[0] |= 1<<LEDTIMER;
	else n_LEDDisp[0] &= ~(1<<LEDTIMER);

	if(n_DispTime && n_DispMode){
		if(n_DispMode & DBYPASS){
			n_NumDisp[0] = BYPASSL;
			n_NumDisp[1] = BYPASSH;
		}
		else if(n_DispMode & DFANSET){
			SpeedToDisp();
		}
		else if(n_DispMode & DTEMPSET){
			TempDisp();
		}
		else if(n_DispMode & DTIMESET){
			TimeToDisp();
		}

	}
	else{
		if(b_ErrSystem){
			n_NumDisp[0] = PWRERRL;
			n_NumDisp[1] = PWRERRH;
		}
/*
		else if(b_ErrEeprom){
			n_NumDisp[0] = MEMERRL;
			n_NumDisp[1] = MEMERRH;
		}
*/
		else if(b_RunTimer) TimeToDisp();
		else TempDisp();
		n_LEDDisp[0] &= ~(1<<LEDSLOW | 1<<LEDFAST);
	}

}

void TempDisp()
{
	if(b_ModeFan){
		if(!n_TempDisp2S){ TempToDisp(); n_TempDisp2S = TIM2S;}
	}
	else if(b_ErrT1Sensor){
		n_NumDisp[0] = T1ERRCODEL;
		n_NumDisp[1] = T1ERRCODEH;
	}
	else TpSetToDisp();
	if(b_ErrT2Sensor) n_NumDisp[0] |= T2ERRCODEL;
}

void TimerProc()
{
	if(b_BT10MS){
		b_BT10MS = 0;
		n_BT02SCnt++;
		if(n_BT02SCnt >= 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<<LEDAUTO | 1<<LEDFAST);
			n_LEDDisp[0] |= 1<<LEDSLOW;

			break;
		case BTNFAST:
			b_AutoFan = FALSE;
			if(n_FanSpeed < FANHIGH){ n_FanSpeed++; n_SysBack10S = TIM10S;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -