基于89C51单片机的智能小车——01.让小车前后左右动起来

基于89C51单片机的智能小车——01.让小车前后左右动起来,第1张

开发所需硬件 电机模块开发L9110s

接通VCC,GND 模块电源指示灯亮
IA1输入高电平,IA1输入低电平,【OA1 OB1】电机正转;
IA1输入低电平,IA1输入高电平,【OA1 OB1】电机反转;
IA2输入高电平,IA2输入低电平,【OA2 OB2】电机正转;
IA2输入低电平,IA2输入高电平,【OA2 OB2】电机反转;

小车底盘

硬件与51单片机的接线图

编程实现让小车前后左右动起来
//调试出小车前后左右控制
#include "reg52.h"
#include "intrins.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;
void Delay1000ms() //@11.0592MHz
{
	unsigned char i, j, k;
	_nop_();
	i = 8;
	j = 1;
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}
void goForward()
{
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}
void goRight()
{
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
}
void goLeft()
{
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}
void goBack()
{
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}
void main()
{
	while(1){
		goForward();
		Delay1000ms();
		Delay1000ms();
		goBack();
		Delay1000ms();
		Delay1000ms();
		goLeft();
		Delay1000ms();
		Delay1000ms();
		goRight();
		Delay1000ms();
		Delay1000ms();
	}
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/578208.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-11
下一篇 2022-04-11

发表评论

登录后才能评论

评论列表(0条)

保存