Quote Originally Posted by Dave View Post
Can you please give some examples?
If you mean code examples, this is what I am currently working with as of now, mind you I'm running this PIC at 64Mhz.

I haven't gotten to the 3rd high priority interrupt, which is next on my list, but I will be using it as soon as I can debug this section I'm at now.

So in that case, I'll have 3 high priority interrupts and 3 low priority interrupts, my mistake.

My interrupt handlers may not be the most efficient but they work.

Code:
    INCLUDE "modedefs.bas"
    INCLUDE "DT_INTS-18F67K40.pbp"     'Base Interrupt System Generated by Darrel Thomas.
    INCLUDE "ReEnterPBP-18.bas"     'Include if using PBP interrupts
@ ERRORLEVEL -306

;*******************************************************************************
    DEFINE OSC 64                                   ; DEFINE THE FREQUENCY USED TO CALCULATE TIME VALUES FOR PAUSES.
'    DEFINE SHIFT_PAUSEUS 2
    DEFINE WRITE_INT 1

' Set LCD Data port
    DEFINE LCD_DREG PORTF
' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 4                              ; 4 BIT PORT CONFIGURATON.
    
    DEFINE LCD_RWREG PORTF ' LCD read/write port
    DEFINE LCD_RWBIT 1 ' LCD read/write pin bit
    
' Set LCD Register Select port
    DEFINE LCD_RSREG PORTF  
' Set LCD Register Select bit
    DEFINE LCD_RSBIT 0                             ; LCD RS INPUT LOCATED AT PORT2.0

' Set LCD Enable port
    DEFINE LCD_EREG PORTF
' Set LCD Enable bit        
    DEFINE LCD_EBIT 2                              ; LCD EN INPUT LOCATED AT PORTF.2.
    
' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
' Set number of lines on LCD
    DEFINE LCD_LINES 4                             ; 4 LINES ON LCD.
    
' Set command delay time in us
    DEFINE LCD_COMMANDUS 1500
' Set data delay time in us
    DEFINE LCD_DATAUS 50
    
;*******************************************************************************   
;USART SET-UP AND CONFIGURATION
;*******************************************************************************  
    DEFINE HSER_RXREG PORTD
    DEFINE HSER_RXBIT 1
    DEFINE HSER_TXREG PORTD
    DEFINE HSER_TXBIT 0
    
    DEFINE HSER2_RXREG PORTG
    DEFINE HSER2_RXBIT 1
    DEFINE HSER2_TXREG PORTG
    DEFINE HSER2_TXBIT 0
    
;------------------------------------------------------------------------------- 
;EUSART_BLUETOOTH:
;   USART1 USER DEFINED REGISTERS AND SETTINGS FOR DIFFERENT CLOCKS.
;-------------------------------------------------------------------------------                                   
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 21  ' 57600 Baud @ 64MHz, -0.08%
    SPBRGH1 = 1
    BAUD1CON.3 = 1         ' Enable 16 bit baudrate generator

'    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
'    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
'    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'    DEFINE HSER_SPBRG 130 ' 9600 Baud @ 64MHz, -0.02%
'    SPBRGH1 = 6
'    BAUD1CON.3 = 1         ' Enable 16 bit baudrate generator

'    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
'    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
'    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'    DEFINE HSER_SPBRG 138 ' 115200 Baud @ 64MHz, -0.08%
'    SPBRGH1 = 0
'    BAUD1CON.3 = 1         ' Enable 16 bit baudrate generator

;-------------------------------------------------------------------------------  
;EUSART_USB:
;   USART2 USER DEFINED REGISTERS AND SETTINGS FOR DIFFERENT CLOCKS.
;-------------------------------------------------------------------------------                                  
'    DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
'    DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
'    DEFINE HSER2_SPBRG 21  ' 57600 Baud @ 64MHz, -0.08%
'    SP2BRGH = 1
'    BAUD2CON.3 = 1         ' Enable 16 bit baudrate generator

    DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER2_SPBRG 138 ' 115200 Baud @ 64MHz, -0.08%
    SP2BRGH = 0
    BAUD2CON.3 = 1         ' Enable 16 bit baudrate generator

