当前位置:网站首页>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
边栏推荐
- An error is reported during the process of setting up ADG. Rman-03009 ora-03113
- 动态库基本原理和使用方法,-fPIC 选项的来龙去脉
- Su embedded training - day4
- [the most detailed in history] statistical description of overdue days in credit
- 数据库查询——第几高的数据?
- Daily question brushing record (16)
- 备库一直有延迟,查看mrp为wait_for_log,重启mrp后为apply_log但过一会又wait_for_log
- How to learn a new technology (programming language)
- ROS from entry to mastery (IX) initial experience of visual simulation: turtlebot3
- After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
猜你喜欢
玩轉Sonar
1293_FreeRTOS中xTaskResumeAll()接口的实现分析
Robomaster visual tutorial (1) camera
Operating system principle --- summary of interview knowledge points
Installation and configuration of sublime Text3
The underlying principles and templates of new and delete
腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
52歲的周鴻禕,還年輕嗎?
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
测试流程不完善,又遇到不积极的开发怎么办?
随机推荐
CoinDesk评波场去中心化进程:让人们看到互联网的未来
"An excellent programmer is worth five ordinary programmers", and the gap lies in these seven key points
【史上最详细】信贷中逾期天数统计说明
How to add automatic sorting titles in typora software?
Smart regulation enters the market, where will meituan and other Internet service platforms go
[basis of recommendation system] sampling and construction of positive and negative samples
[question de programmation] [scratch niveau 2] oiseaux volants en décembre 2019
Set up personal network disk with nextcloud
Cmake learning notes (1) compile single source programs with cmake
Go learning notes (1) environment installation and hello world
Cause analysis and solution of too laggy page of [test interview questions]
[the most detailed in history] statistical description of overdue days in credit
什么是负载均衡?DNS如何实现负载均衡?
If an exception is thrown in the constructor, the best way is to prevent memory leakage?
80% of the people answered incorrectly. Does the leaf on the apple logo face left or right?
赞!idea 如何单窗口打开多个项目?
Fully automated processing of monthly card shortage data and output of card shortage personnel information
DNS 系列(一):为什么更新了 DNS 记录不生效?
How to put recyclerview in nestedscrollview- How to put RecyclerView inside NestedScrollView?
[programming problem] [scratch Level 2] March 2019 draw a square spiral