C语言出租车计价器课程设计报告书

合集下载

出租车计价器专业课程设计报告(含代码)

出租车计价器专业课程设计报告(含代码)

摘要随着社会的发展,出租车是人们生活中非常方便且较普遍的交通工具,出租车计价器的使用日益完善,现在我们引用单片机技术,使用编码和解码信息传递这种方式来完成计价器计数脉冲的形成;单片机可以很精确地检测到传感器信号。

用较少的硬件和适当的软件相互配合可以很容易的实现设计要求,且灵活性强,可以通过软件编程来完成更多的附加功能,本课程设计采用89C51的定时器T0产生的时钟,通过HD8255键盘显示电路用来显示行驶路程和价格及对计价的控制等从而实现了一个小型计价器系统。

关键字:计价器、单片机、89C51、HD8255目录一、设计要求 (1)1.1、基本要求: (3)1.2、要求分析: (3)二、系统组成及工作原理 (3)2.1系统的硬件构成及功能 (3)2.2 AT89S51单片机及其引脚说明 (4)2.3 AT24C01存储单元 (5)2.4系统工作原理 (5)三、方案设计对比 (6)3.1方案一: (6)3.2方案二: (6)3.3方案选择 (7)四、软件设计 (7)4.1系统主程序分析 (7)4.2计算程序 (8)4.3中途等待中断程序 (8)五、实验调试分析与结果 (9)5.1 实验调试 (9)5.2实验结果 (9)六、结论 (10)参考文献 (11)附录一: (12)一、设计要求1.1、基本要求:里程显示为:***.**公里;能预置起步价及单价:如起步3公里6.00元;1.60/公里;1.2、要求分析:1)起步价:乘客上车,显示起步价(6元),行车距离在3公里以内。

2)里程计价:(计价单位为元,并进行四舍五入)a.行车里程 < 3公里时,计价为6元;b.3公里≤行车里程时,计价为:6元+(里程-3)*1.6元/公里二、系统组成及工作原理2.1系统的硬件构成及功能本次设计主要有四个部分模块电组成,脉冲源产生脉冲提供给单片机,用来计算行驶路程,变换电路用来对产生的脉冲进行整形放大,单片机电路则控制整个系统的运行,8255键盘显示电路用来显示行驶路程和价格及对计价的控制。

基于C语言的出租车计价器程序设计

基于C语言的出租车计价器程序设计

目录1 前言 (3)2 系统设计方案 (4)2.1 系统的设计需求 (4)2.2 系统的工作原理 (4)3 系统硬件设计 (5)3.1 单片机介绍 (5)3.2 硬件组成 (8)4 系统软件设计 (12)5 仿真调试 (14)6 结论 (16)7 参考文献 (178)8 心得体会及致谢 (20)附录A 设计总图 (224)附录B 源程序 (235)1 前言随着生活水平的提高,人们已不再满足于衣食住的享受,出行的舒适已受到越来越多人的关注[1]。

相对于公共汽车拥挤与缓慢以及私家车高昂的费用,出租车无疑是一种低价高质的出行交通工具。

近年来越来越多的人为了出行方便舒适愿意选择使用出租车,出租车行业得以快速发展[2]。

出租车计价器是出租车营运收费的专用智能化仪表,随着电子技术的发展,出租车计价器的技术在不断进步和提高[3]。

最初的计价器计费模式较为单一,不便于在不同的运营环境下选取不同的计费模式。

考虑到出租车行驶可能会出现从市区行驶到郊区或者行驶到偏僻地区,郊区或偏僻区打车的人少的现象,司机空车行驶返回成本较高,这时需要乘客为空车返回的路程承担一定的费用,这就需要区分单程/往返不同计价模式。

“单程”模式是指目的地在郊区或者比较偏僻的地方,到达目的地后打车的人比较少,需要乘客乘客承担一定的空车返回的费用;“往返”模式是指目的地在市区,到达目的地后还会有乘客乘车返回,这种情况下司机不需要空车返回,乘客不需要承担回程费用。

考虑到夜晚时出租车的灯光需要消耗能源以及司机夜间服务比白天较为辛苦,所以一般夜晚出租车的价格需要比白天高一点。

早期的出租车计价器均采用模拟电路和数字电路设计。

计价器整体电路的规模较大,需要器件多,容易出故障,难调试。

和模拟电路和数字电路设计相比而言,基于单片机进行设计的计价器,用较少的硬件和适当的软件相互配合就可以很容易的实现设计需求,硬件电路简单,稳定性好,灵活性强[4],通过软件编程就可以实现计费模式的切换。

C语言出租车计价器课程设计

C语言出租车计价器课程设计
图3 A44E霍尔传感器原理
里程计算是通过安装在车轮上的霍尔传感器检测到的脉冲信号,送到单片机产生中断,单片机再根据程序设定,计算出里程。其原理如图4所示。
图4传感器测距示意图
本系统选择了将A44E的脉冲输出口接到P3.3口外部中断1作为信号的输入端(这样可以减少程序设计的麻烦),车轮每转一圈(设车轮的周长是1米),霍尔开关就检测并输出信号,引起单片机的中断,对脉冲计数,当计数达到1000次时,即1公里,单片机就控制将金额自动增加,如图5。
图2单片机最小系统图
AT89S52的复位端是一个史密特触发输入,高电平有效。RST端若由低电平上升到高电平并持续2个周期,系统将实现一次复位操作。在复位电路中,按一下复位开关就使在RST端出现一段时间的高电平,外接11.0592M晶振和两个30pF电容组成系统的内部时钟电路。
2.2 A44E霍尔传感器检测单元
A44E属于开关型的霍尔器件,其工作电压范围比较宽(4.5~18V),其输出的信号符合TTL电平标,可以直接接到单片机的IO端口上,而且其最高检测频率可达到1MHZ。
A44E集成霍耳开关由稳压器A、霍耳电势发生器(即硅霍耳片)B、差分放大器C、施密特触发器D和OC门输出E五个基本部分组成。
在输入端输入电压Vcc,经稳压器稳压后加在霍尔电势发生器的两端,根据霍尔效应原理,当霍尔片处在磁场中时,在垂直于磁场的方向通以电流,则与这二者相垂直的方向上将会产生霍尔电势差VH输出,该VH信号经放大器放大后送至施密特触发器整形,使其成为方波输送到OC门输出。当施加的磁场达到工作点(即Bop)时,触发器输出高电压(相对于地电位),使三极管导通,此时OC门输出端输出低电压,三极管截止,使OC门输出高电压,这种状态为关。这样两次电压变换,使霍尔开关完成了一次开关动作。A44E霍尔传感器原理如图3所示。

c语言出租车计费

c语言出租车计费

c语言出租车计费c语言出租车计费已知某城市普通出租车收费标准为:起步里程为3公里,起步费为8元,10公里以内超过起步里程的部分,每公里加收2元,超过10公里以上的部分加收50%的回空补贴费,即每公里3元。

