// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ
#include <xc.h>
volatile unsigned int count = 0;
void main(void)
{
//Make all PORTD pins low
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
// Configured PORT pins as Output
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
// Timer0 with internal instruction clock and 64 as prescalar
OPTION_REG = 0b00000101;
TMR0 = 0; // Load the time value
GIE = 0; //Clear Global Interrupt
TMR0IF = 0; // clear timer interrupt flag updated line
TMR0IE = 1; //Enable timer interrupt bit
while(1)
{
if( TMR0IF == 1 )
{
count++;
TMR0IF=0; // Clear timer interrupt flag
}
}
return;
}