Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

c language for timer countdown

Status
Not open for further replies.

alexang

Newbie level 4
Joined
Oct 7, 2010
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,331
for example i switch on a LED for 5 second then turn off for 5 second.
i keep repeating this process. now i want the LED just can turn on in total time of total 30 second(total 6 time off my process just now), then the LED wont be light on after this 30 second.
 

as I recall there is a library function that gives you time delay.. It depends on the microcontroller you are using.
another way to creat a time delay is to use loops ..
 

You can just use a countdown variable when the LED is OFF. Every time the LED is OFF, decrement this variable once, and compare the value of this variable to 6, repeat this cycle as long as this variable is smaller than 6. When it reaches 6 then, turn off the LED forever.

Hope this helps.
 

i know that can use counter/timer.
but i wan a simple source code how to use counter/timer by using c language.
 

so you can count 5 seconds now but you count 30 seconds?

if you post your working code to count 5 seconds, I will help count to 30 seconds.
 

void main()
{
unsigned long delay_time=5000;

TRISB = 0b00000111;
TRISA = 0b00000001;

while(1)
{
while((sensor==1)||(SW2==1))
{
in=1;
out=0;
stay=1;
delay(700);
in=0;
out=0;
stay=1;
delay(700);
{
while(stay==1)
{
if(sensor==0)
{
in=0;
out=1;
stay=0;
delay(700);
in=0;
out=0;
stay=0;
}
else
{
in=0;
out=0;
stay=1;
}
}
}
}
while(SW1==1)
{
in=0;
out=1;
stay=0;
delay(700);
in=0;
out=0;
stay=0;
}
}
}

---------- Post added at 00:06 ---------- Previous post was at 00:00 ----------

my project is moving a car in and out
SW1 ON = car moving out for 5 second then automatic stop
SW2 and sensor ON=car go in for 5 second then automatic stop
when sensor OFF car will go out for 5 second then automatic stop
<<problem is i just allow this car stop at outside just for 30 second then automatic moving in for 5 second then stop all process>>
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top