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

📄 ddcjc.c

📁 电动车测试平台控制系统。自动测量电动车各项参数
💻 C
📖 第 1 页 / 共 3 页
字号:
			 UartBuf[20] =  8 + 0xA0;

			 UartBuf[21] = 24 + 0xA0;	   //告
			 UartBuf[22] = 70 + 0xA0;

			 UartLength = 23;
	         break;
	 case 8:
	         //走纸
			 UartBuf[1] = 0x1B;
			 UartBuf[2] = 0x4A;
			 UartBuf[3] = 0x10;
			 UartLength = 4;
	         break;
	}
    //打印
	Uindex = 0;
	 	
	TI = TRUE;
}

void SendDisp (void) interrupt 1
{
	 /*
	 //比较里程
	 if ((KilDistance >= OptKilDis) ||
	     (KilDistance = OptKilDis &&
		  Distance >= OptDis))
	 {
	     TRIP_PIN = FALSE;   //取消测试
		 EX1 = FALSE;        //停止脉冲记数
		 bStartTime = FALSE; //停止计时
		 bDistAlarm = TRUE;	 
		 
		 //显示启动时间
	     IntToLED (StartTime, 2, 2, FALSE, TRUE, 14);		
	     //显示最大车速
	     IntToLED (MaxRate, 2, 1, TRUE, TRUE, 11);   
		 //显示最大速度时的电压
		 IntToLED (MinVoltage, 3, 1, TRUE, TRUE, 4); 
		 //显示最大速度时的电流
		 IntToLED (MaxCurrent, 2, 1, TRUE, TRUE, 8); 	 

		 //保存本次检验数据
		 if (!bSaved)
		 {
		     SaveRecord ();
			 bSaved = TRUE;
		 }

		 goto DISPDISTANCE;
	 }
	 */
	 if (bStartTime)
		 StartTime ++;

	 if (bPauseOver)
	 {
		 DispPause ++;

		 if (DispPause < 20)
		 {
		     RD = 1;    //保持
		     WR = 1;
		 }
		 else if (DispPause == 20)	  //显示满5秒
		 {
		     RD = 1;    //反转
		     WR = 0;
		 }
         else if (DispPause > 20)
		 {
		     if (T0 == 0)
			 {
			     RD = 1;    //停转
		         WR = 1;
				 TRIP_PIN = FALSE;   //取消测试
	         	 EX1 = FALSE;        //停止脉冲记数
				 ET0 = FALSE;
		         //bStartTime = FALSE; //停止计时
				 DispPause = 100;
				 bPauseOver = FALSE; 
				 CheckStatus = END_STATUS;
				 if (PrinterIndex == AUTO_PRINT)
				 {
				     //InitUart ();
					 //Printer(0);
				 }
			 }
		 }
	 }

	 if (DispPause == 100)
	 {
		 return;
	 }	 

	 if (CheckStatus == UNDER_STATUS)
	 { 
	     if (!bUndered)
		 {
		     goto VOLTAGE; 
		 }    
	     else
		 { 
		     if (Voltage > MinVoltage)
			     goto VOLTAGE;
		     else
			 {
			     if (AlarmTime < 2)
			     {
			         DispBuf[4] = 0x00; 
				     DispBuf[5] = 0x00;
				     DispBuf[6] = 0x00;
				     DispBuf[7] = 0x00;
			     }
			     else
			     {
			         IntToLED (MinVoltage, 3, 1, TRUE, TRUE, 4);
				 }
		         goto RATE;
			 } 
		 }
	 }
	 //FlashTime ++;

	 //if (FlashTime == 100)
	 {
	     //FlashTime = 0;
		 //显示电压
		 if (bVoltAlarm && OptVoltage != 0)
		 {
		     if (AlarmTime < 2)
			 {
			     DispBuf[4] = 0x00; 
				 DispBuf[5] = 0x00;
				 DispBuf[6] = 0x00;
				 DispBuf[7] = 0x00;
			 }
			 else
			 {
			     goto VOLTAGE;
			 }
		 }
		 else
		 {
VOLTAGE:
		     IntToLED (Voltage, 3, 1, TRUE, TRUE, 4); 
		 }
	 }

	 
	 //显示电流
     if (bCurrAlarm && OptCurrent != 0)
	 {
	     if (AlarmTime < 2)
		 {
		     DispBuf[9] = 0x00; 
			 DispBuf[10] = 0x00;
			 DispBuf[11] = 0x00;
		 }
		 else
		 {
		     goto CURRENT;
		 }
	 }
	 else
	 {
CURRENT:
	     IntToLED (Current, 2, 1, TRUE, TRUE, 9); 	
	 }
	 
	 if (bRateAlarm && OptRate != 0)
	 {
	     if (AlarmTime < 2)
		 {
		     DispBuf[12] = 0x00; 
			 DispBuf[13] = 0x00;
			 DispBuf[14] = 0x00;
			 DispBuf[15] = 0x00;
			 DispBuf[16] = 0x00;
			 DispBuf[17] = 0x00;
		 }
		 else
		 {
		     goto RATE;
		 }
	 }
	 else
	 {
RATE:
	     //显示轮子周长
	     //IntToLED (Wheel, 3, 3, FALSE, TRUE, 4);	

		 //显示速度
	     IntToLED (Rate, 2, 1, TRUE, TRUE, 12); 
	 }  
	 
	 //显示转速
	 //IntToLED (Rev, 2, 2, FALSE, TRUE, 14);
	 
	 //显示启动时间
	 IntToLED (StartTime/2, 2, 1, TRUE, TRUE, 15);			
	 
//DISPDISTANCE:	 
	 if (bDistAlarm && OptDistance != 0)
	 {
	     if (AlarmTime < 2)
		 {
		     DispBuf[0] = 0x00; 
			 DispBuf[1] = 0x00;
			 DispBuf[2] = 0x00;
			 DispBuf[3] = 0x00;	 
		 }
		 else
		 {
		    goto DISTANCE;
		 }
	 }
	 else
	 {
DISTANCE: 
		 //显示里程
	     if (KilDistance < 10)
	     {
	         //公里
	         IntToLED (KilDistance, 0, 0, TRUE, TRUE, 0);  
	         //小于1公里
	         IntToLED (Distance, 2, 2, FALSE, FALSE, 1);
	     }
	     else //if (KilDistance < 100)
	     {  
	         //公里
	         IntToLED (KilDistance, 1, 1, TRUE, TRUE, 0);  
	         //小于1公里
	         IntToLED (Distance/10, 1, 1, FALSE, FALSE, 2);
	     }
	 }

     AlarmTime ++;
	 AlarmTime %= 4;

	 /*
	 else
	 {
	     //公里
	     IntToLED (KilDistance, 2, 2, TRUE, TRUE, 0);  
	     //小于1公里
	     IntToLED (Distance/100, 0, 0, FALSE, FALSE, 3);
	 }
	 */

     /*
	 //公里
	 IntToLED (KilDistance, 2, 2, TRUE, TRUE, 0);  
	 //小于1公里
	 IntToLED (Distance, 2, 2, TRUE, FALSE, 3);
	 //小于1米
	 IntToLED (uLength, 2, 2, TRUE, FALSE, 6);
	 */
//RELOAD:
	 TH0 = TH0_VAL;
     TL0 = TL0_VAL;	
}

