分享一个别人使用F1mini开发板 使用6050测角度的程序的程序
所有资料51hei提供下载:
程序3 读出数据.rar
(406.83 KB, 下载次数: 41)
stm32单片机源程序(主程序)如下:
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "lcd.h"
- #include "key.h"
- #include "MPU6050.h"
- #include "myiic.h"
- #include "usart.h"
- #include "adc.h"
- #include "dma.h"
- #include "math.h"
- #include "inv_mpu.h"
- #include "inv_mpu_dmp_motion_driver.h"
- //ALIENTEK Mini STM32开发板范例代码19
- //IIC实验
-
- u16 table[8]={0};
- int main(void)
- {
- u8 t;
- float pitch,roll,yaw; //欧拉角
- short aacx,aacy,aacz; //加速度传感器原始数据
- short gyrox,gyroy,gyroz; //陀螺仪原始数据
- short temp;
- NVIC_Configuration();
- delay_init(); //延时函数初始化
- uart_init(9600); //串口初始化为9600
- LCD_Init();
- Init_MUP6050(); //IIC初始化
- while(mpu_dmp_init())
- {
- LCD_ShowString(30,130,200,16,16,"MPU6050 Error");
- delay_ms(200);
- LCD_Fill(30,130,239,130+16,WHITE);
- delay_ms(200);
- }
- LCD_ShowString(30,130,200,16,16,"MPU6050 OK");
- LCD_ShowString(30,150,200,16,16,"KEY0:UPLOAD ON/OFF");
- POINT_COLOR=BLUE;//设置字体为蓝色
- LCD_ShowString(30,170,200,16,16,"UPLOAD ON ");
- LCD_ShowString(30,200,200,16,16," Temp: . C");
- LCD_ShowString(30,220,200,16,16,"Pitch: . C");
- LCD_ShowString(30,240,200,16,16," Roll: . C");
- LCD_ShowString(30,260,200,16,16," Yaw : . C");
-
- while(1)
- {
-
- {
- MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //得到加速度传感器数据
- MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //得到陀螺仪数据
- mpu_dmp_get_data(&pitch,&roll,&yaw);
-
- temp=pitch*10;
- if(temp<0)
- {
- LCD_ShowChar(30+48,220,'-',16,0); //显示负号
- temp=-temp; //转为正数
- }else LCD_ShowChar(30+48,220,' ',16,0); //去掉负号
- LCD_ShowNum(30+48+8,220,temp/10,3,16); //显示整数部分
- LCD_ShowNum(30+48+40,220,temp%10,1,16); //显示小数部分
-
-
- temp=roll*10;
- if(temp<0)
- {
- LCD_ShowChar(30+48,240,'-',16,0); //显示负号
- temp=-temp; //转为正数
- }else LCD_ShowChar(30+48,240,' ',16,0); //去掉负号
- LCD_ShowNum(30+48+8,240,temp/10,3,16); //显示整数部分
- LCD_ShowNum(30+48+40,240,temp%10,1,16); //显示小数部分
- temp=yaw*10;
- if(temp<0)
- {
- LCD_ShowChar(30+48,260,'-',16,0); //显示负号
- temp=-temp; //转为正数
- }else LCD_ShowChar(30+48,260,' ',16,0); //去掉负号
- LCD_ShowNum(30+48+8,260,temp/10,3,16); //显示整数部分
- LCD_ShowNum(30+48+40,260,temp%10,1,16); //显示小数部分
-
-
- }
-
- }
- }
复制代码
|