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

📄 main.c

📁 我做的用lpc2119实现的变电站隔刀动作电流波形采样计算数据上传程序
💻 C
📖 第 1 页 / 共 4 页
字号:
										yy++;
									else
										yy=17;
									
									break;
							case 2:	if(rcv_bufa[xx] == 0x91)
										yy++;
									else
										yy=17;
									
									break;
							case 3:	if(rcv_bufa[xx] == 0xfb)
										yy++;
									else
										yy=17;
									
									break;
							case 4:	if(rcv_bufa[xx] == 0x91)
										yy++;
									else
										yy=17;
									
									break;
							case 5:	if(rcv_bufa[xx] == 0x00)
										yy++;
									else
										yy=17;
									uart0crc[0]=rcv_bufa[xx];
									i=xx;
									break;
							case 6:	if(rcv_bufa[xx] == Locoal_Addr)
										yy++;
									else
										yy=17;
									uart0crc[1]=rcv_bufa[xx];
									break;
							case 7:	for(zz=0;zz<10;zz++)
									{
										uart0crc[2+zz]=rcv_bufa[xx];
										xx++;
										if(xx>=20)
											xx=xx-20;
									}
									rcv_count=0;
									if(uart1test==0xbb)
									{
										two_send(rcv_count,2);
										Uart1SendByte('\n');
										uart1test=0;
									}
									if(uart1test==0xcc)
									{
										for(zz=0;zz<20;zz++)
										{
											two_send(uart0crc[zz],2);
											Uart1SendByte(',');
										}
										Uart1SendByte('\n');
										two_send(rcv_count,2);
										Uart1SendByte('\n');
										uart1test=0;
									}
									yy=17;
									crcb=CRC_16(uart0crc,10);
									Uart1SendByte('0');
									Uart1SendByte('x');
									four_send(crcb,2);
									Uart1SendByte(',');
									Uart1SendByte('0');
									Uart1SendByte('x');
									two_send(uart0crc[9],2);
									two_send(uart0crc[10],2);
									
									Uart1SendByte('\n');
									if(0==CRC_16(uart0crc,10))
									{
										Uart1SendByte('h');
										if(uart0crc[3]==9)
										{
											uart0crc[0]=0;
											uart0crc[1]=Locoal_Addr;
											uart0crc[2]=0xff;
											uart0crc[3]=0;
											uart0crc[4]=0;
											uart0crc[5]=0;
											uart0crc[6]=2;
											uart0crc[7]=1;
											uart0crc[8]=0x55;
											crcb=CRC_16(uart0crc,9);
											uart0crc[9]=crcb>>8;
											uart0crc[10]=crcb;
											
											SendByte(0xeb);
											SendByte(0x90);
											SendByte(0xeb);
											SendByte(0x90);
											SendByte(0xeb);
											SendByte(0x90);
											SendByte(uart0crc[0]);
											SendByte(uart0crc[1]);
											SendByte(uart0crc[2]);
											SendByte(uart0crc[3]);
											SendByte(uart0crc[4]);
											SendByte(uart0crc[5]);
											SendByte(uart0crc[6]);
											SendByte(uart0crc[7]);
											SendByte(uart0crc[8]);
											SendByte(uart0crc[9]);
											SendByte(uart0crc[10]);
											
										}
										else if(uart0crc[3]==4)
										{
											Data_Send();
										}
										rcv_count=0;
									}
									else
									{
										four_send(CRC_16(uart0crc,10),2);
										Uart1SendByte('\n');
									}
									break;
							default:Uart1SendByte('e');
									Uart1SendByte('r');
									Uart1SendByte('r');
									break;
						}
						
					}while(yy<16);
				
				}
			}
			rcv_new = 0;
		}
		*/
