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...
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询