CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

do while loop

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
morebudwiser



Joined: 17 Oct 2005
Posts: 26

View user's profile Send private message

do while loop
PostPosted: Tue Jul 01, 2008 4:51 am     Reply with quote

hi i want to go round my do while loop while port b pin 1 is low and my adc value is not = 2345 but my code comes out of the loop when ever the adc has the correct value and pin B0 is still low
Code:


Set_tris_b(0xFF);  // set port B for input

do{
adc_value = read_adc_value(0);

}while (adc_value != 2345) &&(!input(PIN-B0)));

many thanks Andrew
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Jul 01, 2008 6:03 am     Reply with quote

Code:

}while (adc_value != 2345) &&(!input(PIN-B0)));

To answer you I must assume a lot of things, one of them is that you are using an MCU
with a built-in 12 bits AD Converter, wich is very complex and new. Is the only way that
your ADC output would get such value.
Another comment is the way you are codding, it is very difficult to know if the task inside
the loop were done really or not. I will try to explain:
Being true my first assumption, that you really are using a 12 bit converter, there
is 4094 against 1 possibilities to exit the loop after the first pass, doing nothing.
Being false my first assumption, that you really are NOT using a 12 bit converter, there
is 100% of possibilities to exit the loop after the first pass doing nothing too.

(!input(PIN-B0))); is wrong
Replace it by (!input(PIN_B0)));

The point is that with the posted code, you would never know if it is running or not because
it doesn't matter if the code stay in the loop or not, because it is doing nothing. Just for
debugging, inside the loop it is a good practice to do something "visible" like toggle a LED
or setting a flag or increment a counter or setting a variable that is going to be checked as
soon as exit the loop.

When posting please, give us as much as data as you have, post a complete code and if
you doesn't know how to code it, at least tell us what your intention is. In this way you will
get a lot of help and nobody would be guessing like me.


Humberto

PD:
Andrew,
I like your nick -morebudwiser- but I'd suggest a new one: moreKernighan & Ritchie.
No offence Wink
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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