标题:
蓝牙接收问题
[打印本页]
作者:
狼牙小帅
时间:
2016-5-3 11:30
标题:
蓝牙接收问题
用手机通过蓝牙和12C5A60S2单片机进行通信,读取单片机采集的时间,但是经过测试单片机接收不到手机发的数据,单独的蓝牙程序是可以接收到的,这是拿的问题呢?下面是关于蓝牙的许程序
*/#include <reg51.h>
#include <intrins.h>
#include "bluetooth.h"
unsigned char tmp = 0;
void blueinit() //串口初始化
{
// ES=0; //关中断
// SCON = 0x50; // REN=1允许串行接受状态,串口工作模式1,
// //10位UART(1位起始位,8位数据位,1位停止位,无奇偶校验),波特率可变
//
// TMOD = 0x20; // 定时器1工作于方式2,8位自动重载模式, 用于产生波特率
// TH1=TL1=0xFD; // 波特率9600 (本次测试采用晶振为11.0592)
//
// PCON &= 0x7f; // 波特率不倍增
// TR1 = 1; //定时器1开始工作,产生波特率
// //发送标志位置0
// TI=0; //接收标志位置0
// RI=0;
//
// EA=1; //中断允许
// ES=1;
TMOD|=0X20; //定时器1作为波特率发生器,方式2自动重装载,9600(晶振11.0592)
TH1=0XFD;
TL1=0XFD;
TR1=1;
REN=1; //串口接收允许
SM0=0; //(SM0,SM1):0,1 方式1,十位数据通信起始位、八位数据、停止位,无奇偶校验位
SM1=1;
ES=1; //允许串口中断
EA=1; //中断允许 //允许串口中断
}
/*------------------------------------------------
发送一个字节
------------------------------------------------*/
void SendByte(unsigned char dat)
{
SBUF = dat;
while(!TI);
TI = 0;
}
/*------------------------------------------------
发送一个字符串
------------------------------------------------*/
void SendStr(unsigned char *s)
{
while(*s!='\0')// \0 表示字符串结束标志,
//通过检测是否字符串末尾
{
SendByte(*s);
s++;
}
}
void time1_interrupt() interrupt 4
{
RI=0;
tmp=SBUF;
}
复制代码
/******************************************************************************
*函数名称:void app_control()
*函数功能:手机查询函数
*输入参数:无
*输出参数:无
*返回值:无
*******************************************************************************/
void app_control()
{
if(tmp != 0x00)
{
if(tmp == 0x01)
{
SendStr("CO:");
SendByte(ppm / 1000+0x30);
SendByte(ppm % 1000 /100+0x30 );
SendByte(ppm % 1000 % 100 /10+0x30 );
SendByte(ppm % 10+0x30 );
write_charstr( 0,2," ");
tmp = 0x00; //发送后数据清零
}
if(tmp == 0x02)
{
SendStr("Time:");
SendByte(Year/10+0x30);
SendByte(Year%10+0x30);
SendByte(Month/10+0x30);
SendByte(Month%10+0x30);
SendByte(Day/10+0x30);
SendByte(Day%10+0x30);
SendByte(Hour/10+0x30);
SendByte(Hour%10+0x30);
SendByte(Minute/10+0x30);
SendByte(Minute%10+0x30);
tmp = 0x00; //发送后数据清零
}
if(tmp == 0x03)
{
SendStr("Alarm threshold :");
SendByte(Key_Num/100+0x30);
SendByte(Key_Num/100%10+0x30);
SendByte(Key_Num%10+0x30);
tmp = 0x00; //发送后数据清零
}
}
}
复制代码
请大神指导
作者:
zhanglele0111
时间:
2016-5-3 19:08
用于什么
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1