You are on page 1of 3

#include<reg51f.

h>

//----Including the Reg file

//------------Assigning Control bits for LCD control---------/


sbit rs = P2^0; //----Pin0 of port2 is defined as rs pin for lcd control using t
his command
sbit rw = P2^1;//----Pin0 of port2 is defined as rw pin for lcd control using th
is command---sbit en = P2^2;//----Pin0 of port2 is defined as en pin for lcd con
trol using this command--sbit rd = P2^3; //----Read function for enabling ADC read----//
sbit wr = P2^4;//----Write Function for writing into ADC----//
sbit intr = P2^5;//----Interrupt Function which indicates the End of Conversion---//
//----------------------------------------------------------//
//------------Proto-type Decleration-----------------//
void init_lcd();
//-----Function used for Initializing LCD -----void lcd_comm(unsigned char value1); //------Function used to send command using
pass by reference type----void lcd_data(unsigned char value2);
//------Function used to send data using
pass by reference type----void lcd_msg(unsigned char *ch); //----Sending a String uisng pass by pointer me
thod-----void delay(unsigned int ms);
//------Function use to generate 1ms delay-----//-----Defining the ADC Function-----//
void adc_init();
//-----Inializing adc -----//
void adc_read();
//----Reading Data from ADC---//
void Converter(unsigned char v4);//----Converter data to ascii for display in LC
D---//
//---------------------------------------------------//
unsigned char ascii_lut[] = "0123456789ABCDEF";
//-------------Main Program-------------------------//
void main()
{
P0 = 0x00;
//-----Defining the Port 0 as output---//
P1 = 0xFF;
//-----Input pin used to read data from
ADC---//
P2 = 0x00;
//-----Port 2 as output-----//
init_lcd();
//-----Initializing LCD
adc_init();
//-----ADC initialize
lcd_comm(0x80); //-----1st line of LCD
lcd_msg("ADC=");//----Send a String
while(1)
{
adc_read();
//-- ADC data is send to mu and displayed in LCD
}
}
void adc_init()
{
wr = 1;
igh

//------Initialize the write signal as h

rd = 1;

//------Initialize the read signal as hi

gh
intr = 1;
nversion
}

//------Interrupt Pin to show end the Co

void adc_read()
{
unsigned char v;
wr = 0;
//----When Write Signal goes high to low to high
wr = 1;
//----It state End of Conversion
while(intr == 1); //----Wait till end of conversion
rd = 0;
//---Read is enable to read data from it
v = P1;
//----Move data of ADC to variable v
Converter(v);
intr = 0; //---Clearinng for next state
}
void Converter(unsigned char v4)
{
//---Converter to analog input voltage
float g,h;
unsigned int d,t;
g = ((v4 * 5)/255);
//--Analog input voltage is float type---/
d = g;
//--Move float into interger will eliminate the
decimal point---//
h = g - d;
//--Now calculate the difference between float a
nd interger
t = h * 100;
//--Now Removing the decimal point//
lcd_comm(0x85); //---Forcing to the Centre
lcd_data(d|(0x30));
lcd_data('.');
lcd_data(((t/10)%10)|(0x30));
lcd_data(((t)%10)|(0x30));
lcd_data('V');
//---Converting ADC data to Decimal
lcd_comm(0xC0);
lcd_msg("D=");
lcd_data(((v4/100)%10)|(0x30));
lcd_data(((v4/10)%10)|(0x30));
lcd_data(((v4)%10)|(0x30));
//----Converting the data to hexa
lcd_comm(0xC7);
lcd_msg("H=");
lcd_data(ascii_lut[((v4 & 0xF0)>>4)]);
lcd_data(ascii_lut[((v4 & 0x0F))]);
}
void init_lcd()
{
lcd_comm(0x38);
delay(10);
lcd_comm(0x0E);
delay(10);
lcd_comm(0x01);
delay(10);

//----Initializing 16x2 line LCD dispaly


//-----10ms delay
//----Setting Display ON and Cursor as Blinking
//-----10ms delay
//-----Clearing the LCD display
//-----10ms delay

lcd_comm(0x06);
delay(10);
lcd_comm(0x80);

//-----Auto incrementing Cursor


//-----10ms delay
//-----Setting first location on first line of L

CD
delay(10);

//-----10ms delay

}
void lcd_comm(unsigned char value1)
{
P0 = value1;
//----Sending the command to lcd from Port0
rs = 0; //----RS = Register Select pin, when [rs = 0] means its Command
register
rw = 0; //----RW = Read / Write pin, when [rw = 0] means write function
//----EN = Enable pin, it is use to latch data to lcd when it has high to low pu
lse at en pin
en = 1;
delay(1);
//----1ms delay
en = 0;
}
void lcd_data(unsigned char value2)
{
P0 = value2;//----Sending the command to lcd from Port0
rs = 1; //----RS = Register Select pin, when [rs = 1] means its Data reg
ister
rw = 0; //----RW = Read / Write pin, when [rw = 0] means write function
//----EN = Enable pin, it is use to latch data to lcd when it has high to low pu
lse at en pin
en = 1;
delay(1);
//----1ms delay
en = 0;
}
void lcd_msg(unsigned char *ch)
{
while(*ch != 0)//----Creating super loop with condition that pointer ch pointing
data using address is not equal to zero
{
lcd_data(*ch); //-----Sending String by pointing addresss of data
ch++;
//-----Incrementing the ch pointer variable
}
}
void delay(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<=ms;i++)
plete
for(j=0;j<=120;j++);
plete
}

//-----Nop operation till the loop execution com


//-----Nop operation till the loop execution com

You might also like