当前位置:网站首页>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
边栏推荐
- Prompt configure: error: required tool not found: libtool solution when configuring and installing crosstool ng tool
- Basic principle and usage of dynamic library, -fpic option context
- After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
- Leetcode brush questions
- 应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
- Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
- 华为交换机S5735S-L24T4S-QA2无法telnet远程访问
- 浪潮云溪分布式数据库 Tracing(二)—— 源码解析
- Play sonar
- Set up personal network disk with nextcloud
猜你喜欢
某马旅游网站开发(登录注册退出功能的实现)
35岁真就成了职业危机?不,我的技术在积累,我还越吃越香了
每日刷题记录 (十六)
Play sonar
[basis of recommendation system] sampling and construction of positive and negative samples
QT and OpenGL: load 3D models using the open asset import library (assimp)
Trust orbtk development issues 2022
Go learning notes (1) environment installation and hello world
【编程题】【Scratch二级】2019.09 制作蝙蝠冲关游戏
Robomaster visual tutorial (1) camera
随机推荐
赞!idea 如何单窗口打开多个项目?
爬虫实战(八):爬表情包
Play sonar
应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
What if the testing process is not perfect and the development is not active?
Anaconda+pycharm+pyqt5 configuration problem: pyuic5 cannot be found exe
ABAP ALV LVC模板
单机高并发模型设计
服务器防御DDOS的方法,杭州高防IP段103.219.39.x
[question de programmation] [scratch niveau 2] oiseaux volants en décembre 2019
Trust orbtk development issues 2022
韦东山第二期课程内容概要
"An excellent programmer is worth five ordinary programmers", and the gap lies in these seven key points
[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game
Usage of limit and offset (Reprint)
QT creator add JSON based Wizard
Smart regulation enters the market, where will meituan and other Internet service platforms go
Robomaster visual tutorial (1) camera
[研发人员必备]paddle 如何制作自己的数据集,并显示。
[programming questions] [scratch Level 2] March 2019 garbage classification