Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to write 2 hours delay for timer in pic18f452

Status
Not open for further replies.

mcxim1215

New Member
hi..i need help on writing the program for 2 hours of timer, where after 2 hours, it will reset back and return to 0. please help. im using pic18f452. the code can be in the assembly language which can run in mplab..but in c also can..
 
Have a look at the timer1 section of the 16F88 data sheet. It has example code to make a real time clock and will be easily modifiable to suit your needs.

Mike.
 
Have a look at the timer1 section of the 16F88 data sheet. It has example code to make a real time clock and will be easily modifiable to suit your needs.

Mike.

thank u...but i wonder if u can show me the example to write the code for 2 hours..because as far as i learn now..i've only learn to write the timer for few second...thats why ive got problem to write the code for 2 hours..
 
Hi,

The code you need depends on what you want to do now and in the future.

If you only want to do a 0 - 2 hours delay then reset things, a simple delay based timer will do.

If you want to do different times in the future or run other functions on the Pic at the same time then a Real Time Clock is the better option as Pommie suggested.

Perhaps post the code you have done for the ' timer for a few seconds' and we can point you in the right direction.
You need to specify the oscillator frequency you are using.
 
Step 1: use a counter to count seconds.

Step 2: once you can count seconds, count minutes

Finally step 3: Count hours.

use a variable for each counter. try writing the seconds program, and if you need help we'll help you. I'm going to write a clock program based on a 8 Mhz clock. I have it blinking a LED every 10 seconds based on a second counter variable. Eventually, I will add minutes and hours, but that is a low priority because I have changed my requirements for my current project that does not include a clock. When I add data logging capabilites, I'll add a clock.
 
Last edited:
I build'em like rmain1972: nested count loops until you're above the goal. I like using a very short interrupt every 100mS or so that only resets itself and increments a register.

The main program loop then checks the register for some rollover value (10=1S, 100=10S, etc), updates the next level counters then checks for the timed event value.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top