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

📄 waterctrl4-wdt.c

📁 一个基于PIC18F单片机的开发的流量计量仪表
💻 C
📖 第 1 页 / 共 5 页
字号:
					systemtempint1 = 0;
					loopcnt++;
					ReflashLcdTimeDpy(1);
				}
				if(loopcnt==0)												//one page display 
				{
					loopcnt += 1;
					ClearNumDpy(1,1);
					DPY_SDZorDJ_Num(SheDSL,0x01);

					/*
					ClearNumDpy(2,2);
					YongSL[0] = 0;
					YongSL[1] = 0;
					YongSL[2] = 0;
					DPY_SLorJE_Num(YongSL,0x00);							//display ShuiLiang

					ClearNumDpy(3,3);
					YongJE[0] = 0;
					YongJE[1] = 0;
					YongJE[2] = 0;
					DPY_SLorJE_Num(YongJE,0x01);							//display JinE
					*/
				}
				if(loopcnt==100)												//two page display
				{
					loopcnt += 1;
					ClearNumDpy(1,1),
					DPY_SDZorDJ_Num(DanJ,0x00);
					/*
					READ_1_BYTE_E2PROM(YongSL+1,Current6vBatVolt+1,0);
					ClearNumDpy(2,2);
					DPY_SLorJE_Num(YongSL,0x00);							//voltage
					UnDPY_SL_Area();
					OneLcdFlagSET(21);	
					Wr1BCDNumToLcd(0 , 12);
					Wr1BCDNumToLcd(25 , 13);
					OneLcdFlagSET(67);

					READ_E2PROM(YongJE+2,CurrentGuanYaLi+1,2,0);
					ClearNumDpy(3,3);
					DPY_SLorJE_Num(YongJE,0x01);
					UnDPY_JE_Area();
					OneLcdFlagSET(63);	
					Wr1BCDNumToLcd(21 , 34);
					Wr1BCDNumToLcd(32 , 34);
					YongJE[2] = 0;
					YongJE[3] = 0;								//YaLi
 					*/
				}

				if(loopcnt==250)
				{
					loopcnt = 0;
					carderrorbyte=CheckCardIsMove();
					if(carderrorbyte!=0x01)						//card been remove
					{
						carderrorbyte =0x22;
						KEYDOWNDS;
						KEYUPDS;
						goto checkerror1;
					}
				}

				//-------------------setting
				if(systemflag2 & 0x01)
				{					
					systemflag2 &= 0xfe;
					ClearNumDpy(2,2);
					DPY_SLorJE_Num(YongSL,0x00);							//display ShuiLiang
					ClearNumDpy(3,3);
					DPY_SLorJE_Num(YongJE,0x01);							//display JinE
					systemflag2 = systemflag2 | 0x80;   						//Set setting use water mode flag	
					LcdWheelDisplay();
					break;
				}
				//-------------------open the valev
				if(systemflag2 & 0x08)
				{
					systemflag2 &= 0xf7;   					
					DPY_SLorJE_Num(YongSL,0x00);							//display ShuiLiang
					ClearNumDpy(3,3);
					DPY_SLorJE_Num(YongJE,0x01);							//display JinE
					systemflag2 = systemflag2 | 0x7f;   						//clear setting use water mode flag	
					systemflag &= 0xf7;
					break;
				}

			}		
			YongJE[0] = 0;
			YongSL[0] = 0;
			YongJE[1] = 0;
			YongSL[1] = 0;
			YongJE[2] = 0;
			YongSL[2] = 0;
