ExampleToggleLed

Here's a simple example of toggling an LED using the external interrupt (INT).

LED1   VAR  PORTB.1

INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts

ASM
INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
        INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
    endm
    INT_CREATE               ; Creates the interrupt processor
ENDASM

@   INT_ENABLE   INT_INT     ; enable external (INT) interrupts

Main:
  PAUSE 1
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
     TOGGLE LED1
@ INT_RETURN



Rising Edge: OPTION_REG.6 = 1

By default, the INT input will generate an interrupt on the Rising edge of the signal.

Using the circuit shown to the right, the LED will toggle on and off with each "Press" of the pushbutton (S1).

The INT input can also be configured to interrupt on the Falling edge by changing the INTEDG bit. (OPTION_REG.6)

    INTEDG: Interrupt Edge Select bit
    1 = Interrupt on rising edge of INT pin
    0 = Interrupt on falling edge of INT pin

If you use this circuit with the Falling edge selected, then the LED will toggle on each button "Release".




Falling Edge: OPTION_REG.6 = 0

Usually it's not a good idea to allow the power supply voltage to leave the PC board. So, this circuit is preferred if using pushbuttons.

With INTEDG = 0, the LED will toggle with each button "Press". Or, with INTEDG = 1, it will toggle with each "Release"






Page last modified on February 24, 2018, at 07:22 PM