Positron Compiler Documentation

On_Low_Interrupt

Positron8 · Revision 4.0.6.5 · PDF pages 469–470

On_Low_Interrupt Label

Point to the subroutine that will be called when a Low Priority Hardware interrupt occurs on an 18F device.

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

' Demonstrate the use of context saving of the compiler's System variables
' Creates low and high priority interrupts incrementing on Timer0 and Timer1
' Within the interrupts a value is displayed and incremented
' In the foreground another value is incremented and transmitted serially
'
  Device = 18F26K40          ' Tell the compiler what device to compile for
  Declare Xtal = 16      ' Tell the compiler the device will be operating at 16MHz
  Declare Hserial_Baud = 9600  ' Choose the Baud rate for HRsoutLn
'
' Point to the High Priority interrupt handler to the subroutine
'
  On_Hardware_Interrupt GoTo ISR_High
'
' Point to the Low Priority interrupt handler to the subroutine
'
  On_Low_Interrupt GoTo ISR_Low
'
' Create some variables
'
  Dim HighCounter as Dword         ' Counter for the high interrupt routine
  Dim LowCounter as Dword          ' Counter for the low interrupt routine
  Dim ForeGroundCounter as Dword   ' Counter for the Foreground routine
  Dim wTimer0 as TMR0L.Word        ' Create a 16-bit Word from registers TMR0L/H
  Dim wTimer1 as TMR1L.Word         ' Create a 16-bit Word from registers TMR1L/H

' ------------------------------------------------------------------
Original diagram or table from Positron8, PDF page 469
Original figure / layout · PDF page 469
Text in this figure or table
'
Main:

  HighCounter = 0
  LowCounter = 0
  ForeGroundCounter = 0

'
' Setup Timer0
'
  T0CONbits_T0PS2 = 0        ' \

  T0CONbits_T0PS0 =  1        ' /
' The Main Program Loop Starts Here

  DelayMs 100                 ' Wait for the LCD to stabilise
  INTCON1 = 0                 ' Disable Interrupts
  Low PORTD                   ' Set PORTD to Output Low

  Cls                          ' Clear the LCD

  T0CONbits_T0PS1 = 0        ' | Timer0 Prescaler to 1:4

  T0CONbits_PSA = 0          ' Assign the prescaler
  T0CONbits_T0CS = 0          ' Increment on the internal Clk
  T0CONbits_T08Bit = 0        ' Timer0 is configured as a 16-bit counter
  wTimer0 = 0                  ' Clear Timer0
  T0CONbits_TMR0ON = 1         ' Enable Timer0
View original PDF page 469Open page in PDFOriginal PDF page 469
'
' Setup Timer1
'
  T1CONbits_RD16 = 1          ' Enable Timer1 in 16-bit operation
  T1CONbits_T1CKPS1 = 0       ' \ Timer1 Prescaler to 1:2
  T1CONbits_T1CKPS0 = 0       ' /
  T1CONbits_T1OSCEN = 0        ' Disable External Oscillator
  T1CONbits_TMR1CS = 0        ' Increment on the internal Clk
  wTimer1 = 0                  ' Clear Timer1
  T1CONbits_TMR1ON = 1        ' Enable Timer1
'
' Setup the High and Low priority interrupts
'
INTCON1bits_TMR0IE  = 1        ' Enable the Timer0 overflow interrupt
INTCON2bits_TMR0IP = 0        ' Timer0 Overflow Interrupt to Low priority
INTCON1bits_TMR1IE = 1         ' Enable the Timer1 overflow interrupt
IPR1bits_TMR1IP = 1          ' Timer1 Overflow Interrupt to High priority
RCONbits_IPEN = 1             ' Enable priority levels on interrupts
INTCON1bits_GIEL = 1           ' Enable low priority peripheral interrupts
INTCON1bits_GIE = 1          ' Enable all high priority interrupts
'
' Display value in foreground while interrupts do their thing in background
'
Do                            ' Create a loop
     ' Display the  value on a serial terminal
     HRsoutLn "ForeGround ", Dec ForeGroundCounter
     Inc ForeGroundCounter    ' Increment the value
     DelayMs 200
Loop                          ' Close the loop. i.e. do it forever
'------------------------------------------------------------------
' High Priority Hardware Interrupt Handler
' Interrupt's on a Timer1 Overflow. Display on the LCD and increment a value
'
ISR_High:
'
' Save the compiler's system variables used in the interrupt routine only
' Also save any SFRs used
'
Context Save PORTD, TRISD
  If PIR1bits_TMR1IF = 1 Then    ' Is it a Timer1 overflow interrupt?
     Print At 1,1,"High Int ", Dec HighCounter ' Yes. So Display value on the LCD
     Inc HighCounter             ' Increment the value
     PIR1bits_TMR1IF = 0        ' Clear the Timer1 Overflow flag
  EndIf
Context Restore ' Restore compiler's system variables used and exit the interrupt
'------------------------------------------------------------------
' Low Priority Hardware Interrupt Handler
' Interrupt's on a Timer0 Overflow. Display on the LCD and increment a value
'
ISR_Low:
' Save the compiler's system variables used in the interrupt routine only
' Also save any SFR's used.
'
  Context Save PORTD, TRISD
  If INTCON1bits_TMR0IF = 1 Then   ' Is it a Timer0 overflow interrupt?
     '
     ' Yes. So Disable Timer 1 High priority interrupt while we use the LCD
     '
     PIE1bits_TMR1IE = 0      ' Display the value on line 2 of the LCD
     Print At 2,1,"Low Int  ", Dec LowCounter,"  "
     Inc LowCounter             ' Increment the value
     PIE1bits_TMR1IE = 1      ' Re-Enable the Timer1 High priority interrupt
     INTCON1bits_TMR0IF = 0    ' Clear the Timer0 Overflow flag
  EndIf
Context Restore ' Restore compiler's system variables used and exit the interrupt
View original PDF page 470Open page in PDFOriginal PDF page 470