Fuel Monitoring system using 8051

Fuel Monitoring system using 8051

fuel Monitor System

 

Code for the fuel monitoring System:

Here I am using the 8051 microcontroller and ADC0804 for the fuel monitoring system. If you want a description of this project. then please write in the comment box.

#include <REGX51.H>

//Led
#define LED P3
#define ON 1
#define OFF 0

sbit LED0=P3^0;
sbit LED1=P3^1;
sbit LED2=P3^2;
sbit LED3=P3^3;
sbit LED4=P3^4;

// Adc
#define ADC_DATA P0
sbit ADC_READ=P1^0;
sbit ADC_WRITE=P1^1;
sbit ADC_INTR=P1^2;
sbit PETROL=P1^3;
sbit BUZZER=P1^5;

#define HIGH 1
#define LOW 0

// Lcd
#define LCD P2
sbit RS =P1^6;
sbit EN =P1^7;

//Prototype for ADC
//convert adc data
unsigned char adcConvert();
void IndicateAndDisplayFuelStatus(unsigned char adcData);

//Prototype for Lcd
void lcdCommand(const char command);
void displayOnLcd(const char *pszMessage);
void lcdStart(void);
void delay(unsigned int);


/*Function to write command on Lcd*/
void lcdCommand(const unsigned char command)
{
    LCD = command;
    RS = 0;
    EN  = 1;
    delay(300);
    EN=0;
}

void lcdData(const unsigned char dataPrint)
{
    LCD = dataPrint;
    RS=1;
    EN=1;
    delay(400);
    EN=0;
}
/*Function to Display string on Lcd*/
void displayOnLcd(const char *pData)
{
    while(*pData)
    {
        lcdData(*pData);
        ++pData;
        delay(300);
    }
}
/*Function to Provide delay*/
void delay(unsigned int time)
{
    unsigned int i;
    for(i=0; i<=time; i++);
}

/*Initialize the LCD*/
void lcdStart(void)
{
    delay(500);
    lcdCommand(0x80);
    delay(500);
    lcdCommand(0x0C);
}

unsigned char adcConvert()
{
    unsigned char adcData = 0x00;
    ADC_INTR = HIGH;
    ADC_READ  = HIGH;
    ADC_WRITE = HIGH;
    //Conversion Start
    ADC_WRITE = LOW;
    delay(50);
    ADC_WRITE = HIGH;
    while(ADC_INTR==HIGH)
    {
        //empty
    }
    delay(50);
    //Read Adc data
    ADC_READ = LOW;
    adcData = ADC_DATA;

    return(adcData);
}

/*Analog float     Digital output
   voltage
                                            value of float varies according to this,
  +5V                0XFF
  +4V                0XCC                   voltage lavel of digital will be change
  +3V                0X99
  +2V                0X66                          Do=vcc*256/(V float)
  +1V                0X33
   0V                0X00

*/
void IndicateAndDisplayFuelStatus(unsigned char adcData)
{
    if((adcData<=0xff) && (adcData>=0xCC))
    {
        displayOnLcd("FULL");
        LED=0xff;
        BUZZER=OFF;
        PETROL=OFF;
    }
    else if((adcData<=0xCC) && (adcData>=0x99))
    {
        displayOnLcd(" 75%");
        LED=0xff;
        LED0=OFF;
        BUZZER=OFF;
        PETROL=OFF;
    }

    else if((adcData<=0x99) && (adcData>=0x66))
    {
        displayOnLcd(" 50%");
        LED=0xff;
        LED0=OFF;
        LED1=OFF;
        BUZZER=OFF;
        PETROL=OFF;
    }
    else if((adcData<=0x66) && (adcData>=0x33))
    {
        displayOnLcd(" 25%");
        LED=0xff;
        LED0=OFF;
        LED1=OFF;
        LED2=OFF;
        BUZZER=OFF;
        PETROL=OFF;
    }
    else
    {
        displayOnLcd(" LOW");
        LED=0xff;
        LED0=OFF;
        LED1=OFF;
        LED2=OFF;
        LED3=OFF;
        if(adcData==0x00)   // this condition will switch the relay to PETROL mode
        {
            LED4=OFF;
            BUZZER=ON;
            PETROL=ON;
        }
    }
}

int main()
{
    unsigned char adcData = 0x00;

    while(1)
    {
        lcdStart();
        adcData = adcConvert();
        IndicateAndDisplayFuelStatus(adcData);
    }
}

Recommended Post

Leave a Reply

Your email address will not be published. Required fields are marked *