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

📄 main.c

📁 我做的用lpc2119实现的变电站隔刀动作电流波形采样计算数据上传程序
💻 C
📖 第 1 页 / 共 4 页
字号:
			tem16=CRC_16b(tem16,&Calc_Data[x2]);
			
		}
		
		SendByte(tem16>>8);
		SendByte(tem16);
		
		if(uart1test==0xdd)
		{
			Uart1SendByte(0x0d);
			Uart1SendByte('\n');
			two_send(buf8[0],2);
			two_send(buf8[1],2);
			two_send(buf8[2],2);
			two_send(buf8[3],2);
			two_send(buf8[4],2);
			two_send(buf8[5],2);
			two_send(buf8[6],2);
			
			
			two_send(Calc_Data[ii*SendLenth/2].byte.high,2);
			two_send(Calc_Data[ii*SendLenth/2].byte.low,2);
			two_send(Calc_Data[ii*SendLenth/2+1].byte.high,2);
			two_send(Calc_Data[ii*SendLenth/2+1].byte.low,2);
			two_send(Calc_Data[ii*SendLenth/2+2].byte.high,2);
			two_send(Calc_Data[ii*SendLenth/2+2].byte.low,2);
			
			two_send(tem16>>8,2);
			two_send(tem16,2);
		}
		do
		{
			if(rcv_new==1)
			{
				if((0==CRC_16(rcv_bufa,10))&(rcv_bufa[3]==0x0c))
				{
					if(rcv_bufa[5]==1)
					{
						rcv_count=0;
						
						printstr(" send ",2);
						Uart1SendByte(ii+0x30);
						printstr("st over",2);
						
						Uart1SendByte(0x0d);
						Uart1SendByte('\n');
						rcv_bufa[3]=0;
						rcv_bufa[5]=0;
						ii++;
						break;
					}
					else if(rcv_bufa[5]==0)
					{
						rcv_count=0;
						
						printstr("Resend ",2);
						Uart1SendByte(ii+0x30);
						printstr("st over",2);
						
						Uart1SendByte(0x0d);
						Uart1SendByte('\n');
						rcv_bufa[3]=0;
						rcv_bufa[5]=0;
						break;

					}
					else
					{
						printstr("Command Err ",2);
						Uart1SendByte(0x0d);
						Uart1SendByte('\n');
						rcv_bufa[3]=0;
						rcv_bufa[5]=0;
					}
					rcv_new=0;
					rcv_count=0;
					dx=0x8;
				}
				else
				{
					break;
					break;
				}
				//rcv_new=0;
				//rcv_count=0;
				
			}
			FeedWDT();
		}while(dx<5);
	}while(ii<6);
	uart1test=0;
}


void   myprintf(char*   fmt,uint8 com)   //一个简单的类似于printf的实现,//参数必须都是int   类型 
{   
	char*   pArg=NULL;   //等价于原来的va_list   
	char   c; 

	pArg   =   (char*)   &fmt;   //注意不要写成p   =   fmt   !!因为这里要对//参数取址,而不是取值 
	pArg   +=   sizeof(fmt);   //等价于原来的va_start   

	do 
	{ 
		c   =*fmt; 
		Uart1SendByte(c);
		/*
		if   (c   !=   '% ') 
		{ 
			Uart1SendByte(c);   //照原样输出字符 
		} 
		else 
		{ 
			//按格式字符输出数据 
			switch(*++fmt)   
			{ 
				case   'd ': 
							printf( "%d ",*((int*)pArg));   
							break; 
				case   'x ': 
							printf( "%#x ",*((int*)pArg)); 
							break; 
				default: 
							break; 
			}   
			pArg   +=   sizeof(int);   //等价于原来的va_arg 
		} 
		*/
		++fmt; 
	}while   (*fmt   !=   '\0 ');
	   
	pArg   =   NULL;   //等价于va_end 
	return;   
} 


void Wless_Switch_Send(void)
{
	uint16 tem16;
	uint8  buf11[11];
	uint16 jj;
	uint8 dx;
	Uart1SendByte(0x0d);
	Uart1SendByte('\n');
	printstr("Send Start",2);
	
	Uart1SendByte(0x0d);
	Uart1SendByte('\n');
	
	buf11[0]=0;
	buf11[1]=Locoal_Addr;
	
	buf11[2]=0xff;
	
	buf11[3]=0;
	buf11[4]=0;
	buf11[5]=0;
	buf11[6]=2;
	
	buf11[7]=7;
	
	dx=(KRScan())&3;
	if(dx==1)							//1为合状态
		buf11[8]=1;
	else if(dx==2)						//2为分状态
		buf11[8]=2;
	else
		buf11[8]=0;
		
			
	for(jj=0;jj<3;jj++)
	{
		SendByte(0xeb);
		SendByte(0x90);
	}
	for(jj=0;jj<9;jj++)
	{
		SendByte(buf11[jj]);
	}
	tem16=CRC_16(buf11,9);
	
		
	SendByte(tem16>>8);
	SendByte(tem16);
	
}




