《毕业设计基于单片机的交通信号灯模拟控制系统设计.doc》由会员分享,可在线阅读,更多相关《毕业设计基于单片机的交通信号灯模拟控制系统设计.doc(22页珍藏版)》请在三一办公上搜索。
1、单片机应用设计 交通信号灯模拟控制系统设计参赛学生季策 控制科学与工程学院沙跃 控制科学与工程学院黄佳敏 控制科学与工程学院亢延哲 控制科学与工程学院陈志恒 控制科学与工程学院2012年11月12日目 录1、摘要32、方案论证比较 3 2.1、电源提供方案 3 2.2、数码管驱动方案 3 2.3、显示界面方案 32.4、按键输入方案 43、 系统总体设计 4 3.1芯片的选择 4 3.2系统设计与结构框图 4 3.3电路设计 5 3.3.1时间显示电路5 3.3.2交通灯电路 6 3.3.3按键控制电路74、 工作原理及软件设计 75、 proteus仿真测试结果 86、 附录(程序)10一、
2、 摘要: 本系统由STC89C52单片机为控制器,以74hc595移位寄存器通过串行转并行驱动两个两位数码管显示倒计时。系统包括红、绿、黄灯显示功能、LED数码管显示时间功能、控制与调时开关、通过键盘设置时间功能。 在车辆通行繁忙的十字交叉路口设置的交通灯控制系统,其特点是:道路较窄而车流量较大,主干道,支干道的车辆通行时间不等,同时设有道路应急控制。具体的情况是:在正常的情况下,东西干道通行时间为40秒,南北干道通行时间为60秒,每个方向在绿灯转为红灯时,要求黄灯先亮5秒钟,才能变换运行车道。由于各道路车流量不等,能通过手动按键控制各灯显示时间。二、方案论证比较 2.1、电源提供方案 为使模
3、块稳定工作,须有可靠电源。我们考虑了两种电源方案方案一:采用独立的稳压电源。这个可以由8705组成的电源电路直接提供5V电压,此方案的优点是稳定可靠,且有各种成熟电路可供选用;缺点是各模块都采用独立电源,会使系统复杂,且可能影响电路电平。方案二:采用单片机控制模块提供电源。改方案的优点是系统简明扼要,节约成本;缺点是输出功率不高。综上所述,我们选择第二种方案。2.2、数码管驱动方案数码管需要完成倒计时功能,分为东西和南北方向的倒计时,需要占用较多I/O口,为提高I/O口利用率,提出以下三种方案:方案一:用MAX7219串行转并行,一个芯片即可控制两个两位数码管,优点是占有I/O口少,硬件连接简
4、单,但是价格比较昂贵。方案二:数码管段选和位选分别直接连接I/O口,优点是电路简单,很容易实现编程控制,缺点是占用过多I/O口,且电流过小,数码管显示不清晰。方案三:用74HC595移位寄存器驱动数码管,优点是以前接触过,使用较方便,也能够实现串行转并行,占用I/O口也比较少。综合自己的经验和学习情况,我们选择了方案三。2.3 、显示界面方案该系统要求完成倒计时、状态灯等功能。方案一:完全采用数码管显示。这种方案只显示有限的符号和数码字苻,无法胜任题目要求。方案二:完全采用点阵式LED 显示。这种方案实现复杂,且须完成大量的软件工作;但功能强大,可方便的显示各种英文字符,汉字,图形等。方案三:
5、采用数码管与点阵LED 相结合的方法因为设计既要求倒计时数字输出,又要求有状态灯输出等,为方便观看并考虑到现实情况,用数码管与LED灯分别显示时间与提示信息。这种方案既满足系统功能要求,又减少了系统实现的复杂度。权衡利弊,第三种方案可互补一二方案的优缺,我们决定采用方案三以实现系统的显示功能。2.4、按键输入方案题目要求系统能手动设灯亮时间,我们讨论了两种方案:方案一:使用矩阵键盘,可以在有限的I/O口上能够由更多的按键控制,可以实现更多功能,但本设计不需要过多按键。方案二: 直接在IO口线上接上独立按键开关。因为设计时精简和优化了电路,所以剩余的口资源还比较多,我们使用四个按键,分别是K1、
6、K2、K3、K4。由于该系统对于交通灯及数码管的控制,只用单片机本身的I/O 口就可实现,且本身的计数器及RAM已经够用,故选择方案二三、 系统总体设计3.1芯片的选择 我们选用的是AT89C51单片机,其包含中央处理器(CPU)、程序存储器(ROM)、数据存储器(RAM)、定时/计数器、并行接口、串行接口和中断系统等几大单元及数据总线、地址总线和控制总线等三大总线。 另外,我们在数码管驱动方面选用了74595移位寄存器,大大的节省了I/O口,简化了电路结构。3.2系统设计与结构框图根据题目要求,本系统主要由数码管显示倒计时模块、交通灯亮灭模块,键盘控制模块等构成南北方向 NS G Y R东西
7、方向 EW G Y R 系统控制电路 按键转换3.3电路设计3.3.1时间显示电路因为系统要求南北和东西方向的信号灯时间不一样,所以就通过串转并的移位寄存器74HC595输出数据的段码,位选信号用P2口送出,用动态扫描的方法显示东西、南北的倒计时间。3.3.2交通灯电路本设计利用单片机的P1口来驱动和控制各种信号灯的燃亮和燃亮时间,在实际中,交通灯的信号灯需要用高电压控制,在这里我们只是模拟一下它的控制信号,所以我们就只用单片机的信号引脚直接来控制发光二极管3.3.3按键控制电路按键电路设计共使用了4个独立按键,其中有KEY3,KEY4分别连接在两个外部中断接口(INTO和INT1),按下按键
8、实现两个外部中断,用来处理紧急事故和切换到调节时间模式,另外两个按键通过按下按键向I/O口输送低电平,在调节时间模式实现时间的设置,在普通状态下用来切换红绿灯状态。本设计通过外部中断实现了一个按键两种作用的功能。四、工作原理及软件设计由软件设置交通灯的初始时间,南北方向通行60秒,东西方向通行40秒,数码管采用动态显示,P2口送字位选通信号,通过74595实现段选控制,并通过单片机的P1口控制各种信号灯的燃亮与熄灭,采用中断方式和按键扫描实现按键的功能。总体流程图东西绿灯南北红灯东西黄灯闪南北红灯亮东西红灯南北绿灯东西红灯亮南北黄灯闪五、 proteus仿真测试结果为测试编程效果,我们利用pr
9、oteus软件仿真效果如下:1.交通灯控制系统正常运行时仿真图2交通灯控制系统紧急情况运行时仿真图紧急情况下,数码管显示时间停止,所有方向的灯都显示红灯。3、仿真结果分析仿真实验实现南北方向车道和东西方向车道两条交叉道路的车辆交替运行,南北方向(主干道)每次通行时间设为30秒、东西方向通行时间设为20秒,时间可以在程序中修改。同时能够实现红灯、黄灯、绿灯状态转换,红绿灯转换时间为5秒,转黄期间黄灯亮。可以准确显示每个状态所剩余的时间,按下禁行普通车辆键,东西南北方向都亮红灯;按下南北放行键,南北绿灯亮,东西红灯亮;按下东西放行键,东西绿灯亮,南北红灯亮;任何时候按下返回键,此系统都将回到初始状
10、态,当紧急状况出现时,按下紧急开关,可实现主干道和支干道全部禁止通行,允许紧急车辆安全通行。附:程序#includereg51.h#includeintrins.h#define uchar unsigned char#define uint unsigned intvoid delay(uint z);void light(); /红绿灯函数void keyscan();void smg();void send(uchar Data);/ 串行数据输入void out(void); /并行输出 uchar SN=10;WE=13;Y=3;SNg=10;WEg=8;/SN为南北方向显示时间,W
11、E为东西方向显示时间,WEg为东西绿灯时间 uchar num=0; state;/红绿灯状态标志uchar code lamp4=0xf3,0xeb,0xde,0xdd; /红绿灯4种状态uchar code duan10=0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F; /LED编码表uchar code wei4=0xfb,0xf7,0xfe,0xfd; /数码管位选编码sbit K1=P36; /开关K1接P36管脚sbit K3=P32; /开关K2接P33管脚,外部中断0sbit K2=P35; /开关K3接P35管脚sbit K
12、4=P33; /开关K4接P32管脚,外部中断1sbit w1=P24;/数码管位选sbit w2=P25;sbit w3=P26;sbit w4=P27;sbit SEG=P20; /段选串行数据输入sbit SHcp=P22; /移位时钟脉冲sbit STcp=P23; /输出锁存器控制脉冲/*延时函数*/void delayms(uint z) uint x,y; for(x=z;x0;x-) for(y=110;y0;y-);/*数码管显示函数*/void smg() send(duanSN%10);w1=1;w2=0;w3=1;w4=1;/显示南北方向个位 delay(5); sen
13、d(duanSN/10); w1=0;w2=1;w3=1;w4=1;/显示南北方向十位*delay(5); send(duanWE%10);w1=1;w2=1;w3=1;w4=0;/显示东西方向个位delay(5); send(duanWE/10);w1=1;w2=1;w3=0;w4=1;/显示东西方向十位delay(5); /*74595接收数据函数*/void send(uchar Data) uchar i; for(i=0;i8;i+) SHcp=0;SEG=Data&0x80;Data=Data=20) SN-;/时间减1 WE-; num=0;/重新计数 if(SN=0|WE=0)
14、 state+; if(state3) state=0; switch(state) case 0:SN=SNg;WE=SNg+Y;break; case 1:SN=Y;WE=Y; break; case 2:SN=WEg+Y;WE=WEg;break; case 3:SN=Y;WE=Y; break; Employment tribunals sort out disagreements between employers and employees.You may need to make a claim to an employment tribunal if: you dont agr
15、ee 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 haventappealedagains
16、t 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 da
17、te 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 l
18、ess 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 a
19、way 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 so
20、licitor 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
21、 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,
22、 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
23、 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 wer
24、e 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 i
25、n 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.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎
26、把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。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 t
27、he 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 importan
28、t; 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 hoo
29、ps, suddenly found himself has already cant remember his appearance.童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后,自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要了;然后到了高中,觉得非要吐露出自己的心声才能为高中生涯里的懵懂情愫划上一个句点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场,看着他投过篮球的球框时,突然间发现自己已经想不起他的容颜。Originall
30、y, 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
31、 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.一个人的时候,自己的想法总是特
32、别地清晰。想要的,不想要的,界限明确,好像没有什么可以撼动自己。也曾经好像已经下定了决心去做某件事,但更多的时候是最后又打起了退堂鼓。嫌恶过自己的怯懦,最终却发现有很多缘分,有很多错过,好像冥冥之中真的已经注定。那些曾经所谓的非做不可,只是青葱年华里自己给自己注射的一支强心剂,或者说,是自以为是的精神寄托罢了。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
33、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.此刻,天空是阴暗的,空气里有着刚下过雨之后的清新因子。突然想到那件蓝格子衬衫;那些被折成各种各样形状的信纸;那段从街角深巷伊始的友谊;还有那场还没有开始就宣告了终结的邂逅
34、计划那些年那些天的非做不可,终于和青春一样,都将在我们的人生中谢幕。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 m