[2.4G无线应用]

蓝牙接收不到

[复制链接]
925|7
手机看帖
扫描二维码
随时随地手机跟帖
boy1990|  楼主 | 2016-5-24 22:28 | 显示全部楼层 |阅读模式
用手机通过蓝牙和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;        
}
boy1990|  楼主 | 2016-5-24 22:28 | 显示全部楼层
/******************************************************************************
*函数名称: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;                                        //发送后数据清零
                }
        }
}
求指教。。

使用特权

评论回复
sourceInsight| | 2016-5-24 22:35 | 显示全部楼层
这个不知道是用于干什么的。

使用特权

评论回复
wanglaojii| | 2016-5-24 22:45 | 显示全部楼层
定时器1工作于方式2,8位自动重载模式, 用于产生波特率

使用特权

评论回复
laozhongyi| | 2016-5-24 23:13 | 显示全部楼层
10位UART(1位起始位,8位数据位,1位停止位,无奇偶校验),波特率可变 这种方式不错啊

使用特权

评论回复
Edisons| | 2016-5-24 23:17 | 显示全部楼层
发送一个字节
void SendByte(unsigned char dat)
{
SBUF = dat;
while(!TI);
      TI = 0;

使用特权

评论回复
Mozarts| | 2016-5-24 23:23 | 显示全部楼层
手机查询函数具体是干什么用的,这个没有什么问题吗

使用特权

评论回复
Listate| | 2016-5-24 23:30 | 显示全部楼层
手机查询的返回值为啥是为空呢?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

81

主题

1769

帖子

2

粉丝