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

📄 waterctrlv1.c

📁 一个基于PIC18F单片机的开发的流量计量仪表
💻 C
📖 第 1 页 / 共 5 页
字号:
					if(counterflag&0x03)
					{	
//						carderrorbyte=CheckCardIsMove();
//						if(carderrorbyte!=0x01)
//						{
//							goto CardIsRemove;
//						}						
						switch(counterflag&0x03)
						{
							case 1:
								if((SIN1==1))
								{
									if(counterflag&0B01000000)     //上一次的标记是SIN2的
									{
									 	counterflag &= 0B11101110; //无效
										carderrorbyte = 0x23;
										goto errGuanHuangGuang;
									}
									else
									{								
										counterflag = 0B00010000;
									}
								}	
								else
								{
									//error
									carderrorbyte = 0x24;
									goto errGuanHuangGuang;	
								}
									break;

							case 2:
								if((SIN2=1))
								{
									if(counterflag&0B10000000)     //上一次的标记是SIN1的
									{
										counterflag &= 0B11011101; //无效
										carderrorbyte = 0x23;
										goto errGuanHuangGuang;
									}
									else
									{
										counterflag = 0B00100000;
									}
								}	
								else
								{
									//error
									carderrorbyte = 0x24;
									goto errGuanHuangGuang;
								}
									break;
						    case 3:
								counterflag &= 0x30;
									break;

							default:
									counterflag &= 0x00;
//									carderrorbyte = 0x23;
//									goto errGuanHuangGuang;
									break;
		
						}

						if(counterflag&0x30)              //走了一个单位的水?
						{
							if(counterflag==0B00010000)   //是SIN2走的?记一个标致
								counterflag=0B01000000;
							if(counterflag==0B00100000)   //是SIN1走的?记一个标记
								counterflag=0B10000000;
							AddUsingValueOp(panma);       //DEC water value opertion
							systemflag1 |= 0x10;
						}
						INTCON3bits.INT1IF=0;
						INTCON3bits.INT2IF=0;
						SIN2INTEN=1;
						SIN1INTEN=1;
//						continue;
						if(0)
						{
							errGuanHuangGuang:		
							INTCON3bits.INT1IF=0;
							INTCON3bits.INT2IF=0;
							SIN2INTEN=1;
							SIN1INTEN=1;
							//display errer flger
//							CloseValve();
							ClearNumDpy(1,1);
							DYP_Failure_Flg();
							DisplayErrCode(carderrorbyte);
							Delay10KTCYx(0);
							Delay10KTCYx(0);
//							ClearNumDpy(1,1);
							UnDPY_Failure_Flg();
						}
					}
					
					//--------------------return write card 
  					if(systemflag1 & 0x10)
					{
						systemflag1 &= 0xef;
						carderrorbyte=WrCdMomey(5);
						if(carderrorbyte!=0x01)
						{
							goto CardIsRemove;
						}
					}
					//-------------------setting water valua is over?
					if(systemflag1&0x20)
					{

						CloseValve();
						carderrorbyte=WrCdMomey(5);//at last return card
						if(carderrorbyte!=0x01)
						{
							goto CardIsRemove;
						}
						systemflag1&=0xdf;
						RevBuffer[19]=6;
//						FM1702HARTPD;       //fm1702 power down
						for(RevBuffer[19];RevBuffer[19]>0;RevBuffer[19]--)
						{
						//	ClearNumDpy(0,0);
							ClearNumDpy(1,1);
							ClearNumDpy(2,2);
							Delay10KTCYx(0);// 0.16s
						//	DPY_Card_YLorJE_Num(CardBalance,0);
							DPY_SLorJE_Num(ShuiLiang,0);
							DPY_SDZorDJ_Num(SheDinLiang,1);
							Delay10KTCYx(0);// 0.16s
						}
						ClearNumDpy(0,0);
						Wr1BCDNumToLcd(0,1);
						Wr1BCDNumToLcd(25,2);
						Wr1BCDNumToLcd(14,4);
						Wr1BCDNumToLcd(10,3);
						Delay10KTCYx(0);
						Delay10KTCYx(0);
						Delay10KTCYx(0);
//						write use water record
//						CardStopOp();
						ClearNumDpy(0,0);
						ClearNumDpy(1,1);
						ClearNumDpy(2,2);
						ClearNumDpy(3,3);
						ClearRamValue(); 
						LEDCTRL = 1;//CLOSE BACK LED LIGHT
						INTCON3bits.INT1IF=0;
						INTCON3bits.INT2IF=0;
						SIN2INTEN=1;
						SIN1INTEN=1;
						Settingpricehalf[0]=0;
						Settingpricehalf[1]=0;
						Settingpricehalf[2]=0;
						UnDYP_CardOn_Flg();
						break;
					}
			}		
		}


		//-------------------------------------        


		//-------------------------------------recevice whole frame from RS485?
		if(systemflag & 0x40)//
		{
			systemflag &= 0xbf;
		}
	}
}

