Microcontroller paper reference: 7. Taxi meter

Section 1 Introduction

This course design uses microcontroller technology to implement a multi-functional taxi meter, which has the characteristics of reliable performance, simple circuit and low cost.

1.1   Taxi meter overview

The operating amount displayed on the meter is a function of operating mileage and price (waiting time is generally calculated by converting a certain proportion of mileage). Taxi meters are connected to moving vehicles through sensors. The actual mileage of the taxi is converted into a certain priced operating mileage in the meter through the pulse signal of the sensor. Currently, the functions of taxi meters on the market mainly include data reset function, day/night switching function, data output function, timing and pricing function, etc. However, taxi meters that can perform voice broadcast of data information are still relatively rare. In this regard, we will design a multi-functional taxi meter. Based on the original functions, we will add functions such as unit price output, unit price adjustment, distance output, display of the current system time, and voice broadcast data information.

1.2   This design task

1.2.1Design tasks _ 

    Design a taxi meter based on AT89S51 microcontroller.

1.2.2 Design requirements

1.Basic requirements

Different situations have different charging standards.

        daytime

        night

        Waiting on the way (charges will start after 10 minutes)

The unit price can be modified manually.

With data reset function.

Simple requirements for IO port allocation.

        Distance detection uses Hall switch A44E

        Day/night charge switch

        Data clear switch

Unit price adjustment (it is best to use the + and - buttons)

Data output (using LCM103).

        Unit price output 2 digits

        Distance output 2 digits

        Total amount output 3 digits

button:

        Start timing switch

        Data reset (cleared)

        day/night conversion

2. Play part

        Ability to store unit price and other data in case of power outage.

        Ability to display the current system time.

         Voice broadcast data information.

1.3   Main functions of the system

    The main functions of the taxi meter designed in this course are: data reset, day/night conversion, data output, timed pricing, unit price output and adjustment, distance output, voice broadcast of data information, and implementation when the system is powered off. Functions such as saving information such as unit price and system time. The output adopts 8-segment digital display tube. The meter designed in this circuit can not only realize basic pricing, but also adjust the unit price according to day, night, and waiting in the middle. At the same time, it can also be used as a clock to provide convenience to the driver when not pricing.

Section 2   Calculator Hardware Design

        The hardware design of this system mainly includes the design of the microcontroller AT89S51, data display components, A44E Hall sensor circuit, AT24C02 power-down storage unit, mileage calculation and pricing unit. During the hardware design process, the functions of each component are fully utilized to achieve a multi-functional taxi meter design.

2.1   Hardware composition and functions of the system

        The microcontroller control scheme diagram of the meter is shown in Figure 1. It consists of the following components: microcontroller AT89S51, total amount and unit price display components, keyboard control components, AT24C02 power-down storage control, mileage calculation unit, in-series display drive circuit, etc.

        Utilize the rich IO ports of the microcontroller and its control flexibility to realize basic mileage pricing functions, price adjustment, and clock display functions. It can not only realize the required functions but also expand the functions to a great extent, and can also easily upgrade the system. For specific circuits, please refer to the "Overall Circuit Diagram of Multi-Function Taxi Meter".

2.2 AT89S51 microcontroller and its pin description

        AT89S51 is a low-power, high-performance CMOS 8-bit microcontroller produced by ATMEL Corporation of the United States. It contains 4KB of system-programmable Flash read-only program memory. The device is produced using ATMEL Corporation's high-density, non-volatile storage technology and is compatible with Standard 8051 instruction system and pins. It integrates Flash program memory that can be programmed by either in-circuit programming (ISP) or traditional methods and a general-purpose 8-bit microprocessor in a single chip, which is highly cost-effective.

AT89S51 is a 40-pin chip, and the pin configuration is shown in Figure 2.

The 40 pin functions of the AT89S51 chip are:

VCC supply voltage.

GND Ground.

RST reset input. When RST goes high and remains high for 2 machine cycles, it will reset the microcontroller. WDT overflow will cause this pin to output a high level. Setting the DISRTO bit of SFR AUXR (address 8EH) can turn this function on or off. The DISKRTO bit defaults to the RESET output high-level open state.

