C51单片机应用与C语言程序设计(第4版)——基于机器人工程对象的项目实践 习题及答案 第5讲.docx

C51单片机应用与C语言程序设计(第4版)——基于机器人工程对象的项目实践 习题及答案 第5讲.docx

  1. 1、本文档共7页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多

第5讲

一、画图题

1.我们将搭建并测试红外发射和检测器对,需要用到的新元件如图5-2所示。

元件清单有:

(1)红外检测器,2个。

(2)红外LED(带套筒),2个。

(3)470Q2电阻,2个。

(4)连接线,若干。

下面画出左、右IR组电路图。

二、编程题

编程检测边沿。

1.打开程序FastIrRoaming.c并将其另存为AvoidTableEdge.c;

2.修改程序,使其与下面的例程一致;

3.打开教学板与伺服电机的电源;

4.在带绝缘带边框的场地上测试程序。

#includeBoeBot.h

#includeuart.h

#includeintrins.h

#defineLeftIRP1_2//左边红外接收连接到P1_2

#defineRightlRP1_2//右边红外接收连接到P3_5

#defineLeftLaunchP1_3//左边红外发射连接到P1_3

#defineRightLaunchP3_6//右边红外发射连接到P3_6

voidIRLaunch(unsignedcharIR)

{

intcounter;

if(IR=‘L)//左边发射

for(counter=0;counter38;counter++)

{

LeftLaunch=1;

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

LeftLaunch=0;

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

}

if(IR=R)//右边发射

for(counter=0;counter38;counter++)

{

RightLaunch=1;

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

LeftLaunch=0;

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

}

}

intmain(void)

{

inti,pulseCount;

intpulseLeft,pulseRight;

intirDetectLeft,irDetectRight;

uairt_Init();

printf(ProgramRunning!\n);

do

{

IRLaunch(R);//右边发射

irDetectRight=RightIR;//右边接收

IRLaunch(L);//左边发射

irDetectLeft=LeftIR;//左边接收

if((irDetectLeft=0)(irDetectRight=0))//向前走

{

pulseCount=1;

pulseLef=1700;

pulseRight=1300;

}

elseif((irDetectLeft=1)(irDetectRight=0))//右转

{

pulseCount=10;

pulseLeft=1300;

pulseRight=1300;

}

elseif((irDetectLeft=0)(irDetectRight=1))//左转

{

pulseCount=10;

pulseLeft=1700;

pulseRight=1700;

else//后退

{

pulseCount=15;

pulseLeft=1300;

pulseRight=1700;

}

for(i=0;ipulseCount;i++);

{

P1_1=1;

delaynus(pulseLeft);

P1_1=0;

P1_0=1;

delay_nus(pulseRight);

P1_0=0;

De

您可能关注的文档

文档评论(0)

lai + 关注
实名认证
内容提供者

精品资料

版权声明书
用户编号:7040145050000060

1亿VIP精品文档

相关文档