亲测有效
需要的材料
1.蓝牙串口软件
应用商店可以下载
![蓝牙串口软件](https://i-blog.csdnimg.cn/blog_migrate/dad4c7952c48c2d2aae0415178d7ecbf.jpeg#pic_center)
2.L298N电机驱动模块
淘宝可以买得到
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e321885073afff9c8af3177ebae435e0.jpeg)
3.stc89c52最小系统板
淘宝可以买得到
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2e242f8ff178b8d2b23fe6047332e0d1.jpeg)
4.智能车底盘
淘宝可以买得到
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bebacead91fb6bba4fd4d27e7ea956ea.jpeg)
蓝牙模块:JDY-31
淘宝购买
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9e896cd7ad46ea42a43be34b8371ca14.jpeg#pic_center)
接线资料在买模块的时候会有(自己去实践)
测试代码
#include <reg52.h>
sbit INT=P1^0;
sbit INT2=P1^1;
sbit INT3=P1^2;
sbit INT4=P1^3;
sbit EN1 = P1^4;
sbit EN2 = P1^5;
typedef unsigned int u16;
typedef unsigned char u8;
u8 buf;
u8 speed=100;
u8 pwm;
void CarGo()
{
speed = 50;
INT= 1;
INT2=0;
INT3=1;
INT4=0;
}
void CarBack()
{
speed = 40;
INT= 0;
INT2=1;
INT3=0;
INT4=1;
}
void CarTurnLeft()
{
speed = 35;
INT=0;
INT2=0;
INT3=1;
INT4=0;
}
void CarTurnRight()
{
speed = 35;
INT= 1;
INT2=0;
INT3=0;
INT4=0;
}
void CarStop()
{
INT= 0;
INT2=0;
INT3=0;
INT4=0;
speed = 0;
}
void speedup()
{
INT= 1;
INT2=0;
INT3=1;
INT4=0;
speed+=4;
if(speed>=100)
{
speed = 100;
}
}
void speeddown()
{
INT= 1;
INT2=0;
INT3=1;
INT4=0;
speed-=5;
if(speed<=18)
{
speed = 18;
}
}
void timer ()
{
TMOD|=0X01;
TH0 = (65536-1500)/256;
TL0 = (65536-1500)%256;
TR0 = 1;
ET0 = 1;
EA =1;
}
void init() interrupt 1
{
TH0 = (65536-100)/256;
TL0 = (65536-100)%256;
pwm++;
if(pwm==100)
{pwm = 0;}
if(pwm<=speed)
{
EN1 = 1;
EN2 = 1;
}
if(pwm>speed)
{
EN1 = 0;
EN2 = 0;
}
}
void irinit()
{
SCON=0x50;
PCON=0x00;
EA=1;
TMOD|=0x20;
ES=1;
TR1=1;
TH1=0xFD;
TL1=0xFD;
}
void main()
{
irinit();
timer ();
while(1);
}
void serial() interrupt 4
{
TL1=0xFD;
TH1=0xFD;
buf = SBUF;
while(!RI);
RI = 0;
if(buf=='G')
{
CarGo();
}
if(buf=='B')
{
CarBack();
}
if(buf=='S')
{
CarStop();
}
if(buf=='C')
{
CarTurnLeft();
}
if(buf=='E')
{
CarTurnRight();
}
if(buf=='1')
{
speedup();
}
if(buf=='2')
{
speeddown();
}
}
注意:蓝牙的指令得从串口软件进行设置