hashim5003
Junior Member level 2
- Joined
- Jul 21, 2013
- Messages
- 21
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 3
- Activity points
- 116
void binary_to_decimal()
{
value = OUTPUT; //get value from ADC
x = value / 10; //binary to decimal conversion
a = x / 10; //MSB of digital value
b = x % 10; //middle digit
c = value % 10; //LSB
}
lcddata (a + 0x30); //display digital value on LCD
lcddata (b + 0x30);
lcddata (c + 0x30);
Combine the 3 variables a,b,c
{
int num[3]={a, b, c}, n1, n2,dec_adc;
n1 = num[0] * 100;
n2 = num[1] * 10;
dec_adc = n1 + n2 + num[2];
}
Post code for lcd sent...
void lcdcmd (unsigned char u)
{
ldata = u; //put LCD command values on pins
RS = 0;
RW = 0;
EN = 1; //strobe enable pin
delay();
EN = 0;
}
void lcddata (unsigned char v)
{
ldata = v; //put LCD data values on pins
RS = 1;
RW = 0;
EN = 1; //strobe enable pin
delay();
EN = 0;
}
void lcdinit() //Initialize LCD
{
lcdcmd(0x38); //Function set
delay();
lcdcmd(0x0C); //Display on, cursor off
delay();
lcdcmd(0x01); //Claer LCD
delay();
}
void lcdstring (char *sendstring) //send string to LCD
{
while (*sendstring)
lcddata(*sendstring++);
}
void main()
{
lcdinit(); //Call LCD initialize function
lcdstring("Please wait..");
lcdcmd(0x01); //Clear LCD
conversion (); //convert analog to digital
R = 0;
lcdcmd (0x80);
value = OUTPUT; //get value from ADC
x = value / 10; //binary to decimal conversion
a = x / 10; //MSB of digital value
b = x % 10; //middle digit
c = value % 10; //LSB
a1 = a * 100;
b1 = b * 10;
sum = a1+b1+c;
[COLOR="#FF0000"]lcdstring(sum);[/COLOR]
lcdstring(" mg/dL");
R = 1;
while(1);
}
void lcdstring (char *sendstring) //send string to LCD
{
while (*sendstring)
lcddata(*sendstring++);
}
void lcddata(unsigned char value)
{
ldata=value;
rs = 1;
rw=0;
en=1;
MSDelay(1);
en=0;
return;
}
lcddata(sum);
Try the above one
Assign the value for the variable sum for ex; sum=50;
see the output.
#include <reg51.h>
sfr OUTPUT = 0xA0; //ADC output port define
sbit SR = P3^0; //300mV
sbit R = P3^1; //ADC read
sbit W = P3^2; //ADC start conversion
sbit INTR = P3^3; //ADC conversion complete indication
sfr ldata = 0x90; //LCD port define
sbit RS = P3^7; //LCD data/command enable
sbit RW = P3^6; //LCD data/command write
sbit EN = P3^5; //LCD enable
unsigned char value, x, i, j, a, b, c, f, a1, b1, c1, sum;
void lcdcmd (unsigned char u)
{
ldata = u; //put LCD command values on pins
RS = 0;
RW = 0;
EN = 1; //strobe enable pin
delay();
EN = 0;
}
void lcddata (unsigned char v)
{
ldata = v; //put LCD data values on pins
RS = 1;
RW = 0;
EN = 1; //strobe enable pin
delay();
EN = 0;
}
void lcdinit() //Initialize LCD
{
lcdcmd(0x38); //Function set
delay();
lcdcmd(0x0C); //Display on, cursor off
delay();
lcdcmd(0x01); //Claer LCD
delay();
}
void lcdstring (unsigned char *sendstring) //send string to LCD
{
while (*sendstring)
lcddata(*sendstring++);
}
void main()
{
lcdinit(); //Call LCD initialize function
lcdstring("Please wait..");
lcdcmd(0x01); //Clear LCD
conversion (); //convert analog to digital
R = 0;
lcdcmd (0x80);
value = OUTPUT; //get value from ADC
x = value / 10; //binary to decimal conversion
a = x / 10; //MSB of digital value
b = x % 10; //middle digit
c = value % 10; //LSB
a1 = a * 100;
b1 = b * 10;
sum = 124;
lcddata(sum);
lcdstring(" mg/dL");
R = 1;
while(1);
}
void main()
{
lcdinit(); //Call LCD initialize function
lcdstring("Please wait..");
lcdcmd(0x01); //Clear LCD
while(1)
{
conversion (); //convert analog to digital
R = 0;
lcdcmd (0x80);
value = OUTPUT; //get value from ADC
x = value / 10; //binary to decimal conversion
a = x / 10; //MSB of digital value
b = x % 10; //middle digit
c = value % 10; //LSB
a1 = a * 100;
b1 = b * 10;
sum = 124;
lcddata(sum);
lcdstring(" mg/dL");
R = 1;
}
}
char sumstr[10];
// get data to sum
sprtintf(sumstr,sum);
lcdstring(sumstr);
Hi , the argument for lcdstring must be a string so try to use sprintf to convert sum to a string.
See an example here :https://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htmCode:char sumstr[10]; // get data to sum sprtintf(sumstr,sum); lcdstring(sumstr);
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?