'    DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
'    DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
'    DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
'    DEFINE HSER2_SPBRG 138 ' 57600 Baud @ 32MHz, -0.08%
'    SPBRGH2 = 0
'    BAUD2CON.3 = 1         ' Enable 16 bit baudrate generator

;*******************************************************************************
;   ANALOG TO DIGITAL CONVERTER CONFIGURATION
    DEFINE ADC_BITS 10                              ' Set for 12-bit result
    DEFINE ADC_CLOCK 4                              ' Set clock source (FRC)
    DEFINE ADC_SAMPLEUS 100                         ' Set sampling time in microseconds

;*******************************************************************************
; ANALOG to DIGITAL control registers.
;*******************************************************************************
    ADCON0 = %10010100
    ADCON1 = %00000000
'    ADCON2 = %00000010
'    ADCON3 = %00000000
    ADREF = %00000000
    ADPRE = %00000000

;*******************************************************************************
; Oscillator control registers.
;*******************************************************************************
    OSCCON1 = %01100000                             ' FOSC = 64 MHz
    OSCCON2 = %01100000 
'    OSCCON3 = %00000000      
    OSCEN   = %01111100
    OSCFRQ  = %00001000 ' Set to 64Mhz
'    CLKRCON = %10010000
'    CLKRCLK = %00000001

;*******************************************************************************
; Interrupt priority control registers.
;*******************************************************************************
    INTCON.5 = 1
    IPR3.7 = 1    ; RC2 High Int priority
    IPR3.5 = 1    ; RC1 High Int priority    

;External interrupt priority from Port D will go here. 
    
;*******************************************************************************
; Timer control registers.  Low Priority Interrupt
;*******************************************************************************
    T1CON    = %00100111     ; Prescaler=1:4, TMR1ON.     
    T1GCON   = %00000000     ; Timer 1 Gate disabled.
    T1CLK    = %00000101     ; MFINTOSC 500KHZ Selected for Timer 1 clock source.
    TMR1H    = $FF
    TMR1L    = $FF
    
    T2CON    = %10100010     ; Prescaler=1:1, TMR3ON.     
    T2HLT    = %00000000     ; Timer 3 Gate disabled.
    T2CLKCON = %00000101     ; LFINTOSC Selected for Timer 2 clock source.
    T2TMR    = $FF
    T2PR     = $FF

;*******************************************************************************
; Peripheral Pin Select Modules.
;*******************************************************************************
;INPUTS
    SSP2CLKPPS = $1E        ; MSSP2 CLOCK INPUT  RD6=%0001 1110
    SSP2DATPPS = $1D        ; MSSP2 DATA INPUT   RD5=%0001 1101

    RX1PPS = $19            ; EUSART1 RECIEVE    RD1=%0001 1001
    RX2PPS = $31            ; EUSART2 RECIEVE    RG1=%0011 0001

;External interrupt pin select from Port D will go here. 
    
;OUTPUTS
    RD6PPS = $1B            ; MSSP2 CLOCK OUTPUT RD6=%0001 1110
    RD4PPS = $1C            ; MSSP2 DATA OUTPUT  RD4=%0001 1110
     
    RD0PPS = $0C            ; EUSART1 TRANSMIT   RD0=%0011 0001
    RG0PPS = $0E            ; EUSART2 TRANSMIT   RG0=%0011 0001
    
;*******************************************************************************
; Peripheral Module Disable. Page 243 of the datasheet.
; 0 = enabled, 1 = disabled.
;*******************************************************************************
    PMD0 = %01110000        ; Bit 0 = 0, All IOC modules enabled, CLC.
    PMD1 = %11111001        ; Timer 1, 2 modules module enabled.
    PMD2 = %11111111        ; Comaparators 1/2, ZCD modules disabled.
    PMD3 = %11011111        ; DAC disabled, ADC ensabled.
    PMD4 = %11111111        ; PWM and CCP CWG moduLes disabled.
    PMD5 = %11110001        ; ESUART/MSSP  moduLes Enabled.
    
;*******************************************************************************

; Some more settings over here...

