《毕业论文基于单片机的出租车计价系统设计32123.doc》由会员分享,可在线阅读,更多相关《毕业论文基于单片机的出租车计价系统设计32123.doc(19页珍藏版)》请在三一办公上搜索。
1、基于单片机的出租车计价系统设计1 设计目的,要求和设计方法1.1设计目的(1) 学习基本理论在实践中综合运用的初步经验,掌握电路设计的基本方法、设计步骤,培养综合设计与调适能力,进一步提高综合运用所学知识和设计能力的的目的。(2) 掌握C语言程序设计方法。(3) 培养实践技能,提高分析和解决实际问题的能力,并具备一定程度的设计能力。1.2基本设计要求本出租车自动计费,上电后显示最初的起步价,里程计费单价,等待时间计费单价,通过按键可以调节起步价,里程计费单价,等待时间计费单价。同时具有运行,等待,暂停等状态,可以显示暂停的时间。出租车停止后能够显示行驶的总费用。1.3性能指标 1、费用的计算是
2、按行驶里程收费。设起步价为7.00元。2、当里程3km时,每公里按1.7元计费。4、等待累计时间2min时,按1.5元/min计费。1.4显示功能1、显示行驶里程:用两位数字显示,显示方式为“XX”,单位为km。计程范围0-99km,精确到1km。2、显示等候时间:用两位数字显示,显示方式为“XX”,单位为min。计时范围0-59min,精确到1min。3、显示总费用:用四位数字显示,显示方式为“XXX.X”,单位为元。计价范围0-999.9元,精确到0.1元。1.3 设计方法 本设计采用AT89C51单片机为主控器,并用开关或者频率信号发生器模拟车速,利用AT89C51的定时器工作在方式1下
3、定时实现对出租车的计时及计价设计,输出采用LCD液晶显示屏显示。2 设计方案及原理2.1 设计方案本设计,利用单片机丰富的端口和控制的灵活性,采用AT89C51单片机为主控器,并用开关或频率信号发生器模拟车速,通过石英振荡器,LCD液晶显示和发光二级管以及单片机内部程序构成完整的出租车计价系统,基本可以实现了按运行状态计价的功能,价格调整功能。2.2 设计原理出租车计价是根据车所行驶的路程以及乘客乘车的里程综合决定的。出租车行驶总路程可以通过车轮的周长乘车轮旋转圈数得到。即可计算得到车轮旋转几周出租车能行驶一公里的路程。通过计数接收到的脉冲个数,计算出当前所行驶的路程。同时,通过LCD液晶显示
4、器显示当前的行驶里程、等待时间和需支付的车费。出租车计价器用于记录里程、起步公里数与价格的关系。模拟出租车计价器能根据总里程数、起步公里数的情况作出相应报价等。3 出租车计价器系统的硬件设计3.1 出租车硬件框图图2-1系统的硬件框图3.2 出租车计价器硬件连接图AT89C51的最小系统:时钟电路是单片机内部有一个高增益反相放大器,其输入端为芯片引脚XTAL1,其输出端为引脚XTAL2。通过这两个引脚在芯片外并接石英晶体振荡器和两只电容(电容和一般取30pF)。这样就构成一个稳定的自激振荡器。复位操作是按键复位,按键复位具有上电复位功能外,若要复位,只要按图中的RESET键,电源VCC经电阻R
5、1、R2分压,在RESET端产生一个复位高电平。AT89C51的最小系统硬件图如图3.2(a)所示。图3.2(a) AT89C51的最小系统硬件图液晶显示和LED灯指示电路:显示电路对于现实电路我们采用液晶显示,液晶又分字符型和点阵型,我们使用的液晶是字符型液晶,并且带字符库的,不需要查找代码,英文字符就可以。运行状态指示电路采用发光二级管对运行方式进行指示,可清楚看到计价器的运行状态。液晶显示和LED灯指示电路如图3.2(b)所示。图3.2(b) 液晶显示和LED灯指示电路 按键电路:按键电路是通过按键去调节初始选择、调节,模式选择,开始运行,终止等功能。霍尔传感器里程计算是通过安装在车轮旁
6、的霍尔传感器检测到的信号,送到单片机,经处理计算,送给显示单元的。而由于本次实验室的局限不能利用霍尔传感器,所以我们利用按键来代替霍尔传感器,通过按一次键代表汽车行驶了1公里,当在行驶过程中通过按键来选择运行状态。按键电路如图3.2(c)所示。图3.2(c) 按键电路4 出租车计价器系统的软件设计4.1系统流程图出租车计价器系统流程图如附录1所示。4.2源程序代码 根据设计的要求,在本系统中主要有主程序和延时程序,主程序中包括中断服务程序和键盘显示子程序、计算子程序等。现在应用更广泛的是单片机C语言,因其简单明了,故此次课程设计采用单片机C语言编程。程序源代码如附录2所示。4.3程序调试域运行
7、结果在Keil C51 uvision4中对系统建立项目,选定合适的单片机AT89C51,创建一个计价器的新文件,并将上述的源程序进行编辑和选项操作进行编译,以生成计价器的HEX文件。5 系统仿真及实际调试5.1运行图示仿真开始后,首先按动初始选择按钮, 则可以在运行单价,等待单价,起步价之间切换,每按一次切换一个量,选定后可以按动初始调节按钮进行调节,调节完成后,按下开始运行按钮则开始运行,选择运行模式后开始计费,不同的运行模式会有不同的指示灯亮起,在运行过程中液晶屏会随时显示走过的路程和等待的时间,以及总的费用。仿真图如附录3所示。5.2仿真问题分析问题需要改进,例如本设计经过多次的调试与
8、改正,最终达到了设计方案中的结果。在仿真试验中各种设计要求都能够得到验证。但由于设计的原因,本系统仍然总在一些自动化程度不够,运行模式还需要手动选择。6 总结出租车计费器系统的设计已经全部完成,能利用AT89C51单片机对出租车启动,停止,暂停等运行状态进行选择和显示,能将单价和费用适时通过LCD显示出来。本款出租车计价器包括单价输出、单价调整、显示当前的总费用等功能。虽然达到了基本的设计目的,但仍然存在一些问题,策划的不够全面,对单片机不够熟悉,系统编写不够简洁完善,使得计价器计费不够细致,不够人性化。经过这次课程设计让我学会了很多的东西。经过自己努力,基本上完成了设计要求的内容,在系统可行
9、性分析、原理图设计等方面都作了一些实际工作,同时也遇到了一些问题,存在一些不足。学会了怎么去查找些资料,把所找到的东西与自己的问题所结合起来并给予解决。这次设计使我学会把以前学到的理论知识应用于实践,使我认识到理论知识与实践之间有一定的差距,只有通过不断的努力学习和实践才能很好的把理论知识应用到实践当中,也只有通过不断的实践才能加深对理论知识的理解。 参考文献1 王思明,张金敏,张鑫等.单片机原理及应用系统设计.北京:科学出版社,20122 张金敏,董海棠,高博等.单片机原理与应用系统设计.成都:西南交通大学出版社, 20103 李华,王思明,张金敏.单片机原理及应用.兰州:兰州大学出版社,2
10、001附录1附录2 #include#define uchar unsigned char#define uint unsigned int /*定义1602读写使能端口*/sbit rw=P21;sbit rs=P20;sbit en=P22;sbit b=P07;sbit gl=P10;void lcd_init(); /lcd设置函数void wr_com(uchar command); /命令函数void wr_data(uchar data0); /数据函数void lcd_clear(); /清屏函数void lcd_set(); /屏幕设置函数void busy(); /测忙函数
11、void display(); /启动前显示函数void printstring(uchar *s);void display1(); /启动后显示函数void key1();/启动前按键sbit K=P30;sbit K1=P31;sbit K2=P35; /开始计价sbit K3=P33; /模式选择(行程/等待)sbit K4=P34;/复位sbit g=P27; sbit aa=P23; /运行sbit bb=P24; /等待sbit cc=P25; /暂停/sbit led_run=P30;/sbit led_await=P31;/sbit led_stop=P32;bit f_st
12、art;bit jump_in;bit jump_out;void key(); /启动后按键/*定义液晶显示地址数组*/uchar code table=0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x70;uchar dispbuf=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;uchar dispbuf1=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;uchar v,v1; uchar i,m=0;void init();void chuli();void chuli1();void delay(ucha
13、r t); /延时函数void clear(); /终止函数void set(uchar x);void set1(uchar y); uchar command;uchar count,count1;uchar second,minite,second1,minite1;unsigned int tt,tt1;unsigned char value1=70,value2=17,value3=15; /value1=起步价,value2=超出每公里价格,value3=等待价格unsigned int money; void main()/ Init_Timer1();/定时器中断函数 EX0=
14、1;/开外部中断0 IT0=1;/采用跳变沿触发方式 init(); lcd_init(); while(1) key1();chuli(); display(); if(jump_in=1) jump_in=0; lcd_init(); while(1) key(); chuli1(); display1(); if(jump_out=1) lcd_init(); jump_out=0; clear(); break; void clear() TR0=0; TR1=0; money=0; second=0; second1=0; minite=0; minite1=0; value1=70
15、; value2=17; value3=15; / led_run=1; /led_await=1; / led_stop=1; v=0; v1=0; for(i=0;i15;i+) dispbufi=0; dispbuf1i=0; m=0;void init()/中断定时 TMOD=0x11; TH0=(65536-50000)/256; TL0=(65536-50000)%256; TH1=(65536-50000)/256; TL1=(65536-50000)%256; ET0=1; ET1=1; EA=1; TR0=0; TR1=0;void t0_(void) interrupt 1
16、 using 0 /中断1模式0 用来计时 秒、分 count+; if(count=20) count=0; second+; if(second=60) second=0;minite+;if(minite=99) minite=0; TH0=(65536-50000)/256; TL0=(65536-50000)%256; dispbuf10=m/10; dispbuf11=m%10; dispbuf12=second/10; dispbuf13=second%10;void t1_(void) interrupt 3 using 3 /中断3模式3用来计时 秒、分 count1+; i
17、f(count1=20) count1=0; second1+; if(second1=60) second1=0;minite1+;if(minite1=99) minite1=0; TH1=(65536-50000)/256; TL1=(65536-50000)%256; dispbuf14=minite1/10; dispbuf15=minite1%10; dispbuf16=second1/10; dispbuf17=second1%10; void lcd_init() wr_com(0x3c); wr_com(0x06); wr_com(0x0c); wr_com(0x01);vo
18、id wr_com(uchar command) /命令 busy(); rs=0; rw=0; P0=command; en=1; en=0;void wr_data(uchar data0) /数据 busy(); rs=1; rw=0; P0=data0; en=1; en=0;void busy() /测忙函数 while(1) en=0; rs=0; rw=1; P0=0xff; en=1; if(b!=1)break; en=0;void chuli() /分离出百位十位个位 dispbuf0=value1/100%10; dispbuf1=value1/10%10; dispbu
19、f2=value1%10; dispbuf3=value2/100%10; dispbuf4=value2/10%10; dispbuf5=value2%10; dispbuf6=value3/100%10; dispbuf7=value3/10%10; dispbuf8=value3%10;void display() /初始显示函数 set(0); printstring(step :); wr_data(tabledispbuf0); wr_data(tabledispbuf1); printstring(.); wr_data(tabledispbuf2); set(16); prin
20、tstring(mileage :); wr_data(tabledispbuf3); wr_data(tabledispbuf4); printstring(.); wr_data(tabledispbuf5); set1(0); printstring(await :); wr_data(tabledispbuf6); wr_data(tabledispbuf7); printstring(.); wr_data(tabledispbuf8); set1(16); printstring(run : ); wr_data(tabledispbuf10); wr_data(tabledisp
21、buf11); printstring(:); wr_data(tabledispbuf12); wr_data(tabledispbuf13);void chuli1() if(f_start=1) tt=minite*60+second; tt1=minite1; if(m3) money=value1+value2*(m-3)+value3*tt1; else if(f_start=0) money=0; dispbuf18=money/100%10; dispbuf19=money/10%10; dispbuf110=money%10;void display1() /运行后显示函数
22、set(0); printstring(run: );/ wr_data(tablem);wr_data(tabledispbuf10);wr_data(tabledispbuf11);/ printstring(:);/ wr_data(tabledispbuf12);/ wr_data(tabledispbuf13); set(14); printstring(await:); wr_data(tabledispbuf14); wr_data(tabledispbuf15); printstring(:); wr_data(tabledispbuf16); wr_data(tabledis
23、pbuf17); set1(0); printstring(sum is: ); wr_data(tabledispbuf18); wr_data(tabledispbuf19); printstring(.); wr_data(tabledispbuf110);void printstring(uchar *s) /输出显示函数 while(*s) wr_data(*s+); void key() /启动按键 if(K3=0) delay(50); /延时消抖动.if(K3=0) while(K3=0); v1+; if(v1=4) v1=1; switch(v1) case 1:f_sta
24、rt=1;TR0=1;TR1=0;/*led_run=0;led_await=1;led_stop=1*/;aa=0;bb=1;cc=1;break; /运行case 2:TR0=0;TR1=1;/*led_run=1;led_await=0;led_stop=1*/;aa=1;bb=0;cc=1;break; /等待case 3:TR0=0;TR1=0;/*led_run=1;led_await=1;led_stop=0*/;aa=1;bb=1;cc=0;break;/暂停 if(K4=0) /跳出运行 delay(50); if(K4=0) while(K4=0); jump_out=1;
25、 void delay(uchar t) while(-t);void set(uchar x) command=0x80+x; wr_com(command);void set1(uchar y) command=0xc0+y; wr_com(command);void key1() /初始调节按键 if(K=0) delay(100); if(K=0) while(K=0); v+; if(v=4) v=0; switch(v) case0:break; case 1:if(K1=0)while(K1=0);value1=value1+10;break; case2:if(K1=0)whi
26、le(K1=0);value2=value2+5;break; case 3:if(K1=0)while(K1=0);value3=value3+5;break; if(K2=0) delay(50); if(K2=0) while(K2=0); jump_in=1; void mode( ) interrupt 0 /外部中断0控制选位 m+;附录3 Emloyment tribunals sort out disagreements between employers and employees. You may need to make a claim to an employment
27、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 informu, take advice from one of the organisations listed underFurther help. Employment tribunals are less formal tha
28、n 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
29、of the organisations listed underFurther help. ation 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 redu
30、ce 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 t
31、ribunal will not usually accept i. If you are worried about how the time limits apply to you 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 agreem
32、ent. In England and Wales, your solicitor cant charge you more than 35% of your compensation if you win the case.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 tho
33、se 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 m Cay man Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th ann
34、iversary 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 Ya ya 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
35、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
36、 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 dis
37、illusionment, 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.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些
38、天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。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 tha
39、t 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 t
40、o 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 h
41、is appearance.童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后,自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要了;然后到了高中,觉得非要吐露出自己的心声才能为高中生涯里的懵懂情愫划上一个句点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场,看着他投过篮球的球框时,突然间发现自己已经想不起他的容颜。Originally, this world, can produce a chemical reaction to an e
42、vent, 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 m