找回密码
 立即注册

QQ登录

只需一步,快速开始

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

这是一个蓝牙电灯的程序,通过手机APP来点亮STM32上的彩灯

[复制链接]
ID:237935 发表于 2018-7-9 10:52 | 显示全部楼层 |阅读模式
这是一个关于STM32F103蓝牙点灯的程序。手机APP通过蓝牙连接,可以点亮不同颜色的灯。

单片机源程序如下:
  1. #include "stm32f10x.h"


  2. #include "led_driver.h"
  3. #include "systick_driver.h"
  4. #include "rcc_driver.h"
  5. #include "beef_driver.h"
  6. #include "i2c_driver.h"
  7. #include "head.h"
  8. #include "Bluetooth.h"
  9. #include "ST_string.h"
  10. #include "uart.h"
  11. #include "tim.h"
  12. #include "oled_driver.h"
  13. #include "spi_driver.h"
  14. #include "stdlib.h"




  15. void led_control(void);
  16. uint8_t led_buf[5] = {0};
  17. void led_show(uint8_t led_buf[]);
  18. unsigned char ch[] = {0};
  19. extern const unsigned char F8X16[];

  20. int main(void)
  21. {
  22.        
  23.        
  24.        
  25.         RCC_init();
  26.         systick_init();
  27.         uart1_init();
  28.         uart1_NVIC_init();
  29.         tim2_init();
  30.         tim3_init();
  31.         usart3_init();
  32.         usart3_NVIC_init();
  33.         I2C_GPIOInitConfig();
  34.         LED_GPIO_InitConfig();
  35.        
  36.         OLED_SPI_InitConfig();
  37.         LCD_Init();
  38.        

  39.        
  40.         BLE_BM_S02_Init();
  41.        
  42.        
  43.         while(1){
  44.                                  
  45.                 led_control();
  46.                 delay_ms(100);
  47.                        
  48.                
  49.                 }
  50.                 return 0;
  51.         }


  52. void led_control(void)
  53. {
  54.         u8 cmd = 0,i;
  55.         unsigned char b[128];
  56.         if(Bluetooth_RF_BM_S02_Check_Connect_State() == 0){
  57.                
  58.                 if(usart3_RecvStat.Recvcount >= 6){
  59.                         cmd = Untie_DataPack(usart3_buff,led_buf);
  60.                         printf("%d\n",cmd);
  61.                         for(i = 0;i < 9;i++)
  62.                                 printf("%d ",usart3_buff[i]);
  63.                         printf("\r\n");
  64.                         for(i = 0; i < 3;i++){
  65.                                 printf("%d ",led_buf[i]);       
  66.                                 sprintf(b,"%d",led_buf[i]);
  67.                                 LCD_P6x8Str(50,2+i+i,b);
  68.                         }
  69.                         LCD_P6x8Str(0,2,"red:");
  70.                         LCD_P6x8Str(0,4,"green:");
  71.                         LCD_P6x8Str(0,6,"blue:");
  72.                         Clear_USART_Buff(USART3_BUF);
  73.                        
  74.                        
  75.                        
  76.                         switch(cmd){
  77.                                 case 0x20:
  78.                                         break;
  79.                                 case 0x21:
  80.                                         break;
  81.                                 case 0x22:
  82.                                         break;
  83.                                 case 0x23:
  84.                                         break;
  85.                                 case 36:
  86.                                         led_show(led_buf);
  87.                                 break;
  88.                                 case 0x25:
  89.                                         break;                       
  90.                                 case 0x26:
  91.                                         break;
  92.                         }       
  93.                 }
  94.         }
  95.         else{
  96.                
  97.                         printf("bluetooth disconnect\n");
  98.                 delay_ms(1000);
  99.         }
  100. }

  101. void led_show(uint8_t led_buf[])
  102. {
  103.                 TIM3->CCR3 = led_buf[0];
  104.                 TIM3->CCR2 = led_buf[1];
  105.                 TIM3->CCR1 = led_buf[2];
  106. }

复制代码

所有资料51hei提供下载:
STM32_Color_LED.rar (430.75 KB, 下载次数: 37)


回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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