51单片机蓝牙遥控小车只能一顿一顿的走,原地抽搐,是不是电压不够的原因啊,还是代码的问题呢,我用的是4节南孚驱动两个直流减速电机,电池盒接l298n接电机的。蓝牙模块我用的HC-06,蓝牙模块接单片机开发板是可以正常操控的。
下面是我的代码:
#include <REGX52.H>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit LF=P0^0;//??
sbit LB=P0^1;//??
sbit RF=P0^2;//??
sbit RB=P0^3;//??
void forward()
{
LF=0;
LB=1;
RF=0;
RB=1;
}
void back()
{
LF=1;
LB=0;
RF=1;
RB=0;
}
void left()
{
LF=0;
LB=0;
RF=0;
RB=1;
}
void right()
{
LF=0;
LB=1;
RF=0;
RB=0;
}
void Delay1ms() //@11.0592MHz
{
unsigned char i, j;
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
void Uart_Init(void) //9600bps@11.0592MHz
{
PCON &= 0x7F; //??????
SCON = 0x50; //8???,????? AUXR &= 0xBF; //?????12T?? AUXR &= 0xFE; //??1?????1???????
TMOD &= 0x0F; //???????
TMOD |= 0x20; //???????
TL1 = 0xFD; //???????
TH1 = 0xFD; //???????
ET1 = 0; //?????%d??
TR1 = 1; //???1????
EA=1;
ES=1;
}
int main()
{
Uart_Init();
while(1);
}
void Com_Int(void) interrupt 4
{
uchar receive_data;
EA = 0;
if(RI == 1)
{
RI = 0;
LF=0;
RF=0;
LB=0;
RB=0;
receive_data = SBUF;
Delay1ms();
if(receive_data == '1')
{
forward();
}
else if(receive_data == '2')
{
back();
}
else if(receive_data == '3')
{
left();
}
else if(receive_data == '4')
{
right();
}
else if(receive_data == '0')
{
LF=0;
RF=0;
LB=0;
RB=0;
}
}
EA = 1;
}
顺便问下out1,out2,out3,out4接电机的正负极有没有固定的顺序,是不是也有可能是这方面的问题
感激万分