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

delay_ms() question.

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



Joined: 06 Sep 2003
Posts: 49

View user's profile Send private message

delay_ms() question.
PostPosted: Sun Mar 05, 2006 7:26 pm     Reply with quote

Definition from user manual,
delay_ms(time)
Parameters:
time - a variable 0-255 or a constant 0-65535


So, in the following code, is the value I'm passing a variable or constant? If it is a variable, how can I force it to be a constant?

Code:

#define dropoutTime 100

for(cycle=0;cycle<10;cycle++)
{
    delay_ms(dropoutTime*(10-cycle));
}            
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 05, 2006 7:38 pm     Reply with quote

You can't make it into a constant. You're calculating values at runtime.
That requires a variable.

See this thread for an example of how to create your own delay_ms
function which can accept a 16-bit variable as a parameter.
http://www.ccsinfo.com/forum/viewtopic.php?t=375&highlight=longdelayms
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Mar 06, 2006 9:15 am     Reply with quote

One bad thing about the delay() command is that it causes the PIC to just sit there, twidling it's thumbs, waiting for it to get done. I try not to use it because the PIC could be doing other things while waiting. I like to use the built in timers instead. Just have the portion, that needs the delay, in your main body and have a timer set a flag that will enable that section to continue after a certain amount of time. You can use variables as much as you want this way to adjust the delay time.

Ronald
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