Professional Documents
Culture Documents
h>
rd = 1;
gh
intr = 1;
nversion
}
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);
lcd_comm(0x06);
delay(10);
lcd_comm(0x80);
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
}