rtcc.c - Demonstrates using the secondary oscillator with a 32768 Hz oscillatorΒΆ
See chapter 12.
#include "pic24_all.h"
volatile uint16_t u16_seconds = 0;
//Interrupt Service Routine for Timer1
void _ISRFAST _T1Interrupt (void) {
u16_seconds++;
_T1IF = 0; //clear the timer interrupt bit
}
void configTimer1(void) {
T1CON = T1_OFF | T1_IDLE_CON | T1_GATE_OFF
| T1_SYNC_EXT_OFF
| T1_SOURCE_EXT
| T1_PS_1_1 ; //
PR1 = 0x7FFF; //period is 1 second
_T1IF = 0; //clear interrupt flag
_T1IP = 1; //choose a priority
_T1IE = 1; //enable the interrupt
T1CONbits.TON = 1; //turn on the timer
}
int main(void) {
__builtin_write_OSCCONL(OSCCON | 0x02); // OSCCON.SOSCEN=1;
configBasic(HELLO_MSG); //say Hello!
configTimer1();
while (1) {
outString("Seconds: ");
outUint16Decimal(u16_seconds);
outString("\n");
while (!IS_TRANSMIT_COMPLETE_UART1());
SLEEP();
}
}