Positron Compiler Documentation

On_Hardware_Interrupt

Positron8 · Revision 4.0.6.5 · PDF page 466

On_Hardware_Interrupt Label

Point to the subroutine that will be called when an interrupt occurs. It is used for a High Priority interrupt if using an 18F device.

Label is a valid label name that points to where the interrupt handler routine is located in the BASIC listing.

' Flash an LED on PORTB.0 at a different rate to the LED on PORTB.1
'
   Device = 16F1829          ' Select the device to compile for
  Declare Xtal = 16      ' Tell the compiler the device will be operating at 16MHz
  On_Hardware_Interrupt GoTo ISR_Flash

'---------------------------------------------------
' The main program loop starts here
'
Main:
  Low PORTB = 0             ' Make PORTB all outputs and pull it low
'
' Initiate the interrupt
'
  OPTION_REG = 0b00101111    ' Setup Timer0
  TMR0 = 0                   ' Clear TMR0 initially
  INTCONbits_T0IE = 1       ' Enable a Timer0 overflow interrupt
  INTCONbits_GIE = 1       ' Enable global interrupts
  Do                         ' Create an infinite loop
     Clear PORTB.1          ' Extinguish the LED
     DelayMs 500           ' Wait a while
     Set PORTB.1             ' Illuminate the LED
     DelayMs 500           ' Wait a while
  Loop

'---------------------------------------------------
' Timer0 overflow interrupt handler starts here
' Xor PORTB with 1, which will turn on the LED connected to PORTB.0
' with one interrupt and turn it off with the next interrupt
'
ISR_Flash:
  Context Save      ' Save any variables or SFRs before the interrupt starts
  If INTCONbits_T0IF = 1 Then  ' Is it TMR0 that caused the interrupt?
     PORTB = PORTB ^ 1         ' Yes. So. Xor PORTB.0
     INTCONbits_T0IF = 0       ' Clear the TMR0 overflow flag
  EndIf
  Context Restore    ' Restore any variables or SFRs and exit the interrupt
View original PDF page 466Open page in PDFOriginal PDF page 466

Topics