這是一個關于STM32F103藍牙點燈的程序。手機APP通過藍牙連接,可以點亮不同顏色的燈。
單片機源程序如下:
- #include "stm32f10x.h"
- #include "led_driver.h"
- #include "systick_driver.h"
- #include "rcc_driver.h"
- #include "beef_driver.h"
- #include "i2c_driver.h"
- #include "head.h"
- #include "Bluetooth.h"
- #include "ST_string.h"
- #include "uart.h"
- #include "tim.h"
- #include "oled_driver.h"
- #include "spi_driver.h"
- #include "stdlib.h"
- void led_control(void);
- uint8_t led_buf[5] = {0};
- void led_show(uint8_t led_buf[]);
- unsigned char ch[] = {0};
- extern const unsigned char F8X16[];
- int main(void)
- {
-
-
-
- RCC_init();
- systick_init();
- uart1_init();
- uart1_NVIC_init();
- tim2_init();
- tim3_init();
- usart3_init();
- usart3_NVIC_init();
- I2C_GPIOInitConfig();
- LED_GPIO_InitConfig();
-
- OLED_SPI_InitConfig();
- LCD_Init();
-
-
- BLE_BM_S02_Init();
-
-
- while(1){
-
- led_control();
- delay_ms(100);
-
-
- }
- return 0;
- }
- void led_control(void)
- {
- u8 cmd = 0,i;
- unsigned char b[128];
- if(Bluetooth_RF_BM_S02_Check_Connect_State() == 0){
-
- if(usart3_RecvStat.Recvcount >= 6){
- cmd = Untie_DataPack(usart3_buff,led_buf);
- printf("%d\n",cmd);
- for(i = 0;i < 9;i++)
- printf("%d ",usart3_buff[i]);
- printf("\r\n");
- for(i = 0; i < 3;i++){
- printf("%d ",led_buf[i]);
- sprintf(b,"%d",led_buf[i]);
- LCD_P6x8Str(50,2+i+i,b);
- }
- LCD_P6x8Str(0,2,"red:");
- LCD_P6x8Str(0,4,"green:");
- LCD_P6x8Str(0,6,"blue:");
- Clear_USART_Buff(USART3_BUF);
-
-
-
- switch(cmd){
- case 0x20:
- break;
- case 0x21:
- break;
- case 0x22:
- break;
- case 0x23:
- break;
- case 36:
- led_show(led_buf);
- break;
- case 0x25:
- break;
- case 0x26:
- break;
- }
- }
- }
- else{
-
- printf("bluetooth disconnect\n");
- delay_ms(1000);
- }
- }
- void led_show(uint8_t led_buf[])
- {
- TIM3->CCR3 = led_buf[0];
- TIM3->CCR2 = led_buf[1];
- TIM3->CCR1 = led_buf[2];
- }
復制代碼
所有資料51hei提供下載:
STM32_Color_LED.rar
(430.75 KB, 下載次數(shù): 37)
2018-7-10 03:31 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|