Customizing the DT_INTS-XX.bas Instant Interrupt By mpgmike

Since Daryl Taylor created his Instant Interrupt Routine, Microchip has added many new features and changed PIR locations for their new MCUs. I wanted to share how to customize these Interrupt Routines for whatever processor you may need for your next project.

On pages 106 - 115 of the 18F27K40 Data Sheet is a Registry Summary for the Interrupt Registers (Table 10-5). Every Data Sheet has such a list. It lists INTCON as well as all of the PIR/PIE/IPR Registers. For the K40, there is 1 INTCON and 8 PIE/PIR/IPR Registers (PIR0, PIR1...PIR7). After each register is the Flag name for each Bit. For example, for PIR0 you have TMR0IF, IOCIF, INT2IF, INT1IF, and INT0IF. These names should be familiar, like IOCIF for the Interrupt on Port Change.

PIR7 (page 177) lists Special Functions not found in Daryl’s original DT_INTS Routines such as CRCIF for a relatively new Function called Cyclic Redundancy Check. NVMIF is a new name for an old Interrupt: Old = EEIF for the EEPROM Write Complete Function, now it's called Non-Volatile Memory Write Complete, or NVMIF. You don't need to know what each of the xxIF's do to create a custom DT_INTS, you just need the Interrupt Registry Summary. For the more familiar PIC18F2x_4xK22, the Interrupt Registry Summary is Table 9-1 on Page 133.

Next, open a copy of the applicable DT_INTS-18.bas in your Microcode Studio (PBP). Assuming you have opened the last original Daryl Taylor version (not one that has already been customized by one of the Forum members), starting on Line 59 the Interrupts are Defined. On Line 59 we see:

    #define INT_INT INTCON, INTIF      ;-- INT External, 16F compatible

Every Line of the Defines begin with #define. Next is the Interrupt, INT_INT in the above example. This denotes Hardware Interrupt on PORTB.0 INT pin. For the older processors, the INTIF is in the INTCON Register. It is called INTIF in the Interrupt Registery Summary. After that are comments suggesting what that Interrupt does.

If we leave Line 59 alone and erase from Line 60 to Line 183, we've cleared out all of the #defines for stuff we don't need, and could create conflicts. We'll leave one lone example, which we can copy/paste and modify. Taking the PIR0 listed above, we would make our own #defines like this:

    #define TMR0_INT PIR0, TMR0IF        ;-- Interrupt on TMR0 Overflow
    #define IOC_INT PIR0, IOCIF          ;-- Interrupt on Change
    #define INT2_INT PIR0, INT2IF        ;-- External Interrupt2
    #define INT1_INT PIR0, INT1IF        ;-- External Interrupt1
    #define INT0_INT PIR0, INT0IF        ;-- External Interrupt0

Now we can continue with PIR1:

    #define OSCF_INT PIR1, OSCFIF ;-- …..

And so forth. Save as something unique (like DT_INTS-18_K40.bas) and you're done. The 'Save As' will prevent this custom version from accidentally getting used for the wrong processor.

Next, Starting on Line 218 (of the original) are the same familiar Flags. The same process is used here, where the appropriate name & Registers are used for the MCU you are using. For example, Lines 218 - 220 reads:

	•	ifdef INT0IF ;----{ INT0 External Interrupt }----------[INTCON, INT0IF]---
	•	endif

We would modify it to read:

	•	ifdef INT0IF ;----{ INT0 External Interrupt }------------[PIR0, INT0IF]---
	•	endif

Another quick example, original:

	•	ifdef TMR1IF ;----{ TMR1 Overflow Interrupt }------------[PIR1, TMR1IF]---
	•	endif

Modified for the K40:

	•	ifdef TMR1IF ;----{ TMR1 Overflow Interrupt }------------[PIR4, TMR1IF]---
	•      INT_Source   PIR4,TMR1IF, PIE4,TMR1IE, IPR4,TMR1IP
	•	endif

Looking at the DT_INTS-14 in the Code Editor, the #define’s start on line 190. Let’s assume we want to use the Angular Timer function on a PIC16F1619. To take advantage of the built-in Interrupts using DT_INTS we must add the appropriate identifiers. Scroll down to line 276 (just below ENDASM) and hit Return to add a new line. I would recommend adding a commented line to identify the following as new code; something like

	•	;Added Angular Timer Definitions for PIC16F16xx, Date

Then we copy/paste the format from one of the existing examples and modify it for the new IF/IE/IP names & locations:

	•	#define AT1_INT      PIR5,AT1IF, PIE5,AT1IE         ;Angular Timer
	•	#define PHS_INT      AT1IR0,PHSIF, AT1IE0,PHSIE     ;AT Phase
	•	#define MISS_INT     AT1IR0,MISSIF, AT1IE0,MISSIE   ;AT Missing Pulse
	•	#define PER_INT      AT1IR0,PERIF, AT1IE0,PERIE     ;AT Period
	•	#define CC3_INT      AT1IR1,CC3IF, AT1IE1,CC3IE     ;AT CC3
	•	#define CC2_INT      AT1IR1,CC2IF, AT1IE1,CC2IE     ;AT CC2
	•	#define CC1_INT      AT1IR1,CC1IF, AT1IE1,CC1IE     ;AT CC1

Again, you have the option of saving the new version as something unique like DT_INTS-14_AT. Notice there is more work on the -18 than the -14. The -18 requires modifications in 2 places for every Register, while the -14 only requires changes in the one area.

Hope this helps.

Downloads Custom_DT_INTS-18 by mpgmike (Right click and Save As)

Page last modified on February 23, 2018, at 10:09 AM