/************************************************************************************************************************
**函数原型	:  	int	main(void)
**参数说明	:  	
**返回	值	:	无
**说	明	:主循环函数
***********************************************************************************************************************/

int  main(void)
{ 
	//************************/////////////////////////////////////////////////////////////////////////////////////////////
	/*定义变量*/
	//uint8     rcv_counter;
	UARTMODE  uart0_set;					//uart0设置
	UINT8   KeyS = 0x00;                    //键状态
	UINT32  baud_temp;						//波特率
 	//uint16 j; 	
	/*变量赋值*/
	INT16 CalcBuf[13];
	uint8 trip=0;
	
	
	
	
	
	//*************************////////////////////////////////////////////////////////////////////////////////////////////
	
   
	IO1CLR = LED4;                         //电源指示
	Syn_Sample_Flag = 0x01;				   // 控制同步采样标志 (临时调试用)
	
	/* 设置Io口 */     
	//---------------------------------------------------------------------------------------
	//PINSEL0 = 0x00050005;                // 设置I/O连接到UART0
	PINSEL0 = 0x00055505;                  // 设置I/O连接到UART0  (0x0000  5500  :SPI)

	PINSEL1 = 0x00000001;                
	PINSEL2 = (PINSEL2 & 0xfffffff7);      // 设置P1.16-P1.25连接GPIO   

	myledInit();
	IntputInit();
	OutputInit();


	/*通过开关键设置程序:波特率etc..*/
	 //---------------------------------------------------------------------------------------
	Locoal_Addr = KeyScan();                    // 获得开关键状态
	

	baud_temp = 9600;				//默认波特率为9600bps  
	 //---------------------------------------------------------------------------------------

   
	/* 串口初始化设置 */
	 //---------------------------------------------------------------------------------------
	rcv_new = 0;   
	uart0_set.datab = 8;                 // 8位数据位
	uart0_set.stopb = 1;                 // 1位停止位
	uart0_set.parity = 0;                // 无奇偶校验

	UART0_Ini(baud_temp, uart0_set);     // 初始化串口模式
	UART1_Ini(57600);                	 // 初始化串口1   
	U0FCR = 0x01;                        // 使能FIFO,并设置触发点为8字节
	U0IER = 0x01;                        // 允许RBR中断,即接收中断
	U1FCR = 0x01;                        // 使能FIFO,并设置触发点为8字节
	U1IER = 0x01;                        // 允许RBR中断,即接收中断
	 //---------------------------------------------------------------------------------------


   
	/* 设置中断 */
	 //---------------------------------------------------------------------------------------
	VICIntSelect = 0x00000000;           // 设置所有通道为IRQ中断
	VICVectCntl1 = 0x26;                 // UART0中断通道分配到IRQ slot 0,即优先级最高
	VICVectAddr1 = (int)IRQ_UART0;       // 设置UART0向量地址
	//VICIntEnable = 0x00000040;           // 使能UART0中断

	/* 设置中断允许1为串口1 */
	VICVectCntl3 = 0x27;                 // UART1中断通道分配到IRQ slot 1
	VICVectAddr3 = (int)IRQ_UART1;       // 设置UART1向量地址
	VICIntEnable = 0x000000c0;           // 使能UART0\UART1中断

	/*设置定时中断允许2为定时器0*/
	VICVectCntl0 = 0x24;                 // UART0中断通道分配到IRQ slot 2
	VICVectAddr0 = (int)IRQ_TIME0;       // 设置UART0向量地址
	VICIntEnable = 0x00000010;           // 使能time0中断
	/*设置定时中断允许2为定时器1*/
	VICVectCntl2 = 0x25;                 // UART0中断通道分配到IRQ slot 2
	VICVectAddr2 = (int)IRQ_TIME1;       // 设置UART0向量地址
	//VICIntEnable = 0x00000020;           // 使能time1中断
	/*使能中断设置*/
	
	
	//Eint0_init();						   // 外部中断初始化
	 //---------------------------------------------------------------------------------------
	
        
   

	/*Can 初始化*/
	 //---------------------------------------------------------------------------------------
	InitCAN(0);
	 //---------------------------------------------------------------------------------------
	
	 
	 /* 初始化SPI接口*/
	 //---------------------------------------------------------------------------------------
	MSpiIni();					    	
	SPI16(0xa000);						// 写CFR
	SPI16(0xaa00);						// 写CFR  :single_end 00mode
	//SPI16(0xaa63);						// 写CFR :mode 11 sweep_repeat mode
	//ad_data = SPI16(0xe000);				// 0 ch
	//for (k=0; k<66; k++)   Delay15();
	 //---------------------------------------------------------------------------------------
  	IO0SET = SH;			// 采样
	Calc_Count=0;
	
	
	/*定时器0初始化*/
	 //---------------------------------------------------------------------------------------
	Time0Init();									// 定时器0初始化
	Time1Init();									// 定时器0初始化
	ConfigAFReg ();
	
	/*初始化GPS为接收状态*/
	//-----------------------------------------------------------------------------------------
	WDT_Init();
	while(( WDMOD & 0x04 ) == 0x04)       
    { 
    	printstr("看门狗复位",DebugCom);
      	WDMOD = 0x00;					
    }
	rcv_count=0;
	rcv_new=0;   			// 接收新数据标志
	 //---------------------------------------------------------------------------------------
	Data_Update =0x00;
	switch_flag=0;
	timecount=0;
	IO1SET = LED3;
	IO0SET = LED1;
	IO0SET	= 1<<17;
	IO0CLR	= 1<<17;

	/*实时时钟程序*/
	/*
	   RTCIni();					    // 初始化RTC
	   while(1)	
	   {  IO0SET = LED2;				
	      while( 0==(ILR&0x01) );	    // 等待RTC增量中断标志
	      ILR = 0x01;				    // 清除中断标志
	      IO0CLR = LED2;				
	      while( 0==(ILR&0x01) );
	      ILR = 0x01;
	   }
	*/
	
	
	
	//result_CRC=CRC_16a(tcrc,&A_Channel_Data[0],6,3);
	//com_send(result_CRC,2);
	//SendByte(0x0d);
	//SendByte('\n');
	/*
	result_CRC=CRC_16(test,10);
	com_send(result_CRC);
	SendByte('\n');
	
	result_CRC=udf_crc(test,10,result_CRC);
	com_send(result_CRC);
	SendByte('\n');
	
	result_CRC=crc16(result_CRC,test,10);
	com_send(result_CRC);
	SendByte('\n');
	
	result_CRC=modbusCRC16(test, 10);
	com_send(result_CRC);
	SendByte('\n');
	
	result_CRC=crc16r(test,10);
	com_send(result_CRC);
	SendByte('\n');
	
	result_CRC=crc_gen(test,10);
	com_send(result_CRC);
	SendByte('\n');
	
	
	result_CRC=CRC16b(test,10);
	com_send(result_CRC);
	SendByte('\n');
	
	result_CRC=WNCRC16(0xffff,0xa001,test,10);
	com_send(result_CRC);
	SendByte('\n');
	
	result_CRC=CRC162(test ,10);
	com_send(result_CRC);
	SendByte('\n');
	*/
	/*
	BuildTable16a(0xa001, table_crc);
	for(result_CRC=0;result_CRC<256;result_CRC++)
	{
		SendByte('0');
		SendByte('x');
		four_send(table_crc[result_CRC]);
		SendByte(',');
	}
	SendByte('\n');
	SendByte('\n');
	*/
	Uart1SendByte(0x0d);
	Uart1SendByte('\n');			//换行
	
	printstr("Reset",2);
	Uart1SendByte(0x0d);
	Uart1SendByte('\n');
	printstr("This Board Address Is hex 0x",2);
	two_send(Locoal_Addr,2);
	printstr(" or dec ",2);
	KeyS=Locoal_Addr/100;
	if(KeyS != 0)
		Uart1SendByte(KeyS+0x30);
	Uart1SendByte((Locoal_Addr-KeyS*100)/10+0x30);
	Uart1SendByte((Locoal_Addr-KeyS*100)%10+0x30);
	Uart1SendByte(0x0d);
	Uart1SendByte('\n');
	printstr("wireless isolating switch program ver 1.0",2);
	Uart1SendByte(0x0d);
	Uart1SendByte('\n');
	printstr("2007,12,27",2);
	Uart1SendByte(0x0d);
	Uart1SendByte('\n');
	IO0SET	= 1<<17;
	
	while(1)                             
	{ 
		UINT8 i;
		uint8 zz;//jj,xx,yy,
		uint8 uart0crc[16];
		uint16 crcb;
		/*
		if(rcv_new == 1)
		{
			i = rcv_count;
			
			for(jj=0;jj<6;jj++)
			{
				xx=jj+i;
				if(xx >= 20)
					xx=xx-20;
				if(rcv_bufa[xx] == 0xfb)
				{
					i=xx;
					yy=0;
					do
					{
						xx++;
						if(xx>=20)
							xx=xx-20;
						switch(yy)
						{
							case 0:	if(rcv_bufa[xx] == 0x91)
										yy++;
									else
										yy=17;
									
									break;
							case 1:	if(rcv_bufa[xx] == 0xfb)

⌨️ 快捷键说明

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