Click here to Skip to main content
15,920,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to print strings on LCD using c language. I want to print the voltage and current of my system on the LCD. how do i include float values when printing in a string. I am using SPI to communicate with the LCD.

What i want to print is,
"28.0 VDC 18.0 A"

Where 28.0 and 18.0 are floating point output variables, Vout_Read and Iout_Read. I can't use a printf statement and %f, while trying to do SPI Transfer. Any suggestion or help is greatly appreciated

What I have tried:

I have tried to print messages as is without having a generic variable. I am repeatedly calling different specific strings each with different voltage and current ratings. But i want to generalize this and improve my code's efficiency.
Posted
Updated 29-Jun-18 3:25am

1 solution

sprintf is your friend. Convert your floats and whatever to build a formatted string that you can output over SPI.
 
Share this answer
 
Comments
Member 13892404 29-Jun-18 10:22am    
Thanks for your time and help peter. I have one follow-up question though. The syntax of SPI transfer message is consisting of two arguments. one is the type of value written to the LCD , i.e either a DATA or a COMMAND. and the second argument is the value itself. which is usually a string.

I want this string to hold the floating point variable as part of it. How does using sprintf accommodate that??

If i was to use sprintf to print voltage i would do something like this,

Char string[40];
sprintf(string, "Voltage is = %f", Vout_Read);
puts(str);

But i am using one SPI transfer function to write anything to the LCD.
it's prototype is
void Spi_Transfer_to_LCD ( uint16 Value_type, uint16 Value)

The 16 bit value is typically passed as a string. Now i need that string to print with the generic Vout_Read and Iout_Read variable in it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900