void INIT_INT(void)
{
D_INT0_x = 1; // setting input, INT0 (RF6 )
INTCON2bits.INT0EP = 1; // Interrupt on negative edge
IEC0bits.INT0IE = 1; //Enable INT0 Interrupt Service Routine
IPC0bits.INT0IP = 7;
IFS0bits.INT0IF = 0; // Clear INT0IF
}
void __attribute__((auto_psv,__interrupt__)) _INT0Interrupt(void)
{
freq_counter++;
IFS0bits.INT0IF = 0;
}
int main()
{
INIT_Peripheral();
while(1)
{
printf("freq : %d\n",freq_counter);
}
}
void INIT_TIMER(void)
{
T1CON = 0; // Disable Timer1 for Clock and Reset.
TMR1 = 0x0000; // Clear RTC Timer Register.
PR1 = 10000; // Set Timer1 period register for 10ms
T1CONbits.TCKPS = 1; // Set Timer1 Input Clock Prescale Select bits (1:8)
IFS0bits.T1IF = 0; // Reset Timer 1 interrupt flag
IPC0bits.T1IP = 7; // Set Timer1 interrupt priority level to 7
IEC0bits.T1IE = 1; // Enable Interrrupt w.r.t Timer 1
T1CONbits.TON = 1; // Enable Timer1
}
/* Timer Interrupt */
void __attribute__((__interrupt__,no_auto_psv)) _T1Interrupt(void)
{
IFS0bits.T1IF = 0; //Clear Timer1 interrupt flag
timin = (float)0.01/freq_counter;
freq_counter = 0;
Flag.TimerDelay_10ms = 1;
}