XTAL1 is the input of the inverse oscillator amplifier and the input of the internal clock operating circuit.

XTAL2 is the output from the inverting oscillator amplifier.

Port P0 is a set of 8-bit open-drain bidirectional I/O ports. That is, the address/data bus multiplexing port. When used as an output port, each bit can drive 8 TTL logic gate circuits. Writing "1" to the port can be used as a high-impedance input port. When accessing external data memory or program memory, this group of port lines time-shares the address (lower 8 bits) and data bus multiplexing, and activates the internal pull-up resistor during the access. During Flash programming, the P0 port receives the instruction byte, and during program verification, the instruction byte is output. During verification, an external pull-up resistor is required.

Port P1 is an 8-bit bidirectional I/O port with an internal pull-up resistor. The output buffer stage of P1 can drive (sink or output current) 4 TTL logic gate circuits. Write "1" to the port and pull the port to a high level through the internal pull-up resistor. At this time, it can be used as an input port. When used as an input port, because there is an internal pull-up resistor, a current (IIL) will be output when a certain pin is pulled low by an external signal. During Flash programming and program verification, P1 receives the lower 8-bit address. Some port pins and functions of the P1 port are shown in Table 1.

Port 2 is an 8-bit bidirectional I/O port with internal pull-up resistor. The output buffer stage of P1 can drive (sink or source current) 4 TTL logic gates. Write "1" to the port and pull the port to a high level through the internal pull-up resistor. At this time, it can be used as an input port. When used as an input port, because there is an internal pull-up resistor, a current (IIL) will be output when a certain pin is pulled low by an external signal. When accessing external program memory or external data memory with a 16-bit address, port P2 sends the high 8-bit address data. When accessing an external data memory with an 8-bit address, the content on the P2 port line does not change during the entire access period. During Flash programming and program verification, P2 also receives the lower 8-bit address.

Port P3 is an 8-bit bidirectional I/O port with internal pull-up resistor. The output buffer stage of P3 can drive (sink or source current) four TTL logic gates. When "1" is written to the P3 port, they are pulled to high power by the internal pull-up resistor and can be used as an input port. When used as an input port, the P3 port that is externally pulled low will use a pull-up resistor to output current (IIL). In addition to being a general I/O port line, the P3 port is more important for its secondary function, as shown in Table 2. Port P3 also receives some control signals used during Flash memory programming and program verification.

PSEN/ program storage enable output is the read-first pass signal of the external program memory. When AT89S51 fetches instructions (or data) from the external program memory, PSEN/ is valid twice per machine cycle, that is, two pulses are output. When accessing external data memory, the PSEN/ signal is not valid twice.

EA/VPP external access allowed. In order for the CPU to only access the external program memory, the EA terminal must remain low. It should be noted that if the encryption bit LB1 is programmed, the EA terminal status will be latched internally during reset. When programming Flash memory, +12V programming voltage VPP is added to this pin.

2.3 AT24C02 pin diagram and its pin functions  

The AT24C02 chip pin configuration is shown in Figure 3.

The AT24C02 chip is DIP packaged and has a total of 8 pins, including:

A2~A0 address pins;

SDA, SCL I2C bus interface;

WP write protection pin. When WP is connected to VSS, writing to high-order addresses is prohibited. When WP is connected to VDD, writing to any address is allowed;

VCC power terminal

GND ground terminal

2.4   Design of AT24C02 power-down memory unit

The function of the power-down storage unit is to store the currently set unit price information when the power supply is disconnected. AT24C02 is a 2KB electrically erasable memory chip from ATMEL. It uses a two-wire serial bus to communicate with the microcontroller. The voltage can be as low as 2.5V, the rated current is 1mA, and the quiescent current is 10Ua (5.5V). The data can be saved for more than 40 years when the power is off, and it is packaged in an 8-pin DIP, making it easy to use. The circuit is shown in Figure 4.

