资源描述
电子设计大赛设计报告 题目名称_智能搬运小车 _学生学院_物理与光电工程学院 _队员 庄伟林 林鉴杰 陈奕利 2009年 5月 1日装配图(正面)智能搬运小车设计报告一、 总体框架(1)、本搬动小车通过单片机AT89S52,用三个373分时输入外部信号,通过分析处理,再用一个573芯片输出步进电机驱动信号,成功地实现了取放黑铁,寻找右光源和左光源的功能。(2)、电路方框图。步进电机运转直流电机驱动取放铁片普通光敏电阻控测光源光敏对管PRP控测黑铁片输出声光信号(3)系统总框图。四相六线步进电机LM2003主控芯片AT89S52系统总框图二、硬件实现及单元电路设计。1、主控芯片AT89S52。AT89S52 主要性能; 与MCS-51单片机产品兼容 、8K字节在系统可编程Flash存储器、 1000次擦写周期、 全静态操作:0Hz33Hz 、 三级加密程序存储器 、 32个可编程I/O口线 、三个16位定时器/计数器 八个中断源 、全双工UART串行通道、 低功耗空闲和掉电模式 、掉电后中断可唤醒 、看门狗定时器 、双数据指针 、掉电标识符 。功能特性描述 At89s52 是一种低功耗、高性能CMOS8位微控制器,具有 8K 在系统可编程Flash 存储器。使用Atmel 公司高密度非 易失性存储器技术制造,与工业80C51 产品指令和引脚完 全兼容。片上Flash允许程序存储器在系统可编程,亦适于 常规编程器。在单芯片上,拥有灵巧的8 位CPU 和在系统 可编程Flash,使得AT89S52为众多嵌入式控制应用系统提 供高灵活、超有效的解决方案。 AT89S52具有以下标准功能: 8k字节Flash,256字节RAM, 32 位I/O 口线,看门狗定时器,2 个数据指针,三个16 位 定时器/计数器,一个6向量2级中断结构,全双工串行口, 片内晶振及时钟电路。另外,AT89S52 可降至0Hz 静态逻辑操作,支持2种软件可选择节电模式。空闲模式下,CPU 停止工作,允许RAM、定时器/计数器、串口、中断继续工 作。掉电保护方式下,RAM内容被保存,振荡器被冻结, 单片机一切工作停止,直到下一个中断或硬件复位为止。8 位微控制器 8K 字节在系统可编程 Flash AT89S52。 2、直流电机驱动取放铁片。考虑到电磁铁耗电很大,所以我们选择用直流电机机械方式实现铁片的取放。通过L298芯片驱动,用直流电机实现磁铁的磁铁上升(放下铁块)或下降(吸上铁片)。我们考虑了几种方案实现直流电机的驱动;L298电路图如下。直流电机驱动电路图L298电路图升上磁铁,放下铁片天然磁铁平衡臂步进电机直流电机铁片万向轮放下铁片放铁片原理图直流电机天然磁铁平衡臂步进电机放下磁铁,吸上铁片铁片万向轮取铁片原理图3、 探测黑白铁片与边界。以下为我们考虑的方案;我们使用PRP光电对管实现对黑白铁以及边界的探测。光电对管实物图电压比较器TL084信号处理实物图PRP光电一体化对管原理图R21M光电对管检测电路图4、 步进电机与驱动。方案选择;由于本系统为智能电动车,其驱动轮的驱动电机的选择就显得十分重要。由于小车要实现对路径的准确定位和精确测量,我们综合考虑了一下两种方案:方案1;采用步进电机作为该系统的驱动电机。由于其转过的角度可以精确地定位,可以实现小车前进路程和位置的精确确定位。方案2:采用直流减速电机。直流减速电机转动力矩大,体积小,重量轻,装配方便,但是不能做到很好的定位。权衡利弊,我们选择了第一方案。小车驱动部份我们选择用二相六线步进电机。因为步进电机可以很好地实现同步与精确控制功能,但是缺点是耗电大,震动大。但权衡利弊,与直流电机相双,步进电机驱动力强大,所以我们选择用步进电机。步进电机作为执行元件,是机电一体化的关键产品之一, 广泛应用在各种自动化控制系统中。随着微电子和计算机技术的发展,步进电机的需求量与日俱增,在各个国民经济领域都有应用。步进电机是一种将电脉冲转化为角位移的执行机构。当步进驱动器接收到一个脉冲信号,它就驱动步进电机按设定的方向转动一个固定的角度(称为“步距角”),它的旋转是以固定的角度一步一步运行的。可以通过控制脉冲个数来控制角位移量,从而达到准确定位的目的;同时可以通过控制脉冲频率来控制电机转动的速度和加速度,从而达到调速的目的。步进电机可以作为一种控制用的特种电机,利用其没有积累误差(精度为100%)的特点,广泛应用于各种开环控制。现在比较常用的步进电机包括反应式步进电机(vr)、永磁式步进电机(pm)、混合式步进电机(hb)和单相式步进电机等。永磁式步进电机一般为两相,转矩和体积较小,步进角一般为7.5度 或15度;反应式步进电机一般为三相,可实现大转矩输出,步进角一般为1.5度,但噪声和振动都很大。反应式步进电机的转子磁路由软磁材料制成,定子上有多相励磁绕组,利用磁导的变化产生转矩。混合式步进电机是指混合了永磁式和反应式的优点。它又分为两相和五相:两相步进角一般为1.8度而五相步进角一般为 0.72度。这种步进电机的应用最为广泛,也是本次细分驱动方案所选用的步进电机。我们的步进电机使用的驱动芯片是lm2003。步进电机驱动芯片LM2003实物图LM2003芯片原理图步进电机实物图LM2003步进电机驱动相图二相六线步进电机接线图5、 寻找光源。当光敏二极管正对光源时,电阻变小,经过电压比较器向单片机输入信号。寻找光源用的光敏对管,为了防止干扰,用笔筒套上光敏电阻。6、 电路板。我们通过Protel dxp绘制电路图后,采用热转印方法制成PCB双面板。蜂鸣器与发光二极管,输出声光信号74hc373作为光电对管信号输入锁存器,PO分时读取外部锁存器,实现单片机的输出口和输入口扩展主控电路AT89S52输出锁存器74hc573,作为单片机分时存出的输出口。主板稳压电路1602lcd插口主电路板实物图(正面)主电路板实物图(反面)主电路板pcb图主电路板各部分原理图如下:6智能小车程序框图。初始化前进定时器T2定时中断,中断子程序输入光电对管信号,判断是否遇到黑色信号或白色信号。白铁黑铁判断遇到黑铁或白铁或边界寻找左光源,返回A停车区。寻找右光源,返回B停车区。否向前对齐,继续扫描是否取完3块铁片返回停车区,结束。7、 智能小车源程序。#includeunsigned int minute=0;second=0,sum=0;unsigned char idata minute1=0,second1=0;sum1=0;unsigned char idata recordminute1=0,recordsecond1=0,recordsum1=0;unsigned char idata recordminute2=0,recordsecond2=0,recordsum2=0;unsigned char bdata status=0;unsigned char bdata status1=0;unsigned char bdata status2=0;unsigned char bdata prpflagd;unsigned char bdata prpflage;unsigned int idata time0=0;unsigned long int idata time2=0;unsigned long int idata time2_1;unsigned int idata time2_2;unsigned char data motor=0;unsigned char bdata d=0;unsigned char bdata e=0;unsigned char bdata d1=0;unsigned char bdata e1=0;unsigned char lightcount=0;unsigned char v0;unsigned char vb;sbit prp5_0=d16;sbit prp5_1=d17;sbit prp1_0=d14;sbit prp1_1=d15;sbit prp6_0=d12;sbit prp6_1=d13;sbit prp2_0=d10;sbit prp2_1=d11;sbit prp7_0=e16;sbit prp7_1=e17;sbit prp3_0=e14;sbit prp3_1=e15;sbit prp8_0=e12;sbit prp8_1=e13;sbit prp4_0=e10;sbit prp4_1=e11;sbit prp5_000=prpflagd6;sbit prp5_001=prpflagd7;sbit prp1_000=prpflagd4;sbit prp1_001=prpflagd5;sbit prp6_000=prpflagd2;sbit prp6_001=prpflagd3;sbit prp2_000=prpflagd0;sbit prp2_001=prpflagd1;sbit prp7_000=prpflage6;sbit prp7_001=prpflage7;sbit prp3_000=prpflage4;sbit prp3_001=prpflage5;sbit prp8_000=prpflage2;sbit prp8_001=prpflage3;sbit prp4_000=prpflage0;sbit prp4_001=prpflage1;sbit prp5_00=d6;sbit prp5_01=d7;sbit prp1_00=d4;sbit prp1_01=d5;sbit prp6_00=d2;sbit prp6_01=d3;sbit prp2_00=d0;sbit prp2_01=d1;sbit prp7_00=e6;sbit prp7_01=e7;sbit prp3_00=e4;sbit prp3_01=e5;sbit prp8_00=e2;sbit prp8_01=e3;sbit prp4_00=e0;sbit prp4_01=e1;sbit forward=status0;sbit backward=status1;sbit turnleft=status3;sbit turnright=status2;sbit rightforward=status5;sbit rightbackward=status4;sbit leftforward=status6;sbit leftbackward=status7;sbit flag=status15; sbit whiteiron=status16;sbit blackiron=status20;sbit searchiron=status10;sbit searchrightlight=status11;sbit seachleftlight=status12;unsigned char interfere;unsigned char uninterfere;sbit rightorleft=status14;sbit unflag=status23;sbit foundblack=status24;sbit foundwhite=status25;sbit foundboundary=status26;unsigned char whiteironcount=0;unsigned char blackironcount=0;unsigned char ironcount=0;void timer0initializtion();void timer2initializtion();void turnright90degree();void turnleft90degree();void putdown();void goforwardaccelerat();void gobackwardaccelerat();void putup();void foundblackiron();void foundwhiteiron();void turnright180degree();void backwardalign();void forwardalign();void estimate();void boundaryturnright90degree();void boundaryturnright180degree();void boundaryturnleft180degree();void searchlightblackiron();void oneturnleft80degree();void oneturnright80degree();void oneturnright180degree();void oneturnleft80degree();void searchlightwhiteiron();void searchlightwhiteiron();void scan();void main()timer0initializtion();timer2initializtion();time2=0;while(time2=50);rightorleft=0;status=0;goforwardaccelerat();flag=0;while(flag=0);estimate();if(foundboundary=1)boundaryturnright90degree();scan();estimate();if(foundwhite=1)putdown();searchlightwhiteiron();elseputdown();searchlightblackiron();scan();estimate();if(foundwhite=1)putdown();searchlightwhiteiron();elseputdown();searchlightblackiron();scan();estimate();if(foundwhite=1)putdown();searchlightwhiteiron();elseputdown();searchlightblackiron();scan();estimate();if(foundwhite=1) putdown();searchlightwhiteiron();elseputdown();searchlightblackiron();goto end0200;elseif(foundblack=1)putdown();searchlightblackiron();scan();estimate();if(foundwhite=1) putdown();searchlightwhiteiron();elseputdown();searchlightblackiron();scan();estimate();if(foundwhite=1)putdown();searchlightwhiteiron();elseputdown();searchlightblackiron();scan();estimate();if(foundwhite=1) putdown();searchlightwhiteiron();elseputdown();searchlightblackiron();goto end0200;elseif(foundwhite=1)putdown();searchlightwhiteiron();scan();estimate();if(foundwhite=1)putdown();searchlightwhiteiron();elseputdown();searchlightblackiron();scan();estimate();if(foundwhite=1) putdown();searchlightwhiteiron();elseputdown();searchlightblackiron();scan();estimate();if(foundwhite=1) putdown();searchlightwhiteiron();elseputdown();searchlightblackiron();end0200:while(1);void goforwardaccelerat()status=0;forward=1;vb=5;time2=0;while(time2=8);vb=4;time2=0;while(time2=8);vb=3;time2=0;while(time2=8);vb=2;time2=0;while(time2=8);vb=1;void gobackwardaccelerat()status=0;backward=1;vb=5;time2=0;while(time2=8);vb=4;time2=0;while(time2=8);vb=3;time2=0;while(time2=8);vb=2;time2=0;while(time2=8);vb=1;void scan()status=0;while(foundblack!=1)&(foundwhite!=1)goforwardaccelerat();flag=0;while(flag=0);status=0;estimate();if(foundboundary=1)foundboundary=0;if(rightorleft=1)rightorleft=0;boundaryturnleft180degree();time2=0;while(time2=8);status=0;elserightorleft=1;boundaryturnright180degree();time2=0;while(time2=8);status=0;void searchlightblackiron()unsigned long int lightdalign;rightorleft=0;vb=4;turnright=1;while(prp8_01=1);status=0;time2=0;while(time2=20);turnright=1;time2=0;while(time2=30);time2=0;while(prp8_01=1);status=0;if(time2=180)goto b0173; status=0;turnright=1;time2=0;while(time2=20);while(prp8_01=1);time2=0;while(time2=10);status=0;time2=0;while(time2=20);b0173:time2_1=0;goforwardaccelerat();time2=0;while(time2=40);flag=0;while(flag=0);time2=0;while(time2=40);status=0;putup();time2=0;while(time2=8);turnright180degree();goforwardaccelerat();time2=0;while(time2=90);b0294:status=0;forward=1;flag=0;while(flag=0);estimate();if(foundboundary=0)goto b0294;status=0;time2=0;while(time2=8);gobackwardaccelerat();forwardalign();status=0;vb=4;turnright=1;time2=0;while(prp8_01=1);status=0;lightdalign=time2;if(lightdalign=150)turnleft=1;time2=0;while(time2=lightdalign);status=0;turnleft90degree();turnleft=1;time2=0;while(time2=20);status=0;time2=0;while(time2=8);b0621:vb=1;forward=1;flag=0;while(flag=0);status=0;estimate();if(foundboundary=1)forwardalign();boundaryturnright90degree();elsegoto b0621;elsetime2=0;while(time2=8);turnleft=1;time2=0;while(time2=lightdalign);status=0;forwardalign();boundaryturnright90degree();void searchlightwhiteiron()unsigned long int lightdalign;rightorleft=0;vb=4;turnleft=1;while(prp8_01=1);status=0;time2=0;while(time2=20);turnleft=1;time2=0;while(time2=30);time2=0;while(prp8_01=1);status=0;if(time2=180)goto b0374; status=0;turnleft=1;time2=0;while(time2=20);while(prp8_01=1);time2=0;while(time2=10);status=0;time2=0;while(time2=20);b0374:time2_1=0;goforwardaccelerat();time2=0;while(time2=40);flag=0;while(flag=0);time2=0;while(time2=40);status=0;putup();time2=0;while(time2=8);turnright180degree();goforwardaccelerat();time2=0;while(time2=90);b0410:forward=1;flag=0;while(flag=0);estimate();if(foundboundary=0)goto b0410;status=0;time2=0;while(time2=8);gobackwardaccelerat();forwardalign();status=0;vb=4;turnleft=1;time2=0;while(prp8_01=1);status=0;lightdalign=time2;if(lightdalign=150)turnright=1;time2=0;while(time2=lightdalign);status=0;turnright90degree();turnright=1;time2=0;while(time2=20);status=0;time2=0;while(time2=8);b0431:vb=1;forward=1;flag=0;while(flag=0);status=0;estimate();if(foundboundary=1)forwardalign();boundaryturnright90degree();elsegoto b0431;elsetime2=0;while(time2=8);turnright=1;time2=0;while(time2=lightdalign);status=0;forwardalign();boundaryturnright90degree();void boundaryturnright90degree()status=0;vb=3;backward=1;time2=0;while(time2=30);vb=4;status=0;turnright=1;time2=0;while(time2=122);status=0;time2=0;while(time2=10);void oneturnright80degree()status=0;vb=5;leftforward=1;time2=0;while(time2=215);status=0;time2=0;while(time2=8);void oneturnleft180degree()status=0;vb=5;rightforward=1;time2=0;while(time2=505);status=0;time2=0;while(time2=8);void oneturnright180degree()status=0;vb=5;leftforward=1;time2=0;while(time2=505);status=0;time2=0;while(time2=8);void oneturnleft80degree()status=0;vb=5;rightforward=1;time2=0;while(time2=225);status=0;time2=0;while(time2=8);void boundaryturnleft180degree()status=0;forwardalign();vb=3;status=0;backward=1;time2=0;while(time2=68);status=0;oneturnleft180degree();time2=0;while(time2=10);backwardalign();time2=0;while(time2=8);void boundaryturnright180degree()status=0;forwardalign();vb=3;status=0;backward=1;time2=0;while(time2=68);status=0;oneturnright180degree();time2=0;while(time2=10);backwardalign();time2=0;while(time2=8);void forwardalign()vb=4;status=0;backward=1;time2=0;while(time2=50)break;status=0;time2=0;while(time2=10);forward=1;while(prp4_000=0);status=0;time2=0;while(time2=10);if(prp7_000=1)&(prp1_000=0)status=0;turnright=1;while(prp1_000=0);status=0;time2=0;while(time2=10);if(prp7_000=1)rightbackward=1;while(prp7_000=1);elserightforward=1;while(prp7_000=0);elseif(prp7_000=0)&(prp1_000=1)status=0;turnleft=1;while(prp7_000=0);status=0;time2=0;while(time2=10);if(prp1_000=1)leftbackward=1;while(prp1_000=1);elseleftforward=1;while(prp1_000=0);status=0;time2=0;while(time2=18); void backwardalign()unsigned char backwardaligncount=0;b0353:backwardaligncount+;status=0;vb=4;forward=1;time2=0;while(time2=50)break;status=0;time2=0;while(time2=10);backward=1;while(prp4_000=0);status=0;time2=0;while(time2=10);if(prp6_000=1)&(prp1_000=0)turnleft=1;while(prp1_000=0);status=0;time2=0;while(time2=10);if(prp6_000=1)rightforward=1;while(prp6_000=1);elserightbackward=1;while(prp6_000=0);elseif(prp6_000=0)&(prp1_000=1)turnright=1;while(prp6_000=0);status=0;time2=0;while(time2=10);if(prp1_000=1)leftforward=1;while(prp6_000=1);elseleftbackward=1;while(prp6_000=0);status=0;time2=0;while(time2=18);if(backwardaligncount=3)goto b0353; status=0;void turnleft90degree()vb=4;status=0;turnleft=1;time2=0;while(time2=110);status=0; time2=0;while(time2=10);void turnright90degree()vb=4;status=0;turnright=1;time2=0;while(time2=115);status=0;time2=0;while(time2=10);void turnright180degree()vb=4;status=0;turnright=1; time2=0;while(time2=230); turnright=0;time2=0;while(time2=15);vb=3;void putup()status=0;time2=0;while(time2=80)status=0;P1=0x05;P1=0xff;time2=0;while(time2=30);time2=0;while(time2=80)status=0;P1=0x05;P1=0xff;time2=0;while(time2=30);time2=0;while(time2=80)status=0;P1=0x05; P1=0xff;void putdown()status=0;forward=1;time2=0;while(time2=3);status=0;time2=0;while(time2=150)P1=0x03;P1=0xff;time2=0;while(time2=8);vb=3;status=0;forward=1;time2=0;while(time2=16);status=0;time2=0;while(time2=8);vb=3;status=0;backward=1;time2=0;while(time2=32);status=0;time2=0;while(time2=8);forward=1;time2=0;while(time2=16);status=0;time2=0;while(time2=8); void estimate()unsigned char bj1=0;unsigned char bj2=0;unsigned char bj3=0;unsigned char bj4=0; unsigned char bj5=0;foundblack=0;foundboundary=0;foundwhite=0;e1=e;d1=d;vb=2;forward=1;time2=0;while(time2=50)if(prp1_000=1)bj1=1;if(prp3_000=1)bj2=1;if(prp5_000=1)bj5=1;if(prp7_000=1)bj4=1;if(prp1_001=0)|(prp2_001=0)|(prp3_001=0)|(prp4_001=0)|(prp5_001=0)|(prp6_001=0)|(prp7_001=0)bj3=1;status=0;backward=1;time2=0;while(time2=50);status=0;if(bj5=1)&(bj1=1)|(bj2=1)&(bj4=1)foundboundary=1;elseif(bj3=1)foundwhite=1;WR=0;time2=0;while(time2=18);WR=1;elsefoundblack=1;WR=0;time2=0;while(time2=18);WR=1;time2=0;while(time2=18);WR=0;time2=0;while(time2=18);WR=1;time2=0;while(time2=18);WR=0;time2=0;while(time2=18);WR=1;time2=0;while(time2=18);void timer0initializtion()TMOD=0X01;TH0=0xd8;TL0=0xef;EA=1;ET0=1;PT0=0;TR0=1; void timer2initializtion() /50MSET2=1;TCLK=0;RCLK=0;CP_RL2=0;T2MOD=0x0;C_T2=0;RCAP2H=0x3c;RCAP2L=0xb0;PT2=1;TR2=1; void T2interrupt() interrupt 5 unsigned char idata i;time2+;time2_1+;time2_2+;sum=sum+1;sum1=sum1+1;if(sum=20)sum=0;second=second+1; if(second=60) second=0; minute=minute+1; if(minute=60) minute=0; if(sum1=20)sum1=0;second1=second1+1;if(second1=60) second1=0; minute1=minute1+1; RD=0;P2=0x8c;P0=0xff;for(i=0;i=2;i+);d=P0;d=P0;P2=0x84;P0=0xff;for(i=0;i=2;i+);e=P0;e=P0;RD=1;P2=0xff;if(d!=0xaa)|(e&0xf3)!=0xa2)if(interfere=2)interfere+;if(interfere=3)flag=1;prpflagd=d;prpflage=e;interfere=0;elseinterfere=0; if(d=0xaa)&(e&0xf3)=0xa2)if(uninterfere=vb)v0=0;if(motor=0x18)motor=0x42;else if(motor=0x42) motor=0x24; else if(motor=0x24) motor=0x81; else if(motor=0x81) motor=0x18; else motor=0x18; if(status=0x02) / V=9cm/sif(v0=vb)v0=0;if(motor=0x81)motor=0x24;else if(motor=0x24) motor=0x42; else if(motor=0x42) motor=0x18; else if(motor=0x18) motor=0x81; else motor=0x18; if(status=0x04)if(v0=vb)v0=0;time0=0;if(motor=0x11)motor=0x44;else if(motor=0x44) motor=0x22; else if(motor=0x22) motor=0x88; else if(motor=0x88) motor=0x11; else motor=0x11; if(status=0x08)if(v0=vb)v0=0;time0=0;if(motor=0x88)motor=0x22;else if(motor=0x22) motor=0x44; else if(motor=0x44) motor=0x11; else if(motor=0x11) motor=0x88; else motor=0x11;
展开阅读全文