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 support@ccsinfo.com

While / For Loops Problem

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



Joined: 09 Feb 2007
Posts: 2
Location: San Diego

View user's profile Send private message Visit poster's website

While / For Loops Problem
PostPosted: Fri Feb 09, 2007 11:16 am     Reply with quote

Hello,

PIC16F84A

I have written a simple code like this to flash an LED:

void main()
{
while (TRUE)
{
loop();
}
}

int loop(void)
{
OUTPUT_HIGH(PIN_B4);
delay_ms(1000);
OUTPUT_LOW(PIN_B4);
return 0;
}

Now when I compile, I get a warning about the while loop always being true. But when I run the program the LED does not blink. If I remove the while loop, the LED will turn on, then off after one second as expected. Does anyone know why the while loop is not working?

It seems like the delay_ms function is kicking it out of the loop function and back to main, then repeating.

Frustrated,

Jason
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Feb 09, 2007 11:41 am     Reply with quote

Your led goes off, but only so short that your eyes don't see it. Add a delay between switching off and on again.

Funny to see that so many people make the same mistake, it must be an error in the human brain. This same question has been on this forum for at least 5 times the last couple of years. Here is a link to a similar question: http://www.ccsinfo.com/forum/viewtopic.php?t=28516
flightdecksoft



Joined: 09 Feb 2007
Posts: 2
Location: San Diego

View user's profile Send private message Visit poster's website

PostPosted: Fri Feb 09, 2007 11:53 am     Reply with quote

WOW! Stupid. Embarassed

Thanks!
vsmguy



Joined: 13 Jan 2007
Posts: 91

View user's profile Send private message Visit poster's website

PostPosted: Sat Feb 10, 2007 12:11 pm     Reply with quote

This is a common mistake in iterative programs.... specially when the person has not been close to hardware recently Smile

I did the same mistake the first time ;)
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