News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Serial coms on 18F27K42

Started by JohnB, May 11, 2022, 07:43 AM

Previous topic - Next topic

JohnB

It's a long while since I did any PIC programming and even longer working with 8 bit devices so please be patient if these are silly questions.

The 18F27K42 uses an interrupt vector table similar to that used in the 16 bit series.  Is this supported by the compiler and if so what commands can be used? e.g.
[b]Isr [/b]U1Interrupt

[b]EndIsr[/b]

and should I be adding an interrupt wizard for 8 bit devices where this mechanism is supported?


JohnB

top204

#1
I have not created the code for the interrupt vectors on the 8-bit devices, because I think they are a knee jerk reaction by Microchip and will actually make code less efficient. It has had no thought put into it at all, surprise, surprise. :-)

Each interrupt vector must contain its own context save/restore RAM, and if there are more interrupts, the RAM usage goes up and up, which is not a good thing with the RAM amounts on 8-bit devices. It also takes a large section of code memory for the vector table. I implemented it on the 16-bit devices because they have a true RAM Stack, and quite a lot of linear RAM, along with dedicated code memory for the interrupt vector table, and mnemonics to push and pop values on the stack with efficiency.

It is something I am looking into in the future, but it is something I am not looking forward to using, and will have a declare to place the code back into "compatability" mode for more efficient code/RAM usage and speed.

tumbleweed

#2
QuoteEach interrupt vector must contain its own context save/restore RAM, and if there are more interrupts, the RAM usage goes up and up
That would only be the case if you were to allow nested interrupts. Otherwise, you only need a pair of high-priority and low-priority contexts, just like is the case with the existing 18F compatibility mode.

It's true that you need program space for the vector table, but even in the worst case that's only about 512 bytes (256 interrupts x 2 bytes/intr), and typically half that since 128 interrupts is the max in any of the current devices (18FxxQ83/Q84).

If you're really pressed for space, theoretically you only need vector table entries up to the max interrupt number used, but I like to provide default entries for all of them just in case.

top204

The interrupts are nested. They have priorities, so a higher priority interrupt can interrupt another interrupt, so each interrupt vector routine needs to store its own context save/restore RAM.

With the 16-bit devices, and Positron16, this is just pushed onto the RAM stack with the indirect mnemonics that are stack orientated. Then when another interrupt occures, it also pushes onto the RAM stack, but the 8-bit devices do not have a true stack or mnemonics that cater for indirect operations efficiently, and my implemetation of a software Stack is far too slow for an interrupt handler.

They are trying to copy the AVR mechanism, but they have linear RAM and a true RAM stack and decent stack based mnemonics. It is long overdue for a re-write of the 18F devices to give them additional mnemonics and architecture that is required in the 21st century. They have been the same for 20 years now!!! Instead, they pursued the dreadful "enhanced", that's a joke, 14-bit core devices, and actually stepped back in time for some "inexplicable" reason. :-)


JohnB

Thanks and apologies for my Dyscalculia (look it up) yes of course I meant 18F27K42.
I am looking at the USART1_Buffer.inc file.  It doesn't work with the 18F27K42 with the new style UARTS in these devices.  Has anyone amended this include file for the 18F27K42?


JohnB

tumbleweed

QuoteThe interrupts are nested. They have priorities, so a higher priority interrupt can interrupt another interrupt, so each interrupt vector routine needs to store its own context save/restore RAM.
I was thinking more along the lines of true multi-level interrupt nesting.

Interrupts are only nested from the standpoint that a single high priority request can interrupt a running low priority ISR, same as on the existing PIC18.
Since there are only two priority levels I don't see why you would need more than two context save blocks since only two can be active at any one time.

This is how the hardware context save on the new 18F's work (which is MUCH better than the old method... the only thing it doesn't save are the TBLPTR regs).



JohnB

Still trying to get comms working I have been trying to simply receive data on one UART1 and send it out on UART2.  I have been trying to do this under interrupt control.

ISR_Handler:
 Context Save
 if PIR3bits_U1RXIF = 1 then
  Clear PIR3BIts_U1RXIF
  U2TXB = U1RXB
 EndIf

 if PIR6Bits_U2RXIF = 1 then
  Clear PIR6Bits_U2RXIF
  U1TXB = U2RXB
 endIf

 ISR_Exit:
 Context Restore

Is what I am doing valid? When run nothing happens, not even flashing LEDs which I have in my main loop.  I cannot test it out in ISIS as there is no support for this device family.
JohnB

tumbleweed

In general yes, assuming you've followed all the steps to setup the uarts and PPS (see datasheet section 31).
You can get rid of the 'clear RXIF' parts... RXIF is read-only and clears when the RXB is read.

QuoteWhen run nothing happens, not even flashing LEDs which I have in my main loop.
Are you saying you can't even get a blinky LED working?

Yasin

#8
ANSELC reset required. The default analog pin is selected.

Note: When I write code. I used it in the tags, following the rules. I couldn't write the message, it gave an error. Error 403.

JohnB

I have attached the code
PoolController.txt
To test, I am sending characters into U1Rx which is passed on to U2Tx.  The U2Tx is connected to U2 Rx which is then passed to U1Tx so I should see the original characters sent returned.
JohnB

Gamboa

John,

I have not used that specific microcontroller, but I have used the PIC18F25K22.

I have never used interrupts like you do. I have always saved in a buffer (in this case it would be a one byte buffer) and then when I exit the interrupt I do the treatment of the received frame.

in your example ISR:

 if PIR3bits_U1RXIF = 1 then
   BufferTempo_Byte = U1RXB
   F_FrameReceived_Bit = 1
 EndIf


in your example (Main):

do
  Pulse_LED() ' just to show its alive
  if F_FrameReceived_Bit = 1 then
    F_FrameReceived_Bit = 0
    Hrsout "BufferTempo_Byte:", BufferTempo_Byte
  endif
loop

Don't forget the "DEFINE" for HRSOUT

Regards,
Gamboa

Long live for you

tumbleweed

#11
John,

A few things jump out. Here are some of the highlights...
- config MVECEN must be OFF for compatibility mode interrupts
- you must jump over the ISR_handler code (or move it)
- you have to use PPS to map all outputs... there are no defaults for PPS output pins
- you have to be very aware mixing high-level 'Hser' commands/declares and low-level direct register accesses.

If the compiler doesn't see a reference to HserIn or HserOut, then all the 'Declare Hser XXXXX' statements are ignored and no uart setup code is produced. Either do it all yourself (mode settings, baudrate, PPS, etc) or use the 'Declare' method and Hser commands.

Try the attached... I didn't test it, just looked at the asm code, so...

EDIT: I forgot to add the intosc setup code in the attachment...
SETUP:
' setup intosc for 64MHz
OSCCON1 = $60   ' NOSC=HFINTOSC, NDIV=1
OSCFRQ = $08

top204

The PIC18F27K42 devices, along with all the new 18F devices, have more refined USARTs, so they have a few more SFRs and their names have been changed, and their bit operations are slightly different. However, they follow the same mechanism as the earlier USARTs.

Below is a library include file for an interrupt serial RX buffer for a PIC18F27K42 or PIC18F47K42 device, and it may work on other K42 devices, but I have not tested on them:

$ifndef _Buffered_Serial_
$define _Buffered_Serial_
'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Interrupt-driven serial buffer for USART1 receive using a hardware high priority interrupt.
' This subroutine replaces the compiler's Hserin1/Hrsin1, HSerout1/HRsout1 commands library subroutines
'
' Written by Les Johnson for the Positron8 compiler
'
' The library routine is for PIC18F27K42 and PIC18F47K42 devices only
'
$if _device <> _18F27K42 And _device <> _18F47K42
    $error "This library is only for the PIC18F27K42 or PIC18F47K42 devices"
$endif

    #Disable HRSIn1, HRSIn1To, HRSIn1_RCREG_Read, HRSOut1     ' Disable the library subroutines for Hrsin with and without timeouts, and Hrsout

$ifndef True
    $define True 1
$endif
$ifndef False
    $define False 0
$endif
'
' Create some Compiler system variables
'
    Dim BPF  As Byte System                                     ' A compiler system variable used by the LCD routines to initialise it after power up
    Dim GEN  As Byte System                                     ' \
    Dim GENH As Byte System                                     ' / Buffered Hrsin1 Timeout value storage
    Dim PP0  As Byte System                                     ' \
    Dim PP0H As Byte System                                     ' / Storage for FSR0L\H registers
    Dim PP1  As Byte System                                     ' \
    Dim PP1H As Byte System                                     ' / Buffred Hrsin1 Timeout inside loop counter
'
' Create variables for the interrupt buffered serial receiver
'
    Dim Global_tByteInBuffer1 As Bit                            ' Set true if a byte is received in the USART1 buffer
    Dim USART1_bTimeoutInt    As GEN                            ' \ Create some fill-in variables so they can be combined into 16-bits
    Dim USART1_bTimeoutIntH   As GENH                           ' /
    Dim USART1_wTimeoutValue  As USART1_bTimeoutInt.Word        ' Alias the timeout value to GEN\H
    Dim USART1_wFSR0Save      As Word Heap                      ' Alias the FSR0L\H storage to PP0\H
    Dim USART1_bInsideLoopInt As PP1                            ' \ Create some fill-in variables so they can be combined into 16-bits
    Dim USART1_bInsideLoopIntH As PP1H                          ' /
    Dim USART1_wInsideLoop    As USART1_bInsideLoopInt.Word     ' Alias the inside loop to PP1\H
    Dim USART1_wOutsideLoop   As PRODL.Word                     ' Alias the outside loop to PRODL\H registers
    Dim USART1_bIndexIn       As Byte Access                    ' Pointer to the next empty location in the buffer
    Dim USART1_bIndexOut      As Byte Access                    ' Pointer to the location of the oldest character in the buffer
    Dim USART1_bRXByte        As Byte Access                    ' Holds the byte received from USART1
'
' Create the actual serial buffer in high RAM
'
$define _cUSART1_BufferSize 128                                 ' The amount of RAM reserved for the buffer (Max 255)
    Dim USART1_bRingBuffer[_cUSART1_BufferSize] As Byte Heap    ' Array for holding received bytes (in high RAM because it is used indirectly, so needs no RAM bank switching mnemonics)

    Dim USART1_wFSR0 As FSR0L.Word                              ' Combine SFRs FSR0L\H into a 16-bit SFR
    Dim USART1_wFSR1 As FSR1L.Word                              ' Combine SFRs FSR1L\H into a 16-bit SFR

'------------------------------------------------------------------------------
$ifndef IntGlobal_Enable
    $define IntGlobal_Enable()  INTCON0bits_GIE = 1     ' Enable global interrupts
$endif
$ifndef IntGlobal_Disable
    $define IntGlobal_Disable() INTCON0bits_GIE = 0     ' Disable global interrupts
$endif

'------------------------------------------------------------------------------
$ifndef IntPeriph_Enable
    $define IntPeriph_Enable()  INTCON0bits_GIEL = 1    ' Enable peripheral interrupts
$endif
$ifndef IntPeriph_Disable
    $define IntPeriph_Disable() INTCON0bits_GIEL = 0    ' Disable peripheral interrupts
$endif

'------------------------------------------------------------------------------
$define USART1_RX_IntEnable()  PIE3bits_U1RXIE = 1      ' Enable interrupt on USART1 receive
$define USART1_RX_IntDisable() PIE3bits_U1RXIE = 0      ' Disable interrupt on USART1 receive

'------------------------------------------------------------------------------
$define USART1_TX_IntEnable()  PIE3bits_U1TXIE = 1      ' Enable interrupt on USART1 transmit
$define USART1_TX_IntDisable() PIE3bits_U1TXIE = 0      ' Disable interrupt on USART1 transmit

'------------------------------------------------------------------------------
' Disable USART1 RX and TX
'
$define USART1_Disable() '
    U1CON0bits_TXEN = 0  '
    U1CON0bits_RXEN = 0

'------------------------------------------------------------------------------
' Enable USART1 RX and TX
'
$define USART1_Enable() '
    U1CON0bits_TXEN = 1 '
    U1CON0bits_RXEN = 1

'------------------------------------------------------------------------------
$define USART1_TX_Disable() U1CON0bits_TXEN = 0         ' Disable USART1 TX
$define USART1_TX_Enable()  U1CON0bits_TXEN = 1         ' Enable USART1 TX

'------------------------------------------------------------------------------
$define USART1_RX_Disable() U1CON0bits_RXEN = 0         ' Disable USART1 RX
$define USART1_RX_Enable()  U1CON0bits_RXEN = 1         ' Enable USART1 RX

'------------------------------------------------------------------------------
$define USART1_RX_Flag() PIR3bits_U1RXIF                ' The bit that indicates a byte has been received on USART1
$define USART1_TX_Flag() PIR3bits_U1TXIF                ' The bit that indicates a byte is being transmitted by USART1

'------------------------------------------------------------------------------

    GoTo _USART1_Main                                   ' Jump over the command replacement subroutines

'------------------------------------------------------------------------------
' Wait for a byte from the interrupt driven circular buffer with timeout
' Input     : GEN\GENH hold the timeout value in approx ms (0 to 65535)
' Output    : PP0 and WREG hold the value received
'           : Carry Flag (STATUS.0) Clear if timeout out
' Notes     : Replaces the compiler's HRsin1/HSerin1 library routine with timeout
'           : Uses PRODL\H as temporary variable storage
'           : Uses FSR0L\H as buffer the pointer
'
__HRsin1_With_TimeOut__:
    USART1_wOutsideLoop = USART1_wTimeoutValue          ' Save the timeout value so it doesn't get overwritten
    USART1_wInsideLoop = 0                              ' Reset the inside loop counter
_USART1_OutsideLoop:
    DelayCS 2                                           ' Delay for 2 cycles within the outside loop
