標(biāo)題: MPU6050測(cè)角度stm32程序 [打印本頁(yè)]

作者: 血之殤    時(shí)間: 2017-8-10 14:02
標(biāo)題: MPU6050測(cè)角度stm32程序
分享一個(gè)別人使用F1mini開(kāi)發(fā)板 使用6050測(cè)角度的程序的程序

所有資料51hei提供下載:
程序3 讀出數(shù)據(jù).rar (406.83 KB, 下載次數(shù): 41)

stm32單片機(jī)源程序(主程序)如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "sys.h"
  4. #include "usart.h"
  5. #include "lcd.h"
  6. #include "key.h"  
  7. #include "MPU6050.h"
  8. #include "myiic.h"
  9. #include "usart.h"
  10. #include "adc.h"
  11. #include "dma.h"
  12. #include "math.h"
  13. #include "inv_mpu.h"
  14. #include "inv_mpu_dmp_motion_driver.h"
  15. //ALIENTEK Mini STM32開(kāi)發(fā)板范例代碼19
  16. //IIC實(shí)驗(yàn)  
  17.            
  18. u16 table[8]={0};
  19. int main(void)
  20. {         
  21.          u8 t;
  22.          float pitch,roll,yaw;                 //歐拉角
  23.         short aacx,aacy,aacz;                //加速度傳感器原始數(shù)據(jù)
  24.         short gyrox,gyroy,gyroz;        //陀螺儀原始數(shù)據(jù)
  25.         short temp;
  26.         NVIC_Configuration();
  27.         delay_init();                     //延時(shí)函數(shù)初始化         
  28.         uart_init(9600);                  //串口初始化為9600
  29.          LCD_Init();                 
  30.         Init_MUP6050();                   //IIC初始化

  31.         while(mpu_dmp_init())
  32.         {
  33.                 LCD_ShowString(30,130,200,16,16,"MPU6050 Error");
  34.                 delay_ms(200);
  35.                 LCD_Fill(30,130,239,130+16,WHITE);
  36.                  delay_ms(200);
  37.         }
  38.         LCD_ShowString(30,130,200,16,16,"MPU6050 OK");
  39.         LCD_ShowString(30,150,200,16,16,"KEY0:UPLOAD ON/OFF");
  40.         POINT_COLOR=BLUE;//設(shè)置字體為藍(lán)色
  41.          LCD_ShowString(30,170,200,16,16,"UPLOAD ON ");         
  42.          LCD_ShowString(30,200,200,16,16," Temp:    . C");        
  43.          LCD_ShowString(30,220,200,16,16,"Pitch:    . C");        
  44.          LCD_ShowString(30,240,200,16,16," Roll:    . C");         
  45.          LCD_ShowString(30,260,200,16,16," Yaw :    . C");        
  46.         


  47.         while(1)
  48.         {
  49.         

  50.                 {
  51.                         MPU_Get_Accelerometer(&aacx,&aacy,&aacz);        //得到加速度傳感器數(shù)據(jù)
  52.                         MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);        //得到陀螺儀數(shù)據(jù)
  53.                         mpu_dmp_get_data(&pitch,&roll,&yaw);
  54.                                 
  55.                                 temp=pitch*10;
  56.                                 if(temp<0)
  57.                                 {
  58.                                         LCD_ShowChar(30+48,220,'-',16,0);                //顯示負(fù)號(hào)
  59.                                         temp=-temp;                //轉(zhuǎn)為正數(shù)
  60.                                 }else LCD_ShowChar(30+48,220,' ',16,0);                //去掉負(fù)號(hào)
  61.                                 LCD_ShowNum(30+48+8,220,temp/10,3,16);                //顯示整數(shù)部分            
  62.                                 LCD_ShowNum(30+48+40,220,temp%10,1,16);                //顯示小數(shù)部分
  63.                                 
  64.                                  
  65.                                 temp=roll*10;
  66.                                 if(temp<0)
  67.                                 {
  68.                                         LCD_ShowChar(30+48,240,'-',16,0);                //顯示負(fù)號(hào)
  69.                                         temp=-temp;                //轉(zhuǎn)為正數(shù)
  70.                                 }else LCD_ShowChar(30+48,240,' ',16,0);                //去掉負(fù)號(hào)
  71.                                 LCD_ShowNum(30+48+8,240,temp/10,3,16);                //顯示整數(shù)部分            
  72.                                 LCD_ShowNum(30+48+40,240,temp%10,1,16);                //顯示小數(shù)部分


  73.                                 temp=yaw*10;
  74.                                 if(temp<0)
  75.                                 {
  76.                                         LCD_ShowChar(30+48,260,'-',16,0);                //顯示負(fù)號(hào)
  77.                                         temp=-temp;                //轉(zhuǎn)為正數(shù)
  78.                                 }else LCD_ShowChar(30+48,260,' ',16,0);                //去掉負(fù)號(hào)
  79.                                 LCD_ShowNum(30+48+8,260,temp/10,3,16);                //顯示整數(shù)部分            
  80.                                 LCD_ShowNum(30+48+40,260,temp%10,1,16);                //顯示小數(shù)部分  
  81.                         
  82.                         
  83.                 }
  84.                
  85.         }         

  86. }
復(fù)制代碼





作者: Cunningboy    時(shí)間: 2017-8-10 22:27
這個(gè)引腳怎么連接?




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1