Microchip® Advanced Software Framework

Example

Add this to the main loop or a setup function:

/* Configure push button 0 to trigger an interrupt on falling edge */
ioport_set_pin_dir(EXAMPLE_BUTTON_INT, IOPORT_DIR_INPUT);
if (!gpio_set_pin_callback(EXAMPLE_BUTTON_INT, pb0_callback, 1)) {
printf("Set pin callback failure!\r\n");
while (1) {
}
}
gpio_enable_pin_interrupt(EXAMPLE_BUTTON_INT);
  1. Initialize a pin to trigger an interrupt. Here, we initialize PC03 as an input pin with pull up and glitch filter and to generate an interrupt on a falling edge.
  2. Set a callback for the pin interrupt.
    if (!gpio_set_pin_callback(EXAMPLE_BUTTON_INT, pb0_callback, 1)) {
    printf("Set pin callback failure!\r\n");
    while (1) {
    }
    }
  3. Enable pin interrupt.
    gpio_enable_pin_interrupt(EXAMPLE_BUTTON_INT);

Interrupt Usage

When an interrupt happens on a pin, it will execute your callback function.

static void pb0_callback(void)
{
/* Handle pin interrupt here e.g. toggle an LED */
LED_Toggle(LED0);
}