View previous topic :: View next topic |
Author |
Message |
sahu77
Joined: 08 Sep 2011 Posts: 202
|
right OR wrong |
Posted: Mon Nov 07, 2011 1:24 pm |
|
|
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
|
hi... |
Posted: Mon Nov 07, 2011 1:57 pm |
|
|
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
|
|
Posted: Mon Nov 07, 2011 2:17 pm |
|
|
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
|
|
Posted: Tue Nov 08, 2011 2:38 am |
|
|
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
|
|
Posted: Tue Nov 08, 2011 5:36 am |
|
|
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
|
|
Posted: Fri Nov 11, 2011 12:20 pm |
|
|
Quick answer: Wrong.
Declare a global
Change your function declaration to
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 |
|
 |
|