// Setting Timer2 - postscaler rate = 1:16 ? what does this mean
// Prescale rate = 1:16 ? what does this mean.
T2CON = 0xFF;
TMR2 = 0; // Timer2 initial value
PIE1.TMR2IE = 1; // Timer 2 interrupt enable
INTCON = 0xC0; // Set GIE, PEIE
PR2 = 0xFF; // how to calculate to get the right value -
}
void interrupt() { // Interrupt occurs on every timer register TMR0 overflow.
if (PIR1.TMR2IF) {
cnt++; // Interrupt causes cnt to be incremented by 1
PIR1.TMR2IF = 0; // reset timer 2 interrupt flag
TMR2 = 0; // set TMR2 to initial value
if (cnt > 100) { // actually i trying to get 100 count = 1 sec or may be less ??
cnt = 0; ss++;
}
}
}
/**************** timer0 ***********************/
If you set the prescaler to 16, postscaler to 10 and PR2 to 125 you will get an interrupt 100 time per second (100Hz). Use a counter to count to 100 and then increment your seconds variable.
So,
T2CON=0b01001110;
PR2=125;
The way to work it out is,
Hz=Oscillator/4/prescaler/postscaler/pr2