新手入门
- 积分
- 1
- 金钱
- 1
- 注册时间
- 2020-8-14
- 在线时间
- 0 小时
|
1金钱
本帖最后由 这是真的菜鸡 于 2020-8-14 21:29 编辑
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "key.h"
- #include "usart.h"
- #include "mpu6050.h"
- #include "usmart.h"
- #include "inv_mpu.h"
- #include "inv_mpu_dmp_motion_driver.h"
- /************************************************
- ALIENTEK NANO STM32¿ª·¢°å À©Õ¹ÊµÑé6
- ATK-MPU6050ÁùÖá´«¸ÐÆ÷ʵÑé1 ´®¿ÚÖúÊÖ´òÓ¡-HAL¿â°æ±¾
- ¼¼ÊõÖ§³Ö£ºwww.openedv.com
- ÌÔ±¦µêÆÌ£ºhttp://eboard.taobao.com
- ¹Ø×¢Î¢ÐŹ«ÖÚÆ½Ì¨Î¢Ðźţº"ÕýµãÔ­×Ó"£¬Ãâ·Ñ»ñÈ¡STM32×ÊÁÏ¡£
- ¹ãÖÝÊÐÐÇÒíµç×ӿƼ¼ÓÐÏÞ¹«Ë¾
- ×÷ÕߣºÕýµãÔ­×Ó @ALIENTEK
- ************************************************/
- int main(void)
- {
-
- u8 t=0;
- u8 key=0;
- u8 GetData=1;
- float pitch,roll,yaw; //Å·À­½Ç
- short aacx,aacy,aacz; //¼ÓËÙ¶È´«¸ÐÆ÷ԭʼÊý¾Ý
- short gyrox,gyroy,gyroz; //ÍÓÂÝÒÇԭʼÊý¾Ý
- short temp; //ζÈ
-
- HAL_Init(); //³õʼ»¯HAL¿â
- Stm32_Clock_Init(RCC_PLL_MUL9); //ÉèÖÃʱÖÓ,72M
- delay_init(72); //³õʼ»¯ÑÓʱº¯Êý
- uart_init(115200); //³õʼ»¯´®¿Ú115200
- LED_Init(); //³õʼ»¯LED
- KEY_Init(); //³õʼ»¯°´¼ü
- usmart_init(72); //USMART³õʼ»¯
- printf("ALIENTEK NANO STM32\r\n");
- printf("MPU6050 TEST\r\n");
- while(mpu_dmp_init())//MPU DMP³õʼ»¯
- {
- printf("MPU6050 Error!!!\r\n");
- delay_ms(500);
- LED0=!LED0;//DS0ÉÁ˸
-
- }
- printf("MPU6050 OK\r\n");
- while(1)
- {
-
- key=KEY_Scan(0);
- if(key==WKUP_PRES)
- {
- GetData=!GetData;
- if(GetData)printf("GETDATA ON\r\n");
- else printf("GETDATA OFF\r\n");
- }
- if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
- {
- temp=MPU_Get_Temperature(); //µÃµ½Î¶ÈÖµ
- MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //µÃµ½¼ÓËÙ¶È´«¸ÐÆ÷Êý¾Ý
- MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //µÃµ½ÍÓÂÝÒÇÊý¾Ý
- if(GetData)//GetData=0ʱ ÓÃÓÚUSMARTµ÷ÊÔMPU6050¼Ä´æÆ÷
- {
-
- if((t%10)==0)
- {
- //tempÖµ
- if(temp<0)
- {
- temp=-temp; //תΪÕýÊý
- printf(" Temp: -%d.%dC\r\n",temp/100,temp%10);
- }else
- printf(" Temp: %d.%dC\r\n",temp/100,temp%10);
-
- //pitchÖµ
- temp=pitch*10;
- if(temp<0)
- {
- temp=-temp; //תΪÕýÊý
- printf(" Pitch: -%d.%dC\r\n",temp/10,temp%10);
- }else
- printf(" Pitch: %d.%dC\r\n",temp/10,temp%10);
-
- //rollÖµ
- temp=roll*10;
- if(temp<0)
- {
- temp=-temp; //תΪÕýÊý
- printf(" Roll: -%d.%dC\r\n",temp/10,temp%10);
- }else
- printf(" Roll: %d.%dC\r\n",temp/10,temp%10);
-
- //yawÖµ
- temp=yaw*10;
- if(temp<0)
- {
- temp=-temp; //תΪÕýÊý
- printf(" Yaw: -%d.%dC\r\n",temp/10,temp%10);
- }else
- printf(" Yaw: %d.%dC\r\n",temp/10,temp%10);
-
- printf("\r\n");
- t=0;
- LED0=!LED0;//LEDÉÁ˸
- }
- }
-
- }
- t++;
- }
- }
复制代码
|
|