单片机课程设计论文-基于STC89C52单片机的蓝牙控制小车.docx_第1页
单片机课程设计论文-基于STC89C52单片机的蓝牙控制小车.docx_第2页
单片机课程设计论文-基于STC89C52单片机的蓝牙控制小车.docx_第3页
单片机课程设计论文-基于STC89C52单片机的蓝牙控制小车.docx_第4页
单片机课程设计论文-基于STC89C52单片机的蓝牙控制小车.docx_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

单片机课程设计蓝牙控制小车设计人员:章叶满10214021班 级: 电子1001 完成日期:2012年12月27日指导老师: 黄赞武 摘要:利用蓝牙进行无线传输数据,并以STC89C52单片机为控制芯片控制电机旋转,从而实现通过蓝牙控制小车运动的目的。其中电机驱动为L298N驱动电路,蓝牙模块与单片机的TXD和RXD相连,进行串口通信。速度由单片机输出的PWM波控制。1. 实验目的:通过单片机原理与应用课程设计,使学生掌握单片机及其扩展系统设计的方法和设计原则及相应的硬件调试的方法。进一步加深单片机及其扩展系统设计和应用的理解2设计任务与要求通过设计双单片机控制系统,实现蓝牙控制小车的功能。单片机1通过电机驱动模块来控制电机正反转,从而驱动小车运动。单片机2通过串口TXD,RXD与蓝牙模块从机连接,进行串口通讯,而蓝牙模块主机与电脑相连,从而实现电脑与单片机二之间的通讯。在电脑上通过使用串口调试助手软件向单片机发送控制命令,单片机二接受到电脑的控制命令后,将数据命令转换为I/O口高点电平控制命令,传送到单片机一,进而单片机一根据命令来控制电机而正反转,从而实现电脑控制小车前进、后退、转弯。3. 电路设计3.1单片机控制电路:单片机是控制单元的核心。起着控制小车所有运行状态的作用。单片机控制模块使用的是STC89C52,使用该芯片很容易实现对其他模块的控制。通过对单片机STC89C52写入程序,可以方便的用软件来控制整个过程. 3.2单片机最小系统:包括单片机主机、复位电路、时钟电路。3.3双单片机系统:有两个单片机最小系统组成,其中单片机1的P0.2-P0.7口通过拨码开关分别与单片机2的P3.2-P3.7口相连,利用拨码来控制I/O端口的导通与断开。3.4电机驱动系统直流电机和步进电机都可以用于小车驱动。故有两种方案。方案一:使用直流电机,加上适当减速比的减速器。直流电机具有良好的调速性能,控制起来也比较简单。直流电机只要通上直流电源就可连续不断的转动,调节电压的大小就可以改变电机的速度。直流电机的驱动电路实际上就是一个功率放大器。常用的驱动方式是PWM方式,即脉冲宽度调制方式。此方法性能较好,电路和控制都比较简单。方案二:使用步进电机。步进电机具有良好的控制性能。当给步进电机输入一个电脉冲信号时,步进电机的输出轴就转动一个角度,因此可以实现精确的位置控制。与直流电机不同,要使步进电机连续的转动,需要连续不断的输入点脉冲信号,转速的大小由外加的脉冲频率决定。去而且其转动不受电压波动和负载变化的影响,也不受温度、气压等环境因素的影响,仅与控制脉冲有关。但步进电机的驱动相对较复杂,要由控制器和功率放大器组成。具体差别见下表2-4。表2-4 电机控制方式对比直流电机步进电机调速性能较好较差位置控制精度较差好驱动简单复杂稳定性较好好,仅与控制脉冲有关由上表可以看出步进电机和直流电机都有各自的优点。步进电机能进行精确的位置控制,但驱动电路麻烦,鉴于本设计中小车的位置控制不要求十分精确,直流电机即可满足小车要求的精度。且直流电机易于控制,驱动电路十分简单。驱动电路小车使用的是直流电机。从单片机输出的信号功率很弱,即使在没有其它外在负载时也无法带动电机,所以在实际电路中我们加入了电机驱动芯片提高输入电机信号的功率,从而能够根据需要控制电机转动。直流电机常用的PWM,及脉宽调制方式驱动。本设计中电机驱动采用L298集成H桥芯片。L298中有两套H桥电路,刚好可以控制两个电机。它的使能端可以外接高低电平,也可以利用单片机进行软件控制,极大地满足各种复杂电路需要。另外,L298的驱动功率较大,在646V的电压下,可以提供2A的额定电流,并且具有过热自动关断和电流反馈检测功能,安全可靠;为了保证L298正常工作,我们另外安装了续流二极管。电路如图3-4所示。能根据输入电压的大小输出不同的电压和功率,解决了负载能力不够这个问题。利用单片机调整出PWM脉冲和高低电平对直流电机进行驱动和控制。图3-4 电机驱动电路L298集成H桥芯片。其外形、管脚分布如图3-5所示。 图3-5 L298管脚分布图3.5 PWM调速原理脉冲宽度调制(Pulse Width Modulation),简称PWM。脉冲周期不变,只改变晶闸管的导通时间,即通过改变脉冲宽度来进行直流调速。PWM的理论基础是:冲量相等而形状不同的的窄脉冲加在具有惯性的环节上,其效果基本相同。采用PWM进行电机的调速控制,实际是保持加在电机电机电枢上的脉冲电压频率不变,调节其脉冲宽度。电机是一个惯性环节,它的电枢电流饿转速均不能突变,很高的频率的PWM加在电机上,效果相当于施加一个恒定电压的直流电。如图3-6所示。这个电压可以由脉冲的宽度调节。 图3-6 PWM等效图示意图使用PWM方式可以很容易的实现调速。PWM信号由单片机软件产生,使用非常方便。由于电路总体上并不复杂,驱动电路的控制输入端也可以不用经光耦合隔离,直接与单片机引脚相连。前进时,驱动两个直流电机都正转,后退时,则两电机都反转。左转时前进时,左电机不转而右电机正转,右转前进时,则右电机不转而左电机正转。进入减速区时,由单片机控制进行PWM变频调速,通过软件改变脉冲调宽波形的占空比,实现调速。所有这些都是通过软件编程实现控制。3.6 供电系统:电机电压为7.2V,单片机及蓝牙模块供电电压为5V,通过稳压芯片将7.2V电压转换为5V电压给单片机和蓝牙供电。3.7蓝牙串口通信系统:将蓝牙模块的主机与电脑相连,从机与单片机2的串口相连。传输电脑的控制命令。3.8总体电路图:4. 程序设计:4.1设计流程图:系统初始化小车移动检测外部有无信号输入无信号输入是否调动函数控制小车移动开始传输串口数据是否还有检测信号等待下次数据结束YNNYYN4.2单片机2串口通信程序:#include #define left P3_2#define right P3_3#define go P3_4#define back P3_5#define leftdata 0x11 ;左转控制命令#define rightdata 0x22 ;右转控制命令#define godata 0x33 ;前进控制命令#define backdata 0x44 ;后退控制命令unsigned char a,b,flag;void delay1ms(unsigned int x) unsigned int i,j; for(j=x;j0;j-) for(i=75;i0;i-);main()TMOD=0x20;/定时器工作在方式2TH1=0xfd;TL1=0xfd;/9600波特率TR1=1;/开定时器计数SM0=0;SM1=1;/串行工作方式1REN=1;/允许接收数据EA=1;/开中断总开关ES=1;/允许串行中断while(1) if(flag=1) flag=0; if(b!=a) left=1; right=1; go=1; back=1; switch(b) case leftdata:left=0;break; case rightdata:right=0;break; case godata:go=0;break; case backdata:back=0;break; a=b; delay1ms(30); else left=1; right=1; go=1; back=1; void serial() interrupt 4 /中断法flag=1;b=SBUF;RI=0;/中断标志4.3 单片机1电机控制程序:#include #define uchar unsigned char#define uint unsigned intvoid motor_r_z(void);/右边电动机正转void motor_l_z(void);/左边电动机正转void motor_r_f(void);/右边电动机反转void motor_l_f(void);/左边电动机反转void back(uchar,uchar); /小车后退void go(uchar,uchar);/小车前进void stop(void);/小车停止void left(void);/小车左转void right(void);/小车右转sbit PWM1=P25;sbit PWM2=P24;sbit PWM3=P21;sbit PWM4=P22;sbit EN1=P20;sbit EN2=P23;sbit left_k=P02;sbit back_k=P05;sbit go_k=P04;sbit right_k=P03;sbit sound=P27;uchar data t_0; /每产生一次T0定时器中断的时候t_0加1uchar data motor_r; /motor_r用于存放右边电机转速和转向的数据uchar data motor_l; /motor_l用于存放左边电机转速和转向的数据uchar data Value;uchar data mid;/*初始化函数*/void ini(void)/T0初始化/TMOD=0x01; /T0工作在方式1TH0=0xff; /装入T0初值TL0=0xf6;TR0=1;/开T0中断ET0=1;/T0允许中断EA=1;/t_0=0;/P2=0;sound=1;void go(uchar left_motor,uchar right_motor)/直行Value=right_motor;motor_r_z();Value=left_motor;motor_l_z();void back(uchar left_motor,uchar right_motor)/后退Value=right_motor;motor_r_f();Value=left_motor;motor_l_f();void left(void)/左转Value=0x45;motor_r_z();Value=0x45;motor_l_f();void right(void)/右转Value=0x45;motor_r_f();Value=0x45;motor_l_z();void motor_r_z(void)/右边电动机正转 ACC=0x64+Value; motor_r=ACC; EN1=1;void motor_l_z(void)/左边电动机正转 ACC=0x64-Value; motor_l=ACC; EN2=1;void motor_r_f(void)/右边电动机反转 ACC=0x64-Value; motor_r=ACC; EN1=1;void motor_l_f(void)/左边电动机反转 ACC=0x64+Value; motor_l=ACC; EN2=1;void stop(void)EN2=0;EN1=0;/*T0中断服务程序*/*PWM产生*/void time0(void) interrupt 1 using 2TR0=0;TH0=0xff;TL0=0xf6;+t_0;ACC=t_0;CY=0;ACC-=motor_r;if(CY=1)PWM1=1;PWM2=0;goto PWM_2;PWM1=0;PWM2=1;PWM_2:ACC=t_0;CY=0;ACC-=motor_l;if(CY=1)PWM3=1;PWM4=0;goto HIGHT;PWM3=0;PWM4=1;HIGHT:ACC=t_0;if(ACC!=0xc9)goto EXIT;ACC=0;t_0=ACC;EXIT:TR0=1; void main(void)ini();while(1)aa: while(left_k)/当左按键按下时,left_k等于1. goto bb; P1=0xff; P1=P0; left();/向左转 while(!left_k);/如果left_k一直为一,小车便一直左转 stop();/判断右键是否按下/bb: while(right_k) goto dd; P1=0xff; P1=P0; right(); while(!right_k); stop();/判断向前键是否按下/dd: while(go_k) goto ee; P1=0xff; P1=P0; go(0x64,0x64); while(!go_k); stop();/判断后退键是否按下/ee: while(back_k) goto aa; P1=0xff; P1=P0; back(0x64,0x64); while(!back_k);stop();5. 调试:完成电路设计与焊接后进行调试,给单片机上点并接上蓝牙串口模块,打开串口调试助手,选择相应串口,将波特率设定为9600bps,数据位8位,停止位1,检验位0,然后将键盘按键绑定,即:当按下A时,发送十六进制数据11H,为左转命令;当按下D时,发送十六进制数据22H,为右转命令;当按下W时,发送十六进制数据33H,为前进命令;当按下S时,发送十六进制数据44H,为后退命令。6. 结论:经过多次软件调试,可实现设计的基本要求,即:可通过电脑按键控制小车的运动。g an employment tribunal claimEmployment tribunals sort out disagreements between employers and employees.You may need to make a claim to an employment tribunal if: you dont agree with the disciplinary action your employer has taken against you your employer dismisses you and you think that you have been dismissed unfairly.For more information about dismissal and unfair dismissal, seeDismissal.You can make a claim to an employment tribunal, even if you haventappealedagainst the disciplinary action your employer has taken against you. However, if you win your case, the tribunal may reduce any compensation awarded to you as a result of your failure to appeal.Remember that in most cases you must make an application to an employment tribunal within three months of the date when the event you are complaining about happened. If your application is received after this time limit, the tribunal will not usually accept it.If you are worried about how the time limits apply to you, take advice from one of the organisations listed underFurther help.Employment tribunals are less formal than some other courts, but it is still a legal process and you will need to give evidence under an oath or affirmation.Most people find making a claim to an employment tribunal challenging. If you are thinking about making a claim to an employment tribunal, you should get help straight away from one of the organisations listed underFurther help.If you are being represented by a solicitor at the tribunal, they may ask you to sign an agreement where you pay their fee out of your compensation if you win the case. This is known as adamages-based agreement. In England and Wales, your solicitor cant charge you more than 35% of your compensation if you win the case.If you are thinking about signing up for a damages-based agreement, you should make sure youre clear about the terms of the agreement. It might be best to get advice from an experienced adviser, for example, at a Citizens Advice Bureau. To find your nearest CAB, including those that give advice by e-mail, click onnearest CAB.For more information about making a claim to an employment tribunal, seeEmployment tribunals.The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday.I am going to be at the match tomorrow and I have asked to meet Yaya Toure, he told BBC Sport.For me its about how he felt and I would like to speak to him first to find out what his experience was.Uefa hasopened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win.Michel Platini, president of European footballs governing body, has also ordered an immediate investigation into the referees actions.CSKA said they were surprised and disappointed by Toures complaint. In a statement the Russian side added: We found no racist insults from fans of CSKA.Age has reached the end of the beginning of a word. May be guilty in his seems to passing a lot of different life became the appearance of the same day; May be back in the past, to oneself the paranoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. Always feel oneself should go to do something, or write something. Twenty years of life trajectory deeply shallow, suddenly feel something, do it.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。The end of our life, and can meet many things really do?而穷尽我们的一生,又能遇到多少事情是真正地非做不可?During my childhood, think lucky money and new clothes are necessary for New Year, but as the advance of the age, will be more and more found that those things are optional; Junior high school, thought to have a crush on just means that the real growth, but over the past three years later, his writing of alumni in peace, suddenly found that isnt really grow up, it seems is not so important; Then in high school, think dont want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was eventually infarction when graduation party in the throat, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops, suddenly found himself has already cant remember his appearance.童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后,自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要了;然后到了高中,觉得非要吐露出自己的心声才能为高中生涯里的懵懂情愫划上一个句点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场,看着他投过篮球的球框时,突然间发现自己已经想不起他的容颜。Originally, this world, can produce a chemical reaction to an event, in addition to resolutely, have to do, and time.原来,这个世界上,对某个事件能产生化学反应的,除了非做不可的坚决,还有,时间。A persons time, your ideas are always special to clear. Want, want, line is clear, as if nothing could shake his. Also once seemed to be determined to do something, but more often is he backed out at last. Dislike his cowardice, finally found that there are a lot of love, there are a lot of miss, like shadow really have been doomed. Those who do, just green years oneself give oneself an arm injection, or is a self-righteous spiritual.一个人的时候,自己的想法总是特别地清晰。想要的,不想要的,界限明确,好像没有什么可以撼动自己。也曾经好像已经下定了决心去做某件事,但更多的时候是最后又打起了退堂鼓。嫌恶过自己的怯懦,最终却发现有很多缘分,有很多错过,好像冥冥之中真的已经注定。那些曾经所谓的非做不可,只是青葱年华里自己给自己注射的一支强心剂,或者说,是自以为是的精神寄托罢了。At the moment, the sky is dark, the air is fresh factor after just rained. Suddenly thought of blue plaid shirt; Those were broken into various shapes of stationery; From the corner at the beginning of deep friendship; Have declared the end of the encounter that havent start planning. Those years, those days of do, finally, like youth, will end in our life.此刻,天空是阴暗的,空气里有着刚下过雨之后的清新因子。突然想到那件蓝格子衬衫;那些被折成各种各样形状的信纸;那段从街角深巷伊始的友谊;还有那场还没有开始就宣告了终结的邂逅计划那些年那些天的非做不可,终于和青春一样,都将在我们的人生中谢幕。Baumgartner the disappointing news: Mission aborted. r plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The supersonic descent could happen as early as Sunda.The weatheThe balloon will slowly drift to the edge of space at 120,000 feet ( Then, I

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论