;*******************************************************************************
;ASM INTERRUPTS COURTESY OF DARREL TAYLOR.    
ASM
INT_LIST  macro  ;  IntSource,       Label,             Type,   ResetFlag? 
    INT_Handler     RX1_INT,        _BLE_RX1_DATA,      PBP,    YES    
    INT_Handler     RX2_INT,        _USB_RX2_DATA,      PBP,    YES   
    INT_Handler     TMR2_INT,       _TICKS,             PBP,    YES  
    INT_Handler     IOC_INT,        _PortCIOC,          PBP,    YES  
    INT_Handler     TMR1_INT,       _Heart_Beat,        PBP,    YES        
    endm      
    INT_CREATE              ; Creates the interrupt processor    
ENDASM
@    INT_ENABLE  RX1_INT    ; enable RECEIVER 1 interrupts. 
@    INT_ENABLE  RX2_INT    ; enable RECEIVER  2 interrupts.    
@    INT_ENABLE  TMR1_INT   ; enable Timer 1 interrupts.  Set for 500ms intervals.   
@    INT_ENABLE  IOC_INT    ; enable IOC interrupts.  Set for all pins on Port C
;*******************************************************************************
    goto Start
;******************************************************************************* 
BLE_RX1_DATA:
    HSERIN 5, CountBytes1, [STR BleRxBuffer\64]   'Receive Command Mode bytes.
CountBytes1:  
    for GPCounter11 = 0 to 63
        if BleRxBuffer[GPCounter11] = $00 then
            BLEByteCounts = GPCounter11 
            exit
        endif
    next GPCounter11     
    BleRcvdFlg = 1 

@ INT_RETURN

;*******************************************************************************
USB_RX2_DATA:
    HSERIN2 5, CountBytes2, [STR USBRxBuffer\64]   'Receive Command Mode bytes.
CountBytes2:
    for GPCounter12 = 0 to 63
        if USBRxBuffer[GPCounter12] = $00 then
            USBByteCounts = GPCounter12 
            exit
        endif
    next GPCounter12       
    USBRcvdFlg = 1 

@ INT_RETURN

;*******************************************************************************
PortCIOC:
    for GPCounter5 = 0 to 7
        if IOCCF.0[GPCounter5] = 1 then 
            if IOCCP.0[GPCounter5] = 1 then
                IOCPosFlags.0[GPCounter5]  = 1
            endif
            if IOCCN.0[GPCounter5] = 1 then
                IOCNegFlags.0[GPCounter5]  = 1
            endif         
        endif    
    next GPCounter5
    TempIOCCF = IOCCF ^ $FF
    IOCCF = TempIOCCF & IOCCF

@ INT_RETURN

;*******************************************************************************
Heart_Beat: 
    toggle HeartBeat 
    BleActiveCntr = BleActiveCntr + 1
    ChkPCStatCntr = ChkPCStatCntr + 1

@ INT_RETURN

;*******************************************************************************
TICKS: 
    if EnableRandom = 1 then       
        if RxTxCounter = 5 then
            RxTxCounter = 0
            random RndWord
            Digit = Rndword dig 0
            if digit > 7 then digit = digit - 7
            lookup Digit, ["1","2","3","4","5","6","7","8"], RndmByte 
            NrfChipEn = 0                            ; Disable the NRF Module.
            gosub NrfTxMode        
            NrfTxPckt[0] = WriteTxPld                ; Write Tx payload register address. Address $A0.                           
            NrfTxPckt[1] = "N"                       ; Data for WriteTxPld REGISTER.
            NrfTxPckt[2] = "1"                       ; Data for WriteTxPld REGISTER.
            NrfTxPckt[3] = "R"                       ; Data for WriteTxPld REGISTER.
            NrfTxPckt[4] = "0"                       ; Data for WriteTxPld REGISTER.
            NrfTxPckt[5] = RndmByte                  ; Data for WriteTxPld REGISTER.
            NrfTxPckt[6] = "0"                      ; Data for WriteTxPld REGISTER.
            WriteBytes = 6                           ; Number of byte to write to SPI module. 0 = 1 byte, counts from 0 to ?  
            gosub NrfTx
        else  
         RxTxCounter = RxTxCounter + 1
        endif
    endif

@ INT_RETURN

;*******************************************************************************
NrfIrq:

;External interrupt from Port D will be handled here. 

@ INT_RETURN

;*******************************************************************************
Start:
@    INT_ENABLE  TMR2_INT   ; enable Timer 2 interrupts. Set for 100ms intervals

;Start of working code over here...     


;...until the "end".