出租车营运过程中,因堵车和乘客要求临时停车等客的,按每5分钟加收2元计算,不足5分钟的不计费。

从键盘任意输入行驶里程(精确到0.1公里)和等待时间(精确到分钟),请编程计算并输出乘客应支付的车费,对结果进行四舍五入,精确到元。

输入提示信息:"Input distance and time:"输入格式:用逗号分隔的两个数字,第一个表示距离、第二个表示时间:"%f,%d"输出格式:"fee = %.0f\n" (注意:等号的两边各有一个空格)#includeint main(void){int start_money = 8, less_than_10_km_per_money = 2, beyond_10_km_extra_money = 1, wait_5_min_money = 2,real_wait_time;float start_distense = 3, real_distense ,real_money=0;printf("Input distance and time(eg.3.5,15):");scanf("%f,%d",ℜ_distense,ℜ_wait_time);real_money = start_money;real_money += real_distense > start_distense ? (real_distense - start_distense) * less_than_10_km_per_money : 0 ;real_money += real_distense > 10 ? (real_distense - 10) * beyond_10_km_extra_money : 0 ;real_money += real_wait_time / 5 > 0 ? real_wait_time / 5 *wait_5_min_money : 0 ;real_money = (int)(real_money + 0.5);printf("fee = %.0f\n",real_money);return 0;}。

出租车计价器(单片机c语言)

出租车计价器(单片机c语言)

分类号编号毕业设计题目:基于单片机的出租车计价器的设计——电子设计系别信息工程学院专业电子信息工程姓名学号2010年6月1 日学院毕业设计任务书设计题目:基于单片机的出租车计价器的设计——硬件部分专业:电子信息工程班级学号:姓名:指导教师:设计期限:2011年3月1日开始2011年6月1日结束院、系:北京信息工程学院2011年3 月1 日一、设计目的通过毕业设计使学生了解和掌握单片机应用技术;了解和掌握C语言的程序设计同硬件电路的结合;熟练运用proteus,keilC等软件的操作;了解和掌握单片机硬件电路的焊接和调试;了解和掌握掉电存储芯片AT24C02、霍尔传感器A44E、数码管、驱动芯片74LS245等外部接口芯片器件的应用。

二、主要设计内容实现出租车行驶里程和总金额的显示,预设起步价和起步公里数;实现清零、复位和掉电保护功能;实现对单价的调整。

三、重点研究问题(1)按下启动按键,显示起步里程与起步价。

(2)按模拟传感器信号的按键,显示行驶里程与总金额。

(3)按键控制清零、复位、掉电保护、调整预设单价。

(4)在软件中实现起步价,单价。

四、主要技术指标(1)数码管显示起步里程、单价,总里程、总金额。

(2)用按键控制清零、复位、掉电保护、调整预设单价。

五、设计成果要求(1)源程序通过编译、运行(2)软件烧录单片机硬件进行调试,运行(3)实现所述功能(4)电路板焊接、检测(5)最终提交软硬件、设计说明书、外文翻译、毕业设计说明书等六、其它参考文献:[1] 谭浩强.C程序设计(第二版).清华大学出版社.2003[2]潘永雄.新编单片机原理与应用.西安电子科技大学出版社.2003设计开题报告2011年3 月15日摘要现在各大中城市出租车行业都已普及自动计价器,所以计价器技术的发展已成定局。

而部分小城市尚未普及,但随着城市建设日益加快,象征着城市面貌的出租车行业也将加速发展,计价器的普及也是毫无疑问的,所以未来汽车计价器的市场还是十分有潜力的。

出租车计价器课程设计报告

出租车计价器课程设计报告

昆明理工大学信息工程与自动化学院学生实验报告(2012 —2013 学年第 2 学期)课程名称:可编程逻辑器件设计开课实验室:信自楼 2013 年4月 11日一、引言汽车计价器是乘客与司机双方的交易准则,它是出租车行业发展的重要标志,是出租车中最重要的工具。

它关系着交易双方的利益。

具有良好性能的计价器无论是对广大出租车司机朋友还是乘客来说都是很必要的。

因此,汽车计价器的研究也是十分有一个应用价值的。

我国在70年代开始出现出租车,但那时的计费系统大都是国外进口不但不够准确,价格还十分昂贵。

随着改革开放日益深入,出租车行业的发展势头已十分突出,国内各机械厂家纷纷推出国产计价器。

出租车计价器的功能从刚开始的只显示路程(需要司机自己定价,计算后四舍五入),到能够自主计费,以及现在的能够打一发票和语音提示、按时间自主变动单价等功能。

随着城市旅游业的发展,出租车行业已成为城市的窗口,象征着一个城市的文明程度。

随着出租车行业的发展,出租车已经是城市交通的重要组成部分,从加强行业管理以及减少司机与乘客的纠纷出发,具有良好性能的计价器对出租车司机和乘客来说都是很必要的。

我们设计采用8086为主控器,以A44E霍尔传感器测距,实现对出租车的多功能的计价设计,输出采用8段数码显示管。

二、总体设计方案利用8253作为定时/计数器,控制电机转速并测量电机的转数;8255作为输入输出接口,控制数码管显示启动后经过的里程数(小数点后取2位有效值)。

硬件连接说明:直流电机控制器的基础上,增加了一个电机测速电路构成。

8255的B口作为数码管的笔划码驱动;C口的低4位作为段码控制,显示实际里程,同时,也用于输出键盘的列扫描码;PC6、PC7输入行扫描码,用于识别按键,程序中仅使用了PC6行上的四个按键,其定义如下:X1:启动/停止键;X2:加速键,与X3、X4键组合使用;X3:“+”键;X4:“-”键。

A口仅使用了PA0,输出PWM脉冲信号,通过驱动芯片驱动电机,其输出电压的高低与PWM脉冲的占空比成正比。

出租车计价器课程设计报告

出租车计价器课程设计报告

Engineering Project Management(2)Course paperTitle:Specialty:Taxi meterClass:H1303Name:Han TongLi XinhaoStudent ID:13109205161310920517CATALOG一、INTRODUCTION (1)二、OVERALL DESIGN SCHEME (2)(一)、S OFTWARE AND HARDWARE FLOW CHART (4)(二)、S OURCE PROGRAM DESIGN AND HARDWARE INTRODUCTION (6)2.1 8086 minimum system module (7)2.2 Chip 8255A (8)2.3 Chip 8253 (10)2.4Programmable control chip 8259A ............. 错误!未定义书签。

(三)、P ROBLEMS ENCOUNTERED ......................... 错误!未定义书签。

三、SUMMARY AND EXPERIENCE ........................ 错误!未定义书签。

四、REFERENCE: (15)APPENDIX .......................................... 错误!未定义书签。

