STC的89C52做的循迹小车L298N的电机驱动急求一个C语言的驱动程序做循迹小车的有三个黑白关电 95
正在做一个循迹小车有三个循迹光电电机驱动是L298N的芯片是STC的89C52请各位大侠帮帮忙写一个C程序给我验证可用给分我的光电是直接输出0和1的程序要完整的不要还得改...
正在做一个循迹小车有三个循迹光电电机驱动是L298N的芯片是STC的89C52请各位大侠帮帮忙写一个C程序给我验证可用给分
我的光电是直接输出0和1的程序要完整的不要还得改的如果有也可以发到我的邮箱,280675142@qq.com 展开
我的光电是直接输出0和1的程序要完整的不要还得改的如果有也可以发到我的邮箱,280675142@qq.com 展开
展开全部
#include<reg51.h>
#define sen_port P1
sbit SEN1=P1^0;
sbit SEN2=P1^1;
sbit EN1=P2^2;
sbit IN1=P2^3;
sbit IN2=P2^4;
sbit EN2=P2^5;
sbit IN3=P2^6;
sbit IN4=P2^7;
void delay(int n) //延时子程序
{
unsigned char i,j,k;
for(i=n;i>0;i--)
for(j=100;j>0;j--)
for(k=200;k>0;k--);
}
unsigned char sensor_inp()
{
unsigned char sensor;
sensor = sen_port;
sensor &= 0x03;
P0 = sensor;
return sensor;
}
void forward() //two motos are runing forward
{
IN1=1;
IN2=0;
IN3=1;
IN4=0;
EN1=1;
EN2=1;
}
void backward() //two motos are runing backward
{
IN1=0;
IN2=1;
IN3=0;
IN4=1;
EN1=1;
EN2=1;
}
void turn_left() //left moto is runing, but right moto is brake
{
IN1=1;
IN2=0;
IN3=0;
IN4=0;
EN1=1;
EN2=1;
}
void rotate_left() //right moto is runing forward, and left moto is running backward
{
IN1=1;
IN2=0;
IN3=0;
IN4=1;
EN1=1;
EN2=1;
}
void turn_right() //right moto is runing, but left moto is brake
{
IN1=0;
IN2=0;
IN3=1;
IN4=0;
EN1=1;
EN2=1;
}
void rotate_right() //left moto is running forward, and right moto is running backward
{
IN1=0;
IN2=1;
IN3=1;
IN4=0;
EN1=1;
EN2=1;
}
void free() //two motos is free
{
IN1=0;
IN2=0;
IN3=0;
IN4=0;
EN1=0;
EN2=0;
}
void stop() //two motos stop
{
IN1=1;
IN2=1;
IN3=1;
IN4=1;
EN1=1;
EN2=1;
}
void main(void)
{
delay(10);
P0=0x55;
while(1)
{
// P0=P1;
// delay(100); forward();
// delay(100); stop();
delay(100); backward();
delay(100); stop();
delay(100); turn_left();
delay(100); stop();
delay(100); turn_right();
delay(100); stop();
delay(100); rotate_left();
delay(100); stop();
delay(100); rotate_right();
delay(100); stop();
delay(100); stop();
delay(20); forward();
delay(20); backward();
delay(20);
/*
*/
}
}
这个是没有加传感器的,你试着加上传感器改一下,有问题可以发邮件 815735856@qq.com...
#define sen_port P1
sbit SEN1=P1^0;
sbit SEN2=P1^1;
sbit EN1=P2^2;
sbit IN1=P2^3;
sbit IN2=P2^4;
sbit EN2=P2^5;
sbit IN3=P2^6;
sbit IN4=P2^7;
void delay(int n) //延时子程序
{
unsigned char i,j,k;
for(i=n;i>0;i--)
for(j=100;j>0;j--)
for(k=200;k>0;k--);
}
unsigned char sensor_inp()
{
unsigned char sensor;
sensor = sen_port;
sensor &= 0x03;
P0 = sensor;
return sensor;
}
void forward() //two motos are runing forward
{
IN1=1;
IN2=0;
IN3=1;
IN4=0;
EN1=1;
EN2=1;
}
void backward() //two motos are runing backward
{
IN1=0;
IN2=1;
IN3=0;
IN4=1;
EN1=1;
EN2=1;
}
void turn_left() //left moto is runing, but right moto is brake
{
IN1=1;
IN2=0;
IN3=0;
IN4=0;
EN1=1;
EN2=1;
}
void rotate_left() //right moto is runing forward, and left moto is running backward
{
IN1=1;
IN2=0;
IN3=0;
IN4=1;
EN1=1;
EN2=1;
}
void turn_right() //right moto is runing, but left moto is brake
{
IN1=0;
IN2=0;
IN3=1;
IN4=0;
EN1=1;
EN2=1;
}
void rotate_right() //left moto is running forward, and right moto is running backward
{
IN1=0;
IN2=1;
IN3=1;
IN4=0;
EN1=1;
EN2=1;
}
void free() //two motos is free
{
IN1=0;
IN2=0;
IN3=0;
IN4=0;
EN1=0;
EN2=0;
}
void stop() //two motos stop
{
IN1=1;
IN2=1;
IN3=1;
IN4=1;
EN1=1;
EN2=1;
}
void main(void)
{
delay(10);
P0=0x55;
while(1)
{
// P0=P1;
// delay(100); forward();
// delay(100); stop();
delay(100); backward();
delay(100); stop();
delay(100); turn_left();
delay(100); stop();
delay(100); turn_right();
delay(100); stop();
delay(100); rotate_left();
delay(100); stop();
delay(100); rotate_right();
delay(100); stop();
delay(100); stop();
delay(20); forward();
delay(20); backward();
delay(20);
/*
*/
}
}
这个是没有加传感器的,你试着加上传感器改一下,有问题可以发邮件 815735856@qq.com...
德晟智能
2024-09-04 广告
2024-09-04 广告
舵机伺服电机是一种在自动控制系统中广泛应用的执行元件。它具有快速响应、精准定位的特点,能够将电压信号转化为转矩和转速,以驱动控制对象。在东莞市德晟智能科技有限公司的产品中,舵机伺服电机扮演着重要的角色,广泛应用于各种精密电子设备、交通运输工...
点击进入详情页
本回答由德晟智能提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询