_USART1_InsideLoop:
    DelayCS 1                                           ' Delay for 1 cycle within the inside loop
    WREG = USART1_bIndexIn                              ' \
    Subwf     USART1_bIndexOut,w                        ' / Is there anything in the serial buffer?
    Bnz       USART1_GetByte                            ' Yes. So fetch it
    WREG = 255                                          ' \
    Addwf     USART1_wInsideLoop,f                      ' |
    Addwfc    USART1_wInsideLoopH,f                     ' | Decrement the inside and outside loops
    Addwfc    USART1_wOutsideLoop,f                     ' |
    Addwfc    USART1_wOutsideLoopH,f                    ' /
    Btfss     STATUSbits_C
    Ret                                                 ' Return with the Carry flag clear to indicate timed out
    Infsnz    USART1_wInsideLoop,w
    Incfsz    USART1_wInsideLoopH,w
    GoTo _USART1_OutsideLoop
    USART1_wInsideLoop = ((60 * Xtal) / 4)              ' Set the inside loop counter based upon the Xtal frequency
    GoTo _USART1_InsideLoop

'------------------------------------------------------------------------------
' Wait for a byte from the interrupt driven circular USART1 buffer without timeout
' Input     : None
' Output    : WREG holds the value received
' Notes     : Replaces the compiler's HRsin1/HSerin1 library routine without timeout
'           : Uses FSR0L\H as buffer pointers
'
__HRsin1__:
    While USART1_bIndexIn = USART1_bIndexOut            ' Wait for a byte to appear in the serial buffer
    Wend
'
' Fall through to USART1_GetByte
'------------------------------------------------------------------------------
' Read a byte from the USART1 interrupt driven circular buffer
' Input     : None
' Output    : PP0 and WREG hold the value received
' Notes     : Uses FSR0L\H as buffer pointers
'
Sub USART1_GetByte()
    Inc USART1_bIndexOut                                    ' Increment USART1_bIndexOut pointer (0 to 255)
    If USART1_bIndexOut >= _cUSART1_BufferSize Then         ' End of buffer reached?
        USART1_bIndexOut = 0                                ' Yes. So clear USART1_bIndexOut.
    EndIf
    USART1_wFSR0Save = USART1_wFSR0                         ' Save FSR0L\H registers
    USART1_wFSR0 = AddressOf(USART1_bRingBuffer)            ' Point FSR0L\H to USART1_bRingBuffer
    USART1_wFSR0 = USART1_wFSR0 + USART1_bIndexOut          ' Add the buffer position to FSR0L\H   
    PP0 = INDF0                                             ' Read buffer location (USART1_bIndexOut) into PP0
    USART1_wFSR0 = USART1_wFSR0Save                         ' Restore FSR0\H registers
    WREG = PP0                                              ' Also place it into WREG   
    STATUSbits_C = 1                                        ' Set the Carry flag to indicate a byte received
EndSub

'--------------------------------------------------------------------------------
' Replace the compiler's Hrsout1/HSerout1 library routine with this routine
' Input     : WREG holds the byte to transmit
' Output    : WREG still holds the byte transmitted
' Notes     : None
'
Sub __HRsout1__()
    PP0 = WREG                                              ' Save the byte to transmit
    Repeat: Until USART1_TX_Flag() = 1                      ' Wait for the TX buffer to be ready
    U1TXB = PP0                                             ' Send the byte
    WREG = PP0                                              ' Restore the contents of WREG
EndSub                                                      ' Exit the subroutine

'--------------------------------------------------------------------------------
' Initialise the USART1 RX interrupt
' Input     : None
' Output    : None
' Notes     : Enables interrupt on USART1 receive
'
Proc USART1_InitInterrupt()
    Global_tByteInBuffer1 = False                           ' Reset the byte in buffer flag
    USART1_bIndexIn = 0                                     ' Clear the buffer internal pointer
    USART1_bIndexOut = 0                                    ' Clear the buffer external pointer
    USART1_RX_IntEnable()                                   ' Enable interrupt on USART1 receive
EndProc

'--------------------------------------------------------------------------------
' Disable the USART1 RX interrupt
' Input     : None
' Output    : None
' Notes     : Disables interrupt on USART1 receive
'
Proc USART1_DisableInterrupt()
    Global_tByteInBuffer1 = False
    USART1_bIndexIn = 0                                     ' Clear the buffer internal pointer
    USART1_bIndexOut = 0                                    ' Clear the buffer external pointer
    USART1_RX_IntDisable()                                  ' Disable interrupt on USART1 receive
EndProc

'--------------------------------------------------------------------------------
' Clear the Serial Buffer
' Input     : None
' Output    : None
' Notes     : Also resets the index pointers to the serial buffer
'
Proc USART1_ClearSerialBuffer()
    USART1_RX_IntDisable()                              ' Disable interrupt on USART1 receive
    WREG = U1RXB                                        ' \ Empty the USART's 2-byte serial buffer
    WREG = U1RXB                                        ' /
    USART1_RX_Flag() = False                            ' Clear the byte received flag
    Clear USART1_bRingBuffer                            ' Clear the serial buffer
    Global_tByteInBuffer1 = False                       ' Reset the byte in buffer flag
    USART1_bIndexIn = 0                                 ' Clear the buffer internal pointer
    USART1_bIndexOut = 0                                ' Clear the buffer external pointer
    USART1_RX_IntEnable()                               ' Re-Enable interrupt on USART1 receive
EndProc

'--------------------------------------------------------------------------------
' Enable USART1 and set it up for the buffer
' Input     : None
' Output    : None
' Notes     : None
'
Proc USART1_Open()
    Clear USART1_RX_Flag()                              ' Clear the RX flag
    USART1_Enable()                                     ' Enable USART1
    USART1_ClearSerialBuffer()                          ' Clear serial buffers
    USART1_InitInterrupt()                              ' Enable USART1 interrupt
EndProc

'--------------------------------------------------------------------------------
' Disable USART1
' Input     : None
' Output    : None
' Notes     : None
'
Proc USART1_Close()
    USART1_DisableInterrupt()                           ' Disable USART1 interrupt
    USART1_Disable()                                    ' Disable USART1
    Clear USART1_RX_Flag()                              ' Clear the RX flag
    USART1_ClearSerialBuffer()                          ' Clear serial buffers
EndProc

'--------------------------------------------------------------------------------
_USART1_Main:

$endif      ' _Buffered_Serial_

Save the above library file as "USART1_Buffer_K42.inc" in the "Includes" folder, so all programs can see it: "C:\Users\User Name\PDS\Includes\"

Below is a demo program showing the above library working. It receives bytes from USART1 and even with a very silly long delay, it echoes back what was received because the bytes are being received in the background into the buffer array. The microcontroller is operating at 64MHz using its internal oscillator, so there is no need for an external crystal or resonator.

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Demonstrate the USART1 RX interrupt buffer by receiving data with a long delay between, before echoing what was received.
' Created by Les Johnson for the Positron8 compiler.
'
    Device = 18F27K42                                   ' Tell the compiler what device to compile for
    Declare Xtal = 64                                   ' Tell the compiler that the device will be running at 64MHz
    Declare Access_Upper_64K = True                     ' Set the compiler to see all 128K of flash memory 
    On_Hardware_Interrupt GoTo ISR_Handler              ' Point to the interrupt handler routine
'
' Setup USART1
'
    Declare Hserial1_Baud = 115200                      ' Set the Baud rate for USART1
    Declare Hserout1_Pin  = PORTC.6                     ' Set the pin used for USART1 TX
    Declare HSerin1_Pin   = PORTC.7                     ' Set the pin used for USART1 RX

    Include "USART1_Buffer_K42.inc"                     ' Load the buffered USART1 library routines into the program
 '
 ' Create a variable for the demo
 ' 
    Dim MyByte As Byte
   
'------------------------------------------------------------------------------------------------
' The main program starts here
' Echo back, via USART1, what is received on USART1
'
Main:
    Setup()                                             ' Setup the program
Again:   
    Do                                                  ' Create a loop
        MyByte = HRSIn1, {5000, TimedOut}               ' Receive a byte, with a 5 second timeout                       
        DelayMS 2000                                    ' Create a long delay so the buffer can be tested
        HRSOut1 MyByte                                  ' Transmit what was received
    Loop                                                ' Do it forever
'
' Jump here if a timeout occurs
'   
TimedOut:
    HRSOutLn "\rTimed Out"
    GoTo Again                                          ' Jump back to the loop
    
'------------------------------------------------------------------------------------------------
' Setup the program
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    USART1_Open()                                       ' Open USART1 ready for the interrupt buffer  
    IntPeriph_Enable()                                  ' Enable peripheral interrupts
    IntGlobal_Enable()                                  ' Enable global interrupts
EndProc

'------------------------------------------------------------------------------------------------
' Interrupt handler routine
' Input     : None
' Output    : Array USART1_bRingBuffer holds the characters received from USART1
'           : USART1_bIndexIn points to the current location within the USART1 buffer
'           : Global_tByteInBuffer1 is true if a byte was received on USART1
' Notes     : Interrupts on USART1 receive
'
ISR_Handler:
    Context Save FSR1L, FSR1H                           ' Save any compiler system variables and any SFRs used before we perform the interrupt code
'
' Check the USART1 RX interrupt
'
    If USART1_RX_Flag() = True Then                     ' Was it a USART1 byte receive that triggered the interrupt?
        USART1_bRXByte = U1RXB                          ' Yes. So place the byte received into USART1_bRXByte
        Inc USART1_bIndexIn                             ' Move up the buffer
        If USART1_bIndexIn >= _cUSART1_BufferSize Then  ' End of buffer reached?
            USART1_bIndexIn = 0                         ' Yes. So reset USART1_bIndexIn
        EndIf
        USART1_wFSR1 = AddressOf(USART1_bRingBuffer)    ' Point FSR1L\H to USART1_bRingBuffer
        USART1_wFSR1 = USART1_wFSR1 + USART1_bIndexIn   ' Add the buffer position to FSR1L\H
        INDF1 = USART1_bRXByte                          ' Place the received byte into the buffer
        Global_tByteInBuffer1 = True                    ' Indicate that there is a byte in the buffer
    EndIf

    Context Restore                                     ' Restore any compiler system variables and SFRs, then exit the interrupt routine

'---------------------------------------------------------------------------------------
' Setup for internal oscillator operating at 64MHz on a PIC18F27K42 device
'
Config_Start
    RSTOSC = HFINTOSC_64MHZ     ' HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
    FEXTOSC = Off               ' HS off
    WDTE = Off                  ' WDT Disabled. SWDTEN is ignored
    CLKOUTEN = Off              ' CLKOUT function is disabled
    PR1WAY = Off                ' PRLOCK bit can be set and cleared repeatedly
    CSWEN = On                  ' Writing to NOSC and NDIV is allowed
    Debug = Off                 ' Background debugger disabled
    FCMEN = Off                 ' Fail-Safe Clock Monitor disabled
    MCLRE = EXTMCLR             ' If LVP = 0, MCLR pin is MCLR. If LVP = 1, RE3 pin function is MCLR
    PWRTS = PWRT_Off            ' PWRT is disabled
    MVECEN = Off                ' Interrupt contoller does not use vector table to prioritise interrupts
    IVT1WAY = Off               ' IVTLOCK bit can be cleared and set repeatedly
    LPBOREN = Off               ' ULPBOR disabled
    BOREN = Off                 ' Brown-out Reset disabled
    BORV = VBOR_2P45            ' Brown-out Reset Voltage (VBOR) set to 2.45V
    ZCD = Off                   ' ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = Off               ' PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
    STVREN = Off                ' Stack full/underflow will not cause Reset
    XINST = Off                 ' Extended Instruction Set and Indexed Addressing Mode disabled
    WDTCPS = WDTCPS_2           ' Divider ratio 1:128
    WDTCWS = WDTCWS_0           ' Window delay = 87.5. No software control. Keyed access required
    WDTCCS = LFINTOSC           ' WDT reference clock is the 31.0 kHz LFINTOSC
    BBSIZE = BBSIZE_1024        ' Boot Block size is 1024 words
    BBEN = Off                  ' Boot block disabled
    SAFEN = Off                 ' SAF disabled
    WRTAPP = Off                ' Application Block not write protected
    WRTB = Off                  ' Configuration registers not write-protected
    WRTC = Off                  ' Boot Block not write-protected
    WRTD = Off                  ' EEPROM not write-protected
    WRTSAF = Off                ' SAF not Write Protected
    LVP = Off                   ' HV on MCLR/VPP must be used for programming
    Cp = Off                    ' PFM and EEPROM code protection disabled
Config_End

I will be looking into the vectored interrupt mechanism on the newer 18F devices, but before I implement it, it must follow the rigid rules that I have laid down for the compilers since I created them, which is "No bloat and no wasted time", unlike 90% of other compilers out there.

In the "Includes" folder, there is an interrupt handler library for the PIC18F27K42 devices named: "Positron Int Manager.inc". It is the same mechanism as the manager I created for the Amicus18 microcontroller (18F25K20), but has all the interrupts contained in the PIC18F27K42 device. It has its own mechanism for managed vector, high priority, interrupts.

JohnB

@top204 @Gamboa

Thanks both for your inputs. At the moment I feel like a complete beginner in PIC programming, its been so long since I have attempted anything by the way of a PIC project.  The mistake of not jumping over the interrupt handler is inexcusable, think it must be my age!!!

I'll let you know how it goes.
JohnB

top204

Below is another demo of the "USART1_Buffer_K42.inc" library, but uses the Interrupt Manager I created for the PIC18F27K42 device that was on my Positron8 board that I was going to market. It removes the need for jumping over the ISR handler, or not placing the ISR handler at the beginning of the code etc:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Demonstrate the USART1 RX interrupt buffer by receiving data with a long delay between, before echoing what was received.
' This demo uses the interrupt manager for the PIC18F27K42 device that adds a vectored interrupt type mechanism to it.
'
' Created by Les Johnson for the Positron8 compiler.
'
    Device = 18F27K42                                   ' Tell the compiler what device to compile for
    Declare Xtal = 64                                   ' Tell the compiler that the device will be running at 64MHz
    Declare Access_Upper_64K = True                     ' Set the compiler to see all 128K of flash memory 
'
' Setup USART1
'
    Declare Hserial1_Baud = 115200                      ' Set the Baud rate for USART1
    Declare Hserout1_Pin  = PORTC.6                     ' Set the pin used for USART1 TX
    Declare HSerin1_Pin   = PORTC.7                     ' Set the pin used for USART1 RX

