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.

how to set and reset pin in microcontroller

Status
Not open for further replies.

mshh

Full Member level 6
Joined
May 30, 2010
Messages
349
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
usa
Activity points
3,871
I enabled timer and i want to set and reset pin in microcontroller every two hours, how to do that? i mean i want the pin on for 2 hours and off for another 2 hours.
 
Last edited:

Hi,

what a question...

Neither clear whether the timing is the problem or set/clear a pin
nor does it give a clue about microcontroler, language or compiler.

so: How can we help?

Hint: it is a very basic task (or two tasks) which has been discussed numerous times in the internet and the forum...
What have you done so far to find a solution on your own.

Klaus
 

the problem is i want to set and reset it every 2 hours and every state hold its value for 2 hours
for example
Code:
if( hour=1&minute=59)/// this will set it every 2 hours but it will reset after 1 minute when the condition is false.
{
set
}
 
Last edited:

Hi,

Still unclear what the problem is.

if( hour=1&minute=59)/// this will set it every 2 hours but it will reset after 1 minute when the condition is false.
{
set
}
Wrong. Your code never clears the pin. The pin will be set at 1:59 and it remains in this state.

What about a simple flow chart? You think it´s useless? Or a timing diagram...
What about using a simulator or emulator?

Klaus
 

Code:
if( hour=1&minute=59)/// this will set it every 2 hours but it will reset after 1 minute when the condition is false.
{
set
}
else // when (hours=0&minute=0 or hours=1&minute= 0 or hours=0&minute=59)
{
reset /// for two hours but time is changing so will the condition 
}
ok, i will try in simulator, but i need suggestions to assure that i am using the right path.
 
Last edited:

Hi,

I think it´s time for a little effort on your own. At least for giving complete informations and specifications. And give some clarifications according post#2.

For example:
We don´t know where "hour" and "minute" come from. We don´t know whether this is absolute time in 12h or 24h format or if you may reset the variables as you like.


Klaus
 

Is this for the Arduino?
If yes, then just use the millis() fucntion.

If not then which which micro-controller?
Typically, a Hardware Timer will trigger an interrupt.
Every Timer Interrupt increments a variable until the desired Count ( 2 Hours ) is reached.
Then simply Toggle the Output Bit, reset the variable and repeat forever.
 

I enabled timer and i want to set and reset pin in microcontroller every two hours, how to do that? i mean i want the pin on for 2 hours and off for another 2 hours.

Ok. Let's assume your timer generates interrupt every 100mS.
Now declare a variable as Int or Word (I.e. 16 bits) named Counter.
Declare another variable as 2-hour-flag.

In your 100mS isr, increment the Counter. Also if Counter is >= 72000, then SET 2-hour-flag.

Now in your main routine, setup a loop which checks 2-hour-flag. When it is SET, then TOGGLE your outputpin, and also set 2-hour-flag and Counter to zero.

That's your full code right there.

Of course if your timer interruots at a different rate, then calculate the '72000' accordingly.

- - - Updated - - -

Okay, slight error in above. The variable for Counter naturally has to be defined to be able to hold the count required. So select accordingly. Typical Int will not hold 72000, only upto 65535.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top