欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
STM32解析MPU6050源程序
[打印本頁]
作者:
CNT
時間:
2017-7-27 17:10
標題:
STM32解析MPU6050源程序
使用STM32 MPU6050編寫的程序
單片機源程序如下:
#include "stm32f10x.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "MY_time_Conf.h"
//#include "uart_1.h"
//#include "dma.h"
//#include "RS485.h"
//#include "74hc595.h"
#include "string.h"
/**************************
模板配置信息:
選用芯片是 stm32f103vc
啟動信息:stm32f10x_hd.s
固件庫:stm32固件庫v3.5
***************************/
#define led_PB12 PBout(12) //位綁定,位定義PB12口作為LED輸出。這樣速度最快
//#define led_PB1 PBout(1) //位綁定,位定義PB1口作為LED輸出。這樣速度最快
//#define PA9 PAout(10)
//#define CLK1 PDout(0)
//#define CWW1 PDout(1)
//#define CLK2 PDout(2)
//#define CWW2 PDout(3)
//uint8_t i = 0; //測試用
float a[3],w[3],angle[3],T;
extern unsigned char Re_buf[11],temp_buf[11],counter;
extern unsigned char sign;
/*************************************************
函數: int main(void)
功能: main主函數
參數: 無
返回: 無
**************************************************/
int main(void)
{
unsigned char Temp[11];
//u8 i;
RCC_Configuration(); //初始化時鐘
GPIO_Configuration(); //初始化IO端口
delay_init(72); //初始化延時函數
NVIC_Configuration(); //中斷優先級初始化
USART1_Config(); //初始化 配置USART1
USART2_Config(); //初始化 配置USART2 (用于接收MPU6050數據)
delay_ms(200);
while (1)
{
if(sign)
{
memcpy(Temp,Re_buf,11);
sign=0;
if(Re_buf[0]==0x55) //檢查幀頭
{
switch(Re_buf[1])
{
case 0x51: //標識這個包是加速度包
a[0] = ((short)(Temp[3]<<8 | Temp[2]))/32768.0*16; //X軸加速度
a[1] = ((short)(Temp[5]<<8 | Temp[4]))/32768.0*16; //Y軸加速度
a[2] = ((short)(Temp[7]<<8 | Temp[6]))/32768.0*16; //Z軸加速度
T = ((short)(Temp[9]<<8 | Temp[8]))/340.0+36.25; //溫度
break;
case 0x52: //標識這個包是角速度包
w[0] = ((short)(Temp[3]<<8| Temp[2]))/32768.0*2000; //X軸角速度
w[1] = ((short)(Temp[5]<<8| Temp[4]))/32768.0*2000; //Y軸角速度
w[2] = ((short)(Temp[7]<<8| Temp[6]))/32768.0*2000; //Z軸角速度
T = ((short)(Temp[9]<<8| Temp[8]))/340.0+36.25; //溫度
break;
case 0x53: //標識這個包是角度包
angle[0] = ((short)(Temp[3]<<8| Temp[2]))/32768.0*180; //X軸滾轉角(x 軸)
angle[1] = ((short)(Temp[5]<<8| Temp[4]))/32768.0*180; //Y軸俯仰角(y 軸)
angle[2] = ((short)(Temp[7]<<8| Temp[6]))/32768.0*180; //Z軸偏航角(z 軸)
T = ((short)(Temp[9]<<8| Temp[8]))/340.0+36.25; //溫度
//printf("X軸角度:%.2f Y軸角度:%.2f Z軸角度:%.2f\r\n",angle[0],angle[1],angle[2]);
break;
default: break;
}
printf("X角度:%.2f Y角度:%.2f Z角度:%.2f X速度:%.2f Y速度:%.2f Z速度:%.2f\r\n",angle[0],angle[1],angle[2],w[0],w[1],w[2]);
}
}
delay_ms(50);
}
}
/*
int main(void)
{
//u8 i;
RCC_Configuration(); //初始化時鐘
GPIO_Configuration(); //初始化IO端口
delay_init(72); //初始化延時函數
NVIC_Configuration(); //中斷優先級初始化
USART1_Config(); //初始化 配置USART1
USART2_Config(); //初始化 配置USART2 (用于接收MPU6050數據)
delay_ms(200);
while (1)
{
if(sign)
{
sign=0;
// if(Re_buf[0]==0x55) //檢查幀頭
// {
// switch(Re_buf[1])
// {
// case 0x51: //標識這個包是加速度包
// a[0] = ((short)(Re_buf[3]<<8 | Re_buf[2]))/32768.0*16; //X軸加速度
// a[1] = ((short)(Re_buf[5]<<8 | Re_buf[4]))/32768.0*16; //Y軸加速度
// a[2] = ((short)(Re_buf[7]<<8 | Re_buf[6]))/32768.0*16; //Z軸加速度
// T = ((short)(Re_buf[9]<<8 | Re_buf[8]))/340.0+36.25; //溫度
// break;
// case 0x52: //標識這個包是角速度包
// w[0] = ((short)(Re_buf[3]<<8| Re_buf[2]))/32768.0*2000; //X軸角速度
// w[1] = ((short)(Re_buf[5]<<8| Re_buf[4]))/32768.0*2000; //Y軸角速度
// w[2] = ((short)(Re_buf[7]<<8| Re_buf[6]))/32768.0*2000; //Z軸角速度
// T = ((short)(Re_buf[9]<<8| Re_buf[8]))/340.0+36.25; //溫度
// break;
// case 0x53: //標識這個包是角度包
// angle[0] = ((short)(Re_buf[3]<<8| Re_buf[2]))/32768.0*180; //X軸滾轉角(x 軸)
// angle[1] = ((short)(Re_buf[5]<<8| Re_buf[4]))/32768.0*180; //Y軸俯仰角(y 軸)
// angle[2] = ((short)(Re_buf[7]<<8| Re_buf[6]))/32768.0*180; //Z軸偏航角(z 軸)
// T = ((short)(Re_buf[9]<<8| Re_buf[8]))/340.0+36.25; //溫度
//
// //printf("X軸角度:%.2f Y軸角度:%.2f Z軸角度:%.2f\r\n",angle[0],angle[1],angle[2]);
// printf("%.2f %.2f %.2f\r\n",angle[0],angle[1],angle[2]);
// break;
// default: break;
// }
// }
//printf("X角度:%.2f Y角度:%.2f Z角度:%.2f X速度:%.2f Y速度:%.2f Z速度:%.2f\r\n",angle[0],angle[1],angle[2],w[0],w[1],w[2]);
// if(temp_buf[0]==0x55) //檢查幀頭
// {
// temp_buf[0] = 0;
// switch(temp_buf[1])
// {
// case 0x51: //標識這個包是加速度包
// a[0] = ((short)(temp_buf[3]<<8 | temp_buf[2]))/32768.0*16; //X軸加速度
// a[1] = ((short)(temp_buf[5]<<8 | temp_buf[4]))/32768.0*16; //Y軸加速度
// a[2] = ((short)(temp_buf[7]<<8 | temp_buf[6]))/32768.0*16; //Z軸加速度
// T = ((short)(temp_buf[9]<<8 | temp_buf[8]))/340.0+36.25; //溫度
// break;
// case 0x52: //標識這個包是角速度包
// w[0] = ((short)(temp_buf[3]<<8| temp_buf[2]))/32768.0*2000; //X軸角速度
// w[1] = ((short)(temp_buf[5]<<8| temp_buf[4]))/32768.0*2000; //Y軸角速度
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
STM32解析MPU6050.zip
(386.78 KB, 下載次數: 19)
2017-7-27 17:09 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1