$define Handle_RX1_Int                                  ' Tell the interrupt manager to manage a USART1 RX interrupt

    Include "USART1_Buffer_K42.inc"                     ' Load the buffered USART1 library routines into the program
    Include "Positron Int Manager.inc"                  ' Load the PIC18F27K42 interrupt manager into the program
 '
 ' Create a variable for the demo
 ' 
    Dim MyByte As Byte
   
'------------------------------------------------------------------------------------------------
' The main program starts here
' Echo back what is received on USART1
'
Main:
    Setup()                                             ' Setup the program
Again:   
    Do                                                  ' Create a loop
        MyByte = HRSIn1, {5000, TimedOut}               ' Receive a byte, with a 5 second timeout                       
        DelayMS 2000                                    ' Create a long delay so the buffer can be tested
        HRSOut1 MyByte                                  ' Transmit what was received
    Loop                                                ' Do it forever
'
' Jump here if a timeout occurs
'   
TimedOut:
    HRSOutLn "\rTimed Out"
    GoTo Again                                          ' Jump back to the loop
    
'------------------------------------------------------------------------------------------------
' Setup the program
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    USART1_Open()                                       ' Open USART1 ready for the interrupt buffer  
    IntPeriph_Enable()                                  ' Enable peripheral interrupts
    IntGlobal_Enable()                                  ' Enable global interrupts
EndProc

'------------------------------------------------------------------------------------------------
' USART1 Receive Interrupt handler routine
' Input     : None
' Output    : Array USART1_bRingBuffer holds the characters received from USART1
'           : USART1_bIndexIn points to the current location within the USART1 buffer
'           : Global_tByteInBuffer1 is true if a byte was received on USART1
' Notes     : Interrupts on USART1 receive
'
ISR_RX1(Start)                                          ' Start the RX1 interrupt handler and save contexts
    USART1_bRXByte = U1RXB                              ' Place the byte received into USART1_bRXByte
    Inc USART1_bIndexIn                                 ' Move up the buffer
    If USART1_bIndexIn >= _cUSART1_BufferSize Then      ' End of buffer reached?
        USART1_bIndexIn = 0                             ' Yes. So reset USART1_bIndexIn
    EndIf
    USART1_wFSR1 = AddressOf(USART1_bRingBuffer)        ' Point FSR1L\H to USART1_bRingBuffer
    USART1_wFSR1 = USART1_wFSR1 + USART1_bIndexIn       ' Add the buffer position to FSR1L\H
    INDF1 = USART1_bRXByte                              ' Place the received byte into the buffer
    Global_tByteInBuffer1 = True                        ' Indicate that there is a byte in the buffer
ISR_RX1(Exit)                                           ' Exit the RX1 interrupt handler and restore contexts

'---------------------------------------------------------------------------------------
' Setup for internal oscillator operating at 64MHz on a PIC18F27K42 device
'
Config_Start
    RSTOSC = HFINTOSC_64MHZ     ' HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
    FEXTOSC = Off               ' HS off
    WDTE = Off                  ' WDT Disabled. SWDTEN is ignored
    CLKOUTEN = Off              ' CLKOUT function is disabled
    PR1WAY = Off                ' PRLOCK bit can be set and cleared repeatedly
    CSWEN = On                  ' Writing to NOSC and NDIV is allowed
    Debug = Off                 ' Background debugger disabled
    FCMEN = Off                 ' Fail-Safe Clock Monitor disabled
    MCLRE = EXTMCLR             ' If LVP = 0, MCLR pin is MCLR. If LVP = 1, RE3 pin function is MCLR
    PWRTS = PWRT_Off            ' PWRT is disabled
    MVECEN = Off                ' Interrupt contoller does not use vector table to prioritise interrupts
    IVT1WAY = Off               ' IVTLOCK bit can be cleared and set repeatedly
    LPBOREN = Off               ' ULPBOR disabled
    BOREN = Off                 ' Brown-out Reset disabled
    BORV = VBOR_2P45            ' Brown-out Reset Voltage (VBOR) set to 2.45V
    ZCD = Off                   ' ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = Off               ' PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
    STVREN = Off                ' Stack full/underflow will not cause Reset
    XINST = Off                 ' Extended Instruction Set and Indexed Addressing Mode disabled
    WDTCPS = WDTCPS_2           ' Divider ratio 1:128
    WDTCWS = WDTCWS_0           ' Window delay = 87.5. No software control. Keyed access required
    WDTCCS = LFINTOSC           ' WDT reference clock is the 31.0 kHz LFINTOSC
    BBSIZE = BBSIZE_1024        ' Boot Block size is 1024 words
    BBEN = Off                  ' Boot block disabled
    SAFEN = Off                 ' SAF disabled
    WRTAPP = Off                ' Application Block not write protected
    WRTB = Off                  ' Configuration registers not write-protected
    WRTC = Off                  ' Boot Block not write-protected
    WRTD = Off                  ' EEPROM not write-protected
    WRTSAF = Off                ' SAF not Write Protected
    LVP = Off                   ' HV on MCLR/VPP must be used for programming
    Cp = Off                    ' PFM and EEPROM code protection disabled
Config_End

I creates an interrupt vector mechanism that can be adapted for any 18F or enhanced 14-bit core device, by altering the SFRs and SFR bit names within the library's code and adding or removing preprocessor meta-macros for extra interrupts, or interrupts that are not present on a particular device . But it takes a few hours with a datasheet in hand, and a  lot of patience and a lot of typing. :-) Maybe one day I will create a program that automatically creates Library Manager library files for most devices automatically from the Microchip XML files.

You'll see the ISR vector routine for USART1 RX as ISR_RX1(Start) and ISR_RX1(Exit), and it has branches within the libary itself, so it does not get in the way of the main code, no matter where it is placed, as long it is placed after the Interrupt Manager's Include.

I've corrected the thread's name to 18F27K42, instead of 18F27K24 John. So that casual browsers of the forum will see a recognised device. Since my brain injury, I have to go through all my texts twice, or more, because what comes from my fingertips is not what was in my head. :-) But even then, I miss some texts. :-( So you are not alone, by a long shot. :-)

JohnB

I have done a search of my entire PC and not found the Positron Int Manager.inc file
Is the name correct? or has it not been included in distro.
JohnB

Yasin

"C:\Users\User\PDS\Samples\Amicus18_Board"

This directory in maybe. Perhaps name changed.

top204

Sorry John. I must not have added it to the installer's files yet.

The library listing is below. Name it as "Positron Int Manager.inc", and copy it to the "Includes" folder "C:\Users\User Name\PDS\Includes"

$ifndef _Positron_Int_Manager_
$define _Positron_Int_Manager_
'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
$if (_device <> _18F27K42) And (_device <> _18F47K42)
    $error "Positron Int Manager is only for 18F27K42 or 18F47K42 devices"
