由前文的代码移植到STM32F407ZGT6
STM32F103C8T6+HC05蓝牙模块_善 .的博客-CSDN博客
可以参考上文。手机上做了GUI界面。效果如下

修改了主函数
- #include "stm32f4xx.h" // Device header
- #include "delay.h"
- #include "usart.h"
- #include "led.h"
- #include "lcd.h"
- #include "bluetooth.h"
-
- //蓝牙
- extern int test_number;
- int key_1=0;
- uint8_t Direction=0;
-
- int main(void)
- {
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
-
- delay_init(168); //初始化延时函数
- uart_init(115200); //初始化串口波特率为115200
- LED_Init(); //初始化LED
- LCD_Init(); //初始化LCD FSMC接口
-
- Serial_Init();
-
- POINT_COLOR=BLACK; //画笔颜色:红色
- LCD_Clear(WHITE);
- LCD_ShowString(14*16,28*16,500,16,16,"TEST--LYYXXT");
-
- while(1)
- {
- lanya_transmit();
-
- if(key_1==0)
- {
- test_number++;
- if(test_number==80)
- {
- key_1=1;
- }
- }
- else if(key_1==1)
- {
- test_number--;
- if(test_number==10)
- {
- key_1=0;
- }
- }
-
- if (Serial_GetRxFlag() == 1) //判断是否收到数据
- {
- Direction = Serial_GetRxData(); //读取数据
- LCD_Clear(WHITE);
- LCD_ShowxNum(16,32,key2,2,16,1);
- LCD_ShowChar(16,16,Direction,16,1);
-
- printf("字符:%c 数字:%d\r\n",Direction,key2);
- Serial_SendByte(Direction); //将数据回传到电脑
- }
- }
- }
-
工程文件在GitHub上:LYYSXT/STM32F407 at bluetooth (github.com)
手机的“蓝牙调试器”也发布在GitHub。
蓝牙也是采用串口通信,我选择了串口2。(串口三的TX有问题不能发送数据)
蓝牙模块
PA2_USART2_TX HC05_RX
PA3_USART2_RX HC05_TX
HC05采用5v供电