INT0 – Checking a button using interrupts with antibounce

  1. What this example do?
  2. How I must configure my ORbit16™ to work with this example?
  3. Where I can learn more about this?
  4. Download this example!

What this example do?

This example will invert led L2 status on SW2 pressing. The button is checked using interrupts: SW2 is located on RB7/INT0 and INT0 has an interrupt source on status change (we can select falling edge or rising edge).

Since RB7 is pulled high by a resistor and is pulled down on pushing it, we are going to set the interrupt to be fired on falling edge. On the first button press a counter will start. Counter is mantained by Timer1 interrupt. After counter reaches 0 value, the button is checked another time to confirm the button press and then a flag is raised. Flag is then checked in the main.

This routine is very efficient: the led will not invert his status continuously if we leave the button pushed.

How I must configure my ORbit16™ to work with this example?

Nothing to configure. Only remember to set the jumper for USB in device mode in order to make bootloader work.

Where I can learn more about this?

  • The PIC24F family reference manual, Section 8 – Interrupts
  • dsPIC30F_dsPIC33F_PIC24H_IO_Library_Help.htm (english language)
    This is an HTML file you’ve got with MPLAB C30 installation. Usually this document is located in the following folder:

    C:\Program files\Microchip\MPLAB C30\docs\periph_lib
  • Reading document this will give you extra skills in the usage of interrupts on INTx and CNx I/Os.Note: this documents refers to PIC24H and dsPIC series, so some parameters are not usable with the PIC24F

Download this example!

This file is in ZIP format
INT0 demo - Check a button using interrupts
12.01 kB - Downloaded 33 times