当前位置:网站首页>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
边栏推荐
- 深潜Kotlin协程(二十三 完结篇):SharedFlow 和 StateFlow
- 浪潮云溪分布式数据库 Tracing(二)—— 源码解析
- 测试流程不完善,又遇到不积极的开发怎么办?
- 【编程题】【Scratch二级】2019.12 飞翔的小鸟
- C# 泛型及性能比较
- Single machine high concurrency model design
- Summary of the third course of weidongshan
- 赞!idea 如何单窗口打开多个项目?
- Opengl3.3 mouse picking up objects
- 大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
猜你喜欢
搭建ADG过程中复制报错 RMAN-03009 ORA-03113
Development of a horse tourism website (realization of login, registration and exit function)
浪潮云溪分布式数据库 Tracing(二)—— 源码解析
深潜Kotlin协程(二十二):Flow的处理
STM32F1與STM32CubeIDE編程實例-旋轉編碼器驅動
"An excellent programmer is worth five ordinary programmers", and the gap lies in these seven key points
The underlying principles and templates of new and delete
玩转Sonar
Fully automated processing of monthly card shortage data and output of card shortage personnel information
How does starfish OS enable the value of SFO in the fourth phase of SFO destruction?
随机推荐
paddle入门-使用LeNet在MNIST实现图像分类方法一
RPA云电脑,让RPA开箱即用算力无限?
paddle一个由三个卷积层组成的网络完成cifar10数据集的图像分类任务
ReentrantLock 公平锁源码 第0篇
[programming problem] [scratch Level 2] draw ten squares in December 2019
Emotional post station 010: things that contemporary college students should understand
什么是负载均衡?DNS如何实现负载均衡?
How does the markdown editor of CSDN input mathematical formulas--- Latex syntax summary
Daily question brushing record (16)
腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
Zhou Hongqi, 52 ans, est - il encore jeune?
Notice on organizing the second round of the Southwest Division (Sichuan) of the 2021-2022 National Youth electronic information intelligent innovation competition
How to measure whether the product is "just needed, high frequency, pain points"
Robomaster visual tutorial (0) Introduction
Sqlite数据库存储目录结构邻接表的实现2-目录树的构建
Solution to the problem of unserialize3 in the advanced web area of the attack and defense world
[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game
Summary of the third course of weidongshan
Introduction knowledge system of Web front-end engineers
[C language] objective questions - knowledge points