LowPriorityINTS

So now we have all three examples going at the same time. But, they are all running under High Priority Interrupts.

Adding Low Priority interrupts is just as easy, but first we need to tell DT_INTS-18 to use Low Priority Interrupts.

DEFINE USE_LOWPRIORITY 1

And, if using Basic Language in the LP Ints, we also need to add another INCLUDE file...

INCLUDE "ReEnterPBP-18LP.bas" ; Include if using Low Pr. PBP INTS

Adding this file creates another whole set of locations to save PBP system variables. It's kept separate in order to save RAM space when not using Low Priority interrupts. Then with this file included, you can create another "List" of interrupt handlers for the Low Priority ints.

Let's take the last example (Combine) and add a Low Priority USART Receive interrupt that will set the elapsed timer to a specific time. Since the Low Priority interrupts can be interrupted by the High Priority interrupts, statements that take longer such as HSERIN or I2CWRITE, can run as an interrupt, without interfering with the Timers or other operations that can't be stopped.

Note the "_L" in INT_LIST_L and INT_CREATE_L for the Low Priority list.
Example 4:

; Initialize your Hardware and LCD first

DEFINE HSER_RCSTA 90h   'Hser receive status init
DEFINE HSER_TXSTA 24h   'Hser transmit status init
DEFINE HSER_BAUD 38400  'Hser baud rate

LED1   VAR  PORTE.0
LED2   VAR  PORTE.0

DEFINE  USE_LOWPRIORITY  1
INCLUDE "DT_INTS-18.bas"       ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas"    ; Include if using PBP interrupts
INCLUDE "ReEnterPBP-18LP.bas"  ; Include if using Low Pr. PBP INTS
INCLUDE "Elapsed_INT-18.bas"   ; Elapsed Timer Routines

;----[High Priority Interrupts]-----------------------------------------------
ASM
INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
        INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
        INT_Handler   TMR0_INT,  _ToggleLED2,   PBP,  yes
        INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
    endm
    INT_CREATE               ; Creates the High Priority interrupt processor

;----[Low Priority Interrupts]------------------------------------------------
INT_LIST_L  macro  ; IntSource,        Label,  Type, ResetFlag?
        INT_Handler     RX_INT,     _SetTime,   PBP,  no
    endm
    INT_CREATE_L             ; Creates the Low Priority interrupt processor
ENDASM

T0CON = %10010010             ; T0 = 16-bit, Prescaler 8
@    INT_ENABLE  INT_INT      ; enable external (INT) interrupts
@    INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts
@    INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
@    INT_ENABLE  RX_INT       ; Enable USART Receive interrupts 

GOSUB ResetTime              ' Reset Time to  0d-00:00:00.00
GOSUB StartTimer             ' Start the Elapsed Timer

Main:
    IF SecondsChanged = 1 THEN  
       SecondsChanged = 0
       LCDOUT $FE,2, DEC Days,"days",$FE,$C0,DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
    ENDIF
GOTO Main

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

'---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
ToggleLED2:
    TOGGLE LED2
@ INT_RETURN

'---[USART RX - interrupt handler]---------------------------[Low Priority]---
SetTime:
    HSERIN 100,No232,[wait("T"),DEC2 Hours,skip 1, DEC2 Minutes, skip 1, DEC2 Seconds]
    Ticks = 0
No232:
@ INT_RETURN

Code Size = 2164 bytes

Now we still have the three previous interrupt sources

    LED1 responds to the external INT
    LED2 flashes, timed by TMR0
    the elapsed timer is maintained via TMR1 

And, the Timer can be set via LP ints by sending a line from the serial communicator in MCSP, or a terminal program of your choice.

The Line to send should look like this...

T10:20:17

which will set the Elapsed timer to 10 hours 20 minutes and 17 seconds.

Page last modified on February 07, 2018, at 07:26 PM