//
// Demo code for the PIC16F876
//
// Example of how to use the External Interrupt Pin
//
// For SP.710, Spring 2001
//
// maxdavis(at)mit.edu
//

#include <16f876.h>
#fuses nowdt, hs, noprotect, put, brownout, nolvp 
#use delay(clock=20000000)

#define LED PIN_C5

#int_ext
void ext_interrupt_subroutine() {
  // it doesn't matter what this subroutine is named, but it will
  //  be run every time the "ext interrupt" goes off, which is 
  //  whenever there is a low-to-high transition on pin B0.
  output_high(LED);
  delay_ms(150);
  output_low(LED);
}

void main() {

  // these lines are just a check that the PIC is working

  output_high(LED);
  delay_ms(500);
  output_low(LED);

  disable_interrupts(GLOBAL);   // make sure all interrupts are disabled
  enable_interrupts(INT_EXT);   // select the External Interrupt
  ext_int_edge(L_TO_H);         
  // tell the PIC to look for a low-to-high transition on the
  //  external interrupt pin (pin B0, on this PIC, see the datasheet)
  enable_interrupts(GLOBAL);    // start checking for interrupts

  // wait here and do nothing, forever!
  // (except since interrupts are on, pressing a button on pin B0
  //  should jump to the subroutine above main() and make the LED flash)

  while(1) { 
  }

}








