單片機源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "usart.h"
- #include "exti.h"
- #include "oled.h"
- #include "mpu6050.h"
- #include "inv_mpu.h"
- #include "inv_mpu_dmp_motion_driver.h"
- #include "bmp.h"
- #include "timer.h"
- // OLED_ShowPicture(32,0,96,4,BMP_go);
- // OLED_ShowPicture(32,4,96,8,BMP_back);
- //
- // OLED_ShowPicture(0,0,32,8,BMP_left);
- // OLED_ShowPicture(96,0,128,8,BMP_right);
- float i=0,pitch=0,roll=0,yaw=0; //滾,仰,偏
-
- int main(void)
- {
- delay_init(); //延時函數初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //設置NVIC中斷分組2:2位搶占優先級,2位響應優先級
- uart_init(115200); //串口初始化為
- LED_Init(); //LED端口初始化
- EXTIX_KEY_Init();
- MPU_Init();
- OLED_Init();
- while(mpu_dmp_init())
- {
- delay_ms(10);
- }
-
- while(1)
- {
- delay_ms(2);
- if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
- {
- LED=~LED;
- }
-
- if(pitch > 15 ) //右
- {
- OLED_ShowPicture(96,0,128,8,BMP_right);
- USART_SendData(USART1, 4 );
- }
- else if(pitch < -15 ) //左
- {
- OLED_ShowPicture(0,0,32,8,BMP_left);
- USART_SendData(USART1, 3 );
- }
- else if(roll < -15 ) //go
- {
- OLED_ShowPicture(32,0,96,4,BMP_go);
- USART_SendData(USART1, 1 );
- }
- else if(roll > 15 ) //back
- {
- OLED_ShowPicture(32,4,96,8,BMP_back);
- USART_SendData(USART1, 2 );
- }
- else
- {
- OLED_Clear();
- USART_SendData(USART1, 5 );
- }
- }
- }
復制代碼
全部資料51hei下載地址:
單片機串口代碼移植.7z
(261.71 KB, 下載次數: 40)
2020-12-6 23:21 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|