Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > C functions for PSOC 1

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



C functions for PSOC 1
Moderator:
ARVI

Post Reply
Follow this topic



C functions for PSOC 1

Srinath posted on 01 Feb 2012 1:07 AM PST
Top Contributor
34 Forum Posts

 Is there an inbuilt function that converts ADC's output values to decimal values(in C ) for display purpose. 




Re: C functions for PSOC 1

Bob Marlowe posted on 01 Feb 2012 02:46 AM PST
Top Contributor
1768 Forum Posts

Oh yes, there are.

#include <stdio.h>

and use the sprintf, csprintf functions. The latter is used when the format is a string constant (as usual).

Works correctly for floats with Designer 5.2

 

Bob



Re: C functions for PSOC 1

Srinath posted on 02 Feb 2012 03:48 AM PST
Top Contributor
34 Forum Posts

  thank  you Bob

tough I could not able to use it . I got one similar to it,   "  char *itoa (char *string, int value, int base); "

which convets integer values to string & can be easily displayed on an LCD using " LCD_PrString(CHAR * sRamString); "

 



Re: C functions for PSOC 1

Bob Marlowe posted on 02 Feb 2012 06:48 AM PST
Top Contributor
1768 Forum Posts

Try this

#include <stdio.h>
char Buffer[17];  // 16 chars for LCD-Line + /0 character
void main(void)
csprintf(Buffer,"%s = %d","Test",32767);  // Buffer has now the string "Test = 32767"

LCD_PrString(Buffer);

You are totally free in specifying the format, have a look (http://publications.gbdirect.co.uk/c_book/chapter9/formatted_io.html) at the specs. You can convert (and print) Floats, longs ints and chars.

Bob

 



Re: C functions for PSOC 1

Prasanna posted on 20 Jul 2012 07:00 AM PST
Top Contributor
45 Forum Posts

hi bob,

               i am faced with a similar problem, how to convert a floating point value to a string. my basic requirement is to send a float value to the hyperterminal display through UART. i am using PSoC designer 5.1 . when i use the sprintf function as shown below. the compiler shows out an error saying it expects pointer to flash char but found pointer to char.

sprintf(Buffer,"%s = %d","Test",32767);



Re: C functions for PSOC 1

Bob Marlowe posted on 20 Jul 2012 07:32 AM PST
Top Contributor
1768 Forum Posts

The format is a const string, so you have to use

csprintf(Buffer,"%s =%d","Test",32767)

 

Bob



Re: C functions for PSOC 1

Prasanna posted on 20 Jul 2012 09:03 AM PST
Top Contributor
45 Forum Posts

hi bob,

       i tested my program with the function

csprintf(Buffer,"%s = %d","Test",32767);

actually the function is written inside an infinite while loop along with many other functions. what i observe is whenever this function is not active(commented out) the while loop works. but as soon as the function is made active and included the while loop terminates after a single run. i don't know what could have gone  wrong.



Re: C functions for PSOC 1

Bob Marlowe posted on 20 Jul 2012 09:28 AM PST
Top Contributor
1768 Forum Posts

Is the size of the buffer greater 12?

 

Bob

 



Re: C functions for PSOC 1

Bob Marlowe posted on 20 Jul 2012 09:40 AM PST
Top Contributor
1768 Forum Posts

And for the floats have a look here http://www.cypress.com/?app=forum&id=1573&rID=43329 .

Probably you have to declare an integer and assign 32767 to it, maybe it is interpreted as a 32-bit number which will not be properly handled by sprintf.

 

Bopb

 



Re: C functions for PSOC 1

danaaknight posted on 20 Jul 2012 10:59 AM PST
Top Contributor
1773 Forum Posts

Compilers handle printf()/sprintf() differently, eg. feature set, from one compiler

to another. Typically if printf() handles longs and floats, so does sprintf(). You can

look at .h, .inc files for the definitions typically to confirm, or consult compiler

manufacturer.

 

Regards, Dana.



Re: C functions for PSOC 1

arvi posted on 23 Jul 2012 07:01 AM PST
Cypress Employee
119 Forum Posts

If you know the size of your final string beforehand, it is better to declare the string buffer as

char Buffer[13]  rather than  char * Buffer[];

Here, the value is 13 assuming you have 12 characters ("Test = 32767") + 1 NULL terminator.

 

You can then use UART_PutString(Buffer) which sends the NULL terminated string out the TX.

 

-Arvind






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20