一、IntroductionTaximeter is both passengers and drivers of the trade standards, it is an important symbol of the development of the taxi industry, is in a taxi is the most important tool. It is related to the interests of the parties to the transaction. With good performance of the meter whether is very necessary for the majority of taxi drivers or passengers. Therefore, the automobile valuation of is an application value.Our country in the 1970s began to taxi, but then the billing system mostly imported not only accurate, price is also very expensive. With the deepening of reform and opening up, the development momentum of the taxi industry has been very prominent, the domestic machinery manufacturers have launched domestic meter. Taxi valuation functions from at the beginning of the show only away (the driver himself pricing, calculated after four homes in five), to independent billing, and now can play an invoice and a voice prompt, according to time independent changes in price function. With the development of urban tourism, the taxi industry has become the city's window, a symbol of the civilization of a city Degree.With the development of the taxi industry, the taxi is an importantpart of urban traffic, starting from strengthening the industry management and reduce disputes of driver and passenger, with good performance meter to taxi drivers and passengers are very necessary. We design the 8086 based controller, to a44e Hall sensor location, on the taxi multifunctional pricing design, the output of the 8 digital tube display. 二、Overall design schemeBy 8253 as timer / counter, motor speed and measurement of motor speed control; 8255 as input and output interface, control digital tube display after the start mileage (after the decimal point from two effective value).Hardware connection description:Based on the DC motor controller, a motor speed measurement circuit is added.B the 8255 port as digital tube stroke code driven; the low four bits of aC port as the segment code control, showing the actual mileage. At the same time, also for the keyboard output column scan code; PC6 and PC7 input line scan code for the key identification, procedure using only the PC6 four buttons, which is defined as follows:X1: start / stop button; X2: accelerator key, and X3, X4 key combination to use; X3: "+" button; X4: "-" key.A mouth only uses the PA0, the output PWM pulse signal, by driving the motor, the output voltage is proportional to the duty cycle of the PWM pulse.The number of revolutions of the motor, through the hall element transformation for pulse number, into the 8253 passage 2, counting, speed is converted to mileage, the smallest unit is 0.01 km, send the recorded CPU. The results by the digital tube display.(一)、Software and hardware flow chartMain program flowstream(二)、Interrupt routineMileage counter interrupt routineWhenever Hall sensor outputs a low level signal makes a break, when the mileage counter on the mileage pulse meter over 1000 times, enter the mileage count the interrupt service program, mileage variables plus one. The main function of the total amount also correspondingly changes.Interrupt routineIn the middle of the pending interrupt program, 1ms each generate an interrupt, the current mileage value into a variable cache, every 5 minutes will be variable cache value and current mileage values compared when stop the car, the hall sensor for 5 minutes without signal output, current mileage value cache and variable quantity of the same value, then enter the waiting time, every 5 minutes to remember a price.Display programProcedures for the use of timer 1ms per generated once interrupted, the corresponding variable set, light a digital tube display a data display, recycling within the main function, realize the dynamic scan display, also according to the afterglow of the human eye and the persistence of digital tube, you can achieve the display.Keyboard programKeyboard using the way of inquiry, in the main program, when no key is pressed, the cycle of the main program, once the right button is pressed, they turn to the corresponding subroutine to deal with the end of the treatment to return.2.1 8086Minimum system module1、8086CPU constitute the system block diagram:2.2 Chip 8255A1、The role of 8255AIn this experiment, we use 8255A to transfer the digital quantity of analog quantity to CPU., and 8255 to control the work of ADC0809 by way of inquiry work..8086 sends control signals through 8255 to seven LED displays.2、Function analysis of 8255A8255A is parallel programming interface, can according to external conditions (I / O devices need to signal lines and it can provide the state line) to enable the various interface circuit.8255A internal three data port, namely port a, B, C a port port have three modes: mode 0, type 1 and type 2, and port B can only work in mode 0 or 1, and C usually as contact signal is used. In this experiment, the control word design 80h, initialization 8255, the port B, C as output.In three kinds of work, this design uses only mode 0, 0 is the basic input / output, in this way, three ports can by the program specified input / out of the way, but not both as input as output, did not provide a fixed contact network signal C divided into two four, four high and low four bits can be respectively arranged for input or output.3、Technical parameters of 8255A8255A pin signalSelect signal active, lowCS:Chip;A0:, address signal. A1PC JP52: port;PB JP53: port;1)Connected to a peripheral device.PA7~PA0:A port data signal line;PB7~PB0:B port data signal line;PC7~PC0:CPort data signal line;2)Connected to CPURESET: the reset signal. When this signal comes, all registers are cleared. At the same time three data ports are automatically set to the input port.D7~D0: they are connected to the 8255A data line and the system bus.CS: chip select signal. In the system, general according to all the interface chip to allocate at low address (such as the A5, A4, A3) composed of various chip select code. When the address consists of a low level, on 8255A is selected. Only when available, the signal read and write to the 8255 for reading and writing.RD: read the signal. When this signal is valid, the CPU can read data from the 8255A.WR: write a signal. When this signal is valid, CPU can write data to the 8255A.A0, A1: port selection signal.8255A has 3 data ports and 1 control ports, a total of 4 Ports:A1, A0 is 00, select the A port;A1, A0 is 01, select the B port;A1, A0 is 10, select the C port;A1, A0 11, select the control port.4、8255A mode control word8255A control word has two kinds: one is the way to select the control word, the other is the C port to press the position / reset control wordMode select control wordFigure 1 8255A control tableC port position / reset control wordchart2 8255A set / control table2.3 Chip 82531、8253 function analysisNMOS Intel8253 process is made of programmable counter / timer, there are several types of chip models, external pins and functions are compatible, but the work of the maximum count rate is different, such as 8253 (2.6MHz), 8253-5 (5MHz) Chip 8253 has three counters, were to become counter 0, counters 1 and 2, their bodies are completely the same. Input and output of each counter decided to to set in control register the control word, between each other to work completely independently. Each counter by three of the pins and the external contact and a clock CLK input and a gating signal input end of the gate, another output terminal out. Each internal counter is a 8 bits of the control register and a 16 bit count initial valueregister Cr, a count execution component CE and an output latch application Actuator is actually a 16 bit subtract counters, the initial value is the value of the initial value register, and the initial value register value is set by the program. The output latch Latch value is set by the program. The output latch ol is used to latch the count execution component Ce content, so that the CPU can be this read operation. Incidentally, Cr, CE and ol are 16 bit register, but can also for 8-bit registers to use 18253 role2、8253 pin signalCS:Chip select signal, activelow;A1, A0: address signal;2.4 programmable control chip 8259APrinciple of 8259AA piece of 8959A eight interrupt request line IR0~IR78259A by the operating system initialization, you can receive interrupt signal.8259A from the IR request line an interrupt signal, each request line a triggerto keep the request signal, so as to form the interrupt request register (IRR). At the same time, if the interrupt request signal line not be shielded, 8259A to CPU issued int signal, an interrupt request. At this time, if the CPU is in the allowed the interrupt status, the CPU will send inta signals to the 8259A enter the interrupt response time. If there is more than one letter of request , arriving at the same time, 8259A priority circuit will be priority selection for each request, the request of the highest priority in the interrupt response cycle and sent to interrupt service register (ISR) will it set, and reset the IRR of the corresponding bit. Then CPU again send a inta pulse to the 8259A, start another interrupt the corresponding period.8259A in the corresponding period to the data bus d0-d7 input an interrupt vector CPU according to the vector of X4 value can be from interrupt entry address table (IDT) remove the interruptservice program entry address into the interrupt service Procedures. While 8259A if the work in the automatic end interrupt (AEOI) mode automatically so that the corresponding bit in the ISR reset, or need to issue a EOI command to reset the ISR.In PC-XT/AT old - fashioned generally use a piece of 8259A interrupt request signal. In most modern PC, usually with two 8259A as level even. The piece is master slave, due to master an interrupt request line needs to be connected to the slave int foot, with the actual use of the external interrupt number is 15 (8 * 2 - 1).8259A structure1, data bus buffer --D7 ~ D0Data bus buffer for the three state, two-way, 8 bit registers, the data line D7 ~ D0 and CPU system bus connection, constitute the CPU and 8259A between the transmission of information channel.2, read / write control logic --WR/WDThe read / write control logic is used to receive the read / write control signal and the port address selection signal of the CPU system bus, which is used to control the read / write operation of the 8259A internal register.3, cascade buffer / comparator8259A can operate on a single, also can work in a plurality of cascade, cascade hardware connection as shown in Figure 6.10. Cascade buffer /comparator to provide multi chip 8259A management and selection function, the main chip, for the rest of the from the film.4, interrupt control logicInterrupt control logic to follow the programmed management approach to interrupt, responsible for on-chip components for sending a control signal to the and sent to a CPU interrupt request signal int and receive loopback CPU interrupt response of inta signals, control 8259A disruption into state management.5, interrupt request register (request register interrupt, IRR)IRR is an 8-bit registers, used to record the external interrupt request. Which D7 to d0 respectively and external interrupt request signal ir7 ~ ir0 corresponds, when IRi (I = 0 ~ 7) request (level or edge triggered), IRR the corresponding bit Di is set to 1, in response to interrupts inta signals effectively di is cleared.6, interrupt service register (service register interrupt, ISR)Di impulse impulse response (IRi ISR is an 8-bit registers, used to record the current CPU is service interrupt flag. When the external interrupt I = 0 ~ 7) requested by the CPU to enter service by the CPU to the first interrupt response inta ISR in the corresponding bit di (I = 0 ~ 7) is set to 1, and the ISR is restored to the throne the 8259A interrupt closing decision. If the definition for automatic closing, by the CPU of the second interrupt response inta along will reset to 0; if the definition is not automatically end, the CPU sends to the end of interrupt command in its reset .7, interrupt mask register (mask register interrupt, IMR)IMR is an 8-bit registers, used to store ir7 ~ ir0 interrupt mask flag. Its eight mask bit D7 to d0 and external interrupt request ir7 ~ ir0 corresponding, for controlling IRi request is allowed to enter. When the IMR Di bit is 1, corresponding to the IRi request forbidden; when the IMR Di bit is 0, then allow a corresponding interrupt request to enter. It can be set by software or clear. By programming setting mask word, can change the original priority level.See Appendix for program codeThree, summary and experienceAs a automation's big three students, I think doing computer programming is very meaningful, and it is very necessary. During the university time has passed, most of our contact is professional class. We master English in the classroom is only theoretical knowledge of professional courses, how to exercise our ability to practice? How to apply what we learn professional basic course of theory knowledge to practice it? I want to do a similar course design is for us to provide a good platform for practice.The importance to learn professional course curriculum design in the curriculum design process, I feel the deepest undoubtedly access to a large number of design data. In order to make their design more perfect, access to this information is very necessary, but also essential. Secondly, in this design, we use the previously learned knowledge, such as: assembly language, analog and digital circuit knowledge. Although in the past have never been alone used them, but in the learning process with a problem I find efficiency is very high, this is me to do the curriculum design of a harvest. On the other, the curriculum design, let me feel the team. In the team, I Our mutual cooperation, on the course design, which is crucial, lack of every person will have an impact on our design. Also to be thanked the teacher when we meet with difficulties, giving our suggestions and encouragement. End of the two weeks of the course design, but from the middle school to knowledge will let me a lifetime. The resultsshow that the proposed analysis, solve problems and practical ability raise will benefit to me in the future learning, work and life.For a period of two weeks of graduation design is nearing completion, with the help of Teacher Liu and Wang cordial guidance and students. The design is accomplished. On this to all give me the curriculum design guidance and help teachers and students to express the most sincere thanks:四、Reference1.Wu Xiuqing, Zhou Heqin < microcomputer principle and interface technology fourth edition >2.Zhou Changsen < electronic circuit computer simulation technology >3.Yang Suhang < microcomputer system principle and Application >appendix;Meter (using the speed controller to control the rotation of the motor, read the total mileage)DA TA SEGMENTT EQU 100 ;Timing cycle time (*T)T_HI DB 50 ;High level duration (*T_HI)NOW_T DB TNOW_HI DB 50T8253 EQU 609 ;Timer 8253 initial value =1.19M*0.512MS (basic cycle) =609RUN DB 0 ;Start stop signSPEED DW 0 ; MileageSTEP DW 50 ;10 meters of 8253 pulse number (that is, every 50 pulses, 10 meters ahead)TAB DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH ;0~9Display codeDISP DB 4 DUP (0),52H;Storage speedDA TA ENDSSTACK SEGMENT STACKDW 64 DUP(?) ;Define stack segmentSTACK ENDSCODE SEGMENT ;Code segment definitionASSUME CS:CODE,DS:DA TA ;Designated segmentSTART: MOV AX,DATAMOV DS,AXPUSH DS ;The current user DS segment into the stack to saveMOV AX,0000HMOV DS,AX ;Modify DS=0000H, point to the interrupt vector table where the segmentMOV AX,OFFSET IRQ0 ;Take out the entry offset address of the interrupt processing subroutine (in 0)ADD AX,2000H ;Fixed, actual address = load address offset + relative to the offset of the start of the 0MOV SI,0020H ;IR0 interrupt vector number 08H, in the vector table of the 20H~23HMOV [SI],AX ;Load offset address vector tableMOV AX,0000HMOV SI,0022HMOV [SI],AX ;Load segment address (0000H) into vector tableMOV AX,OFFSET IRQ7ADD AX,2000HMOV SI,0003CHMOV [SI],AX ;Load the offset address into the IRQ7 interrupt vectorMOV AX,0000HMOV SI,003EHMOV [SI],AX ;Load segment address (0000H) into vector tablePOP DS ;Recover user data segment DSMOV AL,13HOUT 20H,AL ;Write to ICW1MOV AL,08HOUT 21H,AL ;Write to ICW2MOV AL,01HOUT 21H,AL ;Write to ICW4MOV AL,7EH ;D7, D0 bit reset to 0OUT 21H,AL ;Write OCW1 (IMR); open IR7 8259A and IR0 interruptMOV AL,34H ;Set 8253 channel 0 working mode, 00110100BOUT 43H,AL ;CH0 uses the first to write low 8, after writing the high 8, the way 2, the binary countMOV AX,T8253 ;The initial value of the count is the basic cycleOUT 40H,AL ;Write to CH0MOV AL,AHOUT 40H,ALMOV AL,0B6H ;Set 8253 channel 2 working mode, 10110110BOUT 43H,AL ;CH2 first write low 8, after writing high 8 bit =0, 3, binary countMOV AX,STEPOUT 42H,ALMOV AL,AHOUT 42H,AL ;Write to CH2MOV AL,88H ;Write the way to control the word 8255A, set the way to work for 10001000BOUT 63H,AL ;A port mode 0 output, C port high 4 bit input, B port mode 0 output, CMouth low 4 bit outputMOV AL,00HOUT 60H,AL ;Off motorSTI ;Open interruptA1: MOV SI,OFFSET DISPMOV BL,2MOV AX,SPEEDA11: AND AL,0FHMOV [SI+3],ALAND AH,0FHMOV [SI+1],AHDEC SIMOV AX,SPEEDMOV CL,4ROR AX,CLDEC BLJNZ A11 ;The speed of the compression BCD code into a non compression code, into the bufferMOV SI,OFFSET DISPCALL DISPLAYMOV AL,00H ;Open switch scanOUT 62H,ALIN AL,62H ;Read C portAND AL,40HJZ A2 ;Key press, turn to read the keyboardJMP EXITA2: MOV AH,00H ;Record key scan codeMOV CX,04 ;Cyclic scan 4 timesMOV DL,77H ;Open the first line of the switch scan A21: INC AH ;Scan code +1ROL DL,1MOV AL,DLOUT 62H,AL ;Open a line of switch scanningIN AL,62H ;Read C portTEST AL,40H ;Take PC6 (Y1)JNZ A22 ;No key press, turnCALL DALEYCALL DALEY ;To shakeIN AL,62H ;Read C portAND AL,40H ;Take PC6 (Y1)JNZ A22 ;,CMP AH,2JNZ RELEA ;Is not to accelerate the key, turn (press theaccelerator key alone is invalid)OR AH,80H ;Is the accelerator key, the D7 bit =1JMP A22RELEA: CALL DISPLAYMOV AL,DLOUT 62H,ALIN AL,62HAND AL,40H ;Wait key releaseJZ RELEAJMP A23 ;AHSave scan code, =1 (X1 key press) start stop, =2 acceleration, =3'+', =4'-' key A22:LOOP A21JMP EXITA23: MOV AL,AHAND AL,0FHCMP AL,01HJNZ A3 ;Not press the start and stop button, then turnMOV AL,RUNTEST AL,01HJNZ A24 ;From start to stopMOV RUN,01 ;Set flagMOV NOW_T,T ;Reload time cycleMOV AL,T_HIMOV NOW_HI,AL ;Reload high level timingMOV SPEED,00 ;Re valuation (mileage)JMP EXITA24: MOV RUN,00 ;Reset start flagMOV AL,00HOUT 60H,AL ;Off motorJMP EXITA3: MOV AL,AHAND AL,0FHCMP AL,03JNZ A6 ;Not '+' button, turnMOV BL,1TEST AH,80HJZ A4 ;Did not press the accelerator keyMOV BL,10 ;Press the accelerator key, plus 10, plus 1.A4: ADD BL,T_HICMP BL,100JBE A5MOV BL,100A5: MOV T_HI,BL ;The percentage increase can not be >100% JMP EXITA6: MOV AL,AHAND AL,0FHCMP AL,04JNZ EXIT ;Not turn - keyMOV BH,01TEST AH,80HJZ A7 ;Did not press the accelerator keyMOV BH,10 ;Press the accelerator key, -10, normal -1 A7: MOV BL,T_HISUB BL,BHJNC A8MOV BL,00A8: MOV T_HI,BL ;The minimum percentage was 0%EXIT: JMP A1;IR0 8259A interrupt processing subroutine (8253 of the CH0 timer basic cycle 0.512MS) IRQ0: PUSH AXSTIMOV AL,RUNAND AL,ALJZ IREXIT ;Does not start, then the test speedMOV AL,NOW_TSUB AL,1JNZ IRSP1MOV NOW_T,T ;Reload time cycleMOV AL,T_HIMOV NOW_HI,AL ;Reload high level timingJMP IREXITIRSP1: MOV NOW_T,AL ;High duration to, the PA0 output is 0 MOV AL,NOW_HITEST AL,ALJNZ IRSP2MOV AH,00H ;High duration to, the PA0 output is 0JMP IRSP3IRSP2: SUB AL,1 ;High level duration less thanMOV NOW_HI,AL ;Value after saving -1MOV AH,01H ;PA0 output is 1, high levelIRSP3: MOV AL,AHOUT 60H,ALIREXIT: MOV AL,20H ;EOI interrupt routineOUT 20H,AL ;Write OCW2 8259ACLIPOP AXIRET ;Interrupt return;IR7 8259A interrupt processing subroutine (8253 CH2 count interrupt, 10 m)IRQ7: PUSH AXSTIMOV AX,SPEEDADD AL,01DAAXCHG AL,AHADC AL,00DAAXCHG AL,AHMOV SPEED,AXMOV AL,20H ;EOI interrupt routineOUT 20H,AL ;Write OCW2 8259ACLIPOP AXIRET ;Interrupt return;DISPLAY:PUSH AXPUSH BXPUSH CXPUSH DXPUSH SIMOV CX,4MOV DL,7FHMOV SI,OFFSET DISPMOV BX,OFFSET TABDISP1: ROL DL,1MOV AL,[SI]XLAT ;Lookup table to display codeTEST DL,02HJNZ DISP2 ;Is the second digit display?OR AL,80H ;Yes, add the decimal point. DISP2: OUT 61H,ALMOV AL,DL ;Allows X1, X2, X3, X4 (PC3~PC0) digital control in turnOUT 62H,ALCALL DALEYINC SILOOP DISP1 ;Four cycles, display speedXOR AL,ALOUT 61H,AL ;Guan XianshiPOP SIPOP DXPOP CXPOP BXPOP AXRET; time delay subroutine ;wait subroutineDALEY: PUSH CXMOV CX,0560H ;Internal cycle timesDALEY1:LOOP DALEY1 ;0560H times, to complete the delay POP CXRETCODE ENDSEND START。

