欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

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

循跡小車程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:633408 發(fā)表于 2019-10-31 18:17 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit Motor_left_vcc=P1^2;  //控制左電機(jī)正極
sbit Motor_left_gnd=P1^3;  //控制左電機(jī)負(fù)極
sbit Motor_right_vcc=P1^1;  //控制右電機(jī)正極
sbit Motor_right_gnd=P1^0;  //控制右電機(jī)負(fù)極
sbit Left=P1^4;  //尋跡左  碰到黑線輸入低電平
sbit Right=P1^5;  //尋跡右          高電平1 低電平0
void delay(uint x)
{
        uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void Motor_Pwm_Go(uint x)  // 直走占空比 1/x+10
{
        Motor_left_vcc=0;
        Motor_left_gnd=1;
        Motor_right_vcc=0;
        Motor_right_gnd=1;
        delay(5);
        Motor_left_vcc=0;
        Motor_left_gnd=0;
        Motor_right_vcc=0;
        Motor_right_gnd=0;
        delay(x);
}
void Motor_Pwm_Left(uint x)  //左轉(zhuǎn)
{
        Motor_left_vcc=0;
        Motor_left_gnd=0;
        Motor_right_vcc=0;   //左轉(zhuǎn):右邊電機(jī)轉(zhuǎn),左邊電機(jī)不轉(zhuǎn)
        Motor_right_gnd=1;
        delay(5);
        Motor_left_vcc=0;
        Motor_left_gnd=0;
        Motor_right_vcc=0;
        Motor_right_gnd=0;
        delay(x);
}
void Motor_Pwm_Right(uint x)  //右轉(zhuǎn)
{
        Motor_left_vcc=0;
        Motor_left_gnd=1 ;
        Motor_right_vcc=0;
        Motor_right_gnd=0;
        delay(5);
        Motor_left_vcc=0;
        Motor_left_gnd=0;
        Motor_right_vcc=0;
        Motor_right_gnd=0;
        delay(x);
}
/*void Motor_Pwm_Stop()  //停
{
        Motor_left_vcc=0;
        Motor_left_gnd=0;
        Motor_right_vcc=0;
        Motor_right_gnd=0;
        }
void Motor_Pwm_Down(uint x)  //后退
{
        Motor_left_vcc=0;
        Motor_left_gnd=1;
        Motor_right_vcc=0;
        Motor_right_gnd=1;
        delay(6);
        Motor_left_vcc=0;
        Motor_left_gnd=0;
        Motor_right_vcc=0;
        Motor_right_gnd=0;
        delay(x);
}
*/
void main()
{
        if(Left==0)   //左邊碰到黑線,右邊不可能碰到黑線,所以不需要檢測(cè)右邊傳感器的值
{
        Motor_Pwm_Left(10);  //左轉(zhuǎn)
}
        if(Right==0)   //右邊碰到黑線,
{
        Motor_Pwm_Right(10);  //左轉(zhuǎn)
}
   if(Left==0&&Right==0)  //都沒碰到黑線,直走
{
        Motor_Pwm_Go(10)  ;
}


       
}

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

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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