cancel
Showing results for 
Search instead for 
Did you mean: 

Knowledge Base Articles

Displaying a Float Value on LCD Using PSoC® 3 or PSoC 5LP – KBA94460

KishoreS_96
Employee

Displaying a Float Value on LCD Using PSoC® 3 or PSoC 5LP – KBA94460

Version: **

Translation - Japanese: PSoC®3またはPSoC 5LPを使用してLCDに浮動小数点値を表示 – KBA94460 - Community Translated (JA)

Question: How do I convert a float value to ASCII and display it on an LCD in PSoC Creator using PSoC 3 or PSoC 5LP?

Answer:

To display a float value on LCD, you first need to convert the float value to a string using the sprintf function.

Use the following snippet of code to display a float value (say -1.2345) on the LCD.

#include <project.h>#include <stdio.h> int main() {  /* Place your initialization/startup code here (e.g. MyInst_Start()) */     char tstr[16];  float compValue = -1.2345;  LCD_Start();  LCD_Position(0,0);  sprintf(tstr, "%+1.4f", compValue ); //converts floats to ASCII and stores it in char array tstr LCD_PrintString(tstr);  for(;;)  {  /* Place your application code here. */ } }

Now, -1.2345 will be printed on the LCD.

0 Likes
Version history
Revision #:
1 of 1
Last update:
‎Jun 15, 2010 11:55 PM
Updated by:
 
Contributors