久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

專注電子技術學習與研究
當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

智能尋跡小車制作 程序+視頻

作者:香蓮清風   來源:香蓮清風   點擊數:  更新時間:2014年06月25日   【字體:

剛學單片機的時候做的一個智能小車,現在把當時的一些資料整理了一下,希望對剛入門的童鞋有幫助!

1、下圖為單片機的最小系統,可以自己用萬用板焊接,順便練練焊接能力也不錯的。本設計采用了51單片機,網上關于51單片機的資料有一大堆,大伙可以從它來入門,推薦郭天祥的視頻(我就是跟著他學的),講的挺詳細的。

       2、這一部分來介紹下驅動電路,如下圖所示為驅動電路的原理圖,采用的是L298驅動芯片,一般的智能小車這個芯片用的比較多,控制起來也比較簡單:芯片兩個使能端輸入高電平(有效電平),再給其余的兩個引腳(比如P1+,P1-)輸入一高一低就能讓電機正反轉從而控制小車的前進后退,當然也可以在EN端輸入PWM信號來控制小車的速度,PWM信號可以由芯片的相應引腳輸出,51單片機不能直接輸出PWM信號,可以用定時器來實現也很方便的。

       3、下面來介紹下循跡傳感器。循跡模塊用的是紅外對管,正常情況下發射端發出的光線可以被接收端接收到接收端導通輸出低電平,而當遇到黑線后,黑線吸收了發射端發射的光線,輸出高電平;輸出的高低電平經過電壓比較器比較輸出后來判斷小車的哪個傳感器在黑線之上,得到小車的位置信息(看起來很簡單大家要動手做才有意思)。


4、下面我把源代碼貼出來,感興趣的童鞋可以看看希望有豪幫助!
  • 以下是“CarDrive.c”文件中的源程序:
#include "CarDrive.h"
 
//左電機正轉 
void LeftMotorCorotation(void)
{
LeftMotor_1 = 1;
LeftMotor_2 = 0;
}
 
//左電機反轉 
void LeftMotorRollback(void)
{
LeftMotor_1 = 0;
LeftMotor_2 = 1;
}
 
//右電機正轉 
void RightMotorCorotation(void)
{
RightMotor_1 = 1;
RightMotor_2 = 0;
}
 
//右電機反轉 
void RightMotorRollback(void)
{
RightMotor_1 = 0;
RightMotor_2 = 1;
}
 
//小車前進 
void CarGoAhead(void)
{
LeftMotorCorotation();
RightMotorRollback();
}
 
 
//小車慢速左拐 
void CarTurnLeft_Low(void)
{
LeftMotor_1 = 0;
LeftMotor_2 = 0;
RightMotorRollback();
}
 
