#include <p18f2620.h>
void chk_isr(void); //checks if int1 set the interrupt
void INT1_ISR(void); //increases pulse by 1
void count_pulse(void); //sets int1 and delays 1 sec for pulse count
unsigned char pulse ; //holds the pulse count
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
#pragma code My_HiPrio_Int = 0x08 // high-priority interrupt location
void My_HiPrio_Int (void)
{
_asm
GOTO chk_isr
_endasm
}
#pragma code
#pragma interrupt chk_isr // used for high-priority interrupt only
void chk_isr (void)
{
if (INTCON3bits.INT1IF==1) //INT1 causes interrupt?
INT1_ISR(); //YES. Execute INT1 program
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
void main(void)
{
TRISBbits.TRISB7=0; // RB7 = OUTPUT
TRISBbits.TRISB1=1; // INT1 = INPUT
while(1)
{
count_pulse();
DelayMs(10);
}
}
void INT1_ISR(void)
{
pulse ++;
INTCON3bits.INT1IF=0; //clear INT1 flag
}
void count_pulse(void)
{
INTCON3bits.INT1IF=0; // clear int1
INTCON3bits.INT1IE=1; // enable int1 interrupt
INTCON2bits.INTEDG1=0; // make it positive edge
INTCON2bits.RBPU=1;
INTCONbits.GIE=1; // enable all interrupts
pulse = 0;
DelayMs(1000); // Delay for 1 sec to count how many pulse happens
INTCONbits.GIE=0; // Disable all interrupts
}