Friday, 27 April 2018

Fuel meter in 8051 micro controller using ADC 0808




Fuel gauges in bikes are mostly of variable resistance type, so a ohmmeter is designed in 8051 micro controller using adc 0808 and the output seen in 16x2 lcd and the adc output is sent in serial communication for code debugging and circuit debugging

in my case the output resistance of the fuel gauge increases as the fuel in the tank decrease, you can also modify the code depending upon the type of gauge

variable resistors are used here for debugging the circuit. which like the variable resistor of the fuel gauge



Components used:

  • 8051 development board
  • adc0808
  • 16 x 2 lcd 

Software used

  • keil u vision(creating and debugging c code)
  • proteus ( for simulation )
  • jet flasher ( for flashing hex file to  microcontroller)

Schematic




c code


///// created by senthamizhanjackie@gmail.com
/////https://hackentronics.blogspot.in/
////created on 27/4/2018

#include<reg51.h>

#define input P2 // adc input port
#define vin 5   // v ref for adc 0808
#define lcd P1  // LCD data lines port

///////////////For adc////////////////////////

sbit eoc = P0^0; // end of conversion (when low, conversion is done)
sbit sc = P0^1;  // start of conversion (high to low)
sbit clk = P0^2; // external clk
sbit oe = P0^3;  // read line (high to low)
sbit ale = P0^4;  //Address latch enable (high to low)

///////////////For LCD///////////////////////

sbit en = P3^5; //enable (high to low)
sbit rw = P3^6; //(Read write 0 for writing data toclcd screen)
sbit rs = P3^7; // register select (0 for command, 1 for data) 


///////////////////////////////////////////////////////////

unsigned char note[13] = "Fuel Percent "; //lcd line 1 

unsigned char line[13] = "Kms Remain   ";//lcd line 2

unsigned char value;

unsigned char mydata; //adcdata storing

unsigned char read_adc();

unsigned int g;

unsigned int h;

unsigned int A,K,C,D,E,F,I,K;

unsigned int M,N,V,L;

unsigned int res,mil;

///////////////////////////////////////////////

void delay(unsigned int);

void intserial();

void sendserial();

void intlcd();

void sendlcdcmd(unsigned char lcdcmd);

void sendlcddata(unsigned char lcddata);


////////////////////////////////////////////////////

void sendlcddata(unsigned char lcddata)
{
rs = 1;
rw = 0;
lcd = lcddata;
en = 1;
delay(2);
en = 0;
delay(2);
}

void sendlcdcmd(unsigned char lcdcmd)
{
rs = 0;
rw = 0;
lcd = lcdcmd;
en = 1;
delay(2);
en = 0;
delay(2);
}


void intlcd()
{
sendlcdcmd(0x38);
sendlcdcmd(0x0e);
  sendlcdcmd(0x06);
sendlcdcmd(0x01);
}

void intserial()
{
TMOD = 0x22;// timer 1 and 2 @ auto reload mode
TL1 = 253; //9600 baud rate
  TH1 = 253; //9600 baud rate 
SCON = 0X50; // 8 bit serial communication
TR1 = 1;
}

void sendserial()
{
TI = 0;
SBUF = mydata;
while(TI == 0);
}


unsigned char read_adc()
{
   ale=0;   
   sc=0;

   delay(1);
sc=1;
   ale=1;

   while(eoc==1);
oe=0;
delay(1);
oe=1;

   value = input;

return value;
}


void timer0() interrupt 1
{
clk=~clk;
}

void delay(unsigned int count)  
{
int i,j;
for(i=0;i<count;i++)
  for(j=0;j<100;j++);
}

/////////////////////main////////////////////////////
void main()
{

 EA = 1;
 ET0 = 1;

 TL0 = 253;
 TH0 = 253;
 TR0=1;

 intserial();
 intlcd();
 sendlcdcmd(0x80); 

 for(g=0;g<13;g++)
{
sendlcddata(note[g]); //line 1 in lcd
}
sendlcdcmd(0xC0); 
for(K=0;K<13;K++)
{
sendlcddata(line[K]); //line 2 in lcd
}

while(1)
{
mydata = read_adc();
sendserial();
res = mydata-100;
mil = (4*res);

sendlcdcmd(0x8d);

C = res/100;
D = res %100;
sendlcddata(C+0x30);
delay(1);

E = D /10;
F = D %10;
sendlcddata(E+0x30);
delay(1);

sendlcddata(F+0x30);
delay(1);

sendlcdcmd(0xCD);


M = mil/100;
N = mil %100;
sendlcddata(M+0x30);
delay(1);

V = D /10;
L = D %10;
sendlcddata(V+0x30);
delay(1);

sendlcddata(L+0x30);
delay(1);
}
}

Proteus simulation







download the C file and the Hex file here





No comments:

Post a Comment

Own IOT website and Hardware Using Node MCU (cyber thinks)

NODE MCU code -- website link  Cyberthinks google drive link  cyberthinks website files #include <ESP8266WiFi.h> #include <ArduinoJ...