《1954416311毕业设计基于单片机AT89C51电子抢答器设计.doc》由会员分享,可在线阅读,更多相关《1954416311毕业设计基于单片机AT89C51电子抢答器设计.doc(19页珍藏版)》请在三一办公上搜索。
1、单片机AT89C51电子抢答器设计 1.系统说明:给主持人设置一个开关,用来控制系统的清零(编号显示数码管灭灯)和抢答器的开始。抢答器具有数据锁存和显示的功能。抢答开始后,若有选手按动抢答器按钮,编号立即锁存,并在LED数码上显示选手的编号,同时扬声器给出音响提示。此外,要封锁输入电路,禁止其他选手抢答。2.硬件电路设计:总体设计图3-1 总体设计如图P3.0为开始抢答,P3.2为停止,P1.0-P1.7为八路抢答输入,数码管段选P0口,位选P2口低3位,蜂鸣器(用绿灯代替)输出为P3.6口。P3.2为时间加1调整,P3.3为时间减1调整。P3.0为开始抢答,P3.1为停止,P1.0-P1.7
2、为八路抢答输入,数码管段选P0口,位选P2的低三位口。(1)外部振荡电路:一般选用石英晶体振荡器。此电路在加电大约延迟10ms后振荡器起振,在XTAL2引脚产生幅度为3V左右的正弦波时钟信号,其振荡频率主要由石英晶振的频率确定。电路中两个电容 C1,C2的作用有两个:一是帮助振荡器起振;二是对振荡器的频率进行微调。C1,C2的典型值为30PF。(2)复位电路的设计:单片机的第9脚RST为硬件复位端,只要将该端持续4个机器周期的高电平即可实现复位,复位后单片机的各状态都恢复到初始化状态,其电路图所示:在方案中使用到了硬件复位和软件复位两种功能,由上面的硬件复位可使寄存器及存储器的值都恢复到初始值
3、,而前面的功能提到了倒计时间需要有记忆功能,该功能实现的前提条件就是不能对单片机进行硬件复位,所以设定了软复位功能。软复位实际上就是当程序执行完毕之后,将程序指针通过一条跳转指令让它跳转到程序执行的起始地址。(3)按钮输入电路的设计:抢答器的输入按钮使用常开开关,这些常开开关组成了抢答按键,硬件电路简单,在程序设计上也不复杂,只要在程序中消除在按键过程中产生的“毛刺” 现象就可以了。这里采用最常用的方法即延时法,其的原理为:因为“毛刺”脉冲一般持续时间短,约为几ms,而按键的时间一般远远大于这个时间,所以当单片机检测到有按键动静后再延时一段时间(这里取10ms)后再判断此电平是否保持原状态,如
4、果是则为有效按键,否则无效。(4)发声:这里能利用程序来控制单片机P3.6口线反复输出高电平或低电平,即在该口线上产生一定频率的矩形波,接上扬声器就能发出一定频率的声音,再利用延时程序控制“高”“低”电平的持续时间,就能改变输出频率,从而改变音调,使扬声器发出不同的声音。3.软件部分:(1)程序系统结构图:硬件电路确定后,软件的编程要与硬件相匹配,软硬件才能结合完成所要实现的功能。由功能分析得到以下的软件结构图:系统初始化模块按键模块正确抢答模块非法抢答模块调整时间模块显示模块程序流程图整个程序主要由定时器T0、定时器T1、外部中断0和主程序构成。定时器T0用于使扬声器发声,当需要响铃时,把响
5、铃标志位置一,每次中断都对P3.7取反,扬声器发声,改变定时器初值,可改变扬声器频率。定时器程流程图如下:P3.7取反定时器重新赋值返回主函数响铃标志为1?NY定时器T1用于倒计时,每次中断为50ms,当计数标志为20时即为一秒,显示数字减1。其流程图如下:返回主函数计时标志加一计数器重新赋值外部中断0用于调整倒计时时间,流程图如下:显示时间R1R1减1返回主函数R1置0R1增1R1置99加1键按下?减1键按下?R1到0?R1到99?返回键按下?YNYYYNNNNY 主程序协调三个中断一起工作,实现抢答功能,其流程图如下:按键发声显示抢答号,剩余时间停止键按下?抢答键按下?停止键按下?开始键按
6、下?程序初始化倒计时显示倒计时开始按键发声准备状态,显示FFF倒计时大于5s?显示法规号码按键发声非法抢答?停止键按下?提醒发声倒计时结束?YNNYNNNNNYYYYY(2)程序代码: ORG 0000H AJMP MAIN ORG 0003H AJMP INT0SUB ORG 000BH AJMP T0INT ORG 001BH AJMP T1INTOK EQU 20H ; 抢答开始标志位RING EQU 22H ; 响铃标志位 ORG 0040HMAIN: MOV R1,#0FH; 初设抢答时间为15s MOV R2,#0AH; 初设答题时间为10s MOV TMOD,#11H; 设置未定
7、时器/模式1 MOV TH0,#0F0H MOV TL0,#0FFH; 越高发声频率越高,越尖 MOV TH1,#3CH MOV TL1,#0B0H; 50ms为一次溢出中断 SETB EA SETB ET0 SETB ET1 SETB EX0 SETB EX1; 允许四个中断,T0/T1/INT0/INT1 CLR OK CLR RING SETB TR1 SETB TR0; 一开始就运行定时器,以开始显示FFF.如果想重新计数,重置TH1/TL1就可以了查询程序:START: MOV R5,#0BH MOV R4,#0BH MOV R3,#0BH ACALL DISPLAY; 未开始抢答时
8、候显示FFF JB P3.0,NEXT ACALL DELAY JB P3.0,NEXT;去抖动,如果开始键按下就向下执行,否者跳到非法抢答查询 ACALL BARK;按键发声 MOV A,R1 MOV R6,A; 送R1-R6,因为R1中保存了抢答时间 SETB OK; 抢答标志位,用于COUNT只程序中判断是否查询抢答 MOV R3,#0AH; 抢答只显示计时,灭号数 AJMP COUNT;进入倒计时程序,查询有效抢答的程序在COUNT里面NEXT: JNB P1.0,FALSE1 JNB P1.1,FALSE2 JNB P1.2,FALSE3 JNB P1.3,FALSE4 JNB P1
9、.4,FALSE5 JNB P1.5,FALSE6 JNB P1.6,FALSE7JNB P1.7,FALSE8 AJMP START非法抢答处理程序:FALSE1: ACALL BARK; 按键发声 MOV R3,#01H AJMP ERRORFALSE2: ACALL BARK MOV R3,#02H AJMP ERRORFALSE3: ACALL BARK MOV R3,#03H AJMP ERRORFALSE4: ACALL BARK MOV R3,#04H AJMP ERRORFALSE5: ACALL BARK MOV R3,#05H AJMP ERRORFALSE6: ACALL
10、 BARK MOV R3,#06H AJMP ERRORFALSE7: ACALL BARK MOV R3,#07H AJMP ERRORFALSE8: ACALL BARK MOV R3,#08H AJMP ERROR倒计时程序(包括有效抢答程序): COUNT: MOV R0,#00H; 重置定时器中断次数 MOV TH1,#3CH MOV TL1,#0B0H; 重置定时器RECOUNT: MOV A,R6; R6保存了倒计时的时间 MOV B,#0AH DIV AB; 除十分出个位/十位 MOV 30H,A; 十位存于(30H) MOV 31H,B; 个位存于(31H) MOV R5,3
11、0H ; 取十位 MOV R4,31H ; 取个位 MOV A,R6 CLR C SUBB A,#07H JNC LARGER ;大于5s跳到LARGER,小于等于5s会提醒 MOV A,R0 CJNE A,#0AH,FULL;1s中0.5s向下运行 CLR RING AJMP CHECKFULL: CJNE A,#14H,CHECK ; 1s时,响并显示号数并清R0,重新计时 SETB RING MOV A,R6 JZ QUIT ; 计时完毕 MOV R0,#00H DEC R6 ; 一秒标志减1 AJMP CHECKLARGER: MOV A,R0 CJNE A,#14H,CHECK ;
12、如果1s向下运行,否者跳到查停/显示 DEC R6; 计时一秒R6自动减1 MOV R0,#00HCHECK: JNB P3.1,QUIT; 如按下停止键退出 ACALL DISPLAY JNB P1.0,TRUE1 JNB P1.1,TRUE2 JNB P1.2,TRUE3 JNB P1.3,TRUE4 JNB P1.4,TRUE5 JNB P1.5,TRUE6 JNB P1.6,TRUE7 JNB P1.7,TRUE8 AJMP RECOUNTQUIT: CLR OK ; 如果按下了停止键重新回到开始 CLR RING ACALL BARK AJMP START正常抢答处理程序:TRUE1
13、: ACALL BARK; 按键发声 MOV A,R2 MOV R6,A; 抢答时间R2送R6 MOV R3,#01H CLR OK; AJMP LOOP2TRUE2:ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#02H CLR OK AJMP LOOP2TRUE3:ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#03H CLR OK AJMP LOOP2TRUE4:ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#04H CLR OK AJMP LOOP2TRUE5: ACALL BARK; MOV A,R2
14、 MOV R6,A MOV R3,#05H CLR OK AJMP LOOP2TRUE6: ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#06H CLR OK AJMP LOOP2TRUE7: ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#07H CLR OK AJMP LOOP2TRUE8: ACALL BARK; MOV A,R2 MOV R6,A MOV R3,#08H CLR OKLOOP2: AJMP DISPLAY ;抢答后停止计时,等待返回SETB RING JNB P3.1 QUIT AJMP LOOP2犯规抢答程序:
15、ERROR: SETB RING ;犯规响铃 MOV R5,#0BH MOV R4,#0BH; 显示FF和犯规号数LOOP3: ACALL DISPLAY JNB P3.1 QUIT1; 等待“停止”键按下 AJMP LOOP3 QUIT1: CLR RING CLR OK AJMP START显示程序:DISPLAY:MOV DPTR,#DAT1; 查表显示程序,利用P0口做段选码口输出/P2低三位做位选码输出 MOV A,R5 MOVC A,A+DPTR MOV P2,#01H MOV P0,A ACALL DELAY MOV DPTR,#DAT2 MOV A,R4 MOVC A,A+DP
16、TR MOV P2,#02H MOV P0,A ACALL DELAY MOV A,R3 MOVC A,A+DPTR MOV P2,#04H MOV P0,A ACALL DELAY RETDAT1:DB 00H,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh,00H,71H;灭,1,2,3,4,5,6,7,8,9,灭,FDAT2:DB 3FH, 06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh,00H,71HDELAY1: MOV 35H,#08HLOOP0: ACALL DISPLAY DJNZ 35H,LOOP0 RET延时(显示和去抖动用到
17、):DELAY: MOV 32H,#12HLOOP: MOV 33H,#0AFHLOOP1: DJNZ 33H,LOOP1 DJNZ 32H,LOOP RET发声程序:BARK: SETB RING ACALL DELAY1 ACALL DELAY1 CLR RING; 按键发声 RETINT0(抢答时间R1调整程序): INT0SUB:MOV A,R1 MOV B,#0AH DIV AB MOV R5,A MOV R4,B MOV R3,#0AH ACALL DISPLAY;先在两个时间LED上显示R1 JNB P3.2,INC0; P3.2为+1s键,如按下跳到INCO JNB P3.3,
18、DEC0; P3.3为-1s键,如按下跳到DECO JNB P3.4,BACK0; P3.4为确定键,如按下跳到BACKO AJMP INT0SUBINC0: MOV A,R1 CJNE A,#63H,ADD0; 如果不是99,R2加1,如果加到99了,R1就置0,重新加起 MOV R1,#00H ACALL DELAY1 AJMP INT0SUBADD0: INC R1 ACALL DELAY1 AJMP INT0SUBDEC0: MOV A,R1 JZ SETR1;如果R1为0, R1就置99, DEC R1 ACALL DELAY1 AJMP INT0SUBSETR1: MOV R1,#
19、63H ACALL DELAY1 AJMP INT0SUBBACK0: RETITO溢出中断(响铃程序):T0INT:MOV TH0,#0ECH MOV TL0,#0FFH JNB RING,OUT CPL P3.6 ; RING标志位为1时候P3.6口不短取反使喇叭发出一定频率的声音OUT: RETIT1溢出中断(计时程序):T1INT: MOV TH1,#3CH MOV TL1,#0B0H INC R0 RETI END4.调试与运行:1.调试:把编写好的程序放入仿真软件中,结合硬件电路进行调试与运行。(1)在仿真软件中按下开始按钮,从而达到仿真的目的; (2)LED显示器显示当前0030
20、初始化;(3)按照本次实际任务要求,逐个调试功能是否能实现。正常抢答过程调试:当主持人按下“开始”键后,允许选手抢答,进入正常抢答流程。若在倒计时时间内有选手抢答,则显示管显示抢答成功的选手编号和答题时间倒计时。若无选手在抢答倒计时时间内抢答,则自动跳回系统开始部分。在选手正常抢答后,如果选手回答成功。则有主持人按下“结束”键,结束本次抢答,系统跳回开始部分。如果选手在答题倒计时内,未能成功回答,则系统自动跳回开始部分。违规抢答过程调试 :在主持人未按下“开始”键时有选手进行抢答则会进入违规抢答流程。显示管闪烁显示违规选手编号并伴有蜂鸣器报警声。当主持人按下“结束”键后系统跳回开始部分。时间控
21、制功能调试:在系统开始工作后按下“抢答(回答)时间控制”键后即可通过“加一“或”减一“键进行时间控制如图5.10所示抢答时间由20s被修改为22s。2.结果:在运行过程中,设计能够满足抢答时间正确显示,违规抢答显示。倒计时显示的功能,程序功能运行良好。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 a
22、gree 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 haventappealedagai
23、nst 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
24、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
25、 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
26、 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
27、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 Citize
28、ns 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 taskforc
29、e, 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 fir
30、st 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 w
31、ere 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
32、 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.一字开头的年龄已经到了尾声。或许是愧疚于自己
33、似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。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
34、 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 import
35、ant; 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 h
36、oops, suddenly found himself has already cant remember his appearance.童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后,自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要了;然后到了高中,觉得非要吐露出自己的心声才能为高中生涯里的懵懂情愫划上一个句点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场,看着他投过篮球的球框时,突然间发现自己已经想不起他的容颜。Origina
37、lly, 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
38、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.一个人的时候,自己的想法总
39、是特别地清晰。想要的,不想要的,界限明确,好像没有什么可以撼动自己。也曾经好像已经下定了决心去做某件事,但更多的时候是最后又打起了退堂鼓。嫌恶过自己的怯懦,最终却发现有很多缘分,有很多错过,好像冥冥之中真的已经注定。那些曾经所谓的非做不可,只是青葱年华里自己给自己注射的一支强心剂,或者说,是自以为是的精神寄托罢了。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 variou
40、s 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, wi