找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3417|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

簡單循跡小車程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:159566 發(fā)表于 2017-1-3 12:50 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
新手上路,很多不足的地方請大神指點(diǎn)。
#include<AT89x51.H>

       

        sbit In8=P1^0;                 
        sbit In7=P1^1;                  
        sbit In6=P1^2;                 
        sbit In5=P1^3;   
        sbit In4=P1^4;
        sbit In3=P1^5;
        sbit In2=P1^6;
        sbit In1=P1^7;            


        sbit out1=P3^4;   
        sbit out2=P3^5;                    
        sbit out3=P3^6;     
        sbit out4=P3^7;   

        int q1,q,q2;
void dianji(int z)
{

if(z == 0)
{
    out1=1;
    out2=0;
    out3=1;
    out4=0;


}
if(z == 4)
{
q1 = 5;                 //轉(zhuǎn)向系數(shù)   轉(zhuǎn)彎的角度
while(q1--)
{
  out1=1;
  out2=0;
  out3=0;
  out4=0;
  }
           }
  if(z == 5)

{

     q1 = 5;                 //轉(zhuǎn)向系數(shù)

while(q1--)
{
  out1=0;
  out2=0;
  out3=1;
  out4=0;
  }
}


if(z == 3 )
{
q1 = 15;                 //轉(zhuǎn)向系數(shù)

while(q1--)
{
  out1=1;
  out2=0;
  out3=0;
  out4=0;
  }
}
if(z == 6)
{
q1 = 15;                        //轉(zhuǎn)向系數(shù)
while(q1--)
{
  out1=0;
  out2=0;
  out3=1;
  out4=0;
  }
}
if(z == 2)
{
q1 = 25;                   //轉(zhuǎn)向系數(shù)
while(q1--)
{
  out1=1;
  out2=0;
  out3=0;
  out4=0;
  }
}
  if(z == 7)
{
q1 = 25;                   //轉(zhuǎn)向系數(shù)
while(q1--)
{
  out1=0;
  out2=0;
  out3=1;
  out4=0;
  }
}
if(z == 1)
{
q1 = 1;                //死循環(huán)
while(q1)
{
  out1=1;
  out2=0;
  out3=0;
  out4=0;
  if(In2 == 1||In3 == 1||In4 == 1||In5 == 1||In6 == 1||In7 == 1)         q1 = 0;
  }
}
if(z == 8)
{
q1 = 1;         //死循環(huán)
while(q1)
{
  out1=0;
  out2=0;
  out3=1;
  out4=0;
if(In2 == 1||In3 == 1||In4 == 1||In5 == 1||In6 == 1||In7 == 1)        q1 = 0;
  }

}


}


void main()
{


while(1)
{

q2 = 1;  //可調(diào)速 與下方q2比值為速度  1:0為全速


while(q2--)
{
q=0;
if(In1 == 1)  q = 1;
if(In2 == 1)  q = 2;
if(In3 == 1)  q = 3;
if(In4 == 1)  q = 4;
if(In5 == 1)  q = 5;
if(In6 == 1)  q = 6;
if(In7 == 1)  q = 7;
if(In8 == 1)  q = 8;

dianji(q);
}


q2 = 0;   //可調(diào)速


while(q2--)
{
out1=0;
    out2=0;
    out3=0;
    out4=0;
}



}          }


  

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:159566 發(fā)表于 2017-1-3 12:50 | 只看該作者
一樓自古為樓主。
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表