当前位置:网站首页>51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
2022-07-08 00:22:00 【Youxin Electronics】
51 Communicate with Bluetooth module ,51 Drive Bluetooth APP Lighting
Introduction of Bluetooth module
This experiment uses JDY31 Bluetooth module ,JDY-31 Bluetooth Based on Bluetooth 3.0 SPP Design ,
Bluetooth module is serial communication , SCM also has serial communication , We only need to configure it to realize the communication between MCU and Bluetooth , Even more functions , This article is about just learning 51 It needs a lot of help to make a Bluetooth Car
Serial port configuration
STC89C52 Of UART There are four working modes :
Pattern 0: Synchronous shift register
Pattern 1:8 position UART, The baud rate is variable ( Commonly used )
Pattern 2:9 position UART, Baud rate is fixed
Pattern 3:9 position UART, The baud rate is variable
This experiment is configured with mode 1; 8 Bit auto reassembly
The program configuration of specific programs can be assisted by STC Official downloader , The downloader comes with a baud rate calculator , Just generate the copy code according to the following figure 
The default baud rate of Bluetooth module is 9600, So here we have to choose 4800 Double speed
Main code
Serial port initialization code :89C52 Single chip microcomputer doesn't have AUXR, You can get rid of these two sentences , And on again EA and ES interrupt
/** * @brief Serial initialization [email protected] * @param nothing * @retval nothing */
void UART_Init()
{
SCON=0x50; //8 Bit data , Variable baud rate
PCON |=0x80; // Enable baud rate multiplier bit SMOD
TMOD &= 0x0F; // Set timer mode
TMOD |= 0x20; // Set timer mode
TL1 = 0xFA; // Set the initial timing value
TH1 = 0xFA; // Set time overload value
ET1 = 0; // Disable timer %d interrupt
TR1 = 1; // Timer 1 Start timing
EA=1; // Open total interrupt
ES=1; // Enable serial port interrupt
}
Serial port sends data :SBUF Serial port data buffer register ,
**
* @brief Serial port sends a byte of data
* @param Byte To send a byte of data
* @retval nothing
*/
void UART_SendByte(unsigned char Byte)
{
SBUF=Byte;
while(TI==0);
TI=0;
}
Main code
void main ()
{
UART_Init(); // Serial initialization
while(1)
{
}
}
void UART_Routine() interrupt 4 // Serial port interrupt number
{
if(RI==1)
{
P1=SBUF; // Receive data control P1
RI=0; // Set the serial port receiving register to zero
}
}
Experimental wiring
Do not connect Bluetooth when downloading SCM , Download the program before connecting , Otherwise the download will fail
| Single chip microcomputer | Bluetooth module |
|---|---|
| 5V | VCC |
| P3.0 | TX |
| P3.1 | RX |
| GND | GND |
mobile phone APP To configure
1, Download at mobile store SPP Bluetooth serial port , This Bluetooth module Apple phone is not available ,
2, It opens at APP Upper right corner Connect the corresponding Bluetooth
3, Customize a button in the place of switch , The configuration is as follows :
After configuration, you can start operation
Experimental phenomena

summary
The data transmitted by Bluetooth exists SBUF In the register , All kinds of operation control can be carried out by processing the received data , This article is equivalent to a serial communication template , If you need a complete project, you can leave a message below
边栏推荐
- Daily question brushing record (16)
- The standby database has been delayed. Check that the MRP is wait_ for_ Log, apply after restarting MRP_ Log but wait again later_ for_ log
- 深潜Kotlin协程(二十二):Flow的处理
- Experience of autumn recruitment in 22 years
- Jouer sonar
- Sqlite数据库存储目录结构邻接表的实现2-目录树的构建
- How to put recyclerview in nestedscrollview- How to put RecyclerView inside NestedScrollView?
- Detailed explanation of interview questions: the history of blood and tears in implementing distributed locks with redis
- Smart regulation enters the market, where will meituan and other Internet service platforms go
- Zhou Hongqi, 52 ans, est - il encore jeune?
猜你喜欢

35岁真就成了职业危机?不,我的技术在积累,我还越吃越香了

STM32F1与STM32CubeIDE编程实例-旋转编码器驱动

快速上手使用本地测试工具postman

Fully automated processing of monthly card shortage data and output of card shortage personnel information

Detailed explanation of interview questions: the history of blood and tears in implementing distributed locks with redis

Is 35 really a career crisis? No, my skills are accumulating, and the more I eat, the better

QT and OpenGL: loading 3D models using the open asset import library (assimp) - Part 2

玩转Sonar

ROS from entry to mastery (IX) initial experience of visual simulation: turtlebot3

Go learning notes (2) basic types and statements (1)
随机推荐
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
Stm32f1 and stm32cubeide programming example - rotary encoder drive
LeetCode刷题
Binder核心API
QT creator add JSON based Wizard
【笔记】常见组合滤波电路
Su embedded training - day4
[question de programmation] [scratch niveau 2] oiseaux volants en décembre 2019
[programming problem] [scratch Level 2] March 2019 draw a square spiral
STM32F1與STM32CubeIDE編程實例-旋轉編碼器驅動
52歲的周鴻禕,還年輕嗎?
Operating system principle --- summary of interview knowledge points
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
Is Zhou Hongyi, 52, still young?
【测试面试题】页面很卡的原因分析及解决方案
Robomaster visual tutorial (1) camera
【编程题】【Scratch二级】2019.03 垃圾分类
商品的设计等整个生命周期,都可以将其纳入到产业互联网的范畴内
ReentrantLock 公平锁源码 第0篇
The underlying principles and templates of new and delete