#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit left_motion=P1^2;
sbit right_motion=P1^3;
sbit a=P1^5;
sbit b=P1^7;
sbit c=P1^6;
sbit d=P1^4;
void delay_nus(unsigned int i) //延时:i>=12 ,i的最小延时单12 us
{
i=i/10;
while(--i);
}
void delay_nms(unsigned int n) //延时n ms
{
n=n+1;
while(--n)
delay_nus(900); //延时 1ms,同时进行补偿
}
void motor_motion(uint lefe_time,uint right_time) //time=1450为基准 正负350达到峰值
{
left_motion = 1;
delay_nus(lefe_time);
left_motion = 0;
right_motion=1;
delay_nus(right_time);
right_motion = 0;
delay_nms(20); //输出一定数量的PWM波形
}
void main()
{
while(1)
{
if(a==0)
motor_motion(1650,1300); // 前进
if(b==0)
motor_motion(1300,1700); // 后退
if(c==0)
motor_motion(1510,1510); //以车中心向右转
// if(d==0)
// motor_motion(1480,1480); //以车中心向左转
// if(a==0&&b==0)
// motor_motion(1480,1480); //停止
}
}
yaokongche.rar_l298_无线遥控车_遥控 车_遥控车
版权申诉
116 浏览量
2022-09-14
18:46:02
上传
评论
收藏 633B RAR 举报
朱moyimi
- 粉丝: 63
- 资源: 1万+