$endif
'
' High priority interrupt manager routines for a PIC18F27K42 device
' Written by Les Johnson for version 4.0.0.0 onwards of the Positron8 compiler
'
' Handler defines available
' Use one, or more, of these defines at the beginning of the main program to tell the Interrupt Manager what interrupts to manage
'
(*
$define Handle_IOC_Int
$define Handle_INT0_Int
$define Handle_INT1_Int
$define Handle_INT2_Int
$define Handle_RX_Int
$define Handle_TX_Int
$define Handle_RX1_Int
$define Handle_TX1_Int
$define Handle_RX2_Int
$define Handle_TX2_Int
$define Handle_SPI_Int
$define Handle_SPI1_Int
$define Handle_I2C_Int
$define Handle_I2C1_Int
$define Handle_I2C2_Int
$define Handle_CCP1_Int
$define Handle_CCP2_Int
$define Handle_CCP3_Int
$define Handle_CCP4_Int
$define Handle_TMR0_Int
$define Handle_TMR1_Int
$define Handle_TMR2_Int
$define Handle_TMR3_Int
$define Handle_TMR4_Int
$define Handle_TMR5_Int
$define Handle_TMR6_Int
$define Handle_ADC_Int
$define Handle_OSC_Int
$define Handle_CMP1_Int
$define Handle_CMP2_Int
$define Handle_NVM_Int
$define Handle_HLVD_Int
$define Handle_TMR1_Gate_Int
$define Handle_TMR3_Gate_Int
$define Handle_TMR5_Gate_Int
$define Handle_TMR2_Match_Int
$define Handle_TMR4_Match_Int
$define Handle_TMR6_Match_Int
$define Handle_CRC_Int
$define Handle_CSW_Int
$define Handle_SMT1PWM_Int
$define Handle_SMT1PRA_Int
$define Handle_SMT1_Int
$define Handle_ZCD_Int
$define Handle_SPI_RX_Int
$define Handle_SPI_TX_Int
$define Handle_SPI1_RX_Int
$define Handle_SPI1_TX_Int
$define Handle_DMA1_ABRT_Int
$define Handle_DMA1_OV_Int
$define Handle_DMA1_DCNT_Int
$define Handle_DMA1_SCNT_Int
$define Handle_DMA2_ABRT_Int
$define Handle_DMA2_OV_Int
$define Handle_DMA2_DCNT_Int
$define Handle_DMA2_SCNT_Int
$define Handle_CLC1_Int
$define Handle_CLC2_Int
$define Handle_CLC3_Int
$define Handle_CLC4_Int
$define Handle_CWG1_Int
$define Handle_CWG2_Int
$define Handle_CWG3_Int
$define Handle_NCO1_Int
*)
'
' Interrupt flag alias names for a PIC18F27K42
'
$define TMR0_IntFlag        PIR3bits_TMR0IF
$define TMR1_IntFlag        PIR4bits_TMR1IF
$define TMR2_IntFlag        PIR4bits_TMR2IF
$define TMR3_IntFlag        PIR6bits_TMR3IF
$define TMR4_IntFlag        PIR7bits_TMR4IF
$define TMR5_IntFlag        PIR8bits_TMR5IF
$define TMR6_IntFlag        PIR9bits_TMR6IF
$define INT0_IntFlag        PIR1bits_INT0IF
$define INT1_IntFlag        PIR5bits_INT1IF
$define INT2_IntFlag        PIR7bits_INT2IF
$define IOC_IntFlag         PIR0bits_IOCIF
$define RX_IntFlag          PIR3bits_U1RXIF
$define TX_IntFlag          PIR3bits_U1TXIF
$define RX1_IntFlag         PIR3bits_U1RXIF
$define TX1_IntFlag         PIR3bits_U1TXIF
$define RX2_IntFlag         PIR6bits_U2RXIF
$define TX2_IntFlag         PIR6bits_U2TXIF
$define SPI_IntFlag         PIR2bits_SPI1IF
$define SPI1_IntFlag        PIR2bits_SPI1IF
$define CCP1_IntFlag        PIR4bits_CCP1IF
$define CCP2_IntFlag        PIR7bits_CCP2IF
$define CCP3_IntFlag        PIR9bits_CCP3IF
$define CCP4_IntFlag        PIR10bits_CCP4IF
$define ADC_IntFlag         PIR1bits_ADIF
$define CMP1_IntFlag        PIR1bits_C1IF
$define CMP2_IntFlag        PIR5bits_C2IF
$define NVM_IntFlag         PIR0bits_NVMIF
$define I2C_IntFlag         PIR3bits_I2C1IF
$define I2C1_IntFlag        PIR3bits_I2C1IF
$define I2C2_IntFlag        PIR6bits_I2C2IF
$define HLVD_IntFlag        PIR0bits_HLVDIF
$define OSC_IntFlag         PIR0bits_OSFIF
$define TMR2_Match_IntFlag  PIR4bits_TMR2IF
$define TMR4_Match_IntFlag  PIR7bits_TMR4IF
$define TMR6_Match_IntFlag  PIR9bits_TMR6IF
$define TMR1_Gate_IntFlag   PIR4bits_TMR1GIF
$define TMR3_Gate_IntFlag   PIR6bits_TMR3GIF
$define TMR5_Gate_IntFlag   PIR8bits_TMR5GIF
$define CRC_IntFlag         PIR0bits_CRCIF
$define CSW_IntFlag         PIR0bits_CSWIF
$define SMT1PWM_IntFlag     PIR1bits_SMT1PWAIF
$define SMT1PRA_IntFlag     PIR1bits_SMT1PRAIF
$define SMT1_IntFlag        PIR1bits_SMT1IF
$define ZCD_IntFlag         PIR1bits_ZCDIF
$define SPI_RX_IntFlag      PIR2bits_SPI1RXIF
$define SPI_TX_IntFlag      PIR2bits_SPI1TXIF
$define SPI1_RX_IntFlag     PIR2bits_SPI1RXIF
$define SPI1_TX_IntFlag     PIR2bits_SPI1TXIF
$define DMA1_ABRT_IntFlag   PIR2bits_DMA1AIF
$define DMA1_OV_IntFlag     PIR2bits_DMA1ORIF
$define DMA1_DCNT_IntFlag   PIR2bits_DMA1DCNTIF
$define DMA1_SCNT_IntFlag   PIR2bits_DMA1SCNTIF
$define CLC1_IntFlag        PIR4bits_CLC1IF
$define CWG1_IntFlag        PIR4bits_CWG1IF
$define NCO1_IntFlag        PIR4bits_NCO1IF
$define DMA2_ABRT_IntFlag   PIR5bits_DMA2AIF
$define DMA2_OV_IntFlag     PIR5bits_DMA2ORIF
$define DMA2_DCNT_IntFlag   PIR5bits_DMA2DCNTIF
$define DMA2_SCNT_IntFlag   PIR5bits_DMA2SCNTIF
$define CLC2_IntFlag        PIR7bits_CLC2IF
$define CWG2_IntFlag        PIR7bits_CWG2IF
$define CLC3_IntFlag        PIR9bits_CLC3IF
$define CWG3_IntFlag        PIR9bits_CWG3IF
$define CLC4_IntFlag        PIR10bits_CLC4IF
'
' Clear the Interrupt flags
'
$define TMR0_ClearIntFlag()        TMR0_IntFlag = 0
$define TMR1_ClearIntFlag()        TMR1_IntFlag = 0
$define TMR2_ClearIntFlag()        TMR2_IntFlag = 0
$define TMR3_ClearIntFlag()        TMR3_IntFlag = 0
$define TMR4_ClearIntFlag()        TMR4_IntFlag = 0
$define TMR5_ClearIntFlag()        TMR5_IntFlag = 0
$define TMR6_ClearIntFlag()        TMR6_IntFlag = 0
$define INT0_ClearIntFlag()        INT0_IntFlag = 0
$define INT1_ClearIntFlag()        INT1_IntFlag = 0
$define INT2_ClearIntFlag()        INT2_IntFlag = 0
$define IOC_ClearIntFlag()         IOC_IntFlag = 0
$define RX_ClearIntFlag()          RX_IntFlag = 0
$define TX_ClearIntFlag()          TX_IntFlag = 0
$define RX1_ClearIntFlag()         RX1_IntFlag = 0
$define TX1_ClearIntFlag()         TX1_IntFlag = 0
$define RX2_ClearIntFlag()         RX2_IntFlag = 0
$define TX2_ClearIntFlag()         TX2_IntFlag = 0
$define SPI_ClearIntFlag()         SPI_IntFlag = 0
$define SPI1_ClearIntFlag()        SPI1_IntFlag = 0
$define CCP1_ClearIntFlag()        CCP1_IntFlag = 0
$define CCP2_ClearIntFlag()        CCP2_IntFlag = 0
$define CCP3_ClearIntFlag()        CCP3_IntFlag = 0
$define CCP4_ClearIntFlag()        CCP4_IntFlag = 0
$define ADC_ClearIntFlag()         ADC_IntFlag = 0
$define CMP1_ClearIntFlag()        CMP1_IntFlag = 0
$define CMP2_ClearIntFlag()        CMP2_IntFlag = 0
$define NVM_ClearIntFlag()         NVM_IntFlag = 0
$define I2C_ClearIntFlag()         I2C_IntFlag = 0
$define I2C1_ClearIntFlag()        I2C1_IntFlag = 0
$define I2C2_ClearIntFlag()        I2C2_IntFlag = 0
$define HLVD_ClearIntFlag()        HLVD_IntFlag = 0
$define OSC_ClearIntFlag()         OSC_IntFlag = 0
$define TMR2_Match_ClearIntFlag()  TMR2_Match_IntFlag = 0
$define TMR4_Match_ClearIntFlag()  TMR4_Match_IntFlag = 0
$define TMR6_Match_ClearIntFlag()  TMR6_Match_IntFlag = 0
$define TMR1_Gate_ClearIntFlag()   TMR1_Gate_IntFlag = 0
$define TMR3_Gate_ClearIntFlag()   TMR3_Gate_IntFlag = 0
$define TMR5_Gate_ClearIntFlag()   TMR5_Gate_IntFlag = 0
$define CRC_ClearIntFlag()         CRC_IntFlag = 0
$define CSW_ClearIntFlag()         CSW_IntFlag = 0
$define SMT1PWM_ClearIntFlag()     SMT1PWM_IntFlag = 0
$define SMT1PRA_ClearIntFlag()     SMT1PRA_IntFlag = 0
$define SMT1_ClearIntFlag()        SMT1_IntFlag = 0
$define ZCD_ClearIntFlag()         ZCD_IntFlag = 0
$define SPI_RX_ClearIntFlag()      SPI_RX_IntFlag = 0
$define SPI_TX_ClearIntFlag()      SPI_TX_IntFlag = 0
$define SPI1_RX_ClearIntFlag()     SPI1_RX_IntFlag = 0
$define SPI1_TX_ClearIntFlag()     SPI1_TX_IntFlag = 0
$define DMA1_ABRT_ClearIntFlag()   DMA1_ABRT_IntFlag = 0
$define DMA1_OV_ClearIntFlag()     DMA1_OV_IntFlag = 0
$define DMA1_DCNT_ClearIntFlag()   DMA1_DCNT_IntFlag = 0
$define DMA1_SCNT_ClearIntFlag()   DMA1_SCNT_IntFlag = 0
$define CLC1_ClearIntFlag()        CLC1_IntFlag = 0
$define CWG1_ClearIntFlag()        CWG1_IntFlag = 0
$define NCO1_ClearIntFlag()        NCO1_IntFlag = 0
$define DMA2_ABRT_ClearIntFlag()   DMA2_ABRT_IntFlag = 0
$define DMA2_OV_ClearIntFlag()     DMA2_OV_IntFlag = 0
$define DMA2_DCNT_ClearIntFlag()   DMA2_DCNT_IntFlag = 0
$define DMA2_SCNT_ClearIntFlag()   DMA2_SCNT_IntFlag = 0
$define CLC2_ClearIntFlag()        CLC2_IntFlag = 0
$define CWG2_ClearIntFlag()        CWG2_IntFlag = 0
$define CLC3_ClearIntFlag()        CLC3_IntFlag = 0
$define CWG3_ClearIntFlag()        CWG3_IntFlag = 0
$define CLC4_ClearIntFlag()        CLC4_IntFlag = 0
'
' Interrupt On Change flags per Port.Pin
'
$define IOC_RA0_IntFlag     IOCAF.0
$define IOC_RA1_IntFlag     IOCAF.1
$define IOC_RA2_IntFlag     IOCAF.2
$define IOC_RA3_IntFlag     IOCAF.3
$define IOC_RA4_IntFlag     IOCAF.4
$define IOC_RA5_IntFlag     IOCAF.5
$define IOC_RA6_IntFlag     IOCAF.6
$define IOC_RA7_IntFlag     IOCAF.7
$define IOC_RB0_IntFlag     IOCBF.0
$define IOC_RB1_IntFlag     IOCBF.1
$define IOC_RB2_IntFlag     IOCBF.2
$define IOC_RB3_IntFlag     IOCBF.3
$define IOC_RB4_IntFlag     IOCBF.4
$define IOC_RB5_IntFlag     IOCBF.5
$define IOC_RB6_IntFlag     IOCBF.6
$define IOC_RB7_IntFlag     IOCBF.7
$define IOC_RC0_IntFlag     IOCCF.0
$define IOC_RC1_IntFlag     IOCCF.1
$define IOC_RC2_IntFlag     IOCCF.2
$define IOC_RC3_IntFlag     IOCCF.3
$define IOC_RC4_IntFlag     IOCCF.4
$define IOC_RC5_IntFlag     IOCCF.5
$define IOC_RC6_IntFlag     IOCCF.6
$define IOC_RC7_IntFlag     IOCCF.7
'
' Clear the IOC interrupt flags per Port.Pin
'
$define IOC_RA0_ClearIntFlag()     IOCAF.0 = 0
$define IOC_RA1_ClearIntFlag()     IOCAF.1 = 0
$define IOC_RA2_ClearIntFlag()     IOCAF.2 = 0
$define IOC_RA3_ClearIntFlag()     IOCAF.3 = 0
$define IOC_RA4_ClearIntFlag()     IOCAF.4 = 0
$define IOC_RA5_ClearIntFlag()     IOCAF.5 = 0
$define IOC_RA6_ClearIntFlag()     IOCAF.6 = 0
$define IOC_RA7_ClearIntFlag()     IOCAF.7 = 0
$define IOC_RB0_ClearIntFlag()     IOCBF.0 = 0
$define IOC_RB1_ClearIntFlag()     IOCBF.1 = 0
$define IOC_RB2_ClearIntFlag()     IOCBF.2 = 0
$define IOC_RB3_ClearIntFlag()     IOCBF.3 = 0
$define IOC_RB4_ClearIntFlag()     IOCBF.4 = 0
$define IOC_RB5_ClearIntFlag()     IOCBF.5 = 0
$define IOC_RB6_ClearIntFlag()     IOCBF.6 = 0
$define IOC_RB7_ClearIntFlag()     IOCBF.7 = 0
$define IOC_RC0_ClearIntFlag()     IOCCF.0 = 0
$define IOC_RC1_ClearIntFlag()     IOCCF.1 = 0
$define IOC_RC2_ClearIntFlag()     IOCCF.2 = 0
$define IOC_RC3_ClearIntFlag()     IOCCF.3 = 0
$define IOC_RC4_ClearIntFlag()     IOCCF.4 = 0
$define IOC_RC5_ClearIntFlag()     IOCCF.5 = 0
$define IOC_RC6_ClearIntFlag()     IOCCF.6 = 0
$define IOC_RC7_ClearIntFlag()     IOCCF.7 = 0
'
' Enable Interrupts
'
$define IntGlobal_Enable()      INTCON0bits_GIE = 1
$define IntPeriph_Enable()      INTCON0bits_GIEL = 1
$define Global_IntEnable()      INTCON0bits_GIE = 1
$define Periph_IntEnable()      INTCON0bits_GIEL = 1
$define TMR0_IntEnable()        PIE3bits_TMR0IE = 1
$define TMR1_IntEnable()        PIE4bits_TMR1IE = 1
$define TMR2_IntEnable()        PIE4bits_TMR2IE = 1
$define TMR3_IntEnable()        PIE6bits_TMR3IE = 1
$define TMR4_IntEnable()        PIE7bits_TMR4IE = 1
$define TMR5_IntEnable()        PIE8bits_TMR5IE = 1
$define TMR6_IntEnable()        PIE9bits_TMR6IE = 1
$define INT0_IntEnable()        PIE1bits_INT0IE = 1
$define INT1_IntEnable()        PIE5bits_INT1IE = 1
$define INT2_IntEnable()        PIE7bits_INT2IE = 1
$define IOC_IntEnable()         PIE0bits_IOCIE = 1
$define RX_IntEnable()          PIE3bits_U1RXIE = 1
$define TX_IntEnable()          PIE3bits_U1TXIE = 1
$define RX1_IntEnable()         PIE3bits_U1RXIE = 1
$define TX1_IntEnable()         PIE3bits_U1TXIE = 1
$define RX2_IntEnable()         PIE6bits_U2RXIE = 1
$define TX2_IntEnable()         PIE6bits_U2TXIE = 1
$define SPI_IntEnable()         PIE2bits_SPI1IE = 1
$define SPI1_IntEnable()        PIE2bits_SPI1IE = 1
$define CCP1_IntEnable()        PIE4bits_CCP1IE = 1
$define CCP2_IntEnable()        PIE7bits_CCP2IE = 1
$define CCP3_IntEnable()        PIE9bits_CCP3IE = 1
$define CCP4_IntEnable()        PIE10bits_CCP4IE = 1
$define ADC_IntEnable()         PIE1bits_ADIE = 1
$define CMP1_IntEnable()        PIE1bits_C1IE = 1
$define CMP2_IntEnable()        PIE5bits_C2IE = 1
$define NVM_IntEnable()         PIE0bits_NVMIE = 1
$define I2C_IntEnable()         PIE2bits_I2C1RXIE = 1
$define I2C1_IntEnable()        PIE2bits_I2C1RXIE = 1
$define I2C2_IntEnable()        PIE6bits_I2C2IE = 1
$define HLVD_IntEnable()        PIE0bits_HLVDIE = 1
$define OSC_IntEnable()         PIE0bits_OSFIE = 1
$define TMR1_Gate_IntEnable()   PIE4bits_TMR1GIE = 1
$define TMR3_Gate_IntEnable()   PIE6bits_TMR3GIE = 1
$define TMR5_Gate_IntEnable()   PIE8bits_TMR5GIE = 1
$define TMR2_Match_IntEnable()  PIE4bits_TMR2IE = 1
$define TMR4_Match_IntEnable()  PIE7bits_TMR4IE = 1
$define TMR6_Match_IntEnable()  PIE9bits_TMR6IE = 1
$define ZCD_IntEnable()         PIE1bits_ZCDIE = 1
$define SPI_RX_IntEnable()      PIE2bits_SPI1RXIE = 1
$define SPI_TX_IntEnable()      PIE2bits_SPI1TXIE = 1
$define SPI1_RX_IntEnable()     PIE2bits_SPI1RXIE = 1
$define SPI1_TX_IntEnable()     PIE2bits_SPI1TXIE = 1
$define DMA1_ABRT_IntEnable()   PIE2bits_DMA1AIE = 1
$define DMA1_OV_IntEnable()     PIE2bits_DMA1ORIE = 1
$define DMA1_DCNT_IntEnable()   PIE2bits_DMA1DCNTIE = 1
$define DMA1_SCNT_IntEnable()   PIE2bits_DMA1SCNTIE = 1
$define DMA2_ABRT_IntEnable()   PIE5bits_DMA2AIE = 1
$define DMA2_OV_IntEnable()     PIE5bits_DMA2ORIE = 1
$define DMA2_DCNT_IntEnable()   PIE5bits_DMA2DCNTIE = 1
$define DMA2_SCNT_IntEnable()   PIE5bits_DMA2SCNTIE = 1
$define CLC1_IntEnable()        PIE4bits_CLC1IE = 1
$define CLC2_IntEnable()        PIE7bits_CLC2IE = 1
$define CLC3_IntEnable()        PIE9bits_CLC3IE = 1
$define CLC4_IntEnable()        PIE10bits_CLC4IE = 1
$define CWG1_IntEnable()        PIE4bits_CWG1IE = 1
$define CWG2_IntEnable()        PIE7bits_CWG2IE = 1
$define CWG3_IntEnable()        PIE9bits_CWG3IE = 1
$define NCO1_IntEnable()        PIE4bits_NCO1IE = 1
$define CRC_IntEnable()         PIE0bits_CRCIE = 1
$define CSW_IntEnable()         PIE0bits_CSWIE = 1
$define SMT1PWM_IntEnable()     PIE1bits_SMT1PWAIE = 1
$define SMT1PRA_IntEnable()     PIE1bits_SMT1PRAIE = 1
$define SMT1_IntEnable()        PIE1bits_SMT1IE = 1
'
' Disable Interrupts
'
$define IntGlobal_Disable()      INTCON0bits_GIE = 0
$define IntPeriph_Disable()      INTCON0bits_GIEL = 0
$define Global_IntDisable()      INTCON0bits_GIE = 0
$define Periph_IntDisable()      INTCON0bits_GIEL = 0
$define TMR0_IntDisable()        PIE3bits_TMR0IE = 0
$define TMR1_IntDisable()        PIE4bits_TMR1IE = 0
$define TMR2_IntDisable()        PIE4bits_TMR2IE = 0
$define TMR3_IntDisable()        PIE6bits_TMR3IE = 0
$define TMR4_IntDisable()        PIE7bits_TMR4IE = 0
$define TMR5_IntDisable()        PIE8bits_TMR5IE = 0
$define TMR6_IntDisable()        PIE9bits_TMR6IE = 0
$define INT0_IntDisable()        PIE1bits_INT0IE = 0
$define INT1_IntDisable()        PIE5bits_INT1IE = 0
$define INT2_IntDisable()        PIE7bits_INT2IE = 0
$define IOC_IntDisable()         PIE0bits_IOCIE = 0
$define RX_IntDisable()          PIE3bits_U1RXIE = 0
$define TX_IntDisable()          PIE3bits_U1TXIE = 0
$define RX1_IntDisable()         PIE3bits_U1RXIE = 0
$define TX1_IntDisable()         PIE3bits_U1TXIE = 0
$define RX2_IntDisable()         PIE6bits_U2RXIE = 0
$define TX2_IntDisable()         PIE6bits_U2TXIE = 0
$define SPI_IntDisable()         PIE2bits_SPI1IE = 0
$define SPI1_IntDisable()        PIE2bits_SPI1IE = 0
$define CCP1_IntDisable()        PIE4bits_CCP1IE = 0
$define CCP2_IntDisable()        PIE7bits_CCP2IE = 0
$define CCP3_IntDisable()        PIE9bits_CCP3IE = 0
$define CCP4_IntDisable()        PIE10bits_CCP4IE = 0
$define ADC_IntDisable()         PIE1bits_ADIE = 0
$define CMP1_IntDisable()        PIE1bits_C1IE = 0
$define CMP2_IntDisable()        PIE5bits_C2IE = 0
$define NVM_IntDisable()         PIE0bits_NVMIE = 0
$define I2C_IntDisable()         PIE2bits_I2C1RXIE = 0
$define I2C1_IntDisable()        PIE2bits_I2C1RXIE = 0
$define I2C2_IntDisable()        PIE6bits_I2C2IE = 0
$define HLVD_IntDisable()        PIE0bits_HLVDIE = 0
$define OSC_IntDisable()         PIE0bits_OSFIE = 0
$define TMR1_Gate_IntDisable()   PIE4bits_TMR1GIE = 0
$define TMR3_Gate_IntDisable()   PIE6bits_TMR3GIE = 0
$define TMR5_Gate_IntDisable()   PIE8bits_TMR5GIE = 0
$define TMR2_Match_IntDisable()  PIE4bits_TMR2IE = 0
$define TMR4_Match_IntDisable()  PIE7bits_TMR4IE = 0
$define TMR6_Match_IntDisable()  PIE9bits_TMR6IE = 0
$define ZCD_IntDisable()         PIE1bits_ZCDIE = 0
$define SPI_RX_IntDisable()      PIE2bits_SPI1RXIE = 0
$define SPI_TX_IntDisable()      PIE2bits_SPI1TXIE = 0
$define SPI1_RX_IntDisable()     PIE2bits_SPI1RXIE = 0
$define SPI1_TX_IntDisable()     PIE2bits_SPI1TXIE = 0
$define DMA1_ABRT_IntDisable()   PIE2bits_DMA1AIE = 0
$define DMA1_OV_IntDisable()     PIE2bits_DMA1ORIE = 0
$define DMA1_DCNT_IntDisable()   PIE2bits_DMA1DCNTIE = 0
$define DMA1_SCNT_IntDisable()   PIE2bits_DMA1SCNTIE = 0
$define DMA2_ABRT_IntDisable()   PIE5bits_DMA2AIE = 0
$define DMA2_OV_IntDisable()     PIE5bits_DMA2ORIE = 0
$define DMA2_DCNT_IntDisable()   PIE5bits_DMA2DCNTIE = 0
$define DMA2_SCNT_IntDisable()   PIE5bits_DMA2SCNTIE = 0
$define CLC1_IntDisable()        PIE4bits_CLC1IE = 0
$define CLC2_IntDisable()        PIE7bits_CLC2IE = 0
$define CLC3_IntDisable()        PIE9bits_CLC3IE = 0
$define CLC4_IntDisable()        PIE10bits_CLC4IE = 0
$define CWG1_IntDisable()        PIE4bits_CWG1IE = 0
$define CWG2_IntDisable()        PIE7bits_CWG2IE = 0
$define CWG3_IntDisable()        PIE9bits_CWG3IE = 0
$define NCO1_IntDisable()        PIE4bits_NCO1IE = 0
$define CRC_IntDisable()         PIE0bits_CRCIE = 0
$define CSW_IntDisable()         PIE0bits_CSWIE = 0
$define SMT1PWM_IntDisable()     PIE1bits_SMT1PWAIE = 0
$define SMT1PRA_IntDisable()     PIE1bits_SMT1PRAIE = 0
$define SMT1_IntDisable()        PIE1bits_SMT1IE = 0
'------------------------------------------------------------------
' INT0
'
$define INT0_Edge_Rising()  Set INTCON0bits_INT0EDG     ' Interrupt on a rising edge on the INT0 pin
$define INT0_Edge_Falling() Clear INTCON0bits_INT0EDG   ' Interrupt on a falling edge on the INT0 pin

