View previous topic :: View next topic |
Author |
Message |
sahu77
Joined: 08 Sep 2011 Posts: 202
|
Software Real Time Clock |
Posted: Sun Jan 15, 2012 11:11 am |
|
|
For Real Time Clock we can use this ??
Code: |
#use delay(clock=4000000)
|
Code: |
/********************************************************
Timer1 Interrupt, executed every 10 ms
********************************************************/
#INT_TIMER1
void TIMER1_isr(void)
{
// Increment time_elasped to keep track of ms
time_elasped++;
// Increment seconds variable if 1000 ms have passed
if (time_elasped == 100) //@ 1000 ms
{
seconds++;
time_elasped = 0;
}
//Reset Timer 1
set_timer1(60545);
clear_interrupt(INT_TIMER1);
}
|
its right ??? _________________ sahu |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sun Jan 15, 2012 1:20 pm |
|
|
Why don't you just use the working software RTC that's in the code library?
What you posted isn't even close to being a real program, so we have no way of knowing that it might work.
BTW one problem with sw rtc is they only run when the PIC is powered ! I've gone to using the DS1307 in my products.The other is the sw overhead(space, time,etc.) |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Jan 15, 2012 1:23 pm |
|
|
It helps when you post a complete program. Now we have to guess as to what processor you are using and the configuration of the Timer1 is missing. Without this we can not tell if it is correct or completely wrong.
You've been a member of this forum for so long now that you should know we always ask for a complete program and you are proofing us to be right again.
Explain how you got to the magic value of 60545. It sounds to be very close to a correct value but depends very much on compiler version and other details. I would like to hear your reasoning.
Clearing the Timer1 interrupt is not required, the compiler will do it automatically. Now it is being cleared twice, a waste of memory and processing power. |
|
|
|