How can i use the function "sprintf()" in PSoC Designer

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

As the subject name says , How can i use the function "sprintf()" in PSoC Designer ,thanx!

0 Likes
3 Replies
Anonymous
Not applicable

I think the latest Imagecraft version that comes with PSD5.0 SP6 and later has printf function.  But this does not show up in the C Language user guide.  I will try to get some information on this.

   

Best Regards,

   

Ganesh

0 Likes
DineshbabuM_66
Employee
Employee
First like received
     We have to use csprintf() to denote that the formated string is a flash string, and not a data SRAM string. This is because of the Harvard architecture of PSoC device. The following sample code shows the usage of csprintf() function.   
   
     #include <m8c.h>        // part specific constants and macros   
   
     #include"PSoCAPI.h"    // PSoC API definitions for all User Modules   
   
     #include <stdio.h>            //definitions for all standard io functions   
   
         
   
     int result=100;   
   
     char str[];       //Character array that holds the formatted string    
   
         
   
         
   
     void main(void)   
   
     {   
   
           //Start LCD module   
   
           LCD_Start();   
   
              
   
           //LCD starting position is (0,0)   
   
           LCD_Position(0,0);   
   
              
   
           //Get the formatted string   
   
           csprintf(str,"%d",result);   
   
         
   
           //Display the string on LCD   
   
           LCD_PrString(str);   
   
         
   
           while(1);   
   
     }   
   
         
   
     The above code displays the value of the variable “result” on LCD. That is 100 will be displayed on LCD.   
   
         
   
     Due to code size requirement, the printf/scanf functions are supported in the following three forms.

1. Basic with no long / floating point, or modifier,
2. Support for long , and
3. Support for floating point.

By default the option 1 is supported. To use option 2 or 3 the following changes are required in the compiler settings.

Support for float:
1. Open local.mk file from "Projects" tab in PSoC Designer. If local.mk file is not already available, create a text file called local.mk in the project directory.
2. At the bottom of local.mk, add CODECOMPRESSOR:=$(CODECOMPRESSOR) -lfpm8c  (this will link the libfpm8c.a, which contains the floating point capability of printf/scanf with modifier support)
3. Save local.mk file and build the project.

More code and data/stack space are needed for the fully featured versions (for the support of long and float).

Support for long:
1. Open local.mk file from "Projects" tab in PSoC Designer. If local.mk file does not already exist, create a text file called local.mk in the project directory.
2. At the bottom of local.mk, add CODECOMPRESSOR:=$(CODECOMPRESSOR) -llpm8c  (this will link the liblpm8c.a , which contains the long data type capability of printf/scanf)
3. Save local.mk file and build the project.
   
   
         
   
     The following sample code shows the usage of csprintf() function with float support.   
   
         
   
     #include <m8c.h>        // part specific constants and macros   
   
     #include"PSoCAPI.h"    // PSoC API definitions for all User Modules   
   
     #include <stdio.h>            //definitions for all standard io functions   
   
         
   
     float result=100.235641;   
   
     char str[];             //Character array that holds the formatted string    
   
         
   
     void main(void)   
   
     {   
   
           //Start LCD module   
   
           LCD_Start();   
   
              
   
     //LCD starting position is (0,0)   
   
           LCD_Position(0,0);   
   
              
   
           //Get the formatted string   
   
           csprintf(str,"%f",result);   
   
         
   
           //Display the string on LCD   
   
           LCD_PrString(str);   
   
         
   
           while(1);    
   
     }   
   
         
   
     The above code will display 100.235641 on LCD.   
   
         
   
    Best Regards,   
   
    Dinesh   
   
        
0 Likes
ShR_298411
Level 1
Level 1

Hi

   

I am trying to use the SAR10 Module in the CY28xxx series PSoC1 and would like to convert the integer result into float and then display on LCD. I can display the count easily, but am not getting beyond this. Apart from this, I have been hunting high and low for a  c..o..m..p..l..e..t..e  C guide for the free included Imagecraft C compiler, but till now have only found the standard one that makes no mention of csprintf and many of the other functions found in stdio.h, etc. Where am I missing something that should be so easy to do and find??? 

   

Your help is highly appreciated.

0 Likes