//*****************************************************************//
//Name 		:InitialPort
//Input		:void
//Output	:void
//Function	:This function initialize all mcu i/oport 
//D.R.P		:QiuHao
//Date		:06.06.05
//*****************************************************************//
void InitializeSystem(void)
{	
	INTCONbits.GIE=0;									    //关总中断
///////////////////////////////////// I/O Port Initialon/////////////  
//	FM1702 Using I/O Port
	DDRHQCMN	=	0;   								
	DDRHQCDI	=	1;	
	DDRHQCDO	=	0;	
	DDRHQCCLK	=	0;
	DDRHQCRST	=	0;
	
	HQCMN		=	1;
	HQCDO		=	1;
	HQCCLK		=	1;
	HQCRST		=	1;

//	KEY
	DDRKEY_OK   =   1;
	DDRSETKEY	=	1;

//	HT1623 Using I/O Port
	DDRLEDCTRL	=	0;
	DDRLCDCS	=	0;
	DDRLCDRD	=	0;
	DDRLCDRW	=	0;
	DDRLCDDA	=	1;

	LEDCTRL		=	1;
	LCDCS		=	1;
	LCDRD		=	1;
	LCDRW		=	1;
	LCDDA_OUT	=	1;	

// 	DS1302 Using I/O Port
	DDRDSCLK	=	0;
	DDRDSRST	=	0;
	DDRDSDA		=	0;

	DSCLK		=	1;
	DSRST		=	1;
	DSDA_OUT	=	1;

//	AT24C1024 Using I/O Port
	DDRE2_WP		=	0;
	DDRE2_CLK		=	0;
	DDRE2_SDA		=	0;

	E2_WP			=	1;
	E2_CLK			=	1;
	E2_SDA_OUT		=	1;

//	Valve Contrl
	DDRCLOSE		=	0;
	DDROPEN			=	0;
	
	CLOSE			=	0;
	OPEN			=	0;

//	counter key
	DDRSIN1         =	1;
	DDRSIN2			=	1;
	DDRSOUT			=	0;
	SOUT			=	0;
	
///////////////////////////////////// Serial port initialon //////////
	DDRTX1 = 0;                                     //TX pin set output
	DDRTX2 = 0;
	DDRRX1 = 1;										//RX pin set input
	DDRRX2 = 1;
///////////////////////////////////////// I/O end ////////////////////

//////////////////////////////////// Configure Serial COM register ///
////// COM1 ////// 
	//Buad Seta Setting 
	SPBRG1 = 25;										//12:=19.2Kbit/s														//25:= 9.6Kbit/s
	//Sent mode
	TXSTA1bits.SYNC = 0;								//ASYN mode
//	TXSTA1bits.TX9 = 0;									//8 Bit mode
	TXSTA1bits.BRGH = 0;								//Low buad reta Mode
	TXSTA1bits.TXEN = 1;                                //TX enialbe
	//Receive.mode
//	RCSTA1bits.RX9 = 0;									//8bit mode
	RCSTA1bits.CREN = 1;								//Continuum receive enialbe
//	RCSTA1bits.ADDEN = 0;								//No 9bit
	RCSTA1bits.SPEN = 1;          	                    //Serial port1 enabled.
														//useing RC6\TX1,RC7\RX1
////// COM2 ////// 
	//Buad Seta Setting 
	SPBRG2 = 12;										//12:=19.2Kbit/s														//25:= 9.6Kbit/s
	//Sent mode
	TXSTA2bits.SYNC = 0;								//ASYN mode
//	TXSTA2bits.TX9  = 0;								//8 Bit mode
	TXSTA2bits.BRGH = 0;								//Low buad reta Mode
	TXSTA2bits.TXEN = 1;                                //TX enialbe
	//Receive.mode
//	RCSTA2bits.RX9   = 0;								//8bit mode
	RCSTA2bits.CREN  = 1;								//Continuum receive enialbe
	RCSTA2bits.ADDEN = 0;								//No 9bit
	RCSTA2bits.SPEN  = 0;          	                    //Serial port2 enabled.
														//useing RC6\TX1,RC7\RX1
	PIE1bits.TX1IE = 0;
	IPR1bits.TX1IP = 1; 
	IPR1bits.RC1IP = 1;									//Low prionty int
	PIE1bits.RC1IE = 1;									
 	RCONbits.IPEN  = 1;	

////// PORT B ////////
 	INTCON2bits.INTEDG0 = 1; //
 	INTCON2bits.INTEDG1 = 0;
 	INTCON2bits.INTEDG2 = 0;
 	INTCON2bits.INTEDG3 = 1;

	INTCON2bits.INT3IP = 0;  
//	INTCON2bits.BRIP   = 0;
	INTCON3bits.INT2IP = 1; //WATER COUNTER KEY IS HIGH INTERRUPT PIRPRITY  
	INTCON3bits.INT1IP = 1;

	INTCONbits.INT0IE  = 1;
//	INTCONbits.INTRBIE = 1;
	INTCON3bits.INT3IE = 0;
	INTCON3bits.INT2IE = 1;
	INTCON3bits.INT1IE = 1;

////// timer0 //////
////// Used by Watchdog   	
////// 
	T0CONbits.TMR0ON   = 0;
	T0CONbits.T08BIT   = 0;								//16bit timer
	T0CONbits.T0CS	   = 0;
//	T0CONbits.T0SE     = 0;
	T0CONbits.PSA      = 0;
	T0CONbits.T0PS2    = 1;								//256:1	
	T0CONbits.T0PS1    = 0;
	T0CONbits.T0PS0    = 1;
	INTCONbits.TMR0IF  = 0;								//Clear interrupt flag
//	INTCON2bits.TMR0IP = 1;								//high interrupt pironty
	INTCON2bits.TMR0IP = 0;								//low  interrupt pironty
	TMR0L = 0x00; 
	TMR0H = 0x00;
	INTCONbits.TMR0IE  = 1;								//Enable interrupt Timer0


/////  timer1  //////////////////////////////////////////////////////////////////
/////  timer1 time : 0.0625uS * 4 * 65535 *8 = 131072uS = 131.072mS   ///////////
/////  used by Open/Close valve                                       ///////////
/////////////////////////////////////////////////////////////////////////////////        
	T1CONbits.TMR1CS = 0;							//using internal clock
//	T1CONbits.T1SYNC								//when TMR1CS = 0,this bit is ignored
	T1CONbits.T1OSCEN = 0;							//
	T1CONbits.T1CKPS0 = 1;							//1:8 
	T1CONbits.T1CKPS1 = 1;							//
	T1CONbits.RD16 = 1;								//set 16 bit timer
	PIR1bits.TMR1IF   = 0;							//
	IPR1bits.TMR1IP = 0;							//low interrupt pirnoty
	TMR1L = 0x00; 
	TMR1H = 0x00;
	PIE1bits.TMR1IE = 1;

/////  timer3  //////////////////////////////////////////////////////////////////
/////  timer1 time : 											      ///////////
/////  used water wheel display                                       ///////////
///////////////////////////////////////////////////////////////////////////////// 
	T3CONbits.T3CKPS1 = 1;							// 1/4 
	T3CONbits.T3CKPS0 = 0;
	T3CONbits.RD16    = 1;							//16 bit timer
	T3CONbits.TMR3CS  = 0;							//clock from fosc/4
	T3CONbits.TMR3ON  = 0;
	IPR2bits.TMR3IP   = 0;							//low interrupt pirnoty
	PIE2bits.TMR3IE   = 1;
	PIR2bits.TMR3IF   = 0;
	TMR3L = 0x00;
	TMR3H = 0x00;

////close some mudle
	CMCON=0x07;											//关闭比较器
	ADCON0=0X00;								        //AD无效,全部为数字口

//////////								
	INTCONbits.PEIE  = 1;                               //Open low interrupt enailbe 
	INTCONbits.GIE = 1;
														//Open interrupt enaible 	
	En_dswork();  
	InitHT1623Port();
	InitialFM1702(0);
	Endisplay();
	InitLcdDpy();
	ReadTime(systemtime);
	Wr1BCDNumToLcd(systemtime[0]&0x0f, 28);      //X
	Wr1BCDNumToLcd((systemtime[0]&0xf0)>>4, 27); //X*10
	Wr1BCDNumToLcd(systemtime[1]&0x0f, 26);
	Wr1BCDNumToLcd((systemtime[1]&0xf0)>>4, 25);
	Wr1BCDNumToLcd(systemtime[2]&0x0f, 24);
	Wr1BCDNumToLcd((systemtime[2]&0xf0)>>4, 23);
	Wr1BCDNumToLcd(systemtime[3]&0x0f, 21);
	Wr1BCDNumToLcd((systemtime[3]&0xf0)>>4, 20);
	Wr1BCDNumToLcd(systemtime[4]&0x0f, 19);
	Wr1BCDNumToLcd((systemtime[4]&0xf0)>>4, 18);
	Wr1BCDNumToLcd(systemtime[6]&0x0f, 17);
	Wr1BCDNumToLcd((systemtime[6]&0xf0)>>4, 16);
	READ_E2PROM(&carderrorbyte,BeingUserFlagADD,1);	
	if(carderrorbyte!=0xa5)
	{
		KEY_B[0]=0xff;
		KEY_B[1]=0xff;
		KEY_B[2]=0xff;
		KEY_B[3]=0xff;
		KEY_B[4]=0xff;
		KEY_B[5]=0xff;
		WRITE_E2PROM(KEY_B,HartCardLoadPWAdd,6);
		Systemnum[0]=0xff;
		Systemnum[1]=0xff;
		Systemnum[2]=0xff;
		WRITE_E2PROM(Systemnum,SystemNumADD,3);
	}
}

//*****************************************************************//
//Name 		:Interruph
//Input		:void
//Output	:void
//Function	:high address interrupt ISR(low prinoty)
//D.R.P		:QiuHao

⌨️ 快捷键说明

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