+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2017
    Posts
    21

    Post PIC18F67K40 DT_INTS that really work.

    Code:
    '****************************************************************
    '* Name : DT_INTS-PIC18F67k40.bas *
    '* Author : Darrel Taylor *
    '* Notice : Copyright (c) 2003 *
    '* Version : 1 *
    '* Date : JUL 28, 20018 *
    ;****************************************************************
    ; Versions: 1 , DT_INTS-1818F67k40.bas *
    ; This code was specificaly modified to work with the *
    ; PIC18F67K40 only. *
    ; Modified by csantex with the help of other members of the *
    ; PicBasic forum: http://www.picbasic.co.uk/forum/ *
    ; I have used extensively with no issues running 5 interrupts *
    ; at a time. 3 of those interrupts had priorities enabled. *
    '****************************************************************
    DISABLE DEBUG
    
    
    DEFINE INTHAND INT_ENTRY_H ' Context saving for High Priority Ints
    DEFINE INTLHAND INT_ENTRY_L ' Context saving for Low Priority Ints
    
    
    wsave var byte BANKA SYSTEM ' location for WREG
    ssave var byte BANK0 SYSTEM ' location for STATUS register
    bsave var byte BANK0 SYSTEM ' location for BSR register
    psaveUH VAR BYTE BANK0 SYSTEM ' PCLATU Hi Pri.
    psaveUL VAR BYTE BANK0 SYSTEM ' Lo Pri.
    psaveH VAR BYTE BANK0 SYSTEM ' PCLATH Hi Pri.
    psaveL VAR BYTE BANK0 SYSTEM ' Lo Pri.
    fsave0H var WORD BANK0 SYSTEM ' locations for FSR registers
    fsave1H var WORD BANK0 SYSTEM
    fsave2H var WORD BANK0 SYSTEM
    fsave0L var WORD BANK0 SYSTEM ' low priority FSR locations
    fsave1L var WORD BANK0 SYSTEM
    fsave2L var WORD BANK0 SYSTEM
    RetAddrH VAR BYTE[3] BANKA SYSTEM ' 21-bit return address Hi Pri.
    RetAddrL VAR BYTE[3] BANKA SYSTEM ' Lo Pri.
    INT_Flags VAR BYTE BANKA SYSTEM
    Serviced_H VAR INT_Flags.0
    Serviced_L VAR INT_Flags.1
    InHPint VAR INT_Flags.2
    NoPriority VAR INT_Flags.3
    
    
    INT_Flags = 0 
    
    
    goto OVER_DT_INTS_18
    
    
    ASM
    ;____ Check for PBPL (PBP ver. 2.50 and above only)__________________________
    PBPLongs_Used = 0
    if (R1 - R0 == 4)
    PBPLongs_Used = 1
    ; messg PBPL Used = 1
    endif
    
    
    nolist
    ;____ DEFINE available interrupt sources_____________________________________
    
    
    #define INT0_INT PIR0, INT0IF ;-- INT0 External 
    #define INT1_INT PIR0, INT1IF ;-- INT1 External 
    #define INT2_INT PIR0, INT2IF ;-- INT2 External 
    #define INT3_INT PIR0, INT3IF ;-- INT3 External
    #define TMR0_INT PIR0, TMR0IF ;-- TMR0 Overflow 
    #define IOC_INT PIR0, IOCIF ;-- Interrupt-on-Change Flag bit
    
    #define OSC_INT PIR1, OSCFIF ;-- Oscillator Fail Interrupt Flag bit
    #define CSW_INT PIR1, CSWIF ;-- Clock-Switch Interrupt Flag bit
    #define ADT_INT PIR1, ADTIF ;-- ADC Threshold Interrupt Flag bit
    #define AD_INT PIR1, ADIF ;-- ADC Interrupt Flag bit
    
    
    #define ZCD_INT PIR2, ZCDIF ;-- Zero-Cross Detect Interrupt Flag bit 
    #define CMP1_INT PIR2, CM1IF ;-- Comparator1
    #define CMP2_INT PIR2, CM2IF ;-- Comparator2
    #define CMP3_INT PIR2, CM3IF ;-- Comparator3
    #define HLVD_INT PIR2, HLVDIF ;-- High/Low Voltage Detect 
    
    #define RX1_INT PIR3, RC1IF ;-- USART1 Receive 
    #define RX2_INT PIR3, RC2IF ;-- USART2 Receive 
    #define TX1_INT PIR3, TX1IF ;-- USART1 Transmit 
    #define TX2_INT PIR3, TX2IF ;-- USART2 Transmit 
    #define BUS1_INT PIR3, BCL1IF ;-- Bus 1 Collision 
    #define BUS2_INT PIR3, BCL2IF ;-- Bus 2 Collision 
    #define SSP1_INT PIR3, SSP1IF ;-- Synchronous Serial Port 1
    #define SSP2_INT PIR3, SSP2IF ;-- Synchronous Serial Port 2
    
    #define RX3_INT PIR4, RC3IF ;-- USART3 Receive 
    #define RX4_INT PIR4, RC4IF ;-- USART4 Receive
    #define RX5_INT PIR4, RC5IF ;-- USART5 Receive 
    #define TX3_INT PIR4, TX3IF ;-- USART3 Transmit 
    #define TX4_INT PIR4, TX4IF ;-- USART4 Transmit 
    #define TX5_INT PIR4, TX5IF ;-- USART5 Transmit 
    
    #define TMR8_INT PIR5, TMR8IF ;-- Timer 8
    #define TMR7_INT PIR5, TMR7IF ;-- Timer 7
    #define TMR6_INT PIR5, TMR6IF ;-- Timer 6
    #define TMR5_INT PIR5, TMR5IF ;-- Timer 5
    #define TMR4_INT PIR5, TMR4IF ;-- Timer 4
    #define TMR3_INT PIR5, TMR3IF ;-- Timer 3
    #define TMR2_INT PIR5, TMR2IF ;-- Timer 2
    #define TMR1_INT PIR5, TMR1IF ;-- Timer 1
    
    #define TMR7G_INT PIR6, TMR7GIF ;-- Timer 7 Gate
    #define TMR5G_INT PIR6, TMR5GIF ;-- Timer 5 Gate
    #define TMR3G_INT PIR6, TMR3GIF ;-- Timer 3 Gate
    #define TMR1G_INT PIR6, TMR1GIF ;-- Timer 1 Gate
    
    #define CCP1_INT PIR7, CCP1IF ;-- ECCP1 
    #define CCP2_INT PIR7, CCP2IF ;-- ECCP2 
    #define CCP3_INT PIR7, CCP3IF ;-- ECCP3 
    #define CCP4_INT PIR7, CCP4IF ;-- ECCP4 
    #define CCP5_INT PIR7, CCP5IF ;-- ECCP5 
    
    
    #define SCAN_INT PIR8, SCANIF ;-- Cyclical Reduncancy Check Scan
    #define CRC_INT PIR8, CRCIF ;-- Cyclical Reduncancy Check Busy
    #define NVM_INT PIR8, NVMIF ;-- EEPROM/FLASH Write Operation
    #define CWG_INT PIR8, CWG1IF ;-- Complimentary Waveform Generator
    
    #define SMT1_INT PIR9, SMT1IF ;-- Signal Measurement Timer1
    #define SMT2_INT PIR9, SMT2IF ;-- Signal Measurement Timer2
    #define SMT1PRA_INT PIR9, SMT1PRAIF ;-- Signal Measurement Timer1
    #define SMT2PRA_INT PIR9, SMT2PRAIF ;-- Signal Measurement Timer2
    #define SMT1WA_INT PIR9, SMT1WAIF ;-- Signal Measurement Timer1
    #define SMT2WA_INT PIR9, SMT2WAIF ;-- Signal Measurement Timer2
    
    
    ENDASM
    
    
    asm
    ; -- macro --
    INT_Source macro IFR, IFB, IER, IEB, IPR, IPB
    if (IflagReg == IFR) && (IflagBit == IFB) 
    list 
    INT_Flag_Reg = IFR
    INT_Flag_Bit = IFB
    INT_Enable_Reg = IER
    INT_Enable_Bit = IEB
    INT_Priority_Reg = IPR
    INT_Priority_Bit = IPB
    Found = 1
    endif
    nolist 
    endm 
    endasm
    
    
    
    
    asm
    ;____________________________________________________________________________
    GetIntInfo macro IflagReg, IflagBit
    nolist
    INT_Flag_Reg = -1
    INT_Flag_Bit = -1
    INT_Enable_Reg = -1
    INT_Enable_Bit = -1
    ifdef IPR1
    INT_Priority_Reg = -1
    INT_Priority_Bit = -1
    endif
    Found = 0
    
    
    ifdef TMR0IF ;----{ TMR0 Overflow }----------[PIR0, TMR0IF]---
    INT_Source PIR0,TMR0IF, PIE0,TMR0IE, IPR0,TMR0IP
    endif
    ifdef INT0IF ;----{ INT0 External Interrupt }----------[INTCON, INT0IF]---
    INT_Source PIR0,INT0IF, PIE0,INT0IE, IPR0, INT0IP
    endif
    ifdef INT1IF ;----{ INT1 External Interrupt }---------[INTCON, INT1IF]---
    INT_Source PIR0,INT1IF, PIE0,INT1IE, IPR0,INT1IP
    endif
    ifdef INT2IF ;----{ INT2 External Interrupt }---------[INTCON, INT2IF]---
    INT_Source PIR0,INT2IF, PIE0,INT2IE, IPR0,INT2IP
    endif
    ifdef INT3IF ;----{ INT3 External Interrupt }---------[INTCON, INT3IF]---
    INT_Source PIR0,INT3IF, PIE0,INT3IE, IPR0,INT3IP
    endif
    ifdef IOCIF ;----{ Interrupt On Change Interrupt }------[INTCON, IOCIF]---
    INT_Source PIR0,IOCIF, PIE0,IOCIE, IPR0,IOCIP
    endif
    ifdef TMR1IF ;----{ TMR1 to PR1 Match Interrupt }------------[PIR5, TMR1IF]---
    INT_Source PIR5,TMR1IF, PIE5,TMR1IE, IPR5,TMR1IP
    endif
    ifdef TMR2IF ;----{ TMR2 to PR2 Match Interrupt }--------[PIR5, TMR2IF]---
    INT_Source PIR5,TMR2IF, PIE5,TMR2IE, IPR5,TMR2IP
    endif
    ifdef TMR3IF ;----{ TMR3 to PR3 Match Interrupt }------------[PIR5, TMR3IF]---
    INT_Source PIR5,TMR3IF, PIE5,TMR3IE, IPR5,TMR3IP
    endif
    ifdef TMR4IF ;----{ TMR4 to PR4 Match Interrupt }------------[PIR5, TMR4IF]---
    INT_Source PIR5,TMR4IF, PIE5,TMR4IE, IPR5,TMR4IP
    endif
    ifdef TMR5IF ;----{ TMR5 to PR5 Match Interrupt }------------[PIR5, TMR5IF]---
    INT_Source PIR5,TMR5IF, PIE5,TMR5IE, IPR5,TMR5IP
    endif
    ifdef TMR6IF ;----{ TMR6 to PR6 Match Interrupt }--------[PIR5, TMR6IF]---
    INT_Source PIR5,TMR6IF, PIE5,TMR6IE, IPR5,TMR6IP
    endif
    ifdef TMR7IF ;----{ TMR7 Overflow Interrupt }------------[PIR5, TMR7IF]---
    INT_Source PIR5,TMR7IF, PIE5,TMR7IE, IPR5,TMR7IP
    endif
    ifdef TMR8IF ;----{ TMR8 to PR8 Match Interrupt }------------[PIR5, TMR8IF]---
    INT_Source PIR5,TMR8IF, PIE5,TMR8IE, IPR5,TMR8IP
    endif 
    
    ifdef TX1IF ;----{ USART1 Transmit Interrupt }-----------[PIR3, TX1IF]---
    INT_Source PIR3,TX1IF, PIE3,TX1IE, IPR3,TX1IP
    endif
    ifdef RC1IF ;----{ USART1 Receive Interrupt }------------[PIR3, RC1IF]---
    INT_Source PIR3,RC1IF, PIE3,RC1IE, IPR3,RC1IP
    endif 
    ifdef TX2IF ;----{ USART2 Transmit Interrupt }-----------[PIR3, TX2IF]---
    INT_Source PIR3,TX2IF, PIE3,TX2IE, IPR3,TX2IP
    endif 
    ifdef RC2IF ;----{ USART2 Receive Interrupt }------------[PIR3, RC2IF]---
    INT_Source PIR3,RC2IF, PIE3,RC2IE, IPR3,RC2IP
    endif 
    ifdef TX3IF ;----{ USART3 Transmit Interrupt }-----------[PIR4, TX3IF]---
    INT_Source PIR4,TX3IF, PIE4,TX3IE, IPR4,TX3IP
    endif
    ifdef RC3IF ;----{ USART3 Receive Interrupt }------------[PIR4, RC3IF]---
    INT_Source PIR4,RC3IF, PIE4,RC3IE, IPR4,RC3IP
    endif 
    ifdef TX4IF ;----{ USART4 Transmit Interrupt }-----------[PIR4, TX4IF]---
    INT_Source PIR4,TX4IF, PIE4,TX4IE, IPR4,TX4IP
    endif 
    ifdef RC4IF ;----{ USART4 Receive Interrupt }------------[PIR4, RC4IF]---
    INT_Source PIR4,RC4IF, PIE4,RC4IE, IPR4,RC4IP
    endif
    ifdef TX5IF ;----{ USART5 Transmit Interrupt }-----------[PIR4, TX5IF]---
    INT_Source PIR4,TX5IF, PIE4,TX5IE, IPR4,TX5IP
    endif
    ifdef RC5IF ;----{ USART5 Receive Interrupt }------------[PIR4, RC5IF]---
    INT_Source PIR4,RC5IF, PIE4,RC5IE, IPR4,RC5IP
    endif 
    
    
    ifdef CM1IF ;----{ Comparator1 Interrupt }-----------------[PIR2, CM1IF]---
    INT_Source PIR2,CM1IF, PIE2,CM1IE, IPR2,CM1IP
    endif 
    ifdef CM2IF ;----{ Comparator2 Interrupt }-----------------[PIR2, CM2IF]---
    INT_Source PIR2,CM2IF, PIE2,CM2IE, IPR2,CM2IP
    endif 
    ifdef CM3IF ;----{ Comparator3 Interrupt }-----------------[PIR2, CM3IF]---
    INT_Source PIR2,CM3IF, PIE2,CM3IE, IPR2,CM3IP
    endif 
    
    
    ifdef BCL1IF ;----{ Bus 1 Collision Interrupt }-------------[PIR3, BCL1IF]---
    INT_Source PIR3,BCL1IF, PIE3,BCL1IE, IPR3,BCL1IP
    endif 
    ifdef BCL2IF ;----{ Bus 2 Collision Interrupt }-------------[PIR3, BCL2IF]---
    INT_Source PIR3,BCL2IF, PIE3,BCL2IE, IPR3,BCL2IP
    endif
    
    
    ifdef HLVDIF ;----{ High/Low Voltage Detect Interrupt }-----[PIR2, HLVDIF]---
    INT_Source PIR2,HLVDIF, PIE2,HLVDIE, IPR2,HLVDIP
    endif 
    
    ifdef ADIF ;----{ ADC Converter Interrupt }--------------[PIR1, ADIF]---
    INT_Source PIR1,ADIF, PIE1,ADIE, IPR1,ADIP
    endif 
    ifdef ADTIF ;----{ ADC Threshold Interrupt }--------------[PIR1, ADTIF]---
    INT_Source PIR1,ADTIF, PIE1,ADTIE, IPR1,ADTIP
    endif 
    
    ifdef SSP1IF ;----{ Synchronous Serial Port1 Interrupt }---[PIR3, SSP1IF]---
    INT_Source PIR3,SSP1IF, PIE3,SSP1IE, IPR3,SSP1IP
    endif
    ifdef SSP2IF ;----{ Synchronous Serial Port2 Interrupt }---[PIR3, SSP2IF]---
    INT_Source PIR3,SSP2IF, PIE3,SSP2IE, IPR3,SSP2IP
    endif
    
    
    ifdef CCP1IF ;----{ CCP1 Interrupt }---------------------[PIR7, CCP1IF]---
    INT_Source PIR7,CCP1IF, PIE7,CCP1IE, IPR7,CCP1IP
    endif
    ifdef CCP2IF ;----{ CCP2 Interrupt Flag }----------------[PIR7, CCP2IF]---
    INT_Source PIR7,CCP2IF, PIE7,CCP2IE, IPR7,CCP2IP
    endif
    ifdef CCP3IF ;----{ CCP3 Interrupt Flag }----------------[PIR7, CCP3IF]---
    INT_Source PIR7,CCP3IF, PIE7,CCP3IE, IPR7,CCP3IP
    endif
    ifdef CCP4IF ;----{ CCP4 Interrupt Flag }----------------[PIR7, CCP4IF]---
    INT_Source PIR7,CCP4IF, PIE7,CCP4IE, IPR7,CCP4IP
    endif
    ifdef CCP5IF ;----{ CCP5 Interrupt Flag }----------------[PIR7, CCP5IF]---
    INT_Source PIR7,CCP5IF, PIE7,CCP5IE, IPR7,CCP5IP
    endif 
    
    
    ifdef OSCFIF ;----{ Osc Fail Interrupt Flag }-----------[PIR1, OSCFIF]---
    INT_Source PIR1,OSCFIF, PIE1,OSCFIE, IPR1,OSCFIP
    endif
    
    
    ifdef CSWIF ;----{ CLOCK SWITCH Interrupt Flag }-----------[PIR1, CSWIF]---
    INT_Source PIR1,CSWIF, PIE1,CSWIE, IPR1,CSWIP
    endif
    
    ifdef ZCDIF ;----{ ZERO CROSS DETECT Interrupt Flag }-----------[PIR2, ZCDIF]---
    INT_Source PIR2,ZCDIF, PIE2,ZCDIE, IPR2,ZCDIP
    endif
    
    ifdef NVMIF ;----{ EEPROM/FLASH Write Operation Interrupt [PIR8, EEIF]---
    INT_Source PIR8,NVMIF, PIE8,NVMIE, IPR8,NVMIP 
    endif 
    
    ifdef SMT1IF ;----{ Signal Measurement1 Interrupt Flag }-[PIR9, SMT1IF]---
    INT_Source PIR9,SMT1IF, PIE9,SMT1IE, IPR9,SMT1IP
    endif
    ifdef SMT2IF ;----{ Signal Measurement2 Interrupt Flag }-[PIR9, SMT2IF]---
    INT_Source PIR9,SMT2IF, PIE9,SMT2IE, IPR9,SMT2IP
    endif
    ifdef SMT1PRAIF;----{ Sig Meas1 Interrupt Flag }--------[PIR9, SMT1PRAIF]---
    INT_Source PIR9,SMT1PRAIF, PIE9,SMT1PRAIE, IPR9,SMT1PRAIP
    endif
    ifdef SMT2PRAIF;----{ Sig Meas2 Interrupt Flag }--------[PIR9, SMT2PRAIF]---
    INT_Source PIR9,SMT2PRAIF, PIE9,SMT2PRAIE, IPR9,SMT2PRAIP
    endif
    ifdef SMT1WAIF ;----{ Sig Meas1 Interrupt Flag }---------[PIR9, SMT1WAIF]---
    INT_Source PIR9,SMT1WAIF, PIE9,SMT1WAIE, IPR9,SMT1WAIP
    endif
    ifdef SMT2WAIF ;----{ Sig Meas2 Interrupt Flag }---------[PIR9, SMT2WAIF]---
    INT_Source PIR9,SMT2WAIF, PIE9,SMT2WAIE, IPR9,SMT2WAIP
    endif 
    list
    endm
    list
    endasm
    
    
    ;____[ if not using Low Priority INTS, create a dummy handler ]_______________
    ASM
    ifndef USE_LOWPRIORITY
    INT_ENTRY_L
    retfie
    else
    if (USE_LOWPRIORITY != 1)
    INT_ENTRY_L
    retfie
    endif
    endif 
    ENDASM 
    
    
    ;_____________________________________________________________________________
    Asm
    asm = 0 ; Assembly language Interrupts
    ASM = 0
    Asm = 0
    pbp = 1 ; Basic language interrupts
    PBP = 1
    Pbp = 1
    YES = 1
    yes = 1
    Yes = 1
    NO = 0
    no = 0
    No = 0
    H equ 'H' ; High Priority
    h equ 'H'
    L equ 'L' ; Low Priority
    l equ 'L'
    
    
    nolist
    
    ;_____________________________________________________________________________
    SaveFSR macro F, Pr
    list
    if (F >= 0) && (F <= 2)
    if (Pr == H) || (Pr == L)
    movff FSR#v(F)L, fsave#v(F)Pr
    movff FSR#v(F)H, fsave#v(F)Pr + 1
    nolist
    else
    ERROR "SaveFSR - Invalid Priority"
    endif
    else
    ERROR "SaveFSR - Invalid FSR number"
    endif
    list
    endm
    ENDASM
    
    
    ;_____________________________________________________________________________
    Asm
    RestFSR macro F, Pr
    list
    if (F >= 0) && (F <= 2)
    if (Pr == H) || (Pr == L)
    movff fsave#v(F)Pr , FSR#v(F)L
    movff fsave#v(F)Pr + 1 , FSR#v(F)H 
    nolist
    else
    ERROR "RestFSR - Invalid Priority"
    endif
    else
    ERROR "RestFSR - Invalid FSR number"
    endif
    list
    endm
    ENDASM
    
    
    ;---[Stay compatible with the 14-bit version]---------------------------------
    Asm
    INT_FINISH_H macro
    endm
    EndAsm
    
    
    ;---[Create the High Priority Interrupt Processor]----------------------------
    ASM
    INT_CREATE_H macro
    local OverCREATE
    goto OverCREATE
    Priority = H 
    
    INT_ENTRY_H 
    movff PCLATU, psaveUH
    movff PCLATH, psaveH
    SaveFSR 0, H
    SaveFSR 1, H
    SaveFSR 2, H
    bsf _InHPint, 0
    List_Start_H
    bcf _Serviced_H, 0 ; Clear Serviced flag
    clrf BSR
    PREV_BANK = 0
    ifdef INT_LIST_H
    INT_LIST_H ; Expand the users list of HP INT handlers
    else
    ifdef INT_LIST
    INT_LIST ; Expand the 16F Compatible List
    else
    error "INT_CREATE_H - INT_LIST or INT_LIST_H not found"
    endif
    endif
    btfsc _Serviced_H,0 ; if anything was serviced
    goto List_Start_H ; go around, and check again
    
    
    ifdef ReEnterHPused ; was ReEnterPBP-18.bas included
    GetAddress21 INT_EXIT_H, RetAddrH
    L?GOTO _RestorePBP_H ; Restore PBP system Vars
    endif
    
    
    INT_EXIT_H
    PREV_BANK = 0
    bcf _InHPint, 0
    RestFSR 0, H ; Restore FSR0, if it was saved?
    RestFSR 1, H ; Restore FSR1, if it was saved?
    RestFSR 2, H ; Restore FSR2, if it was saved?
    movff psaveH, PCLATH
    movff psaveUH, PCLATU
    retfie FAST ; Return from Interrupt
    OverCREATE
    bsf INTCON,GIE;, 0 ; Enable High Priority Interrupts
    bsf INTCON,PEIE;, 0 ; Enable Peripheral Interrupts
    endm
    
    
    ;---[Stay compatible with the 14-bit version]---------------------------------
    INT_CREATE macro
    INT_CREATE_H
    endm
    ENDASM
    
    
    ;---[Create the Low Priority Interrupt Processor]-----------------------------
    ASM
    INT_CREATE_L macro
    local OverCREATE
    goto OverCREATE
    ifdef USE_LOWPRIORITY
    if (USE_LOWPRIORITY != 1)
    error "'DEFINE USE_LOWPRIORITY 1' required for Low Priority Interrupts"
    endif
    else
    error "'DEFINE USE_LOWPRIORITY 1' required for Low Priority Interrupts"
    endif
    Priority = L
    INT_ENTRY_L 
    movff WREG, wsave ; Wreg
    movff STATUS, ssave ; STATUS
    movff BSR, bsave ; BSR
    movff PCLATU, psaveUL
    movff PCLATH, psaveL
    SaveFSR 0, L ; FSR0
    SaveFSR 1, L ; FSR1
    SaveFSR 2, L ; FSR2
    bcf _InHPint, 0 
    List_Start_L
    clrf BSR
    PREV_BANK = 0
    bcf _Serviced_L, 0
    ifdef INT_LIST_L
    INT_LIST_L ; Expand the users list of HP INT handlers
    else
    error "INT_CREATE_L - INT_LIST_L not defined, can not create"
    endif
    btfsc _Serviced_L, 0 ; if anything was serviced
    goto List_Start_L ; go around, and check again
    
    
    ifdef ReEnterLPused ; was ReEnterPBP-18LP.bas included
    GetAddress21 INT_EXIT_L, RetAddrL
    L?GOTO _RestorePBP_L ; Restore PBP system Vars
    endif
    
    
    INT_EXIT_L
    PREV_BANK = 0
    RestFSR 0, L ; Restore saved vars
    RestFSR 1, L
    RestFSR 2, L 
    movff psaveUL, PCLATU
    movff psaveL, PCLATH
    movff bsave, BSR ; BSR
    movff wsave, WREG ; WREG
    movff ssave, STATUS ; STATUS
    retfie ; Return from Interrupt
    OverCREATE
    bsf INTCON,IPEN;, 0 ; Enable Interrupt Priorities <CHANGE THIS
    bsf INTCON,GIEL;, 0 ; Enable Low Priority Interrupts
    endm
    ENDASM
    
    
    ASM
    ;---[Returns the Address of a Label as a Word]--(under 64K)------------------
    GetAddress macro Label, Wout
    CHK?RP Wout
    movlw low Label ; get low byte
    movwf Wout
    movlw High Label ; get high byte
    movwf Wout + 1
    endm
    
    
    ;---[Returns the Address of a Label as a 3 byte array]---(under/over 64k)-----
    GetAddress21 macro Label, Aout
    CHK?RP Aout
    movlw low Label ; get low byte
    movwf Aout
    movlw high Label ; get high byte
    movwf Aout + 1
    movlw upper Label ; get upper byte
    movwf Aout + 2
    endm
    
    
    ;---[find correct bank for a PBP BIT variable]-------------------------------
    CHKRP?T macro reg, bit
    CHK?RP reg
    endm
    
    
    
    
    
    ;---[find Assigned Priority for specified INT Source]------------------------
    INT_Count = 0
    
    
    FindIntPriority macro IntFlagReg, IntFlagBit
    local LoopCount
    nolist
    Pfound = 0
    LoopCount = 1
    while LoopCount <= INT_Count
    if (IntFlagReg == PrList#v(LoopCount)R)
    if (IntFlagBit == PrList#v(LoopCount)B)
    list
    Priority = PrList#v(LoopCount)Priority
    Pfound = 1
    endif
    endif
    LoopCount += 1
    endw
    endm 
    ENDASM
    
    
    ASM
    
    
    ;---[Add an Interrupt Source to the user's list of INT Handlers]--------------
    INT_Handler macro IntFlagReg, IntFlagBit, Label, Type, Reset
    list
    local AfterSave, AfterUser, NoInt
    INT_Count += 1
    PrList#v(INT_Count)R = IntFlagReg
    PrList#v(INT_Count)B = IntFlagBit
    PrList#v(INT_Count)Priority = Priority
    GetIntInfo IntFlagReg, IntFlagBit
    if (Found == YES)
    CHK?RP INT_Enable_Reg ;ADD THIS
    btfss INT_Enable_Reg, INT_Enable_Bit;, 0 ; if INT is enabled
    goto NoInt
    CHK?RP INT_Flag_Reg ;ADD THIS
    btfss INT_Flag_Reg, INT_Flag_Bit;, 0 ; and the Flag set?
    goto NoInt
    if (Priority == H)
    bsf _Serviced_H, 0
    else
    bsf _Serviced_L, 0
    endif
    ifdef NO_CLRWDT
    if (NO_CLRWDT != 1)
    CLRWDT
    endif
    else
    CLRWDT
    endif
    
    if (Type == PBP) ; If INT handler is PBP
    if (Priority == H)
    ifdef ReEnterHPused
    GetAddress21 AfterSave, RetAddrH 
    L?GOTO _SavePBP_H ; Save PBP system Vars in HP INT
    else
    error "ReEnterPBP-18 must be INCLUDEd to use High Priority PBP interrupts"
    endif
    else ; Priority = L
    ifdef ReEnterLPused
    GetAddress21 AfterSave, RetAddrL 
    L?GOTO _SavePBP_L ; Save PBP system Vars in LP INT
    else
    error "ReEnterPBP-18LP must be INCLUDEd to use Low Priority PBP interrupts"
    endif
    endif
    endif
    AfterSave
    PREV_BANK = 0
    if (Priority == H)
    GetAddress21 AfterUser, RetAddrH 
    else ; Priority = L
    GetAddress21 AfterUser, RetAddrL
    endif 
    L?GOTO Label ; goto the users INT handler
    
    AfterUser
    if (Reset == YES) ; reset flag (if specified)
    CHK?RP INT_Flag_Reg ;ADDED 7/26/18
    bcf INT_Flag_Reg, INT_Flag_Bit;, 0 
    endif
    else
    error Interrupt Source (IntFlagReg,IntFlagBit) not found
    endif
    NoInt
    clrf BSR
    PREV_BANK = 0
    endm
    ENDASM
    
    
    asm
    ;---[Returns from a "goto" subroutine]--(21-bit RetAddr? must be set first)---
    INT_RETURN macro
    local Ret2LP, Ret2HP
    btfsc _InHPint, 0
    goto Ret2HP
    Ret2LP
    movff RetAddrL + 2, PCLATU ; Load PC buffers with return address
    movff RetAddrL + 1, PCLATH
    movf RetAddrL, W;, 0
    clrf BSR ; Set to BANK0 before returning
    PREV_BANK = 0 ; Tell PBP about the BANK change
    movwf PCL, 0 ; Go back to where we were
    
    Ret2HP 
    movff RetAddrH + 2, PCLATU ; Load PC buffers with return address
    movff RetAddrH + 1, PCLATH
    movf RetAddrH, W;, 0
    clrf BSR ; Set to BANK0 before returning
    PREV_BANK = 0 ; Tell PBP about the BANK change
    movwf PCL, 0 ; Go back to where we were
    endm 
    
    ;---[Enable an interrupt source]----------------------------------------------
    INT_ENABLE macro IntFlagReg, IntFlagBit
    GetIntInfo IntFlagReg, IntFlagBit
    if (Found == YES)
    FindIntPriority IntFlagReg, IntFlagBit
    if (Pfound == 1)
    if (INT_Priority_Reg != -1)
    CHK?RP INT_Priority_Reg ;ADDED 7/26/18
    if (Priority == H)
    bsf INT_Priority_Reg, INT_Priority_Bit;, 0
    else
    if (Priority == L)
    bcf INT_Priority_Reg, INT_Priority_Bit;, 0
    else
    error "INT_ENABLE - Invalid Priority Specified"
    endif
    endif
    else
    if (Priority == L)
    error "INT0_INT can NOT be assigned to Low Priority"
    endif
    endif
    else
    error "INT_ENABLE - Priority State Not Found"
    endif
    
    bsf INT_Enable_Reg, INT_Enable_Bit;, 0 ; enable the INT source 
    else
    error "INT_ENABLE - Interrupt Source not found!"
    endif
    endm 
    
    
    ;---[Disable an interrupt source]---------------------------------------------
    INT_DISABLE macro IntFlagReg, IntFlagBit
    GetIntInfo IntFlagReg, IntFlagBit
    if (Found == YES)
    bcf INT_Enable_Reg, INT_Enable_Bit;, 0 ; disable the INT source
    else
    error "INT_DISABLE - Interrupt Source not found!"
    endif
    endm 
    
    
    ;---[Clear an interrupt Flag]-------------------------------------------------
    INT_CLEAR macro IntFlagReg, IntFlagBit
    GetIntInfo IntFlagReg, IntFlagBit
    if (Found == YES)
    bcf INT_Flag_Reg, INT_Flag_Bit;, 0 ; clear the INT flag
    else
    error "INT_CLEAR - Interrupt Source not found!"
    endif
    endm
    
    
    ENDASM
    
    
    ; ---[See if we need to save TBLPTR]------------------------------------------
    ASM
    Save_TBLPTR = 0
    
    
    ifdef SIN_USED
    Save_TBLPTR = 1
    endif
    ifdef DTMFOUT_USED
    Save_TBLPTR = 1
    endif
    ifdef SERDELAY_USED
    Save_TBLPTR = 1
    endif
    ifdef CONVBIT_USED
    Save_TBLPTR = 1
    endif
    ifdef ERASECODE_USED
    Save_TBLPTR = 1
    endif
    ifdef READCODE_USED
    Save_TBLPTR = 1
    endif
    ifdef WRITECODE_USED
    Save_TBLPTR = 1
    endif
    ifdef LOOKDOWN?BCLB
    Save_TBLPTR = 1
    endif
    ifdef LOOKDOWN?BCLT
    Save_TBLPTR = 1
    endif
    ifdef LOOKDOWN?BCLW
    Save_TBLPTR = 1
    endif
    ifdef LOOKDOWN?CCLB
    Save_TBLPTR = 1
    endif
    ifdef LOOKDOWN?CCLT
    Save_TBLPTR = 1
    endif
    ifdef LOOKDOWN?CCLW
    Save_TBLPTR = 1
    endif
    ifdef LOOKDOWN?WCLB
    Save_TBLPTR = 1
    endif
    ifdef LOOKDOWN?WCLT
    Save_TBLPTR = 1
    endif
    ifdef LOOKDOWN?WCLW
    Save_TBLPTR = 1
    endif
    ifdef LOOK2_USED 
    Save_TBLPTR = 1
    endif
    ifdef LOOKUP?BCLB
    Save_TBLPTR = 1
    endif
    ifdef LOOKUP?BCLT
    Save_TBLPTR = 1
    endif
    ifdef LOOKUP?BCLW
    Save_TBLPTR = 1
    endif
    ifdef LOOKUP?CCLB
    Save_TBLPTR = 1
    endif
    ifdef LOOKUP?CCLT
    Save_TBLPTR = 1
    endif
    ifdef LOOKUP?CCLW
    Save_TBLPTR = 1
    endif
    ifdef LOOKUP?TCLB
    Save_TBLPTR = 1
    endif
    ifdef LOOKUP?TCLT
    Save_TBLPTR = 1
    endif
    ifdef LOOKUP?TCLW
    Save_TBLPTR = 1
    endif
    Attached Files Attached Files
    Last edited by csantex; - 9th September 2018 at 01:01. Reason: Display error, typos

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,106

    Default Re: PIC18F67K40 DT_INTS that really work.

    Can you please give some examples?
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Jun 2017
    Posts
    21

    Post Re: PIC18F67K40 DT_INTS that really work.

    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".

  4. #4
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,106

    Default Re: PIC18F67K40 DT_INTS that really work.

    Csantex, I do not see where you are setting the HIGH and LOW priority interrupts. This is the code I use for setting HIGH and LOW priority inetrrupts.

    DEFINE USE_LOWPRIORITY 1

    INCLUDE "C:\PBP\INCLUDES\DT_INTS-18.bas" ' Interrupt Control routines
    INCLUDE "C:\PBP\INCLUDES\ReEnterPBP-18.bas" ' Interrupt Control routines
    INCLUDE "C:\PBP\INCLUDES\ReEnterPBP-18LP.bas" ; Include if using Low Pr. PBP INTS

    '************************************************* ********************
    asm
    ;----[High Priority Interrupts]-----------------------------------------------
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _TIMR1, PBP, yes
    endm
    INT_CREATE ; Creates the High Priority interrupt processor

    ;----[Low Priority Interrupts]------------------------------------------------
    INT_LIST_L macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TX1_INT, _UARTTX1, PBP, no
    INT_Handler RX1_INT, _UARTRX1, PBP, no
    INT_Handler TX2_INT, _UARTTX2, PBP, no
    INT_Handler RX2_INT, _UARTRX2, PBP, no
    endm
    INT_CREATE_L ; Creates the LOW Priority interrupt processor
    ENDASM

    @ INT_ENABLE RX1_INT ; Enable RX UART Interrupts
    @ INT_ENABLE RX2_INT ; Enable RX UART Interrupts
    @ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts

    GOTO STARTLOOP

    '************************************************* ********************
    ' Interrupt Routines *
    '************************************************* ********************

    '************************************************* ********************
    TIMR1: 'INTERRUPT SERVICE ROUTINE FOR TIMER 1
    '************************************************* ********************
    @ INT_RETURN

    '************************************************* ********************
    UARTRX1: 'INTERRUPT SERVICE ROUTINE FOR UART RECEIVER
    '************************************************* ********************
    @ INT_RETURN

    '************************************************* ********************
    UARTTX1: 'INTERRUPT SERVICE ROUTINE FOR UART TRANSMITTER
    '************************************************* ********************
    @ INT_RETURN

    '************************************************* ********************
    UARTRX2: 'INTERRUPT SERVICE ROUTINE FOR UART RECEIVER
    '************************************************* ********************
    @ INT_RETURN

    '************************************************* ********************
    UARTTX2: 'INTERRUPT SERVICE ROUTINE FOR UART TRANSMITTER
    '************************************************* ********************
    @ INT_RETURN

    '************************************************* ********************
    ' Subroutines *
    '************************************************* ********************
    Dave Purola,
    N8NTA
    EN82fn

  5. #5
    Join Date
    Jun 2017
    Posts
    21

    Post Re: PIC18F67K40 DT_INTS that really work.

    Quote Originally Posted by Dave View Post
    Csantex, I do not see where you are setting the HIGH and LOW priority interrupts. This is the code I use for setting HIGH and LOW priority inetrrupts.

    DEFINE USE_LOWPRIORITY 1

    INCLUDE "C:\PBP\INCLUDES\DT_INTS-18.bas" ' Interrupt Control routines
    INCLUDE "C:\PBP\INCLUDES\ReEnterPBP-18.bas" ' Interrupt Control routines
    INCLUDE "C:\PBP\INCLUDES\ReEnterPBP-18LP.bas" ; Include if using Low Pr. PBP INTS

    '************************************************* ********************
    asm
    ;----[High Priority Interrupts]-----------------------------------------------
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _TIMR1, PBP, yes
    endm
    INT_CREATE ; Creates the High Priority interrupt processor

    ;----[Low Priority Interrupts]------------------------------------------------
    INT_LIST_L macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TX1_INT, _UARTTX1, PBP, no
    INT_Handler RX1_INT, _UARTRX1, PBP, no
    INT_Handler TX2_INT, _UARTTX2, PBP, no
    INT_Handler RX2_INT, _UARTRX2, PBP, no
    endm
    INT_CREATE_L ; Creates the LOW Priority interrupt processor
    ENDASM
    Dave,

    I have never used a "DEFINE USE_LOW/HIGHPRIORITY 1" for any of the interrupts I have used at work or for personal projects while using DT_INTs.
    I just set the bits accordingly as shown below and it works just fine.

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


    As with this project, I'm running 2 hardware serial ports, 1 hardware SPI port, two timers and since I just finished troubleshooting
    the issues I was having last night, I will be adding and external interrupt which will also be enabled as a high priority. So far, I haven't run into any issues with any my projects at all. If in future projects I do have issues,
    I'll be sure to use them.

    Now if you're telling me that just setting their IPR bits is not enough, then I would think that this would be evident when I run the program. I may be wrong but I haven't seen any evidence in my projects that I need a "Define".
    Thanks for giving me something to think about.

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,106

    Default Re: PIC18F67K40 DT_INTS that really work.

    Csantex, You need to set up one of your HIGH priority interrupts with a port bit that gets set during its routine and cleared at the end of it. Then set up another port bit (different) for the LOW priority interrupt and set it on entry and clear it on exit. Then take a scope and look at both bits during operation and see if the LOW priority is interrupted by the high priority interrupt, it should be.....
    Dave Purola,
    N8NTA
    EN82fn

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    1,466

    Default Re: PIC18F67K40 DT_INTS that really work.

    You need to set up one of your HIGH priority interrupts with a port bit that gets set during its routine and cleared at the end of it. Then set up another port bit (different) for the LOW priority interrupt and set it on entry and clear it on exit. Then take a scope and look at both bits during operation and see if the LOW priority is interrupted by the high priority interrupt, it should be.....
    I would not bother , if you look at the INT_CREATE macro it only creates high priority interrupts


    Code:
    ;---[Stay compatible with the 14-bit version]---------------------------------
    INT_CREATE macro
    INT_CREATE_H
    endm
    ENDASM
    dave is correct , to use h and low priority interrupts you must use INT_CREATE_L and use
    INCLUDE "C:\PBP\INCLUDES\ReEnterPBP-18LP.bas" ; Include if using Low Pr. PBP INTS
    This is more entertaining than Free to Air TV

  8. #8
    Join Date
    Jun 2017
    Posts
    21

    Post Re: PIC18F67K40 DT_INTS that really work.

    Quote Originally Posted by Dave View Post
    Csantex, You need to set up one of your HIGH priority interrupts with a port bit that gets set during its routine and cleared at the end of it. Then set up another port bit (different) for the LOW priority interrupt and set it on entry and clear it on exit. Then take a scope and look at both bits during operation and see if the LOW priority is interrupted by the high priority interrupt, it should be.....
    Dave,

    Ok so I did the experiment but I used two identical timers with identical settings and I ran them both using the same format I've been using and also using the format described in you post and the pbp manual. Each timer had a pauseus delay of different values.
    The high prty timer had pauseus = 10 and the low had pauseus = 20. Using my format only delays the next interrupt from occurring so what I thought were low and high prty interrupts were actually not. Using the correct format as you posted allows the the high prty interrupt timer to extend the low prty timer time, as its being interrupted. Now when I set both pause to equal value and both are set to high prty, one goes right after the other as they are listed. Occasionally, two interrupts will occur before the other one happens. It didn't matter which one was listed first. It was basically a first come first serve type event and setting the bits high or low at the IPR didn't make a difference. Attached is a picture of the first come, first serve events on the scope.

    I think I will keep using the same format I've been using and apparently, they have all been high prty all this time. This would explain why it hasn't shown up as a problem before, it's always been a race to see who gets handled first and I work will really slow events that can wait to be handled when they cross that finish line. I can see the importance of having the difference in priorities when something needs to be handled exactly when it needs to be. I apparently don't need them just yet.

    This exercise very enlightening. Thanks for the insight.

    I am curious as to why you did ask me to show you an example.
    Attached Images Attached Images  
    Last edited by csantex; - 11th September 2018 at 02:43. Reason: Added picture

  9. #9

    Default Re: PIC18F67K40 DT_INTS that really work.

    Just fyi -

    The default state for the IPRx register bits is '1', so all interrupts default to high-priority.

  10. #10
    Join Date
    Jun 2017
    Posts
    21

    Post Re: PIC18F67K40 DT_INTS that really work.

    Quote Originally Posted by tumbleweed View Post
    Just fyi -

    The default state for the IPRx register bits is '1', so all interrupts default to high-priority.
    I see that now.

  11. #11
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,106

    Default Re: PIC18F67K40 DT_INTS that really work.

    Csantex, I just asked out of curiosity. I didn't see how you were selecting the LOW and HIGH priority interrupt vectors.
    Dave Purola,
    N8NTA
    EN82fn

Similar Threads

  1. PIC18F67K40 Timer issues
    By csantex in forum General
    Replies: 5
    Last Post: - 29th July 2018, 04:19
  2. DT_INTS for K42
    By mpgmike in forum Code Examples
    Replies: 8
    Last Post: - 26th November 2017, 21:11
  3. Dt_ints-14
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th November 2013, 07:57
  4. Re: DT_Ints-18
    By Steve_88 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 4th March 2012, 18:39
  5. help getting started with DT_INTS-14
    By E Kizer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd April 2009, 15:44

Members who have read this thread : 20

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts