资源描述
发动机转速电控系统程序设计及仿真目 录摘要 21 引言 32 方案设计 42.1 系统设计方案论证 4 2.1.1第一方案 42.1.2 第二方案 42.2第二方案的总体设计框图 43 系统硬件部分 53.1主控芯片 53.2 滤波电路及LM324芯片 73.3 显示设备 83.4 控制执行机构94系统软件设计104.1 设计思路104.2 程序流程图105 系统仿真与调试125.1 Proteus仿真软件125.2 仿真图建立125.3 仿真调试结果14结论 18致谢 19参考文献 20附录A 原理图 21附录B 程序编译图 22附录C 仿真图 23附录D 程序代码 25摘 要现在汽车的安全性很重要,发动机的转速高低也在安全的范围之列。本文介绍用AT89C52单片机设计制作发动机转速电控系统,仅需AT89C52最小系统,外接一个LCD1602、滤波电路和作为控制机构的电动机。这样就能够对发动机转速进行检测并相应控制电机运作,并将转速显示在LCD1602上。关键词:转速 单片机 显示 控制 LCD16021 引 言 1.1 问题的提出 目前汽车上转速表显示过于复杂,并且处于安全的考虑,要用单片机知识及常见的元器件搭建出能检测汽车发动机或者其它装置的转速,并相应的进行控制将其显示在监视员的视野之内,这样将减少因发动机转速而造成的人身危害。1.2 任务与分析 本文是应用MCS-51单片机原理和控制理论设计发动机转速检测并控制的硬件电路,利用C语言进行程序设计。通过检测单片机的外部中断触发信号来启动内部的定时器定时两个信号之间的时间,所得时间在程序中进行加权滤波、转换,最后将转速在LCD上显示,以此提醒驾驶人员注意发动机的转速。2 方案设计2.1 发动机转速电控系统设计方案论证2.1.1 第一方案本设计程序采用定时计数器0定时一段时间,在此段时间内设置定时器计数1对外部进行计数,最后将所得的个数进行滤波、转换,最后在数码管上显示。但是,这种方案采用数码管显示,较为复杂。第二方案与方案一相比,本方案将转速在LCD上显示并相应的控制其执行机构。这种设计显示部分很简洁,系统稳定性较高。2.2 第二方案的总体设计框图本设计采用89C52作为主控芯片,通过滤波电路处理输入信号,LCD作为输出设备显示转速。其中P3.2作为信号的输入,P1口用作LCD的数据线,P2.5、P2.6、P2.7口用作LCD的控制信号。设计框图如图一所示。图2.1 发动机转速电控系统设计框图3 系统硬件介绍3.1 主控芯片设计中所采用主控芯片为AT89C52。因其价格便宜,在市场上已经很成熟,各个方面都能够满足设计要求故选择它。其采用标准双列直插式引脚DIP-40大规模集成电路封装。它的引脚排列如下图3.1所示图3.1AT89C52的引脚排列引脚介绍:VCC:供电电压。GND:接地。P0口:P0口为一个8位漏级开路双向I/O口,每脚可吸收8TTL门电流。当P1口的管脚第一次写1时,被定义为高阻输入。P0能够用于外部程序数据存储器,它可以被定义为数据/地址的第八位。在FIASH编程时,P0 口作为原码输入口,当FIASH进行校验时,P0输出原码,此时P0外部必须被拉高。P1口:P1口是一个内部提供上拉电阻的8位双向I/O口,P1口缓冲器能接收输出4TTL门电流。P1口管脚写入1后,被内部上拉为高,可用作输入,P1口被外部下拉为低电平时,将输出电流,这是由于内部上拉的缘故。在FLASH编程和校验时,P1口作为第八位地址接收。 P2口:P2口为一个内部上拉电阻的8位双向I/O口,P2口缓冲器可接收,输出4个TTL门电流,当P2口被写“1”时,其管脚被内部上拉电阻拉高,且作为输入。并因此作为输入时,P2口的管脚被外部拉低,将输出电流。这是由于内部上拉的缘故。P2口当用于外部程序存储器或16位地址外部数据存储器进行存取时,P2口输出地址的高八位。在给出地址“1”时,它利用内部上拉优势,当对外部八位地址数据存储器进行读写时,P2口输出其特殊功能寄存器的内容。P2口在FLASH编程和校验时接收高八位地址信号和控制信号。P3口: P3口管脚是8个带内部上拉电阻的双向I/O口,可接收输出4个TTL门电流。当P3口写入“1”后,它们被内部上拉为高电平,并用作输入。作为输入,由于外部下拉为低电平,P3口将输出电流(ILL)这是由于上拉的缘故。P3口也可作为AT89C51的一些特殊功能口,如下表所示:P3口管脚 备选功能:P3.0 RXD(串行输入口)P3.1 TXD(串行输出口)P3.2 INT0(外部中断0)P3.3 INT1(外部中断1)P3.4 T0(记时器0外部输入)P3.5 T1(记时器1外部输入)P3.6 WR(外部数据存储器写选通)P3.7 RD(外部数据存储器读选通)P3口同时为闪烁编程和编程校验接收一些控制信号。RST:复位输入。当振荡器复位器件时,要保持RST脚两个机器周期的高电平时间。ALE/PROG:当访问外部存储器时,地址锁存允许的输出电平用于锁存地址的地位字节。在FLASH编程期间,此引脚用于输入编程脉冲。在平时,ALE端以不变的频率周期输出正脉冲信号,此频率为振荡器频率的1/6。因此它可用作对外部输出的脉冲或用于定时目的。然而要注意的是:每当用作外部数据存储器时,将跳过一个ALE脉冲。如想禁止ALE的输出可在SFR8EH地址上置0。此时, ALE只有在执行MOVX,MOVC指令是ALE才起作用。另外,该引脚被略微拉高。如果微处理器在外部执行状态ALE禁止,置位无效。PSEN: 外部程序存储器的选通信号。在由外部程序存储器取指期间,每个机器周期两次/PSEN有效。但在访问外部数据存储器时,这两次有效的/PSEN信号将不出现。EA/VPP:当/EA保持低电平时,则在此期间外部程序存储器(0000H-FFFFH),不管是否有内部程序存储器。注意加密方式1时,/EA将内部锁定为RESET;当/EA端保持高电平时,此间内部程序存储器。在FLASH编程期间,此引脚也用于施加12V编程电源(VPP)。XTAL1:反向振荡放大器的输入及内部时钟工作电路的输入。XTAL2:来自反向振荡器的输出。振荡器特性: XTAL1和XTAL2分别为反向放大器的输入和输出。该反向放大器可以配置为片内振荡器。石晶振荡和陶瓷振荡均可采用。如采用外部时钟源驱动器件,XTAL2应不接。有余输入至内部时钟信号要通过一个二分频触发器,因此对外部时钟信号的脉宽无任何要求,但必须保证脉冲的高低电平要求的宽度。图3.2 系统最小系统3.2 滤波电路及LM324芯片LM324芯片是差动输入的四运算放大器。该运放放大器可以工作在低到3.0伏或者高到32伏的电源下,静态电流为MC1741的静态电流的五分之一。共模输入范围包括负电源,因而消除了在许多应用场合中采用外部偏置元件的必要性。每一组运算放大器可用图三所示的符号来表示,它有5个引出脚,其中“+”、“-”为两个信号输入端,“V+”、“V-”为正、负电源端,“Vo”为输出端。两个信号输入端中,Vi-为反相输入端,表示运放输出端Vo的信号与该输入端的相位相反;Vi+为同相输入端,表示运放输出端Vo的信号与该输入端的相位相同。图3.3 LM324管脚图霍尔传感器输出信号为正弦信号,而单片机只能处理高低电平信号,为此必须将正弦信号转换成TTL电平信号。设计中利用LM324的比较作用将输入信号与参考电压进行比较,到大于时LM324输出端为高电平,否则为低电平。由于LM324为模拟器件,其驱动能力不足。设计中在输入端串联了一片74LS04的六非门芯片,提高输入的驱动能力,以便于单片机处理。图3.4 信号输入滤波电路3.3 显示设备图3.5 转速显示设备LCD16023.3 控制执行机构通过汽车理论知识学习,我们知道汽车发动机不能超过某一转速。如果长期在高转速下运作,对汽车发动机的寿命将大打折扣。为此,防止发动机高速情况发生,系统特意采用LED作为显示灯,提醒驾驶员此时发动机高转速运行情况,使其做相应的处理。同时电机运作,将控制汽车油路的电磁阀逐渐闭合,使供油减小,发动机转速降低,直至电磁阀完全闭合,停止供油。图3.6 控制机构及指示灯原理图4 系统软件设计4.1 设计思路利用80C52单片机内部的定时计数器和外部中断功能,通过检测P3.2端口的信号启动定时计数器进行计时,当下一次触发信号到来时,定时器停止计时并保存当前值。再启动定时器计时,如此循环。保存值达到五次后,对其进行加权滤波处理。最后将所得的值赋给数码管显示。当转速值大于设定值时,控制电机运作,指示灯亮。4.2 程序流程图图4.1主程序流程图图4.2定时器0中断函数流程图图4.3外部中断函数流程图5 系统仿真与调试5.1 Proteus软件介绍系统采用Proteus软件来进行程序的仿真,这款软件是英国Labcenter electronics公司出版的EDA工具软件。它不仅具有其它EDA工具软件的仿真功能,还能仿真单片机及外围器件。它是目前最好的仿真单片机及外围器件的工具。虽然目前国内推广刚起步,但已受到单片机爱好者、从事单片机教学的教师、致力于单片机开发应用的科技工作者的青睐。5.2 仿真图建立系统采用Proteus软件进行仿真,利用软件自带的仿真模块建立系统的仿真图。图5.1为发动机转速电控系统的最小系统图。图5.1 主控芯片仿真由于汽车上常用的转速传感器为霍尔式,集成的传感器其输出的信号为脉冲信号。在仿真中,采用霍尔传感器的原始信号即正弦信号来作为输入信号,利用LM324芯片的比较功能对其进行滤波处理将其转换成对应的脉冲信号。图5.2为滤波转换电路。图5.2 系统滤波转换电路系统采用LCD1602作为显示器件,其具体的仿真连接图如下。图5.3 系统的显示器件当系统检测完后得到转速大于我所设定的值时,控制执行机构运作同时指示灯将会点亮。当转速正常(小于设定值)时,电机停止工作,指示灯灭。在仿真中我选用直流电机作为执行机构。图5.5 执行机构仿真图5.3 仿真调试结果图5.5,图5.6,图5.7分别表示在不同的输入频率下,对应的LCD显示的转速情况及电机运作情况。图5.6 仿真图(一)当调节信号发生器改变输入的频率值时,单片机通过对其进行计数并运算处理,在数码管上面对应的显示当前值。调节信号发生器为图5.6所示即为18HZ时,LCD显示值为1080r/min,其值和18*60=1080相同。仿真结果正确。图5.7 仿真图(二)当调节信号发生器为50HZ时,LCD显示为3006r/min,这和理论值50*60=3000有一定误差。基本满足设计要求。图5.8 仿真图(三)继续调节信号发生器的频率时直到超过设定值8000r/min时,电机将会转动,由于此为动态效果,我们可以从三极管基极为高电平可以判断出此情况,并且指示灯将点亮。此时输入频率为140HZ,输出为8450r/min,其和理论140*60=8400r/min有一定误差,在设计要求范围内。结论致谢参考文献1 徐峥颖编著.Protel99SE EDA 技术及应用M.北京:机械工业出版社,2005.2 张靖武编著.单片机系统的protues设计与仿真M.北京:电子工业出版社,2007.3 李朝青编著.单片机原理及接口技术M.北京:北京航空航天大学出版社,2005.4 边春远编著.MCS-51单片机应用开发实用子程序M.北京:人民邮电出版社,2005.5 刘守义编著.单片机应用技术M.西安:西安电子科技大学出版社,2002.6 韩志军编著.单片机应用系统设计M.北京:机械工业出版社,2005.7 张毅刚,刘喜元编著.新编MCS-51单片机应用设计M.哈尔滨:哈尔滨工业大学出版社,2003.8 唐岚编著.汽车测试技术M.北京:机械工业出版社,2006.附录A:原理图附录B:程序编译附录C:仿真图附录D:程序代码#include #define uchar unsigned char#define uint unsigned intsbit LED=P31;sbit MO=P33;bit Flag; /第一次中断标志bit Flag_s; /转换标志sbit E=P25;sbit RW=P26;sbit RS=P27;uchar COUNT; /溢出次数unsigned long T5;uchar W5=1,2,3,4,5; /权值void Init(void);unsigned int Smooth(void);void delay(uint N);void write_cmd(uchar cmd);void write_data(uchar date);void LCD_Init();void LCD_Disp(uint d);void Write_Datas(uchar address,uchar Wdata);/-/ 主函数/-void main(void)uchar msg114=Current Rev is;uchar msg214= r/min ;uint i,dis_dat;Flag=0;Flag_s=0;COUNT=0;dis_dat=0;Init();LCD_Init();EA=1;write_cmd(0x80);for(i=0;i14;i+)write_data(msg1i);write_cmd(0x80+0x40);for(i=0;i8000)LED=0;MO=1;elseLED=1;MO=0; LCD_Disp(dis_dat);void delay(uint N)/延时N毫秒子程序uint x,y;for(x=N;x0;x-)for(y=110;y0;y-);void write_cmd(uchar cmd)/写指令子程序RS=0;RW=0;P1=cmd;delay(1);E=1;delay(1);E=0;void write_data(uchar date)/写数据子程序RS=1;RW=0;P1=date;delay(1);E=1;delay(1);E=0;void LCD_init()E=0; write_cmd(0x38);/5*7点阵字符write_cmd(0x0c);/整体显示,关光标,不闪烁write_cmd(0x06);/AC自动增一,画面不动write_cmd(0x01);/清屏write_cmd(0x80);/设置DDRAM地址void Write_Datas(uchar address,uchar Wdata)write_cmd(0x80+address);write_data(0x30+Wdata);/写数据void LCD_Disp(uint d) unsigned char dd4,i;dd0=d/1000;dd1=d%1000/100;dd2=d%1000%100/10;dd3=d%10;for(i=0;i4;i+)Write_Datas(0x42+i,ddi);/-/名称:定时器,中断初始化/功能:定时器0采用16位,中断下降沿触发/-void Init(void)TMOD=0x01;EX0=1;ET0=1;IT0=1;/-/名称:滤波函数/功能:加权滤波,权值1,2,3,4,5/- unsigned int Smooth(void)uchar i;uint dat;float sum;float avg;sum=0;for(i=0;i9999)dat=9999;return dat;/-/外部中断0的中断函数/-void INT(void) interrupt 0if(Flag)static unsigned char m=0; Tm=TH0*256+TL0+65536*COUNT;TH0=0;TL0=0;COUNT=0;m+;if(m=5)m=0;Flag_s=1;elseFlag=1;TH0=0;TL0=0;TR0=1;/-/定时器0的中断函数/-void Time(void) interrupt 1COUNT+;TH0=0;TL0=0;g an employment tribunal claiEmployment 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 i.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 would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end. Skydiver preps for the big jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).cause there- 33 -
展开阅读全文