'------------------------------------------------------------------
' INT1
'
$define INT1_Edge_Rising()  Set INTCON0bits_INT1EDG     ' Interrupt on a rising edge on the INT1 pin
$define INT1_Edge_Falling() Clear INTCON0bits_INT1EDG   ' Interrupt on a falling edge on the INT1 pin

'------------------------------------------------------------------
' INT2
'
$define INT2_Edge_Rising()  Set INTCON0bits_INT2EDG     ' Interrupt on a rising edge on the INT2 pin
$define INT2_Edge_Falling() Clear INTCON0bits_INT2EDG   ' Interrupt on a falling edge on the INT2 pin

'------------------------------------------------------------------
' PORTA.0 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RA0_Rising()  '
    IOCAN.0 = 0           '
    IOCAP.0 = 1

$define IOC_RA0_Falling() '
    IOCAN.0 = 1           '
    IOCAP.0 = 0

'------------------------------------------------------------------
' PORTA.1 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RA1_Rising()  '
    IOCAN.1 = 0           '
    IOCAP.1 = 1

$define IOC_RA1_Falling() '
    IOCAN.1 = 1           '
    IOCAP.1 = 0

'------------------------------------------------------------------
' PORTA.2 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RA2_Rising()  '
    IOCAN.2 = 0           '
    IOCAP.2 = 1

$define IOC_RA2_Falling() '
    IOCAN.2 = 1           '
    IOCAP.2 = 0

'------------------------------------------------------------------
' PORTA.3 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RA3_Rising()  '
    IOCAN.3 = 0           '
    IOCAP.3 = 1

$define IOC_RA3_Falling() '
    IOCAN.3 = 1           '
    IOCAP.3 = 0

'------------------------------------------------------------------
' PORTA.4 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RA4_Rising()  '
    IOCAN.4 = 0           '
    IOCAP.4 = 1

$define IOC_RA4_Falling() '
    IOCAN.4 = 1           '
    IOCAP.4 = 0

'------------------------------------------------------------------
' PORTA.5 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RA5_Rising()  '
    IOCAN.5 = 0           '
    IOCAP.5 = 1

$define IOC_RA5_Falling() '
    IOCAN.5 = 1           '
    IOCAP.5 = 0

'------------------------------------------------------------------
' PORTA.6 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RA6_Rising()  '
    IOCAN.6 = 0           '
    IOCAP.6 = 1

$define IOC_RA6_Falling() '
    IOCAN.6 = 1           '
    IOCAP.6 = 0

'------------------------------------------------------------------
' PORTA.7 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RA7_Rising()  '
    IOCAN.7 = 0           '
    IOCAP.7 = 1

$define IOC_RA7_Falling() '
    IOCAN.7 = 1           '
    IOCAP.7 = 0

'------------------------------------------------------------------
' PORTB.0 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RB0_Rising()  '
    IOCBN.0 = 0           '
    IOCBP.0 = 1

$define IOC_RB0_Falling() '
    IOCBN.0 = 1           '
    IOCBP.0 = 0

'------------------------------------------------------------------
' PORTB.1 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RB1_Rising()  '
    IOCBN.1 = 0           '
    IOCBP.1 = 1

$define IOC_RB1_Falling() '
    IOCBN.1 = 1           '
    IOCBP.1 = 0

'------------------------------------------------------------------
' PORTB.2 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RB2_Rising()  '
    IOCBN.2 = 0           '
    IOCBP.2 = 1

$define IOC_RB2_Falling() '
    IOCBN.2 = 1           '
    IOCBP.2 = 0

'------------------------------------------------------------------
' PORTB.3 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RB3_Rising()  '
    IOCBN.3 = 0           '
    IOCBP.3 = 1

$define IOC_RB3_Falling() '
    IOCBN.3 = 1           '
    IOCBP.3 = 0

'------------------------------------------------------------------
' PORTB.4 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RB4_Rising()  '
    IOCBN.4 = 0           '
    IOCBP.4 = 1

$define IOC_RB4_Falling() '
    IOCBN.4 = 1           '
    IOCBP.4 = 0

'------------------------------------------------------------------
' PORTB.5 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RB5_Rising()  '
    IOCBN.5 = 0           '
    IOCBP.5 = 1

$define IOC_RB5_Falling() '
    IOCBN.5 = 1           '
    IOCBP.5 = 0

'------------------------------------------------------------------
' PORTB.6 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RB6_Rising()  '
    IOCBN.6 = 0           '
    IOCBP.6 = 1

$define IOC_RB6_Falling() '
    IOCBN.6 = 1           '
    IOCBP.6 = 0

'------------------------------------------------------------------
' PORTB.7 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RB7_Rising()  '
    IOCBN.7 = 0           '
    IOCBP.7 = 1

$define IOC_RB7_Falling() '
    IOCBN.7 = 1           '
    IOCBP.7 = 0

'------------------------------------------------------------------
' PORTC.0 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RC0_Rising()  '
    IOCCN.0 = 0           '
    IOCCP.0 = 1

$define IOC_RC0_Falling() '
    IOCCN.0 = 1           '
    IOCCP.0 = 0

'------------------------------------------------------------------
' PORTC.1 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RC1_Rising()  '
    IOCCN.1 = 0           '
    IOCCP.1 = 1

$define IOC_RC1_Falling() '
    IOCCN.1 = 1           '
    IOCCP.1 = 0

'------------------------------------------------------------------
' PORTC.2 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RC2_Rising()  '
    IOCCN.2 = 0           '
    IOCCP.2 = 1

$define IOC_RC2_Falling() '
    IOCCN.2 = 1           '
    IOCCP.2 = 0

'------------------------------------------------------------------
' PORTC.3 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RC3_Rising()  '
    IOCCN.3 = 0           '
    IOCCP.3 = 1

$define IOC_RC3_Falling() '
    IOCCN.3 = 1           '
    IOCCP.3 = 0

'------------------------------------------------------------------
' PORTC.4 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RC4_Rising()  '
    IOCCN.4 = 0           '
    IOCCP.4 = 1

$define IOC_RC4_Falling() '
    IOCCN.4 = 1           '
    IOCCP.4 = 0

'------------------------------------------------------------------
' PORTC.5 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RC5_Rising()  '
    IOCCN.5 = 0           '
    IOCCP.5 = 1

$define IOC_RC5_Falling() '
    IOCCN.5 = 1           '
    IOCCP.5 = 0

'------------------------------------------------------------------
' PORTC.6 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RC6_Rising()  '
    IOCCN.6 = 0           '
    IOCCP.6 = 1

$define IOC_RC6_Falling() '
    IOCCN.6 = 1           '
    IOCCP.6 = 0

'------------------------------------------------------------------
' PORTC.7 IOC (Interrupt On Change) Edge Detection
'
$define IOC_RC7_Rising()  '
    IOCCN.7 = 0           '
    IOCCP.7 = 1

$define IOC_RC7_Falling() '
    IOCCN.7 = 1           '
    IOCCP.7 = 0
   
'------------------------------------------------------------------
' Enable\Disable global interrupts
'
$define Int_Global(pParam) '
    $if pParam = Enable         '
        IntGlobal_Enable()      '
    $elseif pParam = Disable    '
        IntGlobal_Disable()     '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable peripheral interrupts
'
$define Int_Peripheral(pParam)      '
    $if pParam = Enable             '
        IntPeriph_Enable()          '
    $elseif pParam = Disable        '
        IntPeriph_Disable()         '
    $else                           '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer0 overflow interrupt
'
$define Int_TMR0(pParam)        '
    $if pParam = Enable         '
        TMR0_IntEnable()        '
    $elseif pParam = Disable    '
        TMR0_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer1 overflow interrupt
'
$define Int_TMR1(pParam)        '
    $if pParam = Enable         '
        TMR1_IntEnable()        '
    $elseif pParam = Disable    '
        TMR1_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer2 overflow interrupt
'
$define Int_TMR2(pParam)        '
    $if pParam = Enable         '
        TMR2_IntEnable()        '
    $elseif pParam = Disable    '
        TMR2_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer3 overflow interrupt
'
$define Int_TMR3(pParam)        '
    $if pParam = Enable         '
        TMR3_IntEnable()        '
    $elseif pParam = Disable    '
        TMR3_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer4 overflow interrupt
'
$define Int_TMR4(pParam)        '
    $if pParam = Enable         '
        TMR4_IntEnable()        '
    $elseif pParam = Disable    '
        TMR4_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer5 overflow interrupt
'
$define Int_TMR5(pParam)        '
    $if pParam = Enable         '
        TMR5_IntEnable()        '
    $elseif pParam = Disable    '
        TMR5_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer6 overflow interrupt
'
$define Int_TMR6(pParam)        '
    $if pParam = Enable         '
        TMR6_IntEnable()        '
    $elseif pParam = Disable    '
        TMR6_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an INT0 interrupt
'
$define Int_INT0(pParam)        '
    $if pParam = Enable         '
        INT0_IntEnable()        '
    $elseif pParam = Disable    '
        INT0_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an INT1 interrupt
'
$define Int_INT1(pParam)        '
    $if pParam = Enable         '
        INT1_IntEnable()        '
    $elseif pParam = Disable    '
        INT1_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an INT2 interrupt
