> Does anyone have any suggestions? Skip floating point. Use an integer instead. Why do you need the value in HyperTerm ? Is it for test or debugging ? Is it important that the value is a correct interpretation of the actual voltage ? Would not the raw value from the ADC do ? Take "3.0018" as an example. Ad say MULTIPLIER =3D 4. lWhole=3D(long)((float)fInput); will give an integer with value 3, not ? ulPart=3D(long)((float)fInput*MULTIPLIER)-lWhole*MULTIPLIER; That will give the part after the ".", that is "0018", still as an integer. So 30018 - 3000 =3D 18. You do now that leading zeros are realy of "no value", right ? So "0018" is equal to "18". Can not printf() take a float and do the conversion on the fly ? You probably need to use strings if you are going to split the float that way to preserve the leading zero. Or if printf has some params to specify a fixed length equal to MULTIPLIER and with zero fill to the left... Jan-Erik. rchadwic wrote 2011-11-15 23:38: > I am using MPLab C18 Compiler V3.38 to program an 18C4550; presently tryi= ng > to use the ADC to convert voltage on a potentiometer and send it on a ser= ial > UART) interface to be displayed on Hyperterminal. > I am using the code suggested in > http://support2.microchip....aspx?ID=3DSQ6UJ9A003PQX > > to convert a floating point number (ADC voltage), using printf to send th= e > result to the serial output. Code is reproduced below. > I find that the code does not reproduce the ASCII value correctly if the > floating point number leads with a zero behind the decimal point. > Example: > Floating point number 2.9984 ASCII 2.99 (good) > 3.0018 ASCII 3.18 (bad) > 3.095 ASCII 3.95 (bad) > 3.104 ASCII 3.10 (good) > It looks like the code somehow is dropping leading zeros, but I can not s= ee > how or see a way to make it stop doing this. > Does anyone have any suggestions? Thank you. > > CODE: (copied from Microchip note) > float fInput=3D344.9876; // Pick a number > long lWhole=3D0; // Stores digits left of decimal > unsigned long ulPart=3D0; // Stores digits right of decimal > > #define MULTIPLIER 100 //(use 1 for no decimals, 10 for 1 place, > // 100 for 2 places, etc) > > #include > #include // choose your device as needed > > void main(void) > { > // Set up the USART for output (not required, but since printf sends to t= he > USART, it makes the output readable in the output window) > SPBRG=3D15; > TXSTA=3D0x24; > RCSTA=3D0x90; > > > //Convert number from float to fixed point for display. > //The number is converted to two parts. > lWhole=3D(long)((float)fInput); > ulPart=3D(long)((float)fInput*MULTIPLIER)-lWhole*MULTIPLIER; > > printf((far char *)"The floating point number is: %li.%li\n",lWhole,ulPar= t); > while(1); // wait forever > } > > > > --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .