|
|
View previous topic :: View next topic |
Author |
Message |
Koketso
Joined: 05 May 2011 Posts: 4
|
calculations in ccs |
Posted: Sat Nov 05, 2011 9:44 pm |
|
|
Can anyone help me with guidelines on how to handle values beyond 256, since ccs returns incorrect answers, e.g. 250 +250 = -12. Is there a library I am suppose to include apart from math.h? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Nov 05, 2011 9:53 pm |
|
|
While you have a project open, press F11, and the CCS onscreen HELP file will come up.Look on the left side, click on 'data definitions' and read the screen info.
I always have the HELP screens open...very,very handy reference to almost everything you need to know about CCS C ! |
|
|
Koketso
Joined: 05 May 2011 Posts: 4
|
|
Posted: Sat Nov 05, 2011 10:16 pm |
|
|
Tried unsigned long, still getting incorrect values but this time they are different from the ones obtained first. Do I need to do a conversion before I display on a LCD ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Nov 05, 2011 10:52 pm |
|
|
You'll have to show us your code...but yes, the format of the print function has to be coded for the type of data you want to show, again, look at the onscreen help file, lookup 'printf', it's all there or open up any of the examples CCS kindly supplies to see how it's done. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Sun Nov 06, 2011 4:57 am |
|
|
This is not specific to CCS, though it is slightly 'tighter' in CCS, than in most modern languages.
Basically, in C, _you_ have to ensure that the maths type used, can support all possible values at all times, and then select the output format to suit that type.
Now on most C's on the PC (for example), the 'minimum' type used, is at least an int16, so problems are slightly less common, and on more strongly 'typed' languages, the compiler will complain if you try to print a value with a format that doesn't support it. It is both a power and a weakness of C, allowing you to mix types in a way that such languages don't allow, and (especially on little chips like the PIC), avoid using slower maths forms when not needed, but with these advantages, comes the cost of you needing to think at all times whether the types will support what you want to do.....
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|