'
$define Int_INT2(pParam)        '
    $if pParam = Enable         '
        INT2_IntEnable()        '
    $elseif pParam = Disable    '
        INT2_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CCP1 interrupt
'
$define Int_CCP1(pParam)        '
    $if pParam = Enable         '
        CCP1_IntEnable()        '
    $elseif pParam = Disable    '
        CCP1_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CCP2 interrupt
'
$define Int_CCP2(pParam)        '
    $if pParam = Enable         '
        CCP2_IntEnable()        '
    $elseif pParam = Disable    '
        CCP2_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CCP3 interrupt
'
$define Int_CCP3(pParam)        '
    $if pParam = Enable         '
        CCP3_IntEnable()        '
    $elseif pParam = Disable    '
        CCP3_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CCP4 interrupt
'
$define Int_CCP4(pParam)        '
    $if pParam = Enable         '
        CCP4_IntEnable()        '
    $elseif pParam = Disable    '
        CCP4_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an IOC interrupt
'
$define Int_IOC(pParam)         '
    $if pParam = Enable         '
        IOC_IntEnable()         '
    $elseif pParam = Disable    '
        IOC_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an ADC interrupt
'
$define Int_ADC(pParam)         '
    $if pParam = Enable         '
        ADC_IntEnable()         '
    $elseif pParam = Disable    '
        ADC_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif
'------------------------------------------------------------------
' Enable\Disable a UART1 receive interrupt
'
$define Int_RX1(pParam)         '
    $if pParam = Enable         '
        RX1_IntEnable()         '
    $elseif pParam = Disable    '
        RX1_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

$define Int_RX1(pParam) Int_RX1(pParam)
'------------------------------------------------------------------
' Enable\Disable a UART1 transmit interrupt
'
$define Int_TX1(pParam)         '
    $if pParam = Enable         '
        TX1_IntEnable()         '
    $elseif pParam = Disable    '
        TX1_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a UART2 receive interrupt
'
$define Int_RX2(pParam)         '
    $if pParam = Enable         '
        RX2_IntEnable()         '
    $elseif pParam = Disable    '
        RX2_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a UART2 transmit interrupt
'
$define Int_TX2(pParam)         '
    $if pParam = Enable         '
        RX2_IntEnable()         '
    $elseif pParam = Disable    '
        RX2_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

$define Int_TX1(pParam) Int_TX1(pParam)
'------------------------------------------------------------------
' Enable\Disable an SPI1 interrupt
'
$define Int_SPI1(pParam)        '
    $if pParam = Enable         '
        SPI1_IntEnable()        '
    $elseif pParam = Disable    '
        SPI1_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

$define Int_SPI1(pParam) Int_SPI1(pParam)
'------------------------------------------------------------------
' Enable\Disable an Oscillator Fail interrupt
'
$define Int_OSC(pParam)         '
    $if pParam = Enable         '
        OSC_IntEnable()         '
    $elseif pParam = Disable    '
        OSC_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Comparator 1 interrupt
'
$define Int_CMP1(pParam)        '
    $if pParam = Enable         '
        CMP1_IntEnable()        '
    $elseif pParam = Disable    '
        CMP1_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Comparator 2 interrupt
'
$define Int_CMP2(pParam)        '
    $if pParam = Enable         '
        IntEnable_Comp2()       '
    $elseif pParam = Disable    '
        IntDisable_Comp2()      '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an EEPROM and Flash Write interrupt
'
$define Int_Flash(pParam)       '
    $if pParam = Enable         '
        NVM_IntEnable()         '
    $elseif pParam = Disable    '
        NVM_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an MSPI1 Bus collision interrupt
'
$define Int_I2C(pParam)         '
    $if pParam = Enable         '
        I2C_IntEnable()         '
    $elseif pParam = Disable    '
        I2C_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

$define Int_I2C1(pParam) Int_I2C(pParam)
'------------------------------------------------------------------
' Enable\Disable a Low Voltage interrupt
'
$define Int_HLVD(pParam)        '
    $if pParam = Enable         '
        HLVD_IntEnable()        '
    $elseif pParam = Disable    '
        HLVD_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an I2C2 Bus collision interrupt
'
$define Int_I2C2(pParam)        '
    $if pParam = Enable         '
        I2C2_IntEnable()        '
    $elseif pParam = Disable    '
        I2C2_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer2 to PR2 match interrupt
'
$define Int_TMR2_Match(pParam)      '
    $if pParam = Enable             '
        TMR2_Match_IntEnable()      '
    $elseif pParam = Disable        '
        TMR2_Match_IntDisable()     '
    $else                           '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer4 to PR4 match interrupt
'
$define Int_TMR4_Match(pParam)      '
    $if pParam = Enable             '
        TMR4_Match_IntEnable()      '
    $elseif pParam = Disable        '
        TMR4_Match_IntDisable()     '
    $else                           '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer6 to PR6 match interrupt
'
$define Int_TMR6_Match(pParam)      '
    $if pParam = Enable             '
        TMR6_Match_IntEnable()      '
    $elseif pParam = Disable        '
        TMR6_Match_IntDisable()     '
    $else                           '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer1 Gate interrupt
'
$define Int_TMR1_Gate(pParam)       '
    $if pParam = Enable             '
        TMR1_Gate_IntEnable()       '
    $elseif pParam = Disable        '
        TMR1_Gate_IntDisable()      '
    $else                           '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer3 Gate interrupt
'
$define Int_TMR3_Gate(pParam)       '
    $if pParam = Enable             '
        TMR3_Gate_IntEnable()       '
    $elseif pParam = Disable        '
        TMR3_Gate_IntDisable()      '
    $else                           '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a Timer5 Gate interrupt
'
$define Int_TMR5_Gate(pParam)       '
    $if pParam = Enable             '
        TMR5_Gate_IntEnable()       '
    $elseif pParam = Disable        '
        TMR5_Gate_IntDisable()      '
    $else                           '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a ZCD interrupt
'
$define Int_ZCD(pParam)         '
    $if pParam = Enable         '
        ZCD_IntEnable()         '
    $elseif pParam = Disable    '
        ZCD_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an SPI1 RX interrupt
'
$define Int_SPI1_RX(pParam)     '
    $if pParam = Enable         '
        SPI1_RX_IntEnable()     '
    $elseif pParam = Disable    '
        SPI1_RX_IntDisable()    '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an SPI1 TX interrupt
'
$define Int_SPI1_TX(pParam)     '
    $if pParam = Enable         '
        SPI1_TX_IntEnable()     '
    $elseif pParam = Disable    '
        SPI1_TX_IntDisable()    '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a DMA1 Abort interrupt
'
$define Int_DMA1_ABRT(pParam)   '
    $if pParam = Enable         '
        DMA1_ABRT_IntEnable()   '
    $elseif pParam = Disable    '
        DMA1_ABRT_IntDisable()  '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a DMA1 Over-Run interrupt
'
$define Int_DMA1_OV(pParam)     '
    $if pParam = Enable         '
        DMA1_OV_IntEnable()     '
    $elseif pParam = Disable    '
        DMA1_OV_IntDisable()    '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a DMA1 Destination Count interrupt
'
$define Int_DMA1_DCNT(pParam)   '
    $if pParam = Enable         '
        DMA1_DCNT_IntEnable()   '
    $elseif pParam = Disable    '
        DMA1_DCNT_IntDisable()  '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a DMA1 Source Count interrupt
'
$define Int_DMA1_SCNT(pParam)   '
    $if pParam = Enable         '
        DMA1_SCNT_IntEnable()   '
    $elseif pParam = Disable    '
        DMA1_SCNT_IntDisable()  '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a DMA2 Abort interrupt
'
$define Int_DMA2_ABRT(pParam)   '
    $if pParam = Enable         '
        DMA2_ABRT_IntEnable()   '
    $elseif pParam = Disable    '
        DMA2_ABRT_IntDisable()  '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a DMA2 Over-Run interrupt
'
$define Int_DMA2_OV(pParam)     '
    $if pParam = Enable         '
        DMA2_OV_IntEnable()     '
    $elseif pParam = Disable    '
        DMA2_OV_IntDisable()    '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a DMA2 Destination Count interrupt
'
$define Int_DMA2_DCNT(pParam)   '
    $if pParam = Enable         '
        DMA2_DCNT_IntEnable()   '
    $elseif pParam = Disable    '
        DMA2_DCNT_IntDisable()  '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a DMA2 Source Count interrupt
'
$define Int_DMA2_SCNT(pParam)   '
    $if pParam = Enable         '
        DMA2_SCNT_IntEnable()   '
    $elseif pParam = Disable    '
        DMA2_SCNT_IntDisable()  '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CLC1 interrupt
'
$define Int_CLC1(pParam)        '
    $if pParam = Enable         '
        CLC1_IntEnable()        '
    $elseif pParam = Disable    '
        CLC1_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CLC2 interrupt
'
$define Int_CLC2(pParam)        '
    $if pParam = Enable         '
        CLC2_IntEnable()        '
    $elseif pParam = Disable    '
        CLC2_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CLC3 interrupt
'
$define Int_CLC3(pParam)        '
    $if pParam = Enable         '
        CLC3_IntEnable()        '
    $elseif pParam = Disable    '
        CLC3_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CLC4 interrupt
'
$define Int_CLC4(pParam)        '
    $if pParam = Enable         '
        CLC4_IntEnable()        '
    $elseif pParam = Disable    '
        CLC4_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CWG1 interrupt
'
$define Int_CWG1(pParam)        '
    $if pParam = Enable         '
        CWG1_IntEnable()        '
    $elseif pParam = Disable    '
        CWG1_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CWG2 interrupt
'
$define Int_CWG2(pParam)        '
    $if pParam = Enable         '
        CWG2_IntEnable()        '
    $elseif pParam = Disable    '
        CWG2_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CWG3 interrupt
'
$define Int_CWG3(pParam)        '
    $if pParam = Enable         '
        CWG3_IntEnable()        '
    $elseif pParam = Disable    '
        CWG3_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an NCO1 interrupt
'
$define Int_NCO1(pParam)        '
    $if pParam = Enable         '
        NCO1_IntEnable()        '
    $elseif pParam = Disable    '
        NCO1_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CRC interrupt
'
$define Int_CRC(pParam)         '
    $if pParam = Enable         '
        CRC_IntEnable()         '
    $elseif pParam = Disable    '
        CRC_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a CSW interrupt
'
$define Int_CSW(pParam)         '
    $if pParam = Enable         '
        CSW_IntEnable()         '
    $elseif pParam = Disable    '
        CSW_IntDisable()        '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a SMT1PWM interrupt
'
$define Int_SMT1PWM(pParam)     '
    $if pParam = Enable         '
        SMT1PWM_IntEnable()     '
    $elseif pParam = Disable    '
        SMT1PWM_IntDisable()    '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable a SMT1PRA interrupt
'
$define Int_SMT1PRA(pParam)     '
    $if pParam = Enable         '
        SMT1PRA_IntEnable()     '
    $elseif pParam = Disable    '
        SMT1PRA_IntDisable()    '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------
' Enable\Disable an SMT1 interrupt
'
$define Int_SMT1(pParam)        '
    $if pParam = Enable         '
        SMT1_IntEnable()        '
    $elseif pParam = Disable    '
        SMT1_IntDisable()       '
    $else                       '
        $error "Unrecognised parameter. Enable or Disable only" '
    $endif

'------------------------------------------------------------------

$define _Managed_ISR

'----------------------------------------------------------------------------
' The main high priority ISR handler subroutine
'
' This routine calls the relevant peripheral interrupt handlers
'
$if _defined(Handle_IOC_Int) Or _defined(Handle_INT0_Int) Or _defined(Handle_INT1_Int) Or _defined(Handle_INT2_Int)                 '
 Or _defined(Handle_RX_Int) Or _defined(Handle_TX_Int) Or _defined(Handle_RX1_Int) Or _defined(Handle_TX1_Int)                      '
 Or _defined(Handle_RX2_Int) Or _defined(Handle_TX2_Int)                                                                            '
 Or _defined(Handle_SPI1_Int) Or _defined(Handle_SPI_Int)                                                                           '
 Or _defined(Handle_CCP1_Int) Or _defined(Handle_CCP2_Int) Or _defined(Handle_CCP3_Int) Or _defined(Handle_CCP4_Int)                '
 Or _defined(Handle_TMR0_Int) Or _defined(Handle_TMR1_Int) Or _defined(Handle_TMR2_Int) Or _defined(Handle_TMR3_Int)                '
 Or _defined(Handle_TMR4_Int) Or _defined(Handle_TMR5_Int) Or _defined(Handle_TMR6_Int)                                             '
 Or _defined(Handle_HLVD_Int) Or _defined(Handle_ADC_Int) Or _defined(Handle_OSC_Int)                                               '
 Or _defined(Handle_CMP1_Int) Or _defined(Handle_CMP2_Int) Or _defined(Handle_NVM_Int)                                              '
 Or _defined(Handle_I2C_Int)  Or _defined(Handle_I2C1_Int) Or _defined(Handle_I2C2_Int)                                             '
 Or _defined(Handle_TMR1_Gate_Int) Or _defined(Handle_TMR3_Gate_Int) Or _defined(Handle_TMR5_Gate_Int) Or _defined(Handle_CCP3_Int) '
 Or _defined(Handle_TMR2_Match_Int) Or _defined(Handle_TMR4_Match_Int) Or _defined(Handle_TMR6_Match_Int)                           '
 Or _defined(Handle_CRC_Int) Or _defined(Handle_CSW_Int) Or _defined(Handle_ZCD_Int)                                                '
 Or _defined(Handle_SMT1PWM_Int) Or _defined(Handle_SMT1PRA_Int) Or _defined(Handle_SMT1_Int)                                       '
 Or _defined(Handle_SPI_RX_Int) Or _defined(Handle_SPI_TX_Int) Or _defined(Handle_SPI1_RX_Int) Or _defined(Handle_SPI1_TX_Int)          '
 Or _defined(Handle_DMA1_ABRT_Int) Or _defined(Handle_DMA1_OV_Int) Or _defined(Handle_DMA1_DCNT_Int) Or _defined(Handle_DMA1_SCNT_Int)  '
 Or _defined(Handle_DMA2_ABRT_Int) Or _defined(Handle_DMA2_OV_Int) Or _defined(Handle_DMA2_DCNT_Int) Or _defined(Handle_DMA2_SCNT_Int)  '
 Or _defined(Handle_CLC1_Int) Or _defined(Handle_CLC2_Int) Or _defined(Handle_CLC3_Int) Or _defined(Handle_CLC4_Int)                    '
 Or _defined(Handle_CWG1_Int) Or _defined(Handle_CWG2_Int) Or _defined(Handle_CWG3_Int) Or _defined(Handle_NCO1_Int)

