|
|
View previous topic :: View next topic |
Author |
Message |
collison Guest
|
While compares in MPLAB |
Posted: Tue Dec 20, 2005 3:20 pm |
|
|
I am having trouble with a while loop. The code is as follows:
while(j>x)
{
}
For some reason it does not like comparing two variables in this manner. It works if I put a number in the place of one of the variables, but it won't execute with two variables in place. Any ideas on why this is and what I can do to fix it????
Thanks |
|
|
Ttelmah Guest
|
|
Posted: Tue Dec 20, 2005 3:29 pm |
|
|
It should work fine.
The commonest problem, is with forgetting the 'size limits' on variables (remember that if these are only integers, 255 is the largest value, and if 'signed', 127). Test the comparison, by generating an expression, and verify that it would return non zero (true), when you expect. Another 'classic', is with an unsigned variable, that can (of course), never be -ve. The handling of overflows is non-existent/poor in CCS, so you must ensure that your variables can cope in all cases. I have used such expressions in hundreds of places without problems.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 20, 2005 3:30 pm |
|
|
Make a complete (but small) test program that shows the problem.
Show all #include, #fuses, and #use statements. Show all variable
declarations. Initialize the variables to some value. Put something
inside the while loop to show that it's running (such as a printf statement).
Then test it and post it. |
|
|
|
|
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
|