出租车计价器(单片机c语言)

出租车计价器(单片机c语言)
P1.0:接启动/停止按键,控制计价。
P1.1:接功能键。
P1.3:接清零键。
P0口接数码管段选端,P2口接驱动芯片。
P3.4(T0):接模拟开关按键,替代了出租车计价器中的霍尔传感器。
P3.1、P3.0口接掉电保护电路。
2.3
按下计价按键时,显示起步价和起步里程范围,这些在程序中设置;当等于或超过两公里后,按计算总价的公式为:总价=起步价+单价*(总里程-起步里程)+1进行计价。本设计中,起步价为4元,起步里程为2公里,当然这些数据可以在程序中改写,以满足不同时期价格调整的需要。下图是通过在Keil C中编译通过,并生成Hex文件,在PROTEUS中仿真通过的整体硬件原理图:
图2.11时钟电路
2.4.6
按键控制电路中,单片机的P1.0管脚接启动/停止按键,通过软件编程,当按下按键计数器开始工作,开始计价;当弹起按键时,计数器停止工作,停止计价,启动/停止按键带自锁功能。按下启动按键,开关处于导通状态,这时给P1.0送低电平信号,这时TR0=1,计数器开始工作,调用计价子程序开始计价。清零按键接单片机的P1.3管脚,按下清零按键,P1.3为低电平,调用清零子程序,用于将显示数据清零,在程序中给各位赋0代码(0x3f),以达到清零的目的,方便下次计价。另外为功能键,控制价格调整,这个按键是在没有按下启动/停止按键时有作用,计价过程中无效。
能够保证系统可靠的复位,在初始化程序中应安排一定的复位延迟时间。
图2.8复位电路
2.4.4
掉电保护电路中采用了存储芯片AT24C02。
AT24C02是一个CMOS标准的EEPROM存储器,是AT24CXX系列(AT24C01/02/04/08/16)成员之一,这些EEPROM存储器的特点是功耗小、成本低、电源范围宽,静态电源电流约30uA~110uA,具有标准的I2C总线接口,是应用广泛的小容量存储器之一。
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