//小車慢速右拐
void CarTurnRight_Low(void)
{
RightMotor_1 = 0;
RightMotor_2 = 0;
LeftMotorCorotation();
 
//小車快速左拐 
void CarTurnLeft_High(void)
{
LeftMotorRollback();
RightMotorRollback();
}
 
//小車快速右拐
void CarTurnRight_High(void)
{
LeftMotorCorotation();
RightMotorCorotation();
 
 
//小車道路判斷 
void CarRoadJudge(void)
{
if(LeftPhotoelectricCell_1&&(!LeftPhotoelectricCell_2)&&(!RightPhotoelectricCell_2)&&RightPhotoelectricCell_1)
CarGoAhead();
if(LeftPhotoelectricCell_1&&(!LeftPhotoelectricCell_2)&&RightPhotoelectricCell_2&&RightPhotoelectricCell_1)
CarGoAhead();
if(LeftPhotoelectricCell_1&&LeftPhotoelectricCell_2&&(!RightPhotoelectricCell_2)&&RightPhotoelectricCell_1)
CarGoAhead();
if((!LeftPhotoelectricCell_1)&&(!LeftPhotoelectricCell_2)&&RightPhotoelectricCell_2&&RightPhotoelectricCell_1)
CarTurnLeft_Low();
if(LeftPhotoelectricCell_1&&LeftPhotoelectricCell_2&&(!RightPhotoelectricCell_2)&&(!RightPhotoelectricCell_1))
CarTurnRight_Low();
if((!LeftPhotoelectricCell_1)&&LeftPhotoelectricCell_2&&RightPhotoelectricCell_2&&RightPhotoelectricCell_1)
CarTurnLeft_High();
if(LeftPhotoelectricCell_1&&LeftPhotoelectricCell_2&&RightPhotoelectricCell_2&&(!RightPhotoelectricCell_1))
CarTurnRight_High();
if(LeftPhotoelectricCell_1&&LeftPhotoelectricCell_2&&RightPhotoelectricCell_2&&RightPhotoelectricCell_1)
//CarTurnRight_Low();
CarGoAhead();
if((!LeftPhotoelectricCell_1)&&(!LeftPhotoelectricCell_2)&&(!RightPhotoelectricCell_2)&&(!RightPhotoelectricCell_1)) 
CarGoAhead();
}
 
 
  • 以下是“CarDrive.h”文件中的源程序:
#ifndef _CarDrive_H_
#define _CarDrive_H_
 
#include
#define uint unsigned int
#define uchar unsigned char
 
sbit LeftMotor_1 = P0^0;
sbit LeftMotor_2 = P0^1;
sbit RightMotor_1 = P0^2;
sbit RightMotor_2 = P0^3;
 
sbit LeftPhotoelectricCell_1   = P3^0;
sbit LeftPhotoelectricCell_2   = P3^1;
sbit RightPhotoelectricCell_2  = P3^2;
sbit RightPhotoelectricCell_1  = P3^3;
 
void CarGoAhead(void);
//void CarBackOff(void);
void CarTurnLeft_Low(void);
void CarTurnRight_Low(void); 
void CarTurnLeft_High(void);
void CarTurnRight_High(void);
//void CarBrake(void);
void CarRoadJudge(void);
 
 
 
#endif
 
 
  • 以下是“main.h”中的程序:
#ifndef _main_H_
#define _main_H_
 
#include
#include "CarDrive.h"
 
#define uint unsigned int
#define uchar unsigned char
 
#endif
 
  • 以下是“main.c”中的程序:
#include "main.h"
 
void main(void)
{
while(1)
{
CarRoadJudge();
}
}
5、下面是小車的視頻
總結:好了,電路圖、程序源碼、視頻都在這了,大家多動手才是,最后感謝童鞋們花費寶貴的時間來瀏覽我的博客,我是“香蓮清風”咱們下次見!
關閉窗口

相關文章

主站蜘蛛池模板: 亚洲av毛片成人精品 | 亚洲91视频| 人人射人人插 | 91在线观看网址 | 国产精品日韩在线观看 | 国产免费观看一级国产 | 欧美国产激情二区三区 | 国产欧美精品区一区二区三区 | 日韩av高清在线 | 欧美色性| 一区二区三区福利视频 | 一区二区三区免费 | xx性欧美肥妇精品久久久久久 | 久久亚洲一区二区 | 成人日韩av | 黄网站涩免费蜜桃网站 | 久久久精彩视频 | 91免费入口| 亚洲电影一区二区三区 | 男女免费在线观看视频 | 丁香综合 | 福利电影在线 | 日本三级网站在线观看 | 欧美日韩成人一区二区 | 中文字幕在线一区 | 亚洲系列第一页 | 成年女人免费v片 | 看片国产 | 久久久资源 | 国产成人免费视频网站视频社区 | 国产成人精品a视频一区www | 国产精品一区二区三区在线播放 | 成人深夜福利网站 | 蜜桃av人人夜夜澡人人爽 | 91色综合| 北条麻妃av一区二区三区 | 羞羞的视频免费看 | 久久久久国产精品人 | 欧美精品久久久久久久久久 | 免费久久网 | 97人澡人人添人人爽欧美 |