当前位置:网站首页>51与蓝牙模块通讯,51驱动蓝牙APP点灯
51与蓝牙模块通讯,51驱动蓝牙APP点灯
2022-07-07 22:17:00 【优信电子】
蓝牙模块简介
本次实验用到是JDY31蓝牙模块,JDY-31 蓝牙基于蓝牙 3.0 SPP 设计,
蓝牙模块是串口通讯,单片机也有串口通讯,我们只需要配置好既可以实现单片机于蓝牙通讯,甚至是实现更多的功能,本文对刚学习51需要制作蓝牙小车的帮助很大
串口配置
STC89C52的UART有四种工作模式:
模式0:同步移位寄存器
模式1:8位UART,波特率可变(常用)
模式2:9位UART,波特率固定
模式3:9位UART,波特率可变
本次实验配置的是模式1; 8位自动重装
具体的程序的程序配置可以借助STC官方的下载器,下载器自带一个波特率计算器,按下面的图配置生成复制代码就行
蓝牙模块默认波特率是9600,所以这里要选择4800倍速
主要代码
串口初始化代码:89C52单片机没有AUXR,可以去掉这两句程序,再打开EA和ES中断
/** * @brief 串口初始化[email protected] * @param 无 * @retval 无 */
void UART_Init()
{
SCON=0x50; //8位数据,可变波特率
PCON |=0x80; //使能波特率倍速位SMOD
TMOD &= 0x0F; //设置定时器模式
TMOD |= 0x20; //设置定时器模式
TL1 = 0xFA; //设置定时初始值
TH1 = 0xFA; //设置定时重载值
ET1 = 0; //禁止定时器%d中断
TR1 = 1; //定时器1开始计时
EA=1; //开启总中断
ES=1; //开启串口中断
}
串口发送数据:SBUF是串口数据缓冲寄存器,
**
* @brief 串口发送一个字节数据
* @param Byte 要发送一个字节数据
* @retval 无
*/
void UART_SendByte(unsigned char Byte)
{
SBUF=Byte;
while(TI==0);
TI=0;
}
主要代码
void main ()
{
UART_Init(); //串口初始化
while(1)
{
}
}
void UART_Routine() interrupt 4 //串口中断号
{
if(RI==1)
{
P1=SBUF; //接收数据控制P1
RI=0; //串口接收寄存器置零
}
}
实验接线
单片机下载的时候不要连接蓝牙,要先下载程序再连接,否则下载会失败
单片机 | 蓝牙模块 |
---|---|
5V | VCC |
P3.0 | TX |
P3.1 | RX |
GND | GND |
手机APP配置
1,在手机商店下载SPP蓝牙串口,本蓝牙模块苹果手机不可用,
2,点开APP右上角连接对应的蓝牙
3,在开关这个地方自定义一个按钮,配置如下图:
配置好之后即可开始操作
实验现象
总结
蓝牙传输的数据存在SBUF寄存器中,对接收到的数据进行处理就可以进行各种操作控制,本文相当于一个串口通讯模板,需要完整工程的可以下方留言
边栏推荐
- 用語雀寫文章了,功能真心强大!
- Enterprise application demand-oriented development of human resources department, employee attendance records and paid wages business process cases
- Basic learning of SQL Server -- creating databases and tables with code
- Prompt configure: error: required tool not found: libtool solution when configuring and installing crosstool ng tool
- C language 001: download, install, create the first C project and execute the first C language program of CodeBlocks
- Introduction to programming hardware
- Common selectors are
- The difference between -s and -d when downloading packages using NPM
- 【编程题】【Scratch二级】2019.09 绘制雪花图案
- 自动化测试:Robot FrameWork框架90%的人都想知道的实用技巧
猜你喜欢
[question de programmation] [scratch niveau 2] oiseaux volants en décembre 2019
52歲的周鴻禕,還年輕嗎?
Is Zhou Hongyi, 52, still young?
Fully automated processing of monthly card shortage data and output of card shortage personnel information
Preliminary test of optical flow sensor: gl9306
C language 001: download, install, create the first C project and execute the first C language program of CodeBlocks
Opengl3.3 mouse picking up objects
Go learning notes (2) basic types and statements (1)
爬虫实战(八):爬表情包
腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
随机推荐
单机高并发模型设计
About the difference between ch32 library function and STM32 library function
Two small problems in creating user registration interface
Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
paddle入门-使用LeNet在MNIST实现图像分类方法二
某马旅游网站开发(对servlet的优化)
Operating system principle --- summary of interview knowledge points
paddle入门-使用LeNet在MNIST实现图像分类方法一
Opengl3.3 mouse picking up objects
Robomaster visual tutorial (1) camera
Fully automated processing of monthly card shortage data and output of card shortage personnel information
Tools for debugging makefiles - tool for debugging makefiles
Basic learning of SQL Server -- creating databases and tables with the mouse
面试题详解:用Redis实现分布式锁的血泪史
One click installation with fishros in blue bridge ROS
Go time package common functions
玩转Sonar
CoinDesk评波场去中心化进程:让人们看到互联网的未来
The result of innovation in professional courses such as robotics (Automation)
limit 与offset的用法(转载)