出租车计价器课程设计目录前言1、系统工作原理1.1 功能说明1.2 基本原理2、硬件设计2.1 单片机最小系统单元2.2 A44E霍尔传感器检测单元2.3 AT24C01存储单元2.4 键盘调整单元2.5 显示单元3、软件设计3.1 系统主程序3.2 中断程序3.2.1 里程计数中断程序3.2.2 中途等待中断程序3.3 计算程序3.4 显示程序3.5 键盘程序4、总结参考文献附录A 系统原理图附录B 系统源程序前言随着出租车行业的发展,出租车已经是城市交通的重要组成部分,从加强行业管理以及减少司机与乘客的纠纷出发,具有良好性能的计价器对出租车司机和乘客来说都是很必要的。

而采用模拟电路和数字电路设计的计价器整体电路的规模较大,用到的器件多,造成故障率高,难调试。

而采用单片机进行的设计,相对来说功能强大,用较少的硬件和适当的软件相互配合可以很容易地实现设计要求,且灵活性强,可以通过软件编程来完成更多的附加功能。

本设计采用AT89S52单片机为主控器,以A44E霍尔传感器测距,实现对出租车的多功能的计价设计,并采用AT24C01实现在系统掉电的时候保存单价等信息,输出采用8段数码显示管。

本电路设计的计价器不但能实现基本的计价,而且还能根据白天,黑夜和中途等待来调节单价。