#ifdef wireless		
		if(rcv_new == 1)
		{
			
			
			rcv_new = 0;
			rcv_count=0;
			if(0==CRC_16(rcv_bufa,10))
			{
					if(rcv_bufa[3]==9)
					{
						uart0crc[0]=0;
						uart0crc[1]=Locoal_Addr;
						uart0crc[2]=0xff;
						uart0crc[3]=0;
						uart0crc[4]=0;
						uart0crc[5]=0;
						uart0crc[6]=4;
						uart0crc[7]=1;
						uart0crc[8]=0x55;
						uart0crc[9]=3;
						if(Data_Update==0xaa)
							uart0crc[10]=1;
						else
							uart0crc[10]=0;
						crcb=CRC_16(uart0crc,11);
						uart0crc[11]=crcb>>8;
						uart0crc[12]=crcb;
											
						SendByte(0xeb);
						SendByte(0x90);
						SendByte(0xeb);
						SendByte(0x90);
						SendByte(0xeb);
						SendByte(0x90);
						SendByte(uart0crc[0]);
						SendByte(uart0crc[1]);
						SendByte(uart0crc[2]);
						SendByte(uart0crc[3]);
						SendByte(uart0crc[4]);
						SendByte(uart0crc[5]);
						SendByte(uart0crc[6]);
						SendByte(uart0crc[7]);
						SendByte(uart0crc[8]);
						SendByte(uart0crc[9]);
						SendByte(uart0crc[10]);
						SendByte(uart0crc[11]);
						SendByte(uart0crc[12]);
						//SendByte(uart0crc[10]);
						printstr("巡检成功",2);
						Uart1SendByte(0x0d);
						Uart1SendByte('\n');					
					}
					else if(rcv_bufa[3]==4)
					{
						
						
						Data_Send();
						printstr("波形数据上传完毕",2);
						Uart1SendByte(0x0d);
						Uart1SendByte('\n');
						//Wless_Switch_Send();
						//printstr("开关数据上传完毕",2);
						//Uart1SendByte(0x0d);
						//Uart1SendByte('\n');
						VICIntEnClr = 0x00000020;
						timecount=0;
						Data_Update=0;
						VICIntEnable = 0x00000010;
						Data_Update=0;
						IO0SET = LED1;
					}
					else if(rcv_bufa[3]==0x0b)
					{
						
						
						Wless_Switch_Send();
						printstr("开关数据上传完毕",2);
						Uart1SendByte(0x0d);
						Uart1SendByte('\n');
						
					}
					rcv_count=0;
			}
			else
			{
				
				printstr("CRC Err ",2);
				four_send(CRC_16(rcv_bufa,10),2);
				Uart1SendByte(0x0d);
				Uart1SendByte('\n');
			}
			rcv_new = 0;
		}
		if(uart1test==0xbb)
		{
			for(zz=0;zz<15;zz++)
			{
				two_send(rcv_bufa[zz],2);
				Uart1SendByte(',');
			}
			Uart1SendByte(0x0d);
			Uart1SendByte('\n');
			printstr("rec_count is  ",2);
			two_send(rcv_count,2);
			Uart1SendByte(0x0d);
			Uart1SendByte('\n');
			uart1test=0;
		}
#endif		
#ifdef CanCommication		
		if(ReadCANRcvCyBuf(0,&CRBuf) == 0)
		{
			//////////////////将接收到的数据存放在tempbuf数组中/////////////////////////
			TempBuf[0]=(UINT8)CRBuf.CANRcvFS.Bits.DLC_BIT | ((UINT8)CRBuf.CANRcvFS.Bits.FF_BIT << 7)|      //帧信息
							((UINT8)CRBuf.CANRcvFS.Bits.RTR_BIT << 6);
			for(i=0;i<4;i++)
			{
				TempBuf[1+i]=*((UINT8 *)&CRBuf.RxCANID + 3-i);        //Can标志符
			}
			for(i=0;i<4;i++)
			{
				TempBuf[5+i]=*((UINT8 *)&CRBuf.CANRDA+i);             //Can A组数据
			}
			for(i=0;i<4;i++)
			{
				TempBuf[9+i]=*((UINT8 *)&CRBuf.CANRDB+i);             //Can B组数据
			}
			
			////////////////////////////////////////////////////////////////////////////
			//////////////////以下为数据处理部分////////////////////////////////////////
			//if(Can_Locoal_Addr[3] == TempBuf[4])
			//{	
				if(0x09 == TempBuf[5])                       //循检命令09H
				{
					Can_Check_Send(0x00,0x02,Can_Locoal_Addr,0x55,0x01);    //循检应答
					//SendByte('a');
				}
				else if(0x04 == TempBuf[5])					//上传命令04H 
				{
					VICIntEnClr = 0x00000020;
					Can_ABC_Send(0,1,Can_Locoal_Addr,1,0x1800);
					DelayNS(5);
					Can_Switch_Send(0,Can_Locoal_Addr,1);
					
					timecount=0;
					Data_Update=0;
					VICIntEnable = 0x00000010;
					IO0SET = LED1;
				}
				else if(0x0b == TempBuf[5])					//查询隔刀当前分合状态回应
				{
					KeyS=KRScan();
					if(KeyS==0)
						KeyS=2;
					else if(KeyS==0x07)
						KeyS=1;
					else
						KeyS=0;
					Can_CheckState_Send(0x00,0x02,Can_Locoal_Addr,KeyS,0x01);
				}
				else if(0x0a == TempBuf[5])					//停止请求上传指令,下位机收到此回应后停止发送请求不用回应
				{
					Data_Update=0;
					
				}
				
			//}	

		}
		
		
		if(Data_Update==0xaa)				//隔刀动作
		{
			if(timecount==2)
			{
				Can_Request_Send(0x00,0x03,Can_Locoal_Addr,0x01,0x01);
								
				VICIntEnable = 0x00000020;
				timecount++;
			}
			else if(timecount>50)
			{
				Can_Request_Send(0x00,0x03,Can_Locoal_Addr,0x01,0x01);
				
				timecount=0;
			}
			
		}
