Home Blog Blog Details

Design a taxi meter based on AT89C52 microcontroller

March 03 2025
Ampheo 10

Inquiry

Global electronic component supplier AMPHEO PTY LTD: Rich inventory for one-stop shopping. Inquire easily, and receive fast, customized solutions and quotes.

QUICK RFQ
ADD TO RFQ LIST
Designing a taxi meter using the AT89C52 microcontroller involves several steps, including hardware design, software programming, and integration.

Designing a taxi meter using the AT89C52 microcontroller involves several steps, including hardware design, software programming, and integration. Below is a basic outline of how you can design a taxi meter using the AT89C52 microcontroller.

Hardware Components:

  1. AT89C52 Microcontroller: The main control unit.

  2. LCD Display: To display the fare, distance, and other information.

  3. Keypad: For inputting initial parameters like base fare, rate per kilometer, etc.

  4. Distance Sensor: To measure the distance traveled (e.g., using a rotary encoder attached to the wheel).

  5. Real-Time Clock (RTC): To keep track of time for calculating waiting charges.

  6. Buzzer: To alert the driver or passenger when the fare changes.

  7. Power Supply: To power the microcontroller and other components.

  8. EEPROM: To store fare data and other settings.

Hardware Connections:

  1. LCD Display:

    • Data pins (D0-D7) connected to Port 2 of AT89C52.

    • RS, RW, and E pins connected to Port 1.

  2. Keypad:

    • Rows and columns connected to Port 3.

  3. Distance Sensor:

    • Output connected to an external interrupt pin (e.g., INT0) of AT89C52.

  4. Real-Time Clock (RTC):

    • SDA and SCL pins connected to Port 0 with pull-up resistors.

  5. Buzzer:

    • Connected to a GPIO pin (e.g., P1.0).

  6. EEPROM:

    • SDA and SCL pins connected to Port 0 with pull-up resistors.

Software Design:

The software for the taxi meter will be written in C and compiled using a compiler like Keil uVision. The program will include the following modules:

  1. Initialization:

    • Initialize the LCD, keypad, RTC, and EEPROM.

    • Set initial parameters like base fare, rate per kilometer, and waiting charges.

  2. Distance Calculation:

    • Use the distance sensor to measure the distance traveled.

    • Increment the distance counter based on the sensor input.

  3. Fare Calculation:

    • Calculate the fare based on the distance traveled and waiting time.

    • Fare = Base Fare + (Distance * Rate per Kilometer) + (Waiting Time * Waiting Charge per Minute).

  4. Display Update:

    • Continuously update the LCD with the current fare, distance, and waiting time.

  5. Keypad Input:

    • Allow the driver to input initial parameters and reset the meter.

  6. EEPROM Storage:

    • Store fare data and settings in EEPROM for persistence.

  7. Buzzer Control:

    • Activate the buzzer when the fare changes or when the trip ends.

Example Code Snippet:

c
 
#include <reg52.h>
#include <stdio.h>
#include <intrins.h>

#define LCD_PORT P2
#define RS P1_0
#define RW P1_1
#define EN P1_2

void LCD_Command(unsigned char cmd);
void LCD_Data(unsigned char data);
void LCD_Init();
void LCD_String(char *str);
void Delay(unsigned int ms);

void main() {
    unsigned int distance = 0;
    float fare = 0.0;
    float base_fare = 50.0; // Example base fare
    float rate_per_km = 10.0; // Example rate per kilometer
    float waiting_charge = 1.0; // Example waiting charge per minute
    unsigned int waiting_time = 0;

    LCD_Init();
    LCD_String("Taxi Meter");

    while (1) {
        // Simulate distance and waiting time (replace with actual sensor input)
        distance++;
        waiting_time++;

        // Calculate fare
        fare = base_fare + (distance * rate_per_km) + (waiting_time * waiting_charge);

        // Display fare, distance, and waiting time
        LCD_Command(0xC0); // Move cursor to second line
        LCD_String("Fare: ");
        LCD_Data((int)fare);
        LCD_String(" Dist: ");
        LCD_Data(distance);
        LCD_String(" Wait: ");
        LCD_Data(waiting_time);

        Delay(1000); // Update every second
    }
}

void LCD_Command(unsigned char cmd) {
    LCD_PORT = cmd;
    RS = 0;
    RW = 0;
    EN = 1;
    _nop_();
    EN = 0;
    Delay(2);
}

void LCD_Data(unsigned char data) {
    LCD_PORT = data;
    RS = 1;
    RW = 0;
    EN = 1;
    _nop_();
    EN = 0;
    Delay(2);
}

void LCD_Init() {
    LCD_Command(0x38); // 8-bit mode, 2 lines, 5x7 dots
    LCD_Command(0x0C); // Display on, cursor off
    LCD_Command(0x01); // Clear display
    LCD_Command(0x06); // Increment cursor
}

void LCD_String(char *str) {
    while (*str) {
        LCD_Data(*str++);
    }
}

void Delay(unsigned int ms) {
    unsigned int i, j;
    for (i = 0; i < ms; i++)
        for (j = 0; j < 123; j++);
}

Explanation:

  • LCD_Command: Sends a command to the LCD.

  • LCD_Data: Sends data to the LCD.

  • LCD_Init: Initializes the LCD.

  • LCD_String: Displays a string on the LCD.

  • Delay: Creates a delay in milliseconds.

  • main: The main loop where the fare is calculated and displayed.

Conclusion:

This is a basic design for a taxi meter using the AT89C52 microcontroller. The actual implementation may require additional features like EEPROM storage for fare data, more sophisticated distance measurement, and handling of different fare structures. The code provided is a starting point and can be expanded based on specific requirements.

Ampheo