In the figure, R8 and R10 are pull-up resistors. Their function is to reduce the static power consumption of AT24C02. Since the data lines and address lines of AT24C02 are multiplexed and the data is transmitted through the serial port, only two lines SCL (shift) are used. pulse) and SDA (data/address) to transmit data with the microcontroller.

Whenever the unit price is set, the system automatically calls the storage program and saves the unit price information in the chip; when the system is powered on again, it automatically calls the memory read program to read the unit price and other information in the memory into the cache unit. For use by the main program.

2.5   Design of mileage calculation and pricing unit

    The mileage calculation is based on the signal detected by the Hall sensor A44E installed on the wheel, sent to the microcontroller, processed and calculated, and sent to the display unit. The principle is shown in Figure 5.

Since the A44E is a switching Hall device, its operating voltage range is relatively wide (4.5~18V), its output signal complies with the TTL level standard, and can be directly connected to the IO port of the microcontroller, and its maximum detection frequency can reach 1MHZ .

The A44E integrated Hall switch consists of five basic parts: voltage regulator A, Hall potential generator (ie silicon Hall chip) B, differential amplifier C, Schmitt trigger D and OC gate output E.

Input the voltage CC V at the input end , and then add it to both ends of the Hall potential generator after being stabilized by the voltage regulator. According to the principle of the Hall effect, when the Hall piece is in a magnetic field, a voltage passes through it in the direction perpendicular to the magnetic field. Current, the Hall potential difference HV output will be generated in the direction perpendicular to the two. The HV signal is amplified by the amplifier and sent to the Schmitt trigger for shaping, so that it becomes a square wave and is sent to the OC gate output . When the applied magnetic field reaches the "operating point" (i.e. OP B ), the flip-flop outputs a high voltage (relative to the ground potential), causing the transistor to conduct. At this time, the OC gate output terminal outputs a low voltage. This state is usually called " open". When the applied magnetic field reaches the "release point" (i.e. rP B ), the flip-flop outputs a low voltage and the transistor is turned off, causing the OC gate to output a high voltage. This state is "off". Such two voltage transformations enable the Hall switch to complete a switching action.

We chose port P3.2 as the signal input terminal, and used external interrupt 0 internally (this can reduce the trouble of programming). Every time the wheel rotates (we assume the circumference of the wheel is 1 meter), the Hall switch detects And output a signal, causing the microcontroller to interrupt and count the pulses. When the count reaches 1000 times, which is 1 kilometer, the microcontroller will control the amount to automatically increase. The calculation formula is: current unit price × number of kilometers = amount.

2.6   Data display unit design

Due to the design requirements of unit price (2 digits), distance (2 digits), and total amount (3 digits) display output, and we also expanded the clock display (including the display of hours, minutes and seconds), using LCD segment code display, in the distance The data cannot be seen clearly from the screen 1 meter away, which cannot meet the requirements, and its contrast cannot meet the requirements during the day. Therefore, we use a split-screen display of 6-digit LED digital tubes, as shown in Figure 6:

The split-screen display of data is switched by pressing S1, as shown in Figure 7.

When the taxi is not driving, press S1 to display the data on a split screen; when the taxi is driving, only the total amount and unit price are displayed on the display. When it reaches the destination, the customer asks to see the total mileage. , you can press S1 to switch to the mileage and unit price display for customers to check. The circuit schematic diagram of the display circuit is shown in Figure 8.

The signal output from the serial port of the microcontroller is first sent to the left shift register (74HC164). Due to the effect of the shift pulse, the data is shifted to the right to achieve the purpose of display. The shift register 74HC164 also serves as the driver of the digital tube. Plug 1 (header1) is connected to the power supply, and plug 2 (header2) is connected to the data and pulse output terminals. The function of the three rectifiers D1~D3 in the circuit is to reduce the working voltage of the digital tube and increase its service life.

Section 3 System Software Design

The software design of this system can be mainly divided into six modules: the main program module, the timing counting interrupt program, the mileage counting interrupt service program, the waiting interrupt service program, the display subroutine service program, and the keyboard service program. Below is an introduction to each module.

3.1 System main program design