第一章系统工作原理1.1 功能说明出租车计价器根据乘客乘坐汽车行驶距离和等候时间的多少进行计价,并在行程中同步显示车费值。

从起步价开始,当汽车程行驶未满3公里时,均按起步价计算。

过3公里后,实现每1公里单价收费,中间遇暂停时,计程数不再增加,开始计时收费,测距收费和测时收费的和便构成了一位乘客的车费。

同时,白天和夜晚价格不同,可以进行切换。

白天单价、夜晚单价、等待单价和起步价格都可通过独立键盘进行调节。

(默认起步价为5元/3公里,里程单价白天为1.5元/公里,夜晚为1.8元/公里,等待计时单价为0.5元/5分钟)1.2 基本原理计数器系统主要由五部分组成:A44E霍尔传感器、AT89S52单片机、独立键盘、EEPROM AT24C01和显示数码管。

霍尔传感器安装在车轮上,主要检测汽车行进的公里数,并产生一系列相应的脉冲输出,脉冲送到单片机进行处理,单片机根据程序设定通过计算脉冲数换算出行驶公里数,再根据从EEPROM中读取的价格等相关数据进行金额的计算,计算好的金额、里程和单价都实时地显示在数码管上。

独立键盘可以调节价格等相关数据,按下相应的按钮,产生信号交由单片机处理并实时显示出来,调节好的数据存储到EEPROM中,掉电后可以使调好的数据不丢失,下次得电后直接从EEPROM读到单片机,系统结构图如图1。

图1 系统结构图第二章硬件设计2.1 单片机最小系统单元主控机系统采用了Atmel 公司生产的 AT89S52单片机,它含有256 字节数据存储器,置8K 的电可擦除FLASH ROM,可重复编程,大小满足主控机软件系统设计,所以不必再扩展程序存储器。

复位电路和晶振电路是AT89S52 工作所需的最简外围电路。

单片机最小系统电路图如图2所示。

图2 单片机最小系统图AT89S52 的复位端是一个史密特触发输入,高电平有效。

RST端若由低电平上升到高电平并持续2个周期,系统将实现一次复位操作。

在复位电路中,按一下复位开关就使在RST端出现一段时间的高电平,外接11.0592M 晶振和两个30pF 电容组成系统的部时钟电路。

2.2 A44E霍尔传感器检测单元A44E 属于开关型的霍尔器件,其工作电压围比较宽(4.5~18V),其输出的信号符合TTL电平标准,可以直接接到单片机的IO 端口上,而且其最高检测频率可达到1MHZ。

A44E 集成霍耳开关由稳压器A、霍耳电势发生器(即硅霍耳片)B、差分放大器C、施密特触发器D和OC门输出E五个基本部分组成。

在输入端输入电压Vcc,经稳压器稳压后加在霍尔电势发生器的两端,根据霍尔效应原理,当霍尔片处在磁场中时,在垂直于磁场的方向通以电流,则与这二者相垂直的方向上将会产生霍尔电势差VH输出,该VH信号经放大器放大后送至施密特触发器整形,使其成为方波输送到OC门输出。

当施加的磁场达到工作点(即Bop)时,触发器输出高电压(相对于地电位),使三极管导通,此时OC门输出端输出低电压,三极管截止,使OC门输出高电压,这种状态为关。

