簡體   English   中英

如何檢測設備是否獲得我的手機藍牙名稱?

[英]How to detect if a device get my phone bluetooth name?

藍牙和藍牙與藍牙

我想你想要這樣的東西: VIDEO

讓我們從基礎開始:

新藍牙HC-05模塊的典型默認出廠設置為:

  • 默認藍牙名稱:“ HC-05”
  • 默認密碼:1234或0000
  • 默認通信:從設備
  • 默認模式:數據模式
  • 默認數據模式波特率:9600、8,N,1
  • 默認命令模式波特率:38400,8,N,1
  • 默認固件:LINVOR

1.要從您的android設備使用id測試藍牙連接,建議您使用此 APK

2.如圖所示,連接HC-05 BT模塊

在此處輸入圖片說明

3.在微控制器端(側面)初始化UART接收器

(代碼包括用於引腳33和引腳34的2個LED)

/*
* LAB Number: 17
* LAB Name: Bluetooth Module HC-05 Interfacing (Smartphone -> MCU)
* Author: Khaled Magdy
* For More Information Visit My Website @ DeepBlueMbedded.com
*
*/

#include <xc.h>
#include <stdint.h>
#include "config.h"
#define _XTAL_FREQ 4000000
//--[ Control Data ]--
#define Blue_LED_ON    49
#define Blue_LED_OFF   50
#define Yellow_Toggle  51
//--------------------------------
// Functions Declarations
void UART_RX_Init(void);
// Globals
uint8_t UART_Buffer = 0;
//--------------------------------

// Main Routine
void main(void)
{
  //--[ Peripherals & IO Configurations ]--
  UART_RX_Init(); // Initialize The UART in Master Mode @ 9600bps
  TRISB0 = 0;     // Blue LED  (Switch)
  TRISB1 = 0;     // Yellow LED (Toggle)
  RB0 = 0;        // Initially OFF
  RB1 = 0;        // Initially OFF
  //---------------------------
  while(1) 
  {

  }
  return;
}
//--------------------------------
// Functions Definitions

void UART_RX_Init()
{
  BRGH = 1; // Set For High-Speed Baud Rate
  SPBRG = 25; // Set The Baud Rate To Be 9600 bps
  // Enable The Ascynchronous Serial Port
  SYNC = 0;
  SPEN = 1;
  // Set The RX-TX Pins to be in UART mode (not io)
  TRISC6 = 1; // As stated in the datasheet
  TRISC7 = 1; // As stated in the datasheet
  //--[ Enable UART Receiving Interrupts ]--
  RCIE = 1; // UART Receving Interrupt Enable Bit
  PEIE = 1; // Peripherals Interrupt Enable Bit
  GIE = 1; // Global Interrupt Enable Bit
  //------------------
  CREN = 1; // Enable Data Continous Reception
}

void interrupt ISR (void)
{
  if (RCIF == 1)
  {
    UART_Buffer = RCREG; // Read The Received Data Buffer

    // This could have been done within the main loop. Since it's not
    // Excessive processing, so it's OK to do it here below
    if(UART_Buffer == Blue_LED_ON)
      RB0 = 1; // Blue LED ON
    if(UART_Buffer == Blue_LED_OFF)
      RB0 = 0; // Blue LED OFF
    if(UART_Buffer == Yellow_Toggle)
      RB1 = ~RB1; // Toggle Yellow LED 

    RCIF = 0; // Clear The Interrupt Flag
  }
}

注意數據字節(49、50和51)是數字字符(分別為1、2和3)的ASCII等效項。

4.下載此apk將命令發送到您的HC05: APK

有關更多信息,請參見參考: LINK

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM