【求助】蓝牙小车接收程序有问题

2019-07-15 11:25发布

手机向51单片机传数据小车无反应。以下是接收程序
#include<reg52.h>
#include<math.h>
#define uchar unsigned char
#define uint unsigned int
uint i,j;
sbit Left_Positive=P1^4;
sbit Left_Negative=P1^5;
sbit Right_Positive=P1^6;
sbit Right_Negative=P1^7;
uchar buff;
/********************************************************************
* 名称 : Delay_1ms()
* 功能 : 延时子程序,延时时间为 1ms * x
* 输入 : x (延时一毫秒的个数)
* 输出 : 无
***********************************************************************/
void Delay_1ms(uint i)//1ms延时
{
uchar x,j;
for(j=0;j<i;j++)
for(x=0;x<=148;x++);
}
/********************************************************************
* 名称 : Com_Int()
* 功能 : 串口中断子函数
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Com_Int(void) interrupt 4
{
EA = 0;
if(RI == 1) //当硬件接收到一个数据时,RI会置位
  {
  RI = 0;
    buff=SBUF;
  
  }
EA = 1;
}
/********************************************************************
* 名称 : Com_Init()
* 功能 : 串口初始化,晶振11.0592,波特率9600,使串口中断
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Com_Init(void)
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFd; //设置波特率 9600
TL1 = 0xFd;
TR1 = 1; //启动定时器1
ES = 1; //开串口中断
EA = 1; //开总中断
}
/********************************************************************
* 名称 :qianjin()
* 功能 : 电机1、2启动,都是前进,整车表现为前进。
* 输入 : 无
* 输出 : 无                                                                        问题
***********************************************************************/
void qianjin()
{
Right_Negative=0;
Left_Positive=0;
Left_Negative=1;
Right_Positive=1;
}
/********************************************************************
* 名称 :houtui()
* 功能 : 电机1、2启动,都是后退,整车表现为后退。
* 输入 : 无
* 输出 : 无
***********************************************************************/
void houtui()
{
Left_Positive=0;
Right_Positive=0;
Right_Negative=1;
Left_Negative=1;
}
/********************************************************************
* 名称 :zuozhuan()
* 功能 : 电机1后退,电机2前进,整车表现为左转。
* 输入 : 无
* 输出 : 无
***********************************************************************/
void zuozhuan()
{
Left_Negative=0;
Right_Positive=0;
Right_Negative=1;
Left_Positive=1;
}
/********************************************************************
* 名称 :youzhuan()
* 功能 : 电机1前进,电机2后退,整车表现为右转。
* 输入 : 无
* 输出 : 无
***********************************************************************/
void youzhuan()
{
Right_Negative=0;
Left_Negative=0;
Left_Positive=1;
Right_Positive=1;
}
/********************************************************************
* 名称 :tingche()
* 功能 : 电机1停止,电机2停止,整车表现为停止。
* 输入 : 无
* 输出 : 无
***********************************************************************/
void tingche()
{
Right_Negative=0;
Left_Negative=0;
Left_Positive=0;
Right_Positive=0;
}
void main()
{
Delay_1ms(100);
Com_Init();//串口初始化
            
while(1)//循环结构,选择函数控制小车的状态
{   
  switch(buff)
  {
   case 'E': tingche(); break;
   case 'W': qianjin(); break;
   case 'S': houtui(); break;
   case 'A': zuozhuan(); break;
   case 'D': youzhuan(); break;
   default:break;
  }
}
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。