cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

Hi,

   

Programming on PSoC Creator I went int trouble about the conversion from  float to ASCII, i searched and found this:

   

http://www.cypress.com/?id=4&rID=39791

   

I give it a try with this code:

   

#include <stdio.h>
const float PI = 3.1416;
int n=0; byteswritten = 0;
float x = 0;
char str[6];

void main()
{
               while (1)
                 {
                   x= sprintf(str, "%f", PI);
                 }
}

   

The conversion went good, have my string.... but "n" went affected, debug shows n = 12337, i tried changing the name... but no solution, its a big problem for me because i'll use "n" on next step, and it gets affected always in the cicle.

0 Likes
Reply
1 Solution
Esteemed Contributor

The len of str[ ] must be # characters + 1, + 1 for the null string

   

terminating character.

   

 

   

I will try code to see if I get same result.

   

 

   

Regards, Dana.

View solution in original post

0 Likes
Reply
10 Replies
Esteemed Contributor

The len of str[ ] must be # characters + 1, + 1 for the null string

   

terminating character.

   

 

   

I will try code to see if I get same result.

   

 

   

Regards, Dana.

View solution in original post

0 Likes
Reply
Esteemed Contributor

I changed the variable name "n" to "nofn", and it worked.

   

 

   

Looks like "n" is a reserved word in Keil, but I could not find

   

the reserved word list in docs.

   

 

   

Regards, Dana.

0 Likes
Reply
Anonymous
Not applicable

Thanks Dana, worked with the n + 1, also found here:

   

http://www.psocdeveloper.com/forums/viewtopic.php?f=42&t=7625

   

written by you, thanks for the quick reply.

0 Likes
Reply
Esteemed Contributor

I found the reserved words list in assembler, but "n" does not show up

   

there.

   

 

   

Bug report to Keil ?

   

 

   

Regards, Dana.

0 Likes
Reply
Anonymous
Not applicable

Don't know, have an issue with 1 letter variables and that compiler, try "B" and get some trouble... the quickpatch i found for it its numering "B1" etc, my vars.

0 Likes
Reply
Anonymous
Not applicable

 i think itis something to do with optimization. it is declared but not referenced. If you actually use it, it may be correct. However, it is best to give a name to any variable as it would make your debugging much easier.

0 Likes
Reply
Esteemed Contributor

" i think itis something to do with optimization. it is declared but not referenced. "

   

 

   

When I renamed variable it remained unused, but worked. Furthermore I turned off

   

all optimization, "n" was still a problem as a variable name. Optimization is not the

   

source of the problem.

   

 

   

Regards, Dana.

0 Likes
Reply
Anonymous
Not applicable

I dont know what the problem here is...but I have used single letter variables a number of times before and thay've worked fine!!!

0 Likes
Reply
Anonymous
Not applicable

 I may be using optimization incorrectly.

   

But KEIL complier produce very good code and RAM usage.

   

to my understanding, 

   

1. If a variable is declared by not used. the compiler can USE the RAM location for other use it needs, OR it may not be use, it is up to the compiler.

   

2. Change to a different variable name would mean chaning the lcoation of the vaiable list during compilation and may point to different location which again MAY or MAY not be use by other purpose.

0 Likes
Reply
Esteemed Contributor

1. If a variable is declared by not used. the compiler can USE the RAM location for other use it needs, OR it may not be use, it is up to the compiler.

   

 

   

You can always ask Keil and confirm if their optimization of unused variables is that in consistant.

   

 

   

Regards, Dana.

0 Likes
Reply