void PulseInput (void) interrupt 2
{ 
	 uchar Meter;     //米数
	 uint  LowMeter;  //小于米数

	 PreCount ++;

	 if (PreCount == PREHZ)
	 {	 
		 PreCount = 0;	
		 PulseCount ++;	 
		 DisPulse ++; 
		 
		 if (DisPulse == NValue)
	     { 
	         DisPulse = 0;
		     uLength = uLength + Wheel;
		     Meter = uLength / 1000;     //商数
		     LowMeter = uLength % 1000;  //余数
		     if (Meter > 0)
		     {
		         Distance = Distance + Meter;
			     uLength = LowMeter;
		     }

		     Meter = Distance / 1000;
		     LowMeter = Distance % 1000;
		     if (Meter > 0)
		     {
		         KilDistance = KilDistance + Meter;
			     Distance =LowMeter;
		     }
			 
			 if (bStartFlag)
			 {
			     bStartTime = TRUE;
				 bStartFlag = FALSE;
			 }    
	     }
	 }
}

void LEDShow (void) interrupt 3
{ 
	 Display ();

	 ShineTimes ++;
	 
	 if (ShineTimes == 10)
	 {
		 //信号灯闪烁
	     switch (CheckStatus)
		 {
		 case START_STATUS:
		      DispBuf[8] ^= 0x01;
		      //START_LED = !START_LED;
			  break;
		 case UNDER_STATUS:
		      DispBuf[8] ^= 0x02;
			  //UNDER_LED = !UNDER_LED;
			  break;
		 case OVER_STATUS:
		      DispBuf[8] ^= 0x04;
		      //OVER_LED = !OVER_LED;
			  break;
		 case END_STATUS:
		      DispMode();
		      break;
		 }
		       
	 }

     TH1 = TH1_VAL;
     TL1 = TL1_VAL;	
}

