5 Replies Latest reply on Jan 27, 2015 9:24 PM by userc_39492

    output a float number onto LCD

        • 1. Re: output a float number onto LCD

          Welcome in the forum!


          Easiest solution without any formatting is to use ftoa().


          More complex but much more universal is sprintf(). Formatting specifiers here: publications.gbdirect.co.uk/c_book/chapter9/formatted_io.html


          Internal enabling see here : www.cypress.com/


          So increase stack and address the linker addition.





          • 2. Re: output a float number onto LCD

            Usefull formatting discussion, attached.




            Regards, Dana.

            • 3. Re: output a float number onto LCD

               First, just want say sorry because I created the thread but couldnt type anything on the post due to some weird error on my web browser (Google Chrome).Really appreciate your reply. 

                   I'm new to community and was struggling with the sprinf() whole day. I'm writing a code to implement a stopwatch on PSoC 5LP kit. I used a timer block to count the time between the Start and Stop buttons are pressed. Stopwatch is the Timer block. the code is roughly like below:   
                   #include "stdio.h"    
                   #include <project.h>    
                   #define TRUE 1    
                   #define FALSE 0    
                   #define STOPWATCH_FREQ 10000    
                   asm (".global _printf_float"); //adds ~8000 bytes to the program    
                   int main()    
                       //Set to TRUE if the stopwatch has started, else FALSE    
                       uint8 started_b = FALSE;    
                       //Temporary storage for status register    
                       uint8 reg;    
                       //Capture/counter read value    
                       uint32 capture;    
                       //Capture/counter converted to seconds    
                       float seconds;    
                       //Temporary string for sprintf to use    
                       char tstr[16];    
                       /* Place your initialization/startup code here (e.g. MyInst_Start()) */    
                       Display_Position(0, 0);    
                       Display_PrintString("Stopped")      ;    
                       /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */    
                               //If the stopwatch isn't known to have started yet,    
                               //see if the start button has been pressed. If it has    
                               //been pressed, the stopwatch has started.    
                                   started_b = TRUE;    
                                   Display_Position(0, 0);    
                                   Display_PrintString("Started")      ;    
                   //Else, check to see if the stopwatch has been stopped.    
                               reg = Stopwatch_ReadStatusRegister()      ;    
                               //If the stopwatch has been stopped, first read the capture    
                               if(reg & Stopwatch_STATUS_CAPTURE)    
                                   capture = Stopwatch_ReadCapture();    
                                   started_b = FALSE;    
                               //Else, just read the counter    
                                   capture = Stopwatch_ReadCounter();    
                               //Convert the capture/counter to seconds and print it    
                               capture = Stopwatch_ReadPeriod() - capture;    
                               if(capture != 0)    
                                   seconds = capture / (float)STOPWATCH_FREQ;    
                                   Display_Position(1, 0);    
                                   sprintf(tstr, "%1.4f", seconds);    
                               //If the stopwatch has stopped, reset it    
                                   Display_Position(0, 0);    
                                   Display_PrintString("Stopped")      ;    
                   For some reasons, the whole project seems to be working but the "tstr" is not displayed on the LCD. I can see the value of "seconds" and "capture" are updated as soon as I press Start and Stop buttons (SWStart, SWStop).   
                   I tried to manually debug it by replacing the "seconds" by an integer and it works. So I suspect that the spintf function just doesnt like the float value.   
              • 4. Re: output a float number onto LCD

                You have enabled the nano support in the library -








                http://www.cypress.com/?id=4&rID=87354     nano library






                Regards, Dana.

                • 5. Re: output a float number onto LCD

                   Hi Dana,


                  Yes I intentionally added another 8K of flash into my code so that it can handle printing or scanning floating point. 


                  The result is same when i adjust the linker files by following your link.


                  Thank you for your help.