C functions for PSOC 1

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

cross mob
Anonymous
Not applicable

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

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

View solution in original post

0 Likes
10 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

  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); "

    

 

   
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

Anonymous
Not applicable

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);

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

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

   

 

   

Bob

0 Likes
Anonymous
Not applicable

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.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Is the size of the buffer greater 12?

   

 

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

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

0 Likes