void UartInt(void) interrupt 4
{
	 /*
	 WordType idata CRC;
	 if (RI)
	 {
		 RI = FALSE;
		 UartBuf[Uindex] = SBUF;   //写缓冲区
		 
		 Uindex ++;

		 if (Uindex == 4)
		 {
			 Uindex = 0;
	  
         	 //计算校验码
	         CRC.w = CRC16(UartBuf, 2);
	         if (CRC.b[0] == UartBuf[2] &&		  //比较校验码
	         	 CRC.b[1] == UartBuf[3])
	         {
		         //准备数据
		         Get8583Data (RECORD, UartBuf, 16);

		         //计算CRC码
		         UartLength = 18;
	         	 CRC.w = CRC16(UartBuf, UartLength-2);
		         UartBuf[UartLength-2] = CRC.b[0];
		         UartBuf[UartLength-1] = CRC.b[1];
		         SBUF = UartBuf[0];
	         }
		 }
	 }

	 if (TI)
	 {
		 TI = FALSE; 
		 
		 Uindex ++;
		 
		 if (Uindex < UartLength)
		 {
		     SBUF = UartBuf[Uindex];
		 }
		 else
		 {
			 Uindex = 0;
		 }     
	 }
	 */

	 if (TI)
	 {
	     TI = FALSE;
		 PT1 = TRUE;

		 if (PrintIndex < 8)
		 {
			 if (Uindex < UartLength) 
			 {
			     PrinterByte(UartBuf[Uindex++]);
			 }
			 else if (Uindex == UartLength)
			 {	 
			     PrintIndex ++;
				 Printer (PrintIndex);	 
			 } 
     	 }
		 else
		 {
		     if (Uindex < UartLength)
			 {
			     PrinterByte(UartBuf[Uindex++]);
			 }
			 else
			 {
				 ES = FALSE;
			     PT1 = FALSE;
			 }	  
		 }
	 }
	 
}


void OnPulseTerm (void) interrupt 5	
{    	  
	 //dword RevTemp;

	 TF2 = FALSE;
     
	 PerTime ++;

	 if (PerTime == RATE_TIME)
	 {
	     //满1秒,计算滚筒转速
		 //RevTemp = 60 * (dword)PulseCount / NValue;
		 //计算线速度
		 //Rate = (dword)(3 * RevTemp * Wheel) / 5000;
		 Rate = 9 * (dword)PulseCount * Wheel / (250 * NValue);
		 //显示脉冲
	     //IntToLED (RevTemp, 3, 3, FALSE, TRUE, 0);

		 if (Rate != 0)
		 {
		     if (abs(Rate - OldRate) < 5)
		     {
		         bStartTime = FALSE;

				 DisTheory = Battery*19 /(2*RateCurrent);

				 if (ModeIndex == 3)
				 {
				     TRIP_PIN = FALSE;   //取消测试
	         	     EX1 = FALSE;        //停止脉冲记数
		      		 ET0 = FALSE;
					 ET2 = FALSE; 
					 CheckStatus = END_STATUS;

					 IntToLED (DisTheory, 3, 3, FALSE, TRUE, 0);
					 IntToLED (RateVoltage, 3, 1, TRUE, TRUE, 4); 
					 IntToLED (RateCurrent, 2, 1, TRUE, TRUE, 9);
					 IntToLED (MaxRate, 2, 1, TRUE, TRUE, 12); 

					 if (PrinterIndex == AUTO_PRINT)
					 {
					     InitUart ();
					     Printer(0);
					 }
				 }
		     }
		     else
		     {
		         OldRate = Rate;
		     }
		 }
		 

		 if (Rate > MaxRate)
		 {
			 MaxRate = Rate;
			 RateVoltage = Voltage;
			 RateCurrent = Current;
		 }

		 if (Rate > OptRate)	//超速报警
		     bRateAlarm = TRUE;
		 else 
		     bRateAlarm = FALSE;

	      if (P2 != 0xFF)
		  {
		      Delay (15, 15);
		      switch (~P2)
		      {
		      case 0x20:	 //开始刹车检测
			       if (CheckStatus == UNDER_STATUS)	 //过流检测
				   {
				       switch (ModeIndex)
					   {
					   case 0:
							  RD = 0;
						      WR = 1;
						      bPause = TRUE;
							  CheckStatus = OVER_STATUS;
					          break;
					   case 2:
					          break;
					   }
				   }
				   if (CheckStatus == START_STATUS)	 //欠压检测
				   {  
				       switch (ModeIndex)
					   {
					   case 0:
					   case 2:
					          CheckStatus = UNDER_STATUS;
					          break;
					   case 1:
							  RD = 0;
						      WR = 1;
						      bPause = TRUE;
							  CheckStatus = OVER_STATUS;
							  break;       
					   }
				   }
				   break;
		      }
		  }

		 PerTime = 0;
		 PulseCount = 0;
	 }

	 if (bPause)
	 {
	     if (Rate < ZERORATE || T1 == 0)
	     {
	         bPause = FALSE;
			 bPauseOver = TRUE;
			 RD = 1;    //保持
		     WR = 1;
			 TRIP_PIN = FALSE;   //取消测试
	         EX1 = FALSE;        //停止脉冲记数
			 ET0 = FALSE;
			 ET2 = FALSE; 
		     bStartTime = FALSE; //停止计时
			 DispPause = 0;
			 CheckStatus = END_STATUS;

			 IntToLED (DisTheory, 3, 3, FALSE, TRUE, 0);
			 
			 if (ModeIndex == 0 ||
			     ModeIndex == 2)
		         //显示欠压电压
		         IntToLED (MinVoltage, 3, 1, TRUE, TRUE, 4); 
		     else 
			     IntToLED (0, 3, 1, TRUE, TRUE, 4); 
		     
			 //显示过流电流
		     IntToLED (MaxCurrent, 2, 1, TRUE, TRUE, 9);
			  IntToLED (MaxRate, 2, 1, TRUE, TRUE, 12);

			 if (PrinterIndex == AUTO_PRINT)
			 {
			     InitUart ();
			     Printer(0);
			 }
	     }
	 }	 
}

