The microcontroller PIC16F877A has one external hardware interrupt at pin RB0/INT. When an interrupt occurs, the microcontroller immediately executes the code attached with the interrupt, after finishing the interrupt code the microcontroller returns to the main code. This topic shows to configure and use the PIC16F877A external interrupt.
PIC16F877A External hardware interrupt example circuit:
The following circuit schematic shows a simple circuit that turns on and off the LED connected to RC0 using a push button connected to RB0 pin. The external interrupt is used to toggle the status of the LED.
PIC16F877A External interrupt example C code:
The C code below was tested with CCS C compiler version 5.051.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // PIC16F877A external interrupt example CCS C code // http://simple-circuit.com/ #include <16F877A.h> #use delay(crystal=8000000) #INT_EXT void ext_isr(void) { clear_interrupt(INT_EXT); // Clear external interrupt flag bit output_toggle(PIN_C0); } void main() { output_low(PIN_C0); ext_int_edge(H_TO_L); // External interrupt edge from high to low clear_interrupt(INT_EXT); // Clear external interrupt flag bit enable_interrupts(INT_EXT); // Enable external interrupt enable_interrupts(GLOBAL); // Enable global interrupts while(TRUE) ; // Endless loop } |
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.