Design of a Taxi Mileage Meter Based on the 51 Microcontroller (Accurate Billing and Display)

With the advancement of technology and the acceleration of urbanization, taxis, as an important component of urban public transportation, require a high level of accuracy and reliability in their billing systems. This article introduces a design for a taxi mileage meter based on the 51 microcontroller, which can achieve precise mileage billing and clear information display.

1. System Overview
This system is centered around the 51 series microcontroller, utilizing a Hall sensor to collect the wheel’s rotational speed signal. After processing, it calculates the vehicle’s travel mileage. The system calculates the fare based on preset billing standards and displays real-time information such as mileage, unit price, and total price on an LCD screen. Additionally, the system supports switching between day and night billing modes, as well as operations such as start, pause, and reset.

2. Hardware Design
1. Minimum System of the Microcontroller
The system uses the STC89C52 microcontroller as the core controller, completing all module control and data processing tasks. The microcontroller is connected to a crystal oscillator, reset circuit, and power filtering to form a minimum system, providing a stable operating environment.

2. Hall Speed Measurement Module
The Hall sensor is used to detect the rotation of the wheels, generating a pulse signal for each complete rotation. The microcontroller captures the pulse signal through an external interrupt and calculates the vehicle’s travel mileage based on the tire circumference. Below is an example code for the Hall sensor interrupt handling:

void hall_interrupt() interrupt 0<br/>{<br/>    // Record pulse count<br/>    pulse_count++;<br/>    // Calculate distance (assuming tire circumference is 1 meter)<br/>    distance = pulse_count * 1.0;<br/>}

3. Display Module
An LCD1602 liquid crystal display is used to show real-time information such as time, mileage, and costs. The LCD communicates with the microcontroller via a parallel interface, and the displayed content is dynamically updated through the program.

4. Key Module
Four buttons are used to implement functions such as mode switching, start, pause, and reset. The buttons are connected to the microcontroller’s I/O ports and their states are detected through scanning.

3. Software Design
1. Main Program Flow
The main program first initializes the system, including the timer, interrupts, and LCD display. It then enters a loop to check the button states, process mileage and fare calculations, and update the display content. Below is an example code for the main program:

void main()<br/>{<br/>    // Initialize system<br/>    init_system();<br/>    while(1)<br/>    {<br/>        // Check button<br/>        check_key();<br/>        // Calculate mileage and fare<br/>        calculate();<br/>        // Update display<br/>        update_display();<br/>    }<br/>}

2. Mileage Calculation Subroutine
The mileage calculation subroutine calculates the vehicle’s travel mileage based on the pulse count collected by the Hall sensor and the tire circumference. Below is an example code for the mileage calculation subroutine:

void calculate_distance()<br/>{<br/>    // Calculate mileage based on pulse count<br/>    distance = pulse_count * wheel_circumference;<br/>}

3. Fare Calculation Subroutine
The fare calculation subroutine computes the fare based on the preset billing standards and travel mileage. Below is an example code for the fare calculation subroutine:

void calculate_fare()<br/>{<br/>    // Calculate fare based on mileage<br/>    if(distance <= base_distance)<br/>    {<br/>        fare = base_price;<br/>    }<br/>    else<br/>    {<br/>        fare = base_price + (distance - base_distance) * unit_price;<br/>    }<br/>}

4. System Testing
1. Functional Testing
All functions of the system were tested, including mileage calculation, fare calculation, display functionality, and button operations. The test results showed that the system accurately performs all functions.

2. Accuracy Testing
The accuracy of the system’s mileage calculation was tested by comparing the actual travel mileage with the mileage displayed by the system. The test results indicated that the system’s mileage calculation error is within an acceptable range.

5. Conclusion
The taxi mileage meter design based on the 51 microcontroller introduced in this article can achieve precise mileage billing and clear information display. The system has advantages such as simple structure, low cost, and high reliability, making it suitable for practical applications in taxi billing systems.

Leave a Comment