Jump to content

ADC an Display

Recommended Posts


I programming a LCD Interface an a ADC Input. Now I would display the voltage from ADC to my LCD Display!. But I have two values, one in the low byte another in the high byte. How I can convert the binary value to a decimal value?

Also I think, I must compute: U = Uinput * 5 / 1,024, because the pic can messure 5V with 10Bit (1024), so the PIC can messure 2,8828 mV Steps 5V/1024, right?

Has anybody implimented a voltage messure and display on a LCD?




Link to comment
Share on other sites

  • 2 weeks later...
  • 2 years later...
U = Uinput * 5 / 1,024


You could multiply by 44, then divide by 9 to get a value that's roughly 0-5000 mV.


My solution is so complicated that I would have gone with Steve's solution, but here goes:


I get the ADC value in int multi.


I multiply the value by 4.882 ( comes from 5000/1024, therefor 1023(+1) will be 5000) as follows:


void Voltage (void)

{ multi=multi+1; // add one








Then I do the BCD extraction:


void bcdext (void)




hund =(multi/100);




thou=thou+48; //the 48 gets added to get the LCD value






Then I do rounding of the value so a ADC value of 1023 will show 5000 while a value of zero will still show 0.


void roundd (void)

{if (ones>(4+48)) //ie ones +48(to get LCD value)>4


/*if the LCD value for 9 increases by one it becomes the value for character ':' */

if (tens>(9+48))



if (hund>(9+48))




This gives an adc value of 1023 a value of 5000.

Link to comment
Share on other sites



Try my adaption of the Bresenham Line algorithm - I kept thinking that we have x and y, and a slope so came up with this (I just found up the Bresengam line alogrithm and adapted it :( ).


Its pretty accurate, 511 gives 2499.

The down side is that it takes alot of iterrations to find the value.


Just pass the adc value (0 to 1023) and the converted value is returned.


int BresenhamLine( int adcval )
   if( adcval == 0 )
       return 0;
   int xnum = 2500;
   int y, x = 0;
   for (y = 0; y < 5000; y++)
       xnum += 1023;
       if (xnum >= 5000)
           xnum -= 5000;
           if( x == adcval )

   return y;	



Let me know what you think.




Link to comment
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...