You are on page 1of 1

#include <xc.

h>
__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & BOREN_ON & LVP_ON &
CPD_OFF & WRT_OFF & CP_OFF);
#define _XTAL_FREQ 4000000
#include "stdint.h"
#define LED RB0

uint8_t C = 0; // Global Counter Variable

void __interrupt() tc_int (void)


{
// Check The Flag Bit
if (TMR1IF)
{
C++;
if(C == 15) //C is number of overflows
{
// Toggle The Yellow LED Each Second
LED = ~LED;
// Clear The Global Counter
C = 0;
}
TMR1IF = 0; // Clear The Flag Bit
}
}

void main()
{
TRISB0 = 0;
RB0 = 0;
// -- [[ Configure Timer1 + Interrupts ]] --
TMR1 = 0;//Clear The Timer1 Register. To start counting from 0
TMR1CS = 0; //Choose the local clock source (timer mode)
//Choose the desired pre-scaler ratio (1:1)
T1CKPS0 = 0;
T1CKPS1 = 0;

TMR1IE = 1; //Timer1 Interrupt Enable Bit


PEIE = 1; //Peripherals Interrupts Enable Bit
GIE = 1; //Global Interrupts Enable Bit
TMR1IF = 0; //interrupt flag
TMR1ON= 1; //Switch ON Timer1 Module

while(1)
{
}
}

You might also like