Hey, i'm in the process of creating a Real Time Clock using the Timer1 register of a PIC16F88. I will be using a external 32.768KHz crystal to pulse the register.
I've done a little maths and figured that I need to preload the TMR1H and TMR1L registers with the value 32768 in order to achieve a 1 second count until overflow.
I have wrote the following code below in SourceBoost:
Any help is greatly appreciated, thanks.
I've done a little maths and figured that I need to preload the TMR1H and TMR1L registers with the value 32768 in order to achieve a 1 second count until overflow.
I have wrote the following code below in SourceBoost:
I have wrote the Interrupt code under the "void isr" heading, now I need this code to be called every time the Timer1 register overflows i.e after every second. I just dont know how to implement this. I've tried just calling the interrupt from the main code but once inside the interrupt code the program never leaves it, but I need the interrupt code to be constantly running in the background whilst the main code runs.#include <system.h>
#include <pic16F88.h>
volatile bit RA1 @ PORTA.1;
volatile bit RA4 @ PORTA.4;
volatile bit RB4 @ PORTB.4;
int seconds=0,minutes=0,hours=0;
void init(void)
{
t1con=00001111b;
pie1.0=1; //set Interrupt Enable bit
trisa=10010b;
trisb=0b;
porta=0b;
portb=0b;
osccon=01111110b; //internal 8Mhz clock
intcon=10000000b; //enable GIE
cmcon=00000010b;
cvrcon=11000100b;
delay_s(1);
}
void isr()
{
tmr1h=10000000b; //pre-load timer1 reg with 32768
pir1.0=1; //clear interrupt flag
++seconds;
if(seconds>59)
{
++minutes;
seconds=0;
}
if(minutes>59)
{
++hours;
minutes=0;
}
}
void main() //start of main function
{
init(); //call initialisations
while(1) //infinite loop
{
REST OF CODE....
}
Any help is greatly appreciated, thanks.