void main ()
{
	 uchar uCurrYear, uCmpYear;
	 
	 bDispTime = TRUE;

	 InitSys ();  

	 while (1)
	 {
	      if (bDispTime)
		      DisplaySysTime ();

		  
		  if (P2 != 0xFF)
		  {
		      Delay (30, 100);

			  switch (~P2)
			  {
			  case /*0x08*/0x20:
			       if (CheckStatus == END_STATUS)
	               {
				       //显示当前记录编号 
					   IsShine = FALSE;
				       IsOption = FALSE;
					   bUndered = FALSE;
					   bDispTime = FALSE;
					   ClearAllData ();
					   if (ModeIndex == 0 ||
					       ModeIndex == 2)
					   {
					       MinVoltage = 0xFFFF;
					   }  
					   ClearLED ();
					   RecordIndex ++;
					   IntToLED (RecordIndex, 3, 3, FALSE, FALSE, 0);    
					   GetVoltage ();
					   IntToLED (Voltage, 3, 1, TRUE, TRUE, 4); 
					   Delay (255, 255);
					   InitT2 ();	  
					   TRIP_PIN = TRUE;     //开始测试
					   CheckStatus = START_STATUS; 
					   EX1 = TRUE;	        //开始脉冲记数 
					   ET0 = TRUE;
					   bStartFlag = TRUE;
				   }
			  	   break;			 
			  case 0x10:
			       IsShine = FALSE;
			       IsOption = FALSE;
			       TRIP_PIN = FALSE;    //取消测试
				   EX1 = FALSE;         //停止脉冲记数
				   ET0 = FALSE; 
				   DispPause = 0;
				   bPause = FALSE;
				   bPauseOver = FALSE; 
				   CheckStatus = END_STATUS;
				   bDispTime = TRUE;
				   break;
		      default:	   
			       if (EX1 == FALSE)
				   {
				       ReadKey ();
				   }
			  }
		  }
		  
		  
		  if (EX1 == TRUE)
		  {
		      GetVoltage ();
		      GetCurrent ();
		  }

		  //比较年份,满4年进一
		  Get8583Data(CMP_YEAR, &uCmpYear, 1); 
		  if (uCmpYear == 0x03)	   //是第4年则检查年份
		  {	 
		      Get8583Data(YEARDATE, &uCurrYear, 1);
			  if (GetYear(uCurrYear) == 0x00)	//若发现年份变为00,则加一
			  {
			      Get8583Data(BASE_YEAR, &uCurrYear, 1);
				  uCurrYear ++;
				  Set8583Byte (BASE_YEAR, uCurrYear);
				  Set8583Byte (CMP_YEAR, 0x00);
			  }
		  }    
	 } 	   
}

⌨️ 快捷键说明

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