找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

智能小車循跡程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:91738 發(fā)表于 2015-10-6 18:24 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include<reg52.h>
sbit IN1 = P0^0;
sbit IN2 = P0^1;
sbit IN3 = P0^2;
sbit IN4 = P0^3;
sbit PWM1 = P0^5;
sbit PWM2 = P0^4;
sbit L1 = P3^5;
sbit G1 = P3^4;
sbit G2 = P3^3;
sbit R1 = P3^2;
unsigned char count1 = 0;
unsigned char count2 = 0;
void left1()//左前
{
  IN1 = 1;IN2 = 0;
}
void left2()//左退
{
IN1 = 0;IN2 = 1;
}
void right1()//右前
{
IN3 = 1;IN4 = 0;
}
void right2()//右退
{
IN3 = 0;IN4 = 1;
}
void sleep1(int c,int d)
{ if(c<=d)
PWM1 = 1;
else PWM1 = 0;
}
void sleep2(int c,int d)
{ if(c<=d)
PWM2 = 1;
else PWM2 = 0;
}
void str(int c1 ,int d1,int c2, int d2)
{
right1();
left1();
sleep1(c1,d1);
sleep2(c2,d2);
}
void left(int c1, int d1,int c2 ,int d2)
{
right1();
left2();
sleep1(c1,d1);
sleep2(c2,d2);
}
void right(int c1, int d1,int c2, int d2)
{
right2();
left1();
sleep1(c1,d1);
sleep2(c2,d2);
}
void main()
{
  TMOD = 0x11;
TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
EA = 1;
TR0 = 1;
ET0 = 1;
TH1 = (65536-1000)/256;
TL1 = (65536-1000)%256;
TR1 = 1;
ET1 = 1;
while(1)
{{ if(L1==0&&G1==0&&G2==0&&R1==0)
  str(count1, 500,count2 ,500);
  }
  { if(L1==0&&G1==0&&G2==0&&R1==1)
  left(count1, 200,count2 ,700);
  }
  { if(L1==0&&G1==1&&G2==1&&R1==0)
  str(count1 ,500,count2 ,500);
  }
  { if(L1==1&&G1==0&&G2==0&&R1==0)
  right(count1, 700,count2 ,200);
  }
}
}
void time0() interrupt 1
{ TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
count1++;
if(count1 >= 1000)
count1 = 0;
}
void time1() interrupt 1
{ TH1 = (65536-1000)/256;
TL1 = (65536-1000)%256;
count2++;
if(count2 >= 1000)
count2 = 0;
}

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的積分獎勵!

查看全部評分

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

使用道具 舉報

沙發(fā)
ID:1 發(fā)表于 2015-10-6 19:30 | 只看該作者
非常好,謝謝分享,樓主能提供一下,這個程序的硬件圖嗎
回復(fù)

使用道具 舉報

板凳
ID:104790 發(fā)表于 2016-2-16 10:37 來自觸屏版 | 只看該作者
好,學(xué)到東西了
回復(fù)

使用道具 舉報

地板
ID:142920 發(fā)表于 2016-10-16 11:23 | 只看該作者
使能端不需要嗎?ENA ENB???
回復(fù)

使用道具 舉報

5#
ID:142920 發(fā)表于 2016-10-16 11:24 | 只看該作者
使能端不要嗎? ENA  ENB??
回復(fù)

使用道具 舉報

6#
ID:157513 發(fā)表于 2016-12-25 16:48 | 只看該作者
大神能加點文字說明嗎?你那有兩個中斷舵機要一個請問另外那個是控制紅外線的嗎?

回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

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

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