Jump to content

Problem With External Interrupt Pic16F877A

Recommended Posts

Hi, I am new to the forum, nice to meet you everyone!


I am working on a project that needs to do an interrupt from external source (RB0/INT) every time that there is a falling edge (TTL), at the moment I am just testing it with a push button, but the final idea is to use a quadrature signal as a input, similar to an encoder signal (I do not know if that can be done yet), but I want to go step by step. Below is my code, basically every time that I push the button it should go to the interrupt but it won't go when I am debugging, I do not know if I am doing something wrong, i would appreciate your help.


By the way I am using boostc compiler and pic16f877a. Many thanks.


#include <system.h>

#ifdef _PIC16F877A

#pragma CLOCK_FREQ 16000000
void inter_set();

void main()



							porte.0 = 0;


void inter_set()

	trisb = 0b11111111;			//PortB as input
	trise = 0b00000000;			//PortE as output
	option_reg = 0b10000000;	// Interrupt on falling edge of RB0/INT pin
	intcon = 0b00000000;		  // Clear interrupt
	intcon = 0b10010000;		  // Enables the RB0/INT external interrupt																		


void interrupt()

porte.0 = 1;
clear_bit( intcon, RBIF );  // Clear flag bit




My configuration:



Link to post
Share on other sites



In your interrupt service routine you are clearing the wrong flag.

For external interrupt the flag to be cleared and tested is intcon.INTF


I'm not sure the interrupts are not happening but the way you coded the signal to the outside "porte.0" it will go off so fast that you don't have time to see it.

You must set up some kind of delay after it is turned on and before turning it off to give you time to see it.

Also note that for each press of the button you will receive multiple interrupts due to the mechanical noise (bouncing) of the switch contacts.


Best regards


Edited by JorgeF
Link to post
Share on other sites
  • 2 months later...

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...