void Send_AtitudeToPC()
{
	int _temp;
	uint8_t sum=0;
	UART1_Put_Char(0x88);
	UART1_Put_Char(0xAF);
	UART1_Put_Char(0x1c);
//发送姿态数据:
	_temp = (int)(Q_ANGLE.Pitch+200);
	sum += Uart1_Put_Char((unsigned char)(_temp>>8));
	sum += Uart1_Put_Char((unsigned char)(_temp&0x00ff));
	_temp = (int)(Q_ANGLE.Roll+200);
	sum += Uart1_Put_Char((unsigned char)(_temp>>8));
	sum += Uart1_Put_Char((unsigned char)(_temp&0x00ff));
  _temp = (int)(Q_ANGLE.Yaw+200);
	sum += Uart1_Put_Char((unsigned char)(_temp>>8));
	sum += Uart1_Put_Char((unsigned char)(_temp&0x00ff));
//发送电机数据:
	_temp =TIM2->CCR1/10;
	sum += Uart1_Put_Char((unsigned char)(_temp&0xff00)>>8);
	sum += Uart1_Put_Char((unsigned char)(_temp&0x00ff));
  _temp =TIM2->CCR2/10;
  sum += Uart1_Put_Char((unsigned char)(_temp&0xff00)>>8);
  sum += Uart1_Put_Char((unsigned char)(_temp&0x00ff));
  _temp = TIM2->CCR3/10;
  sum += Uart1_Put_Char((unsigned char)(_temp&0xff00)>>8);
  sum += Uart1_Put_Char((unsigned char)(_temp&0x00ff));
  _temp =TIM2->CCR4/10;
  sum += Uart1_Put_Char((unsigned char)(_temp&0xff00)>>8);
  sum += Uart1_Put_Char((unsigned char)(_temp&0x00ff));
	Uart1_Put_Char(sum);
}
Beispiel #2
0
/**************************实现函数********************************************
*函数原型:		void UART2_Put_String(unsigned char *Str)
*功  能:		RS232发送字符串
输入参数:
		unsigned char *Str   要发送的字符串
输出参数:没有
*******************************************************************************/
void UART1_Put_String(unsigned char *Str)
{
    //判断Str指向的数据是否有效.
    while(*Str) {
        //是否是回车字符 如果是,则发送相应的回车 0x0d 0x0a
        if(*Str=='\r')UART1_Put_Char(0x0d);
        else if(*Str=='\n')UART1_Put_Char(0x0a);
        else UART1_Put_Char(*Str);
        //等待发送完成.
        //while (!(USART1->SR & USART_FLAG_TXE));
        //指针++ 指向下一个字节.
        Str++;
    }
    /*
    	//判断Str指向的数据是否有效.
    	while(*Str){
    	//是否是回车字符 如果是,则发送相应的回车 0x0d 0x0a
    	if(*Str=='\r')USART_SendData(USART1, 0x0d);
    		else if(*Str=='\n')USART_SendData(USART1, 0x0a);
    			else USART_SendData(USART1, *Str);
    	//等待发送完成.
      	while (!(USART1->SR & USART_FLAG_TXE));
    	//指针++ 指向下一个字节.
    	Str++;
    	}		 */
}
Beispiel #3
0
void out_int16_t(int16_t * data)
{
  char ctemp;
  if(data[0]<0)data[0]=32768-data[0];
	ctemp=data[0]>>8;
	UART1_Put_Char(ctemp);
	ctemp=data[0];
	UART1_Put_Char(ctemp);
}
Beispiel #4
0
/********************************************
              往蓝牙写入一个指令包
********************************************/
void Uart1SendaBTCmd(const char *p)
{
	char i;

	for(i=0; i<CmdreturnLength; i++) Cmdreturn[i] = 0; //释放指令接收缓存
	LedA_on;
	delay_ms(100);//写完一条指令,延时500ms再度接收缓存
	LedA_off;
	for(i=0; i<strlen(p); i++)
		UART1_Put_Char(*(p+i));
	delay_ms(100);//写完一条指令,延时500ms再度接收缓存


	i=0;
	while(UartBuf_Cnt(&UartRxbuf) != 0)     //当串口缓冲不为空时,将串口缓冲赋值给指令结果缓冲
		Cmdreturn[i++] = UartBuf_RD(&UartRxbuf);
}
Beispiel #5
0
/********************************************
              往蓝牙写入一个指令包 (Bluetooth is written to a command packet)
********************************************/
void Uart1SendaBTCmd(const char *p)
{
  char i;
	
  for(i=0;i<CmdreturnLength;i++) Cmdreturn[i] = 0;//释放指令接收缓存 //Release command receive buffer
	LedA_on;
	delay_ms(100);//写完一条指令,延时500ms再度接收缓存 //Finished an instruction 500ms delay once again receive buffer
	LedA_off;
  for(i=0;i<strlen(p);i++)
  UART1_Put_Char(*(p+i));  
  delay_ms(100);//写完一条指令,延时500ms再度接收缓存 //Finished an instruction 500ms delay once again receive buffer
	
	
  i=0;
  while(UartBuf_Cnt(&UartRxbuf) != 0)     //当串口缓冲不为空时,将串口缓冲赋值给指令结果缓冲 //When the serial buffer is not empty , the serial buffer is assigned to command the result buffer
  Cmdreturn[i++] = UartBuf_RD(&UartRxbuf);
}
Beispiel #6
0
int main(void)
{
  int16_t data[9];

  int16_t result[3];
  int i=0;

  SystemInit();
  delay_init(72);
  GPIO_Configuration();
  Initial_UART1(115200L);
  I2C_GPIO_Config();
  NVIC_Configuration();
  
  delay_ms(10);
  Init_MPU6050();
  
  delay_ms(10);
  HMC5883L_Init();
  delay_ms(10);

  IMU_init();
  
  Initial_Timer3();
  system_microsec=micros();

  
  while(1)
  {
    //delay_ms(10);

    //if(micros()-system_microsec>upload_time)
    {
    
      Read_MPU6050_ACC(&data[0]);
      Read_MPU6050_GYRO(&data[3]);
      HMC5883L_Read(&data[6]);
      IMU_getYawPitchRoll(result,data);
      
      UART1_Put_Char(0xff);
      UART1_Put_Char(0xaa);

      /*out_int16_t(&data[0]);
      out_int16_t(&data[1]);
      out_int16_t(&data[2]);

      out_int16_t(&data[3]);
      out_int16_t(&data[4]);
      out_int16_t(&data[5]);

      out_int16_t(&data[6]);
      out_int16_t(&data[7]);
      out_int16_t(&data[8]);
      
      */
      out_int16_t(&result[0]);
      out_int16_t(&result[1]);
      out_int16_t(&result[2]);
      
      //out_int16_t(&_hlt);
      //system_microsec = micros();
    }

    

  }
		     
}