这样两次电压变换,使霍尔开关完成了一次开关动作。

A44E霍尔传感器原理如图3所示。

图3 A44E霍尔传感器原理里程计算是通过安装在车轮上的霍尔传感器检测到的脉冲信号,送到单片机产生中断,单片机再根据程序设定,计算出里程。

其原理如图4所示。

图4 传感器测距示意图本系统选择了将A44E的脉冲输出口接到P3.3口外部中断1作为信号的输入端(这样可以减少程序设计的麻烦),车轮每转一圈(设车轮的周长是1米),霍尔开关就检测并输出信号,引起单片机的中断,对脉冲计数,当计数达到1000次时,即1公里,单片机就控制将金额自动增加,如图5。

图5 A44E霍尔元件接线图2.3 AT24C01存储单元存储单元的作用是在电源断开的时候,存储当前设定的单价信息。

AT24C01 是Ateml 公司的1KB的电可擦除存储芯片,采用两线串行的总线和单片机通讯,电压最低可以到2.5V,额定电流为1mA,静态电流10uA(5.5V),芯片的资料可以在断电的情况下保存40年以上,而且采用8 脚的DIP 封装,使用方便。

AT24C02芯片引脚配置如图6所示。

存储单元电路连接如图7所示。

图 7 存储单元电路原理图图中R4、R5 是上拉电阻,其作用是减少AT24C01 的静态功耗。

由于AT24C01的数据线和地址线是复用的,采用串口的方式传送数据,所以只用两根线SCL(时钟脉冲)和SDA (数据/地址)与单片机P2.2和P2.3口连接,进行传送数据。

每当设定一次单价,系统就自动调用存储程序,将单价信息保存在芯片;当系统重新上电的时候,自动调用读存储器程序,将存储器的单价等信息,读到缓存单元中,供主程序使用。

2.4 键盘调整单元当单价等信息需要进行修改时,就要用到键盘进行修改。

由于调节信息不多,故采用4个独立键盘即可,分别实现清零、切换、增大、减小和功能等作用。

电路原理如图8所示。

图8 键盘调整单元接线图S1:接P1.0口,对上一次的计费进行清零,为下次载客准备S2:接P1.1口,实现白天和夜晚单价的切换;当功能键S4按下时,S2可对数据进行增大。

S3:接P1.2口,当功能键S4按下时,S3可对数据进行减小。

S4:接P1.3口,按1次,进入调整白天单价;按2次,进入调整夜晚单价;按3次,进入调整等待单价;按4次,进入调整起步价;按5次,返回。

2.5 显示单元显示单元由7个8段共阳数码管组成,采用动态扫描进行显示。

前三个数码管分别接P3.0、P3.1和P3.2,用于显示总金额;中间两个分别接P3.4和P3.5,用于显示里程;后边两个分别接P3.6和P3.7,用于显示单价。

电路如图9所示。

图9 数码管显示图第三章软件设计3.1 系统主程序在主程序模块中,需要完成对各参量和接口的初始化、出租车起价和单价的初始化以及中断、计算、循环等工作。

另外,在主程序模块中还需要设置启动/清除标志寄存器、里程寄存器和价格寄存器,并对它们进行初始化。

然后,主程序将根据各标志寄存器的容,分别完成启动、清除、计程和计价等不同的操作。

当汽车运行起来时,就启动计价,根据里程寄存器中的容计算和判断行驶里程是否已超过起步价公里数。

若已超过,则根据里程值、每公里的单价数和起步价数来计算出当前的总金额,并将结果存于总金额寄存器中;中途等待时,无脉冲输入,不产生中断,当时间超过等待设定值时,开始进行计时,并把等待价格加到总金额里,然后将总金额、里程和单价送数码管显示出来。

程序流程如图10所示。

图10 主程序流程图图11 计算程序流程图3.2 中断程序3.2.1 里程计数中断程序每当霍尔传感器输出一个低电平信号就使单片机中断一次,当里程计数器对里程脉冲计满1000次时,进入里程计数中断服务程序中,里程变量加一。

主函数中总金额也相应地变化。

3.2.2 中途等待中断程序在中途等待中断程序中,每1ms产生一次中断,将当前里程值送入某个缓存变量,每5分钟将缓存变量中的值和当前里程值比较,当汽车停止,霍尔传感器5分钟没有输出信号,当前里程值和缓存变量的值相同,则进入等待计时,每5分钟记一次价格。

3.3 计算程序计算程序根据里程数分别进入不同的计算公式。

如果里程大于3公里,则执行公式:总金额=起步价+(里程-3)*单价+等待时间*等待单价;否则,执行公式:总金额=起步价+等待时间*等待单价。

程序流程图如图11所示。

3.4 显示程序显示程序利用定时器每1ms产生一次中断,相应变量置位,点亮一个数码管,显示一位数据,利用主函数的循环,实现动态扫描显示,同时根据数码管余辉和人眼暂留现象,即可实现显示。

3.5 键盘程序键盘采用查询的方式,放在主程序中,当没有按键按下的时候,单片机循环主程序,一旦右按键按下,便转向相应的子程序处理,处理结束再返回。

流程图如图12。

图12 键盘程序流程图第四章总结经过这些天有关于出租车计价器的课程设计,使我对单片机的应用有了更深的了解。

在课程设计的过程中,还是碰到了许多的问题。

比如,对于数码管动态扫描显示和键盘的延时防抖的综合编程不能较好地解决;对于代码的前后顺序及调用掌握得还不够好;对于一些相关的应用软件没能熟练掌握。

通过这几天晚上的苦想和反复调试,以及参考网上的程序,最终还是把问题解决了。

通过这次课程设计,我最大的收获就是自己的动手能力和独立解决问题的能力得到了很大的提高,也充分体会到了自己设计东西的乐趣、学会查阅资料和对别人的东西融会变通的重要性,也明白了很多知识光靠趴在书本上学是学不到其中的精髓的,必须亲自去试着实践,亲自去经历才能对它们真正的掌握,凡事都要自己去动下手,去实践一下,遇到困难,永远不要沮丧气馁。

在动手的过程中,不仅能增强实践能力,而且在理论上可以有更深的认识;这次设计给了我极大的鼓舞和信心,相信在以后的学习中可以通过不断的摸索和实践来提高其他方面的知识。

