Ejemplo n.º 1
0
int main(void)
{	
	u8 i=0,m=0;
	//char buff[6];
	SystemInit();//初始化RCC 设置系统主频为72MHZ
	USART1_Config();
	delay_init();	     //延时初始化
	Ultran_Init();
	I2c_Init_MI();
	TIM5_Cap_Init(0xfffe,8);
	TIM2_Cap_Init(0xfffe,8);
	TIM3_Cap_Init(0xfffe,8);
	TIM1_Cap_Init(0xfffe,8);
	TIM4_Cap_Init(0xfffe,8);
	TIM8_Cap_Init(0xfffe,8);
	USART1_Config();
	USART2_Config();
	USART3_Config();
	delay_ms(1000);
	delay_ms(1000);
	esp8266_ap_server_init();
	for(i=0;i<99;i++)//数组初始化
	{
		data_pc[i]=0x30;
	}
	data_pc[0]=0xff;
	data_pc[1]=0xff;
  while(1)
{	
//		char *buff[10]={"AT",
//	"AT+CIPSTATUS"};
	Ultra_Ranging();
	if(state_0x0a==1)//字符串解析函数
	{
		u8 i=0,weizhi=0;
		data_exist=bf( data_cu,ESP_Responses[5]);
		if(data_exist!=-1)
		{
			data_exist1=bf( data_cu,ESP_Responses[10]);
			if(data_exist1!=-1)
			{	
				data_exist2=data_exist1-data_exist-7;
				if(data_exist2==1)
				{
					data_length1=data_cu[data_exist+7];
					data_length1=data_length1-0x30;
					data_length=data_length1;
					weizhi=9;
				}

				if(data_exist2==2)
				{
					data_length1=data_cu[data_exist+7];
					data_length1=data_length1-0x30;
					data_length1=data_length1*10;

					data_length2=data_cu[data_exist+8];
					data_length2=data_length2-0x30;
					data_length=data_length1+data_length2;
					weizhi=10;
				}

				for(i=0;i<data_length;i++)
				{
					data_wifi[i]=data_cu[data_exist+weizhi+i];				
				}
//				USART_printf(USART1, data_right);//发送通过校验的数据到电脑上方便调试
//				USART_printf(USART1, "\r\n");
			}


		}
		cun=0;
		for(i=0;i<100;i++)//清空接收数组
		{
			data_cu[i]=0;
		}
		state_0x0a=0;//接收状态变量清零
		//data_exist=0;
	}
	if(state_0x0a1==1)//字符串解析函数
	{
		u8 i=0,weizhi=0;
		data_exist3=bf( data_cu1,ESP_Responses[5]);
		if(data_exist3!=-1)
		{
			data_exist4=bf( data_cu1,ESP_Responses[10]);
			if(data_exist4!=-1)
			{	
				data_exist5=data_exist4-data_exist3-7;
				if(data_exist5==1)
				{
					data_length4=data_cu1[data_exist3+7];
					data_length4=data_length4-0x30;
					data_length3=data_length4;
					weizhi=9;
				}

				if(data_exist5==2)
				{
					data_length4=data_cu1[data_exist3+7];
					data_length4=data_length4-0x30;
					data_length4=data_length4*10;

					data_length5=data_cu1[data_exist3+8];
					data_length5=data_length5-0x30;
					data_length3=data_length4+data_length5;
					weizhi=10;
				}

				for(i=0;i<data_length3;i++)
				{
					data_wifi1[i]=data_cu1[data_exist3+weizhi+i];				
				}
				//USART_printf(USART1, data_right);//发送通过校验的数据到电脑上方便调试
				//USART_printf(USART1, "\r\n");
			}


		}
		cun1=0;
		for(i=0;i<100;i++)//清空接收数组
		{
			data_cu1[i]=0;
		}
		state_0x0a1=0;//接收状态变量清零
		//data_exist=0;
	}	 
	data_test=0;
	for(data_long=0;data_long<9;data_long++)//将接收到的数据进行加和,准备进行校验
	{
		data_test+=data_wifi[data_long];

	}
	if(data_test==data_wifi[9])//校验通过就将数据转移并且保存
	{
		for(data_long=0;data_long<9;data_long++)
		{
			data_right[data_long]=data_wifi[data_long];

		}
	}
	data_test=0;
	for(data_long=0;data_long<9;data_long++)//将接收到的数据进行加和,准备进行校验
	{
		data_test+=data_wifi1[data_long];

	}
	if(data_test==data_wifi1[9])//校验通过就将数据转移并且保存
	{
		for(data_long=0;data_long<9;data_long++)
		{
			data_right1[data_long]=data_wifi1[data_long];

		}
	}
	
	for(i=0;i<6;i++)//将转速数据放入data_pc数据包
	{
		sprintf(revolving,"%d",juli[i]);
		for(m=0;m<5;m++)
		{
			if(revolving[m]==0)
				revolving[m]=0xaa;
		}
		for(m=revolving_long;m>0;m--)
		{
			data_pc[i*revolving_long+m+1]=revolving[m-1];

		}
		for(m=0;m<revolving_long;m++)							//将revolving在这里清零
		{
			revolving[m]=0;
		}
	}

	for(i=0;i<8;i++)
	{
		data_pc[32+i+8*(data_right[8]-1)]=data_right[i];
	}
	for(i=0;i<8;i++)
	{
		data_pc[32+i+8*(data_right1[8]-1)]=data_right1[i];
	}	
      crc_code = yb_crc(data_pc,80);//计算CRC校验码
			
	USART_printf(USART1, data_pc);//发送通过校验的数据到电脑上方便调试
	USART_printf(USART1, "\r\n");
	//printf(data_right);
	//printf("\r\n");
	//			printf("电机1=%d ",juli);
	//			printf("电机2=%d\r\n",juli1);
	//			printf("*********\r\n");
	//USART_printf(USART1,buff[1] );
	//delay_ms(100);
	//esp8266_ap_server_init();
	}
			//printf("电机1=%d\s\n",juli);
			//printf("电机2=%s\r\n",juli1);
			
 }
Ejemplo n.º 2
0
/***
		初始化				 触发引脚  采样捕捉引脚
		硬件配置为TIM4  GPIOB6    GPIOB7
***/
void SupperSonic_Init(void)
{		
	TIM4_Trig_Config();
	TIM4_Cap_Init();
}