#include <xc.h>
// PIC16F15324 Configuration Bit Settings
// CONFIG1
#pragma config FEXTOSC = HS // External Oscillator mode selection bits (Oscillator not enabled)
#pragma config RSTOSC = EXT4X // Power-up default value for COSC bits (HFINTOSC = 32MHz)
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit (FSCM timer enabled)
// CONFIG2
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
/***************************
INTERRUPT SERVICE ROUTINE
***************************/
void interrupt isr(void) {
PIR4bits.TMR1IF = 0;
LATCbits.LATC2 = 0;
}
/***************************
Main function
***************************/
void main(void) {
// Init CPU
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
PIE4bits.TMR1IE = 1;
// Oscillator in LATA2
TRISCbits.TRISC2 = 0;
while(1) {
LATCbits.LATC2 = 1;
PIR4bits.TMR1IF = 1;
}
}