参考文献[1] 马淑华,王凤文,美金编著. 单片机原理与接口技术(第二版). 北京:北京邮电大学,2007.[2] 谭浩强著. C程序设计(第三版). 北京:清华大学,2005.附录A 系统原理图源程序#include<reg52.h>#include <intrins.h>#define uchar unsigned char#define uint unsigned int#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();_nop_();};uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};sbit exter=P3^3; //外部中断sbit key0=P1^0; //清零sbit key1=P1^1; //切换/+sbit key2=P1^2; //-sbit key3=P1^3; //功能键sbit p30=P3^0; //数码管各位控制sbit p31=P3^1;sbit p32=P3^2;sbit p34=P3^4;sbit p35=P3^5;sbit p36=P3^6;sbit p37=P3^7;sbit SDA=P2^3; //IIC引脚sbit SCL=P2^2;uint inter,aa,bb,temp,temp1;uint zongjine,licheng,dengdai;uint key3num,qiehuantemp,delaytemp;uchar danjia1,danjia2,danjia3,danjia,qibu;void delay(uint x) //延时时基为1ms {int i,j;for(i=x;i>0;i--)for(j=340;j>0;j--);}void start() //IIC开始位{SDA = 1;SCL = 1;delayNOP();SDA = 0;delayNOP();SCL = 0;}void stop() // IIC停止位{SDA = 0;delayNOP();SCL = 1;delayNOP();SDA = 1;}void respons() //IIC应答位{uchar i;SCL=1;delayNOP();while((SDA==1)&&(i<250))i++;SCL=0;delayNOP();}uchar read_byte() // 从EEPROM读到MCU {uchar i,j;for(i=0;i<8;i++){SCL=1;j<<=1;j|=SDA;SCL=0;}return(j);}void write_byte(uchar date) // 从MCU写到EEPROM {uchar i,temp;temp=date;for(i=0;i<8;i++){temp=temp<<1;SCL=0;delayNOP();SDA=CY;delayNOP();SCL=1;delayNOP();}SCL=0;delayNOP();SDA=1;delayNOP();}void write_data(uchar addr, uchar date) // 在指定地址addr处写入数据date {start();write_byte(0xa0);respons();write_byte(addr);respons();write_byte(date);respons();stop();}uchar read_data(uchar addr) // 在指定地址addr读取数据{uchar date;start();write_byte(0xa0);respons();write_byte(addr);respons();start();write_byte(0xa1);respons();date=read_byte();stop();return date;}void display(uint zongjine0,uint licheng0,uint danjia0) //数码管显示{uint jbai,jshi,jge,lshi,lge,dshi,dge;uint numwei,numshu;//数码管位置分配jbai=zongjine0/100;jshi=zongjine0%100/10;jge=zongjine0%100%10;lshi=licheng0/10;lge=licheng0%10;dshi=danjia0/10;dge=danjia0%10;//数码管动态显示if(aa){aa=0;numshu++;if(numshu==7)numshu=0;P3=0xff;switch(numwei){case 0:p30=0;P0=table[jbai];break;case 1:p31=0;P0=table[jshi]&0x7f;break; case 2:p32=0;P0=table[jge];break;case 3:p34=0;P0=table[lshi];break;case 4:p35=0;P0=table[lge];break;case 5:p36=0;P0=table[dshi]&0x7f;break;case 6:p37=0;P0=table[dge];break;}numwei++;if(numwei==7)numwei=0;}}void keyscan() //键盘扫描{if(key3==0) //功能键调节{delay(5);if(key3==0){key3num=1;while(!key3);delay(5);while(!key3);while(key3num){if(key3num==1) //调白天单价{if(key1==0){delay(5);if(key1==0){danjia1++;if(danjia1==100)danjia1=0;while(!key1);delay(5);while(!key1); }}if(key2==0){delay(5);if(key2==0){danjia1--;if(danjia1==-1)danjia1=99;while(!key2);delay(5);while(!key2);}}display(1,0,danjia1);}if(key3num==2) //调夜晚单价{write_data(1,danjia1);if(key1==0){delay(5);if(key1==0){danjia2++;if(danjia2==100)danjia2=0;while(!key1);delay(5);while(!key1);}}if(key2==0){delay(5);if(key2==0){danjia2--;if(danjia2==-1)danjia2=99;while(!key2);delay(5);while(!key2); }}display(2,0,danjia2);}if(key3num==3) //调等待单价{write_data(2,danjia2);if(key1==0){delay(5);if(key1==0){danjia3++;if(danjia3==100)danjia3=0;while(!key1);delay(5);while(!key1);}}if(key2==0){delay(5);if(key2==0){danjia3--;if(danjia3==-1)danjia3=99;while(!key2);delay(5);while(!key2);}}display(3,0,danjia3);}if(key3num==4) //调起步价{write_data(3,danjia3);if(key1==0){delay(5);if(key1==0){qibu++;if(qibu==100) qibu=0;while(!key1); delay(5);while(!key1); }}if(key2==0){delay(5);if(key2==0){qibu--;if(qibu==-1) qibu=99;while(!key2); delay(5);while(!key2);}} display(4,0,qibu);}if(key3num==5) //退出功能键{write_data(4,qibu);key3num=0;}if(key3==0){delay(5);if(key3==0){key3num++;while(!key3);delay(5);while(!key3);}}}}}}void init(){SDA=1;SCL=1;zongjine=0;licheng=0;dengdai=0;danjia1=read_data(1);danjia2=read_data(2);danjia3=read_data(3);qibu=read_data(4);aa=0; //数码管动态扫描的定时器时基个数bb=0; //判断是否等待的时基个数inter=0;EA=1; //开总中断EX1=1; //开外部中断1IT1=1; //触发方式下降沿TMOD=0x01;TH0=(65536-1000)/256;TL0=(65536-1000)%256;ET0=1; //开定时器T0中断TR0=1; //开定时器T0P3=0x08;P0=table[0];}void jisuan()if(licheng>3)zongjine=qibu+(licheng-3)*danjia+dengdai*d anjia3; //金额计算elsezongjine=qibu+dengdai*danjia3;//起步公里金额计算}void qiehuan(){if(key1==0)//白天夜晚切换{delay(5);//键盘防抖if(key1==0)qiehua ntemp=!qiehuantemp;while(!key1);delay(5);while(!key1);}if(qiehuantemp==0)danjia=danjia2;if(qiehuantemp==1)danjia=danjia1;}void main(){init();qiehuantemp=1;key3num=0;while(1){qiehuan();//切换白天夜晚单价jisuan();//计算总金额display(zongjine,licheng ,danjia);keyscan();if(key0==0)//清零键init() ;}}void inter1() interrupt 2 //脉冲中断{delay(5);//if(exter==0) / /{//IT1=1;inter++;if(inter==5){inter=0;licheng++;}}//while(!exter);//delay(5);//while(!exter);//}void timer0() interrupt 1{TH0=(65536-1000)/256;TL0=(65536-1000)%256;aa++;bb++;temp1=licheng;//测试是否进入等待if(bb==10000)//10s无反应进入等待计费{bb=0;if(temp=temp&temp1)dengdai++;temp=licheng;}}原来文件地址http://blog.sina../s/blog_609003ef0100dt1o.html存储器可以不用。

相关文档
最新文档