目录
一、PWM方式实现小车转向
原理:左轮定时器0调速,右轮定时器1调速,那么左转就是右轮速度大于左轮
二、代码实现
main.c
#include "motor.h"
#include "delay.h"
#include "uart.h"
#include "time.h"
extern char speedLeft; //此变量/函数是在别处定义的,要在此处引用
extern char speedRight;
void main()
{
Time0Init(); //定时器0初始化
Time1Init(); //定时器1初始化
UartInit(); //串口初始化
while(1){
speedLeft = 10; //10份单位时间全速运行,30份停止,所以慢,20ms是40份的500us
speedRight = 40;
Delay1000ms();
Delay1000ms();
speedLeft = 40;
speedRight = 10;
Delay1000ms();
Delay1000ms();
}
}
motor.c
#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;
void goForWardLeft(){

本文介绍了使用PWM技术来控制智能小车转向的原理和代码实现。通过调整左轮和右轮的定时器(定时器0和定时器1)速度,实现小车左转和右转。主要涉及文件包括main.c、motor.c、motor.h、delay.c、delay.h、uart.c(串口初始化)、uart.h以及time.c和time.h(用于初始化和开启定时器中断)。
最低0.47元/天 解锁文章
1505

被折叠的 条评论
为什么被折叠?



