- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Labels:
-
PSoC 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found the reserved words list in assembler, but "n" does not show up
there.
Bug report to Keil ?
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
" 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.