In the main program module, it is necessary to complete the initialization of each interface chip, the initialization of the starting price and unit price of taxis, the design of interrupt vectors, and the work of enabling interrupts and loop waiting. In addition, the start/clear flag register, mileage register and price register need to be set and initialized in the main program module. Then, the main program will complete different operations such as startup, clearing, metering and pricing based on the contents of each flag register. The main program flow chart is shown in Figure 9. When S1 is pressed, pricing is started, and whether the mileage has exceeded the starting price kilometers will be calculated and judged based on the contents of the mileage register. If it has exceeded, the current cumulative price is calculated based on the mileage value, the unit price per kilometer and the starting price, and the result is stored in the price register, and then the time and current cumulative price are sent to the display circuit for display. When arriving at the destination, since the Hall switch does not send a pulse signal, the pricing will stop and the current amount to be paid and the corresponding unit price will be displayed. When pricing is started next time, the system will automatically clear the display and start again. initialization process.

3.2 Scheduled interrupt service routine

In the scheduled interrupt service program, an interrupt is generated every 100ms. When 10 interrupts are generated, it is one second. Data is sent to the corresponding display buffer unit and the display subroutine is called for real-time display. The program flow is shown in Figure 10.

3.3   Mileage counting interrupt service routine

Whenever the Hall sensor outputs a low-level signal, the microcontroller is interrupted once. When the mileage counter counts mileage pulses 1000 times, the microcomputer enters the mileage counting interrupt service program. In this program, it is necessary to complete the accumulation operation of the current mileage and total amount, and store the results in the mileage and total amount registers.

3.4 Waiting for interrupt service routine

When the Hall switch does not output a signal in the counting state, the on-chip T1 timer is started. Whenever the timer reaches 10 minutes, the unit price of the midway wait is added to the current amount, and the midway wait is automatically added every ten minutes thereafter. unit price. When the waiting period ends, it will automatically switch to normal pricing.

3.5 Display subroutine service program

Since the data is displayed on a split screen, four display subroutines are used, namely: hour, minute and second display subroutine (HMS_DIS), amount unit price display subroutine (CP_DIS), distance unit price display subroutine (DP_DIS), unit price adjustment Subroutine (PA_DIS).

3.6  Keyboard service program

The keyboard adopts the query method and is placed in the main program. When no keys are pressed, the microcontroller loops the main program. Once a key is pressed, it turns to the corresponding subroutine for processing, and then returns after the processing is completed.

Section 4 System Debugging and Test Result Analysis

According to the system design plan, the debugging of this system is divided into three parts: hardware debugging, software debugging and software and hardware joint debugging. The test includes mileage pricing test and power-off storage test.

4.1 Instruments used  

Digital multimeter DT9203

Microcontroller emulator WAVE6000

Programmer GF2100

Dual trace voltage and current stabilized power supply DH1718E-5

Digital oscilloscope TDS1002

4.2 System debugging

According to the system design plan, the debugging of this system is divided into three parts: hardware debugging, software debugging and software and hardware joint debugging. Since the module design method is adopted in the system design, it is convenient to test the functions of each circuit module step by step.

4.3 Test results

    slightly.

4.4 Test result analysis

    slightly.

Conclusion

        This taxi meter has many more functions than those currently on the market, including unit price output, unit price adjustment, distance output, display of the current system time, and voice broadcast data information. In addition, the multifunctional taxi meter also has the characteristics of reliable performance, simple circuit, low cost, and strong practicability. Coupled with the optimized program, it has a high level of intelligence.

        Through this course design, I learned a lot of knowledge that cannot be learned in books, and also deeply realized the wide application fields of single-chip microcomputer technology. Not only did I consolidate the knowledge of single-chip microcomputer, but also I also became more interested in the course of microcontroller.

        During the design process of this course, I learned to find resources on the Internet for various hardware related to this design, including: AT89S51 microcontroller and its pin description, AT24C02 pin diagram and its pin functions, etc. Design provides certain information. Since we rarely carry out course design, we have only recently come into contact with the format of course design reports. After these two designs, we have laid a certain foundation for the production of our graduation projects in the future.

Guess you like

Origin blog.csdn.net/m0_49968063/article/details/132921732