Declare Reminders = Off
Declare Warnings = Off
    On_Hardware_Interrupt GoTo _ISR_High
    GoTo _InterruptManagerMain               ' Jump over the interrupt handler subroutine

_ISR_High:

$ifdef _Managed_ISR
    Context Save FSR0L, FSR0H, FSR1L, FSR1H
$endif

'----------------------------------------------------------------------------
$if _defined(Handle_RX_Int) Or _defined(Handle_RX1_Int)
    If RX_IntFlag = 1 Then
        GoTo _ISR_RX1
_ISR_RX1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$if _defined(Handle_SPI_Int) Or _defined(Handle_SPI1_Int)
    If SPI_IntFlag = 1 Then
        GoTo _ISR_SPI1
_ISR_SPI1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR0_Int
    If TMR0_IntFlag = 1 Then
        GoTo _ISR_TMR0
_ISR_TMR0_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR1_Int
    If TMR1_IntFlag = 1 Then
        GoTo _ISR_TMR1
_ISR_TMR1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR3_Int
    If TMR3_IntFlag = 1 Then
        GoTo _ISR_TMR3
_ISR_TMR3_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR4_Int
    If TMR4_IntFlag = 1 Then
        GoTo _ISR_TMR4
_ISR_TMR4_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR5_Int
    If TMR5_IntFlag = 1 Then
        GoTo _ISR_TMR5
_ISR_TMR5_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR6_Int
    If TMR6_IntFlag = 1 Then
        GoTo _ISR_TMR6
_ISR_TMR6_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_INT0_Int
    If INT0_IntFlag = 1 Then
        GoTo _ISR_INT0
_ISR_INT0_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_INT1_Int
    If INT1_IntFlag = 1 Then
        GoTo _ISR_INT1
_ISR_INT1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_INT2_Int
    If INT2_IntFlag = 1 Then
        GoTo _ISR_INT2
_ISR_INT2_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_IOC_Int
    If IOC_IntFlag = 1 Then
        GoTo _ISR_IOC
_ISR_IOC_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$if _defined(Handle_TX_Int) Or _defined(Handle_TX1_Int)
    If TX_IntFlag = 1 Then
        GoTo _ISR_TX1
_ISR_TX1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_RX2_Int
    If RX2_IntFlag = 1 Then
        GoTo _ISR_RX2
_ISR_RX2_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TX2_Int
    If TX2_IntFlag = 1 Then
        GoTo _ISR_TX2
_ISR_TX2_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CCP1_Int
    If CCP1_IntFlag = 1 Then
        GoTo _ISR_CCP1
_ISR_CCP1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CCP2_Int
    If CCP2_IntFlag = 1 Then
        GoTo _ISR_CCP2
_ISR_CCP2_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CCP3_Int
    If CCP3_IntFlag = 1 Then
        GoTo _ISR_CCP3
_ISR_CCP3_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CCP4_Int
    If CCP4_IntFlag = 1 Then
        GoTo _ISR_CCP4
_ISR_CCP4_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_ADC_Int
    If ADC_IntFlag = 1 Then
        GoTo _ISR_ADC
_ISR_ADC_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CMP1_Int
    If CMP1_IntFlag = 1 Then
        GoTo _ISR_CMP1
_ISR_CMP1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CMP2_Int
    If CMP2_IntFlag = 1 Then
        GoTo _ISR_CMP2
_ISR_CMP2_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_NVM_Int
    If NVM_IntFlag = 1 Then
        GoTo _ISR_NVM
_ISR_NVM_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$if _defined(Handle_I2C_Int) Or _defined(Handle_I2C1_Int)
    If I2C_IntFlag = 1 Then
        GoTo _ISR_I2C1
_ISR_I2C1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_I2C2_Int
    If I2C2_IntFlag = 1 Then
        GoTo _ISR_I2C2
_ISR_I2C2_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_HLVD_Int
    If HLVD_IntFlag = 1 Then
        GoTo _ISR_HLVD
_ISR_Low_Voltage_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_OSC_Int
    If OSC_IntFlag = 1 Then
        GoTo _ISR_OSC
_ISR_OSC_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR1_Gate_Int
    If TMR1_Gate_IntFlag = 1 Then
        GoTo _ISR_TMR1_Gate
_ISR_TMR1_Gate_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR3_Gate_Int
    If TMR3_Gate_IntFlag = 1 Then
        GoTo _ISR_TMR3_Gate
_ISR_TMR3_Gate_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR5_Gate_Int
    If TMR5_Gate_IntFlag = 1 Then
        GoTo _ISR_TMR5_Gate
_ISR_TMR5_Gate_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR2_Match_Int
    If TMR2_Match_IntFlag = 1 Then
        GoTo _ISR_TMR2_Match
_ISR_TMR2_Match_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR4_Match_Int
    If TMR4_Match_IntFlag = 1 Then
        GoTo _ISR_TMR4_Match
_ISR_TMR4_Match_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_TMR6_Match_Int
    If TMR6_Match_IntFlag = 1 Then
        GoTo _ISR_TMR6_Match
_ISR_TMR6_Match_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CRC_Int
    If CRC_IntFlag = 1 Then
        GoTo _ISR_CRC
_ISR_CRC_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CSW_Int
    If CSW_IntFlag = 1 Then
        GoTo _ISR_CSW
_ISR_CSW_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_ZCD_Int
    If ZCD_IntFlag = 1 Then
        GoTo _ISR_ZCD
_ISR_ZCD_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_SMT1PWM_Int
    If SMT1PWM_IntFlag = 1 Then
        GoTo _ISR_SMT1PWM
_ISR_SMT1PWM_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_SMT1PRA_Int
    If SMT1PRA_IntFlag = 1 Then
        GoTo _ISR_SMT1PRA
_ISR_SMT1PRA_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_SMT1_Int
    If SMT1_IntFlag = 1 Then
        GoTo _ISR_SMT1
_ISR_SMT1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$if _defined(Handle_SPI_RX_Int) Or _defined(Handle_SPI1_RX_Int)
    If SPI1_RX_IntFlag = 1 Then
        GoTo _ISR_SPI1_RX
_ISR_SPI1_RX_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$if _defined(Handle_SPI_TX_Int) Or _defined(Handle_SPI1_TX_Int)
    If SPI1_TX_IntFlag = 1 Then
        GoTo _ISR_SPI1_TX
_ISR_SPI1_TX_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_DMA1_ABRT_Int
    If DMA1_ABRT_IntFlag = 1 Then
        GoTo _ISR_DMA1_ABRT
_ISR_DMA1_ABRT_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_DMA1_OV_Int
    If DMA1_OV_IntFlag = 1 Then
        GoTo _ISR_DMA1_OV
_ISR_DMA1_OV_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_DMA1_DCNT_Int
    If DMA1_DCNT_IntFlag = 1 Then
        GoTo _ISR_DMA1_DCNT
_ISR_DMA1_DCNT_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_DMA1_SCNT_Int
    If DMA1_SCNT_IntFlag = 1 Then
        GoTo _ISR_DMA1_SCNT
_ISR_DMA1_SCNT_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_DMA2_ABRT_Int
    If DMA2_ABRT_IntFlag = 1 Then
        GoTo _ISR_DMA2_ABRT
_ISR_DMA2_ABRT_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_DMA2_OV_Int
    If DMA2_OV_IntFlag = 1 Then
        GoTo _ISR_DMA2_OV
_ISR_DMA2_OV_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_DMA2_DCNT_Int
    If DMA2_DCNT_IntFlag = 1 Then
        GoTo _ISR_DMA2_DCNT
_ISR_DMA2_DCNT_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_DMA2_SCNT_Int
    If DMA2_SCNT_IntFlag = 1 Then
        GoTo _ISR_DMA2_SCNT
_ISR_DMA2_SCNT_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CLC1_Int
    If CLC1_IntFlag = 1 Then
        GoTo _ISR_CLC1
_ISR_CLC1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CLC2_Int
    If CLC2_IntFlag = 1 Then
        GoTo _ISR_CLC2
_ISR_CLC2_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CLC3_Int
    If CLC3_IntFlag = 1 Then
        GoTo _ISR_CLC3
_ISR_CLC3_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CLC4_Int
    If CLC4_IntFlag = 1 Then
        GoTo _ISR_CLC4
_ISR_CLC4_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CWG1_Int
    If CWG1_IntFlag = 1 Then
        GoTo _ISR_CWG1
_ISR_CWG1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CWG2_Int
    If CWG2_IntFlag = 1 Then
        GoTo _ISR_CWG2
_ISR_CWG2_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_CWG3_Int
    If CWG3_IntFlag = 1 Then
        GoTo _ISR_CWG3
_ISR_CWG3_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef Handle_NCO1_Int
    If NCO1_IntFlag = 1 Then
        GoTo _ISR_NCO1
_ISR_NCO1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
$ifdef _Managed_ISR
    Context Restore
$else
    Retfie Fast
$endif  ' _Managed_ISR

'----------------------------------------------------------------------------
' Interrupt On Change interrupt manager
'
$define ISR_IOC(pParam)         '
$if pParam = START              '
    GoTo _ISR_IOC_Over          '
_ISR_IOC:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    IOC_IntFlag = 0             '
    GoTo _ISR_IOC_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_IOC_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' INT0 interrupt manager
'
$define ISR_INT0(pParam)        '
$if pParam = START              '
    GoTo _ISR_INT0_Over         '
_ISR_INT0:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    INT0_IntFlag = 0            '
    GoTo ISR_INT0_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_INT0_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' INT1 interrupt manager
'
$define ISR_INT1(pParam)        '
$if pParam = START              '
    GoTo _ISR_INT1_Over         '
_ISR_INT1:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    INT1_IntFlag = 0            '
    GoTo _ISR_INT1_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_INT1_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' INT2 interrupt manager
'
$define ISR_INT2(pParam)        '
$if pParam = START              '
    GoTo _ISR_INT2_Over         '
_ISR_INT2:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    INT2_IntFlag = 0            '
    GoTo _ISR_INT2_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_INT2_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer0 overflow interrupt manager
'
$define ISR_TMR0(pParam)        '
$if pParam = START              '
    GoTo _ISR_TMR0_Over         '
_ISR_TMR0:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR0_IntFlag = 0            '
    GoTo _ISR_TMR0_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR0_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer1 overflow interrupt manager
'
$define ISR_TMR1(pParam)        '
$if pParam = START              '
    GoTo _ISR_TMR1_Over         '
_ISR_TMR1:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR1_IntFlag = 0            '
    GoTo _ISR_TMR1_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR1_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer3 overflow interrupt manager
'
$define ISR_TMR3(pParam)        '
$if pParam = START              '
    GoTo _ISR_TMR3_Over         '
_ISR_TMR3:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR3_IntFlag = 0            '
    GoTo _ISR_TMR3_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR3_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer4 overflow interrupt manager
'
$define ISR_TMR4(pParam)        '
$if pParam = START              '
    GoTo _ISR_TMR4_Over         '
_ISR_TMR4:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR4_IntFlag = 0            '
    GoTo _ISR_TMR4_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR4_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer5 overflow interrupt manager
'
$define ISR_TMR5(pParam)        '
$if pParam = START              '
    GoTo _ISR_TMR5_Over         '
_ISR_TMR5:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR5_IntFlag = 0            '
    GoTo _ISR_TMR5_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR5_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer6 overflow interrupt manager
'
$define ISR_TMR6(pParam)        '
$if pParam = START              '
    GoTo _ISR_TMR6_Over         '
_ISR_TMR6:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR6_IntFlag = 0            '
    GoTo _ISR_TMR6_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR6_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' UART1 receive interrupt manager
'
$define ISR_RX(pParam)         '
$if pParam = START              '
    GoTo _ISR_RX1_Over          '
_ISR_RX1:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    GoTo _ISR_RX1_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_RX1_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

$define ISR_RX1(pParam) ISR_RX(pParam)

'----------------------------------------------------------------------------
' UART1 transmit interrupt manager
'
$define ISR_TX(pParam)         '
$if pParam = START              '
    GoTo _ISR_TX1_Over          '
_ISR_TX1:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    GoTo _ISR_TX1_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TX1_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

$define ISR_TX1(pParam) ISR_TX(pParam)

'----------------------------------------------------------------------------
' UART2 receive interrupt manager
'
$define ISR_RX2(pParam)         '
$if pParam = START              '
    GoTo _ISR_RX2_Over          '
_ISR_RX2:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    GoTo _ISR_RX2_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_RX2_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' UART2 transmit interrupt manager
'
$define ISR_TX2(pParam)         '
$if pParam = START              '
    GoTo _ISR_TX2_Over          '
_ISR_TX2:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    GoTo ISR_TX2_Exit           '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TX2_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' SPI interrupt manager
'
$define ISR_SPI(pParam)         '
$if pParam = START              '
    GoTo _ISR_SPI1_Over         '
_ISR_SPI1:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    SPI_IntFlag = 0             '
    GoTo _ISR_SPI1_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_SPI1_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

$define ISR_SPI1(pParam) ISR_SPI(pParam)

'----------------------------------------------------------------------------
' CCP1 interrupt manager
'
$define ISR_CCP1(pParam)        '
$if pParam = START              '
    GoTo _ISR_CCP1_Over         '
_ISR_CCP1:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CCP1_IntFlag = 0            '
    GoTo _ISR_CCP1_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CCP1_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' CCP2 interrupt manager
'
$define ISR_CCP2(pParam)        '
$if pParam = START              '
    GoTo _ISR_CCP2_Over         '
