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

right OR wrong

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



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

right OR wrong
PostPosted: Mon Nov 07, 2011 1:24 pm     Reply with quote

im doing right OR wrong
Code:
/*************************************************************************
  Function Delay_sec for 1 sec
 ****************************************************************************/
void Delay_sec(void)
{
   delay_ms(1000);
}

hear OK ?
NOW I CAN USE LIKE ? ...
Code:
     if (Delay_sec>260)
           BlinkLED3();

_________________
sahu
vortexe9000



Joined: 07 Jun 2010
Posts: 50
Location: Banned - spammer

View user's profile Send private message

hi...
PostPosted: Mon Nov 07, 2011 1:57 pm     Reply with quote

sqsdf532
_________________
Banned for spamming his own posts


Last edited by vortexe9000 on Sun Feb 19, 2012 7:38 am; edited 1 time in total
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Nov 07, 2011 2:17 pm     Reply with quote

Delay_sec is a function that returns void. So your IF statement waits one second and then compares void to 260. I would expect the compiler to gag.
_________________
The search for better is endless. Instead simply find very good and get the job done.
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Tue Nov 08, 2011 2:38 am     Reply with quote

SherpaDoug wrote:
Delay_sec is a function that returns void. So your IF statement waits one second and then compares void to 260. I would expect the compiler to gag.
can you give 1 example ?
_________________
sahu
ckielstra



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

View user's profile Send private message

PostPosted: Tue Nov 08, 2011 5:36 am     Reply with quote

Sorry, we can not help you because we do not understand what you want to do. Please explain more.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Nov 11, 2011 12:20 pm     Reply with quote

Quick answer: Wrong.


Declare a global
Code:
int Seconds;


Change your function declaration to
Code:
Int Delay_sec()


Code:

Int Delay_sec()
{
   delay_ms(1000);
   Seconds++;
   Return(Seconds)
}



Code:
     
if (Delay_sec>255)
BlinkLED3();



.... as above should do what you want... but only upto 255 seconds.
.... you have to place your Delay_Sec function inside a loop though..or somthing... that calls it the amount of time you want ... you can use the Seconds variable you declared as the counter for the loop...
.... you can figure it out from here...


you are better of doing:

Code:
Void Delay_Sec(int Seconds)
{
   while(Counter<Seconds)
   {
   Delay_ms(1000);
   Counter++;
   }
}


but the above makes your code stay in the loop for upto 255 seconds... which makes your code HORRIBLE... and renders your PIC useless for a hell of a long power wasting time...which is what everybody else here has been telling you...
for such long delays... its probably better to have an external RTC with alarm... or 1hz signal and have it interrupt... and count that...
or a zillion smaller interrupts using the timers... somthing else other than calling a delay function until you get the desired delay...
its possible but bad idea.

g
_________________
CCS PCM 5.078 & CCS PCH 5.093
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