Displaying decimal points on LCD

Status
Not open for further replies.

drkidd22

Member
Hello,

I have the following code, it works fine, the only other thing I want it to do is display decimal point to the LCD. It simply reads some voltage on a analog pin and displays it on the screen, it work fine for single digit only as it is. Any help will be appreciated.

Code:
void Voltage (void)
{
char line[16];
int Vref = 5000.0;  //Converts reading from ADC to mV
double ADCBubbleV, BubbleV;
int bADCVal, BubbleVi;

SetChanADC(ADC_CH6);
XLCDDelay4ms ();
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
XLCDDelay4ms ();
bADCVal = ReadADC(); // Read ADC
ADCBubbleV = ((bADCVal/1024.0) * Vref);
XLCDDelay4ms ();
BubbleV = ((ADCBubbleV)/(204.0));
XLCDDelay4ms ();
XLCDL2home();
XLCDPutRomString("Bubble (V): ");
BubbleVi = (int)BubbleV;
sprintf(line,"%d",BubbleVi);
XLCDPutRamString(line);
XLCDPutRomString("                ");
XLCDDelay4ms ();
}
 
This is the way I would do it. There is probably a better subroutine out there though.

Code:
int result;
BubbleVi = (int)BubbleV * 100; // 2.34v would change to 234

result = BubbleVi / 100;
XLCDPutRamString('0' + result); // 234/100=2.34 (2 as int)

XLCDPutRamString('.'); // Decimal point

result = (BubbleVi / 10) % 10;
XLCDPutRamString('0' + result); // 234/10=23.4
                                              //  23.4 mod 10 = 3.4 (3 as int)

result = BubbleVi % 10;
XLCDPutRamString('0' + result); // 234 mod 10 = 4
 
Last edited:
i think that it depends uppon the variable kind that you've assigned, if it is float or long , then it will be displyed with the decimal point,

this is my view!! hopefully correct
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…