#endif
		
		if((calc_flag == 0xaa) & (Data_Update != 0xaa))
		{
			for(KeyS=0;KeyS<13;KeyS++)
			{
				CalcBuf[KeyS]=A_Channel_Data[KeyS].Word-32000;
			}
			Calc_Data[Calc_Count].Word=(uint16)(calcL(CalcBuf)*0.7143);
			if(uart1test==0xcc)
			{
				VICIntEnClr = 0x00000010;
				VICIntEnable=0x00000020;	
				trip=0;
				switch_flag=0;
				Data_Update=0xaa;
				uart1test=0;
				IO0SET = LED1;
			}
			if(uart1test==0xaa)
			{
				com_send(CalcBuf[0],2);
				Uart1SendByte(',');
				com_send(CalcBuf[1],2);
				Uart1SendByte(',');
				com_send(CalcBuf[2],2);
				Uart1SendByte(',');
				com_send(CalcBuf[3],2);
				Uart1SendByte(',');
				com_send(CalcBuf[4],2);
				Uart1SendByte(',');
				com_send(CalcBuf[5],2);
				Uart1SendByte(',');
				com_send(CalcBuf[6],2);
				Uart1SendByte(',');
				com_send(CalcBuf[7],2);
				Uart1SendByte(',');
				com_send(CalcBuf[8],2);
				Uart1SendByte(',');
				com_send(CalcBuf[9],2);
				Uart1SendByte(',');
				com_send(CalcBuf[10],2);
				Uart1SendByte(',');
				com_send(CalcBuf[11],2);
				Uart1SendByte(',');
				com_send(CalcBuf[12],2);
				Uart1SendByte(' ');
				Uart1SendByte(' ');
				com_send(Calc_Data[Calc_Count].Word,2);
				Uart1SendByte(0x0d);
				Uart1SendByte('\n');
				KeyS = KeyScan();
				com_send(KeyS,2);
				Uart1SendByte(0x0d);
				Uart1SendByte('\n');
				uart1test=0;
			}
			calc_flag=0;
			if(trip==0)
			{
				if((Calc_Data[Calc_Count].Word>1500) & (Calc_Data[Calc_Count-1].Word>1500) & (Calc_Count>1))
				{
					trip=0xaa;
					switch_flag=0;
					IO0CLR = LED1;
				}
			}
			else
			{
				switch_flag++;
				if(switch_flag>2900)
				{
					VICIntEnClr = 0x00000010;
					VICIntEnable = 0x00000020;
					trip=0;
					switch_flag=0;
					Data_Update=0xaa;
					IO0SET = LED1;
					StartSampleDot=Calc_Count;
				}
			}
			if(Calc_Count>=3000)
				Calc_Count=0;
			else
				Calc_Count++;
		}
		FeedWDT();
		
		//系统检测CAN_bus将挂起的CAN激活
		for(i=0;i<2;i++)
		{
			if(CANMOD(i).Bits.RM_BIT != 0)
			{
				CANGSR(i).Word=0;
				CANMOD(i).Bits.RM_BIT=0x00;
				CANCMR(i).Word=0x02;
			}
		}
		
		//SendByte('K');
		//ABC_Phase_Sample();
		
	 	//IO1SET = IO1SET	| LED1;			// LED1熄灭
		//IO0SET = IO0SET | LED2;			// LED1熄灭
		//IO1SET = LED3;					// LED1熄灭
		//DelayNS(50);
		//IO1CLR = IO1CLR | LED1;			// LED1点亮
		//IO0CLR = IO0CLR | LED2;			// LED1熄灭
		//IO1CLR = LED3;					// LED1熄灭
		
		/*
		
		KeyS=KRScan();
		
		SendByte(ToASC(KeyS));
		
		KeyS = KeyScan(); 
		SendByte(ToASC(KeyS)); 
		SendByte('\n');
		SendByte('\n');
		*/
	}

	return(0);
}



 //---------------------------------------------------------------------------------------
 //---------------------------------------------------------------------------------------
 //---------------------------------------------------------------------------------------
 //									end of file
 //

⌨️ 快捷键说明

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