找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1594|回复: 0
收起左侧

STM32单片机串口代码移植 HC-05蓝牙模块收发程序

[复制链接]
ID:653310 发表于 2020-12-6 20:42 | 显示全部楼层 |阅读模式
单片机源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "usart.h"
  6. #include "exti.h"
  7. #include "oled.h"
  8. #include "mpu6050.h"
  9. #include "inv_mpu.h"
  10. #include "inv_mpu_dmp_motion_driver.h"
  11. #include "bmp.h"
  12. #include "timer.h"

  13. //                        OLED_ShowPicture(32,0,96,4,BMP_go);
  14. //                        OLED_ShowPicture(32,4,96,8,BMP_back);
  15. //               
  16. //                        OLED_ShowPicture(0,0,32,8,BMP_left);
  17. //                        OLED_ShowPicture(96,0,128,8,BMP_right);


  18. float i=0,pitch=0,roll=0,yaw=0;                 //滚,仰,偏
  19.        
  20. int main(void)
  21. {       
  22.         delay_init();                     //延时函数初始化          
  23.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
  24.         uart_init(115200);         //串口初始化为
  25.         LED_Init();                             //LED端口初始化
  26.         EXTIX_KEY_Init();
  27.         MPU_Init();
  28.         OLED_Init();       
  29.         while(mpu_dmp_init())
  30.         {
  31.                 delay_ms(10);
  32.         }
  33.        
  34.         while(1)
  35.         {
  36.                 delay_ms(2);
  37.                 if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
  38.                 {
  39.                         LED=~LED;
  40.                 }
  41.                
  42.                 if(pitch > 15 )   //右
  43.                 {
  44.                         OLED_ShowPicture(96,0,128,8,BMP_right);
  45.                         USART_SendData(USART1, 4 );
  46.                 }       
  47.                 else if(pitch < -15 )  //左
  48.                 {
  49.                         OLED_ShowPicture(0,0,32,8,BMP_left);
  50.                         USART_SendData(USART1, 3 );
  51.                 }       
  52.                 else if(roll < -15 )  //go
  53.                 {
  54.                         OLED_ShowPicture(32,0,96,4,BMP_go);
  55.                         USART_SendData(USART1, 1 );
  56.                 }       
  57.                 else if(roll > 15 )  //back
  58.                 {
  59.                         OLED_ShowPicture(32,4,96,8,BMP_back);
  60.                         USART_SendData(USART1, 2 );
  61.                 }       
  62.                 else
  63.                 {
  64.                         OLED_Clear();
  65.                         USART_SendData(USART1, 5 );
  66.                 }       
  67.         }        
  68. }
复制代码

全部资料51hei下载地址:
单片机串口代码移植.7z (261.71 KB, 下载次数: 40)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表