rising edge interrupt on a micro pic 18f

Status
Not open for further replies.

jay543_uk

New Member
Hi, im trying to count how many pulses happen over a 1 sec delay on the rising edge of int1 of a pic 18f2620. My problem is that my code never seems to enter the interrupt routine, i believe the circuit is working fine so can any1 see anything wrong with my code
many thanks


Code:
#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
}

attached my input circuit, i have changed the resistor value
 

Attachments

  • Draft50.png
    36.6 KB · Views: 398
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…