_ISR_CCP2:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CCP2_IntFlag = 0            '
    GoTo _ISR_CCP2_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CCP2_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' CCP3 interrupt manager
'
$define ISR_CCP3(pParam)        '
$if pParam = START              '
    GoTo _ISR_CCP3_Over         '
_ISR_CCP3:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CCP3_IntFlag = 0            '
    GoTo _ISR_CCP3_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CCP3_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' CCP4 interrupt manager
'
$define ISR_CCP4(pParam)        '
$if pParam = START              '
    GoTo _ISR_CCP4_Over         '
_ISR_CCP4:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CCP4_IntFlag = 0            '
    GoTo _ISR_CCP4_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CCP4_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' ADC interrupt manager
'
$define ISR_ADC(pParam)         '
$if pParam = START              '
    GoTo _ISR_ADC_Over          '
_ISR_ADC:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    ADC_IntFlag = 0             '
    GoTo _ISR_ADC_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_ADC_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Comparator 1 interrupt manager
'
$define ISR_CMP1(pParam)       '
$if pParam = START             '
    GoTo _ISR_CMP1_Over        '
_ISR_CMP1:                     '
    $ifdef _Managed_ISR        '
        High_Int_Sub_Start     '
    $endif                     '
$elseif pParam = EXIT          '
    CMP1_IntFlag = 0           '
    GoTo _ISR_CMP1_Exit        '
    $ifdef _Managed_ISR        '
        High_Int_Sub_End       '
    $endif                     '
_ISR_CMP1_Over:                '
$else                          '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Comparator 2 interrupt manager
'
$define ISR_CMP2(pParam)       '
$if pParam = START             '
    GoTo _ISR_CMP2_Over        '
_ISR_CMP2:                     '
    $ifdef _Managed_ISR        '
        High_Int_Sub_Start     '
    $endif                     '
$elseif pParam = EXIT          '
    CMP2_IntFlag = 0           '
    GoTo _ISR_CMP2:_Exit       '
    $ifdef _Managed_ISR        '
        High_Int_Sub_End       '
    $endif                     '
_ISR_CMP2_Over:                '
$else                          '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Non Volatile Memory write interrupt manager
'
$define ISR_NVM(pParam)         '
$if pParam = START              '
    GoTo _ISR_NVM_Over          '
_ISR_NVM:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    NVM_IntFlag = 0             '
    GoTo _ISR_NVM_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_NVM_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' I2C1 Bus_Collision interrupt manager
'
$define ISR_I2C1(pParam)        '
$if pParam = START              '
    GoTo _ISR_I2C1_Over         '
_ISR_I2C1:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    I2C1_IntFlag = 0            '
    GoTo _ISR_I2C1_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_I2C1_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' I2C2 Bus Collision interrupt manager
'
$define ISR_I2C2(pParam)        '
$if pParam = START              '
    GoTo _ISR_I2C2_Over         '
_ISR_I2C2:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    I2C2_IntFlag = 0            '
    GoTo _ISR_I2C2_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_I2C2_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Low Voltage interrupt manager
'
$define ISR_HLVD(pParam)        '
$if pParam = START              '
    GoTo _ISR_HLVD_Over         '
_ISR_HLVD:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    HLVD_IntFlag = 0            '
    GoTo _ISR_Low_Voltage_Exit  '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_HLVD_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Oscillator Fail interrupt manager
'
$define ISR_OSC(pParam)         '
$if pParam = START              '
    GoTo _ISR_OSC_Over          '
_ISR_OSC:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    OSC_IntFlag = 0             '
    GoTo _ISR_OSC_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_OSC_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer1 Gate interrupt manager
'
$define ISR_TMR1_Gate(pParam)   '
$if pParam = START              '
    GoTo _ISR_TMR1_Gate_Over    '
_ISR_TMR1_Gate:                 '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR1_Gate_IntFlag = 0       '
    GoTo _ISR_TMR1_Gate_Exit    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR1_Gate_Over:            '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer3 Gate interrupt manager
'
$define ISR_TMR3_Gate(pParam)   '
$if pParam = START              '
    GoTo _ISR_TMR3_Gate_Over    '
_ISR_TMR3_Gate:                 '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR3_Gate_IntFlag = 0       '
    GoTo _ISR_TMR3_Gate_Exit    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR3_Gate_Over:            '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer5 Gate interrupt manager
'
$define ISR_TMR5_Gate(pParam)   '
$if pParam = START              '
    GoTo _ISR_TMR5_Gate_Over    '
_ISR_TMR5_Gate:                 '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR5_Gate_IntFlag = 0       '
    GoTo _ISR_TMR5_Gate_Exit    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR5_Gate_Over:            '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer2 to PR2 match interrupt manager
'
$define ISR_TMR2_Match(pParam) '
$if pParam = START              '
    GoTo _ISR_TMR2_Match_Over   '
_ISR_TMR2_Match:                '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR2_Match_IntFlag = 0      '
    GoTo _ISR_TMR2_Match_Exit   '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR2_Match_Over:           '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer4 to PR4 match interrupt manager
'
$define ISR_TMR4_Match(pParam) '
$if pParam = START              '
    GoTo _ISR_TMR4_Match_Over   '
_ISR_TMR4_Match:                '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR4_Match_IntFlag = 0      '
    GoTo _ISR_TMR4_Match_Exit   '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR4_Match_Over:           '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' Timer6 to PR6 match interrupt manager
'
$define ISR_TMR6_Match(pParam) '
$if pParam = START              '
    GoTo _ISR_TMR6_Match_Over   '
_ISR_TMR6_Match:                '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    TMR6_Match_IntFlag = 0      '
    GoTo _ISR_TMR6_Match_Exit   '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_TMR6_Match_Over:           '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif


'----------------------------------------------------------------------------
' CRC interrupt manager
'
$define ISR_CRC(pParam)         '
$if pParam = START              '
    GoTo _ISR_CRC_Over          '
_ISR_CRC:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CRC_IntFlag = 0             '
    GoTo _ISR_CRC_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CRC_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' CSW interrupt manager
'
$define ISR_CSW(pParam)         '
$if pParam = START              '
    GoTo _ISR_CSW_Over          '
_ISR_CSW:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CSW_IntFlag = 0             '
    GoTo _ISR_CSW_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CSW_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' ZCD interrupt manager
'
$define ISR_ZCD(pParam)         '
$if pParam = START              '
    GoTo _ISR_ZCD_Over          '
_ISR_ZCD:                       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    ZCD_IntFlag = 0             '
    GoTo _ISR_ZCD_Exit          '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_ZCD_Over:                  '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' SMT1PWM interrupt manager
'
$define ISR_SMT1PWM(pParam)     '
$if pParam = START              '
    GoTo _ISR_SMT1PWM_Over      '
_ISR_SMT1PWM:                   '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    SMT1PWM_IntFlag = 0         '
    GoTo _ISR_SMT1PWM_Exit      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_SMT1PWM_Over:              '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' SMT1PRA interrupt manager
'
$define ISR_SMT1PRA(pParam)     '
$if pParam = START              '
    GoTo _ISR_SMT1PRA_Over      '
_ISR_SMT1PRA:                   '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    SMT1PWM_IntFlag = 0         '
    GoTo _ISR_SMT1PRA_Exit      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_SMT1PRA_Over:              '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' SMT1 interrupt manager
'
$define ISR_SMT1(pParam)        '
$if pParam = START              '
    GoTo _ISR_SMT1_Over         '
_ISR_SMT1:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    SMT1_IntFlag = 0            '
    GoTo _ISR_SMT1_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_SMT1_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' SPI RX interrupt manager
'
$define ISR_SPI_RX(pParam)      '
$if pParam = START              '
    GoTo _ISR_SPI_RX_Over       '
_ISR_SPI_RX:                    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    SPI_RX_IntFlag = 0          '
    GoTo _ISR_SPI_RX_Exit       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_SPI_RX_Over:               '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' SPI TX interrupt manager
'
$define ISR_SPI_TX(pParam)      '
$if pParam = START              '
    GoTo _ISR_SPI_TX_Over       '
_ISR_SPI_TX:                    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    SPI_TX_IntFlag = 0          '
    GoTo _ISR_SPI_TX_Exit       '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_SPI_TX_Over:               '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' DMA1_ABRT interrupt manager
'
$define ISR_DMA1_ABRT(pParam)   '
$if pParam = START              '
    GoTo _ISR_DMA1_ABRT_Over    '
_ISR_DMA1_ABRT:                 '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    DMA1_ABRT_IntFlag = 0       '
    GoTo _ISR_DMA1_ABRT_Exit    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_DMA1_ABRT_Over:            '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' DMA1_OV interrupt manager
'
$define ISR_DMA1_OV(pParam)     '
$if pParam = START              '
    GoTo _ISR_DMA1_OV_Over      '
_ISR_DMA1_OV:                   '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    DMA1_OV_IntFlag = 0         '
    GoTo _ISR_DMA1_OV_Exit      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_DMA1_OV_Over:              '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' DMA1_DCNT interrupt manager
'
$define ISR_DMA1_DCNT(pParam)   '
$if pParam = START              '
    GoTo _ISR_DMA1_DCNT_Over    '
_ISR_DMA1_DCNT:                 '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    DMA1_DCNT_IntFlag = 0       '
    GoTo _ISR_DMA1_DCNT_Exit    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_DMA1_DCNT_Over:            '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' DMA1_SCNT interrupt manager
'
$define ISR_DMA1_SCNT(pParam)   '
$if pParam = START              '
    GoTo _ISR_DMA1_SCNT_Over    '
_ISR_DMA1_SCNT:                 '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    DMA1_SCNT_IntFlag = 0       '
    GoTo _ISR_DMA1_SCNT_Exit    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_DMA1_SCNT_Over:            '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' DMA2_ABRT interrupt manager
'
$define ISR_DMA2_ABRT(pParam)   '
$if pParam = START              '
    GoTo _ISR_DMA2_ABRT_Over    '
_ISR_DMA2_ABRT:                 '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    DMA2_ABRT_IntFlag = 0       '
    GoTo _ISR_DMA2_ABRT_Exit    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_DMA2_ABRT_Over:            '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' DMA2_OV interrupt manager
'
$define ISR_DMA2_OV(pParam)     '
$if pParam = START              '
    GoTo _ISR_DMA2_OV_Over      '
_ISR_DMA2_OV:                   '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    DMA2_OV_IntFlag = 0         '
    GoTo _ISR_DMA2_OV_Exit      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_DMA2_OV_Over:              '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' DMA2_DCNT interrupt manager
'
$define ISR_DMA2_DCNT(pParam)   '
$if pParam = START              '
    GoTo _ISR_DMA2_DCNT_Over    '
_ISR_DMA2_DCNT:                 '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    DMA2_DCNT_IntFlag = 0       '
    GoTo _ISR_DMA2_DCNT_Exit    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_DMA2_DCNT_Over:            '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' DMA2_SCNT interrupt manager
'
$define ISR_DMA2_SCNT(pParam)   '
$if pParam = START              '
    GoTo _ISR_DMA2_SCNT_Over    '
_ISR_DMA2_SCNT:                 '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    DMA2_SCNT_IntFlag = 0       '
    GoTo _ISR_DMA2_SCNT_Exit    '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_DMA2_SCNT_Over:            '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' CLC1 interrupt manager
'
$define ISR_CLC1(pParam)        '
$if pParam = START              '
    GoTo _ISR_CLC1_Over         '
_ISR_CLC1:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CLC1_IntFlag = 0            '
    GoTo _ISR_CLC1_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CLC1_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' CLC2 interrupt manager
'
$define ISR_CLC2(pParam)        '
$if pParam = START              '
    GoTo _ISR_CLC2_Over         '
_ISR_CLC2:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CLC2_IntFlag = 0            '
    GoTo _ISR_CLC2_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CLC2_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' CLC3 interrupt manager
'
$define ISR_CLC3(pParam)        '
$if pParam = START              '
    GoTo _ISR_CLC3_Over         '
_ISR_CLC3:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CLC3_IntFlag = 0            '
    GoTo _ISR_CLC3_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CLC3_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' CLC4 interrupt manager
'
$define ISR_CLC4(pParam)        '
$if pParam = START              '
    GoTo _ISR_CLC4_Over         '
_ISR_CLC4:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CLC4_IntFlag = 0            '
    GoTo _ISR_CLC4_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CLC4_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

$ifdef Handle_CWG1_Int
    If CWG1_IntFlag = 1 Then
        GoTo _ISR_CWG1
_ISR_CWG1_Exit:
    EndIf
$endif

'----------------------------------------------------------------------------
' CWG1 interrupt manager
'
$define ISR_CWG1(pParam)        '
$if pParam = START              '
    GoTo _ISR_CWG1_Over         '
_ISR_CWG1:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CWG1_IntFlag = 0            '
    GoTo _ISR_CWG1_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CWG1_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' CWG2 interrupt manager
'
$define ISR_CWG2(pParam)        '
$if pParam = START              '
    GoTo _ISR_CWG2_Over         '
_ISR_CWG2:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CWG2_IntFlag = 0            '
    GoTo _ISR_CWG2_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CWG2_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' CWG3 interrupt manager
'
$define ISR_CWG3(pParam)        '
$if pParam = START              '
    GoTo _ISR_CWG3_Over         '
_ISR_CWG3:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    CWG3_IntFlag = 0            '
    GoTo _ISR_CWG3_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_CWG3_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

'----------------------------------------------------------------------------
' NCO1 interrupt manager
'
$define ISR_NCO1(pParam)        '
$if pParam = START              '
    GoTo _ISR_NCO1_Over         '
_ISR_NCO1:                      '
    $ifdef _Managed_ISR         '
        High_Int_Sub_Start      '
    $endif                      '
$elseif pParam = EXIT           '
    NCO1_IntFlag = 0            '
    GoTo _ISR_NCO1_Exit         '
    $ifdef _Managed_ISR         '
        High_Int_Sub_End        '
    $endif                      '
_ISR_NCO1_Over:                 '
$else                           '
    $error "Parameter must be START or EXIT" '
$endif

$endif      ' _defined(Handle_XXXX)
'----------------------------------------------------------------------------
_InterruptManagerMain:

$endif      ' _Positron_Int_Manager_