gonogetwater:
			KEYUPDS;	
			KEYSELDS;
			KEYONOFFDS;
			KEYDOWNDS;
			systemflag2 &= 0xf0;								//clear all key flag
			ADPWRON;
			//she ding liang is 0?
			if(SheDSL[0] == 0)
				if(SheDSL[1] == 0)
					if(SheDSL[2]<0x50)
					{
						goto checkerror1;
					}
			for(systemtemp=0;systemtemp<YuKou;systemtemp++)	//dec 200L 	
			{ 
				AddUsingValueOp();
			}
			systemtemp = CntReturnWr();
			if(systemtemp != 0x01)
			{
				carderrorbyte = 0x22;
				goto stopusewater;
			}
			ReflhDisplayVal();
			DYP_OpenValve_Flg();

			//setting A/D
			ADCON1bits.VCFG1 = 0;				//use vcc and vss for Vref 
			ADCON1bits.VCFG0 = 0;
			ADCON1bits.PCFG3 = 1;				//AN0~AN6 available
			ADCON1bits.PCFG2 = 0;
			ADCON1bits.PCFG1 = 0;
			ADCON1bits.PCFG0 = 0;
			OPVEL;
			SIN1INTEN;
			SIN2INTEN;
			OPOUT1;
			OPOUT2;
			carderrorbyte = 1;
			systemflag2 &= 0xf0;
			countWTRCNT = 0;				
			cntkeyerr = 0;
			cntorder = 0;
			systemtemp = 0;

			loopcnt = 0;	
			systemtempint1 = 0;

			//Will Open Valve ,loop end When Open-key is turn on  
			while(VELSTACLIN)
			{
					/*
					//---------------------------------out of time check      25s Check
					loopcnt++;
					if(loopcnt==65530)
					{
						loopcnt = 0;
						systemtempint1 ++;
					}
					if(systemtempint1>1024)
					{
						systemtempint1 = 0;

					}
					//---------------------------------
					*/

					if(countWTRCNT> 0)
					{
						countWTRCNT -= 1;
						AddUsingValueOp();
						WaterWheelStChg();
						ClearNumDpy(4,4);				
						DPY_LJSLorRQ_Num(LieJSL,1);
						ReflhDisplayVal();
					}
						ReflashLcdTimeDpy(1);	
			}
			RSTVEL; 
			KEYDOWNEN;
			systemflag3 |= 0x08;
			loopcnt = 0;	
			timerscnt = 0;		
			//---------------------------------this loop is aboat count value of uesing water
			while(1)
			{

					loopcnt += 1;		

					//-------------------------------------
					DSGIE;
					if(SheDSL[0]<=YongSL[0])						//setting water is over
					{
						if(SheDSL[1]<=YongSL[1])
						{
							if(SheDSL[2]<=YongSL[2])
							{
								goto stopusewater;	
							}
						}		
					}
					//-------------------------------------Card Eu E emtpy
					if(CardYE[0]==0)
					{
						if(CardYE[1]==0)
						{
							if(CardYE[2]==0)
							{
								carderrorbyte = 0x30;
								CdBnk5Grp[14] |=0x02;
								goto stopusewater;	
							}
						}	
					}
					ENGIE;	
					if(loopcnt > 24000)
					{
						timerscnt += 1;
						loopcnt2 +=1;
						loopcnt=0;
						ReflashLcdTimeDpy(1);
					}
					if(loopcnt2>2)
					{
						loopcnt2 = 0;
						carderrorbyte=CheckCardIsMove();
						if(carderrorbyte!=0x01)						//card been remove
						{
							timerscnt = 0;
							carderrorbyte =0x22;
							goto stopusewater;
						}

					}
					if(timerscnt == 1)									//Select YaLi	way
					{
						timerscnt++;
						ADSELCLR;
						ADPRESSSEL;

						TURNADON;									
					}
					if(timerscnt == 3)
					{												//Start A/D
						timerscnt++;
						STARTAD;
					}
					if(timerscnt == 5)									//Read A/D
					{
						timerscnt++;
						if(!ADSTA)
						{
							PressureVal = ADVALH;
							TURNADOFF;				
						}
					}

					if(timerscnt==7)									//Count YaLi
					{
						timerscnt ++;
						CUT_YaLi();
					}

					if(timerscnt==10)
					{	
						timerscnt+=1;	
						ClearNumDpy(1,1);						//display SheDinLiang
						DPY_SDZorDJ_Num(SheDSL,0x01);
						ClearNumDpy(4,4);
						DPY_LJSLorRQ_Num(LieJSL,1);					//display LieJiLiang
						systemflag3 |= 0x08;
					}

					if(timerscnt == 12)
					{
						timerscnt++;
						ADSELCLR;
						ADPWRSEL;
						TURNADON;	
					}
					if(timerscnt == 16)
					{
						timerscnt++;
						STARTAD;
					}
					if(timerscnt == 18)
					{
						timerscnt++;
						if(!ADSTA)
						{
							VoltageVal = ADVALH;	
							TURNADOFF;	
							if(VoltageVal<143)
							{
								carderrorbyte = 0x2c;
								DPY_0Pow_Flg();						//display on power 
//								systemflag4 |= 0x01;		
								goto stopusewater;	
							}
						}
					}

					if(timerscnt==20)									//Count Voltage
					{
						timerscnt ++;
						CUT_Volt();
					}

					if(timerscnt>22)
					{
						timerscnt=0;
						ClearNumDpy(1,1);										//display DJ
						DPY_SDZorDJ_Num(DanJ,0x00);
						ClearNumDpy(4,4);
						if(systemflag2&0x10)										//display YaLi	 Volt
						{
							DPY_YaLi();
							systemflag2 &= 0xef;
						}	
						else
						{	
							systemflag2 |= 0x10;				
							DPY_Volt();
						}
						systemflag3 &= 0xf7;
					}

					//-------------------user turn on the ON/OFF KEY
					if(systemflag2&0x08)
					{
						systemflag2 &= 0xf7;
						KEYDOWNDS; 
						goto stopusewater;
					}
					//--------------------counter water
					if( countWTRCNT > 0)
					{
						while( countWTRCNT)
						{
							countWTRCNT -= 1;
							AddUsingValueOp();
							WaterWheelStChg();
							RtWrCdCNT+=1;
						}
						ReflhDisplayVal();

						if(systemflag3 & 0x08)					//reflash LieJiLiang			
						{
							ClearNumDpy(4,4);				//
							DPY_LJSLorRQ_Num(LieJSL,1);
						}	
					}
				
					//--------------------GuanHuanGuang error
					if(cntkeyerr!=0)
					{
						if(cntkeyerr&0x22)
						{
							carderrorbyte = 0x31;	
							cntkeyerr = 0;
							cntorder = 0;
							goto stopusewater;
						}
						if(GuHGERRCNT<12)
						{
							cntkeyerr = 0;
							cntorder = 0;
						}
						else
						{
							GuHGERRCNT = 0;
							carderrorbyte = 0x0c;
							cntkeyerr = 0;
							cntorder = 0;
							goto stopusewater;
						}

					}

					//-------------------return write card
					if(RtWrCdCNT>9)
					{
						RtWrCdCNT = 0;
						systemtemp = CntReturnWr();
						if(systemtemp != 0x01 )
						{
							carderrorbyte = 0x22;
							goto stopusewater;	
						}

					}
					//-------------------user use water stop 
					if(0)		
					{
stopusewater:
						CLVEL;
						DPY_CloseValve_Flg();
						KEYDOWNDS;
						
						systemtempint1 = 0;
						loopcnt = 0;
						while(VELSTAOPIN)
						{
							/*
							//---------------------------------out of time check      25s Check
							loopcnt++;
							if(loopcnt==65530)
							{
								loopcnt = 0;
								systemtempint1 ++;
							}
							if(systemtempint1>1024) 
							{
								systemtempint1 = 0;

							}
							//---------------------------------
							*/

							while( countWTRCNT)
							{	
								countWTRCNT -= 1;
								AddUsingValueOp();
								WaterWheelStChg();
								ReflhDisplayVal();
								ClearNumDpy(4,4);				
								DPY_LJSLorRQ_Num(LieJSL,1);
							}
							ReflashLcdTimeDpy(1);
						}
						RSTVEL;	
						systemtemp=CntReturnWr();
						if(systemtemp!=0x01)								//card been remove
						{
							timerscnt = 0;
							carderrorbyte =0x22;
						}

						if(carderrorbyte != 0x22)								//card is be three? return value
						{

							for(systemtemp=0;systemtemp<YuKou;systemtemp++)	//add 200L 	
							{ 
								BCDBytesAdd(CardYE,DanJCnt,5);				//
								BCDBytesSub(YongSL,OPnum3,3);				//Yong Shui Liang add 1unit
								BCDBytesSub(YongJE,DanJCnt,5);				//yong jing E add 1 unit
								BCDBytesSub(LieJSL,OPnum4,5);				//LIeJiShuiLiang add 1 unit
							}
							ReflhDisplayVal();
							ClearNumDpy(4,4);	
							DPY_LJSLorRQ_Num(LieJSL,1);
							CntReturnWr();
							if(carderrorbyte!=1 )
								goto tillit2;
							KEYDOWNEN;
							KEYUPEN;
							while(1)
							{
								loopcnt++;
								if(loopcnt==8000)

⌨️ 快捷键说明

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