標(biāo)題:
“T”字路口循跡程序 51單片機(jī)尋跡小車
[打印本頁(yè)]
作者:
51hei小胡
時(shí)間:
2017-4-3 22:57
標(biāo)題:
“T”字路口循跡程序 51單片機(jī)尋跡小車
分享幾個(gè)調(diào)試通過(guò)的51單片機(jī)尋跡小車代碼
源程序:
/*NewWay 循跡模塊專用程序*/
/*簡(jiǎn)單循跡程序,此程序能讓小車尋到T字路后停下*/
/*你可以任意使用、修改該程序,如果你要把該程序用于商業(yè),請(qǐng)與我聯(lián)系,不然一切后果自己承擔(dān)*/
/*作者:劉偉*/
/*當(dāng)你看到這個(gè)程序的時(shí)候,請(qǐng)注意,這個(gè)程序是不能直接使用的,你要自己實(shí)現(xiàn)小車的向前,向后,向左,向右,及其延時(shí)的子程序*/
#include <REGX52.H>
void CarGo();
void CarBack();
void CarTurnLeft();
void CarTurnRight();
void Delayms(unsigned char n);
void CarStop();
/*定義循跡傳感器管腳*/
sbit CLP=P1^0;
sbit SS1=P1^1;
sbit SS2=P1^2;
sbit SS3=P1^3;
sbit SS4=P1^4;
sbit SS5=P1^5;
sbit Near=P1^6;
void CarGoLine() //小車沿黑線走
{
if(SS2==0)
{
CarTurnLeft();
}
else
{
if(SS4==0)
{
CarTurnRight();
}
else
{
CarGo();
}
}
}
void main()
{
unsigned char flag;
flag=0;
while(flag==0)
{
CarGoLine();
if((SS1==0)&&(SS5==0))
{
CarGo();
Delayms(200);// 判斷不是 “十” 字形接口 具體延時(shí)時(shí)間看小車的速度和性能
if(SS3==1) flag=1;
}
}
CarStop();
}
復(fù)制代碼
完整源碼和資料下載:
http://www.torrancerestoration.com/bbs/dpj-80504-1.html
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1