标题: 这个单片机程序出什么问题了?蓝牙的,运行不了啊.用的SPP [打印本页]

作者: 孤山半月    时间: 2018-10-1 11:11
标题: 这个单片机程序出什么问题了?蓝牙的,运行不了啊.用的SPP
//手机APP蓝牙遥控控制单片机LED灯的亮灭开关单片机源代码:

#include<reg52.h>
#include <stdio.h>
unsigned char Rx_buf[4],Rxnum=0;
sbit LED1=P1^0;
sbit LED2=P1^1;

void InitUART(void)                //这是串口的基本配置,配置他的波特率是9600.这些参数都是标准的。
{
    TMOD = 0x20;
    SCON = 0x50;
    TH1 = 0xFD;
    TL1 = TH1;
    PCON = 0x00;
    EA = 1;
    ES = 1;
    TR1 = 1;
}

void Delay_ms(unsigned int n)//n 毫秒延时
{
unsigned char j;
        while(n--)
        {
                for(j=0;j<125;j++);
        }
}

void main()
{
  unsigned char   Tx_Buf[10];
  unsigned char LEDstatus;//灯的状态
         InitUART();                        //初始化串口
        while(1)        
        {
                ;
        }
}

/*****************串口接收中断函数,接收蓝牙模块的数据*********************/
void UARTInterrupt(void) interrupt 4
{        
        ES=0;        //关闭中断
    if(RI)          //接收到数据
    {
                Rx_buf[Rxnum]=SBUF;  //接收数据进数组
                if(Rx_buf[Rxnum]==0x08)
                Rxnum=0;
                else
                Rxnum++;
                if(Rx_buf[0]==0x01)//LED1灯
                {
                        if(Rx_buf[1]==0x01)//开灯
                        LED1=0;//开灯
                        else
                        LED1=1;        //关灯        
                }
                if(Rx_buf[0]==0x02)//LED2灯
                {
                        if(Rx_buf[1]==0x01)//开灯
                        LED2=0;//开灯
                        else
                        LED2=1;        //关灯        
                }


        }
    RI=0;
           ES=1;          //关闭中断
}

作者: cccc888    时间: 2018-10-1 11:11
下位机程序不健壮。




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1