DT_INTS-18 is a series of include files that simplify the process of creating interrupt driven programs for PicBasic Pro using PIC18F's. The following is a guide to using these INCLUDE files effectively.
Darrel Taylor's "First rule of interrupts", Never Wait for anything. Interrupt handlers should execute as fast as possible, and exit as soon as possible.
DT's Interrupts MUST be used with PicBasic Pro and MPASM.
Each interrupt "source" is given a unique name that is used to reference it. The system "Looks Up" the correct bit locations for that name. Reducing those RTFM sessions to a minimum. The 16-Bit Index lists the Named Interrupts.
Zip Includes all files needed to use Instant Interrupts with PicBasic Pro and 18F PIC's.
Extract the files to your PBP folder. (The folder that has PBPW.EXE in it)
List of Interrupts based on DT_INTS-18 vers. 3.4
DT_INTS-18.bas and ReEnterPBP-18.bas should be placed in your working folder. The following INCLUDE files should be near the beginning of your program. Other INCLUDE files for special functions will be discussed in the appropriate location.
*
INCLUDE "DT_INTS-18.bas" ....for 16it devises
INCLUDE "ReEnterPBP-18.bas" ...Include if using PBP interrupts
INCLUDE "ReEnterPBP-18LP.bas" ...Include if using Low Pr. PBP INTS
Command functions:
INT_CREATE...................Creates the interrupt processor
INT_ENABLE xxx_INT.....to enable interrupt after handler is created.
INT_CLEAR xxx_INT.......clear interrupt flags bits
INT_DISABLE xxx_INT....clear interrupt enable bits
INT_RETURN...................to restore interrupt and return to the program location where interrupt was made.
The following variables are located at the beginning of DT_INT-1x.bas. Copy them to your main program. The compiler will instruct you as to what should be done, if anything, once you compile. DO NOT make changes in DT_INT-1x.bas program.
wsave var byte $20 system ;location for W if in bank0
wsave var byte $70 system ;location for W if in bank0
..... If any of these next three lines cause an error ...Comment them out to fix the problem...
............which variables are needed, depends on the chip you are using.......
wsave1 var byte $A0 system ;location for W if in bank0
wsave2 var byte $120 system ;location for W if in bank0
wsave3 var byte $1A0 system ;location for W if in bank0
The following block of instructions will establish the interrupt processor used and the PBP label (your ISR) to jump to once interrupt occurs. Remember; all PBP labels or variables used inside ASM code blocks must be preceded by the underscore,( _ToggleLED1). After creating the interrupt processor all instruction to the processor should be in ASM and preceded by the @ symbol and to the far left column of the editor if not included in ASM code blocks.
@ INT_DISABLE INT_INT
INT_LIST explanation
macro......... Under macro are the individual macros used in your instant interrupt INT_LIST code block.
IntSource... Under IntSource you will locate the interrupt you are using. Up to 14 are allowed. located in 1x-Bit Index.
Label.......... This is the location for your Interrupt service routine, make sure the PBP label is preceded by an _underscore.
Type........... Type of interrupt (ASM or PBP) that is located at the ISR identified by your label.
ResetFlag?.. Do you want DT_INT to reset you interrupt flag? Or will you do that in you code? Yes or No
INTerrupts Execution:
ASM
INT_LIST macro ;IntSource Label, Type, ResetFlag? INT_Handler INT_INT _ToggleLED1 PBP Yes endm INT_CREATE ; Creates the interrupt processor INT_ENABLE INT_INT ;enables external (INT) interrupts
ENDASM
NOTE: Make sure IN_Handler, INT_CREAT, and INT_ENABLE are indented!
Multiple interrupts may be used.
ASM
INT_LIST macro ;IntSource Label, Type, ResetFlag? INT_Handler INT_INT _ToggleLED1 PBP Yes INT_Handler TMR0_INT _TimeOut PBP Yes INT_Handler TMR1_INT _TimeOut2 PBP Yes endm INT_CREAT ; Creates the interrupt processor INT_ENABLE INT_INT ;enables external (INT) interrupts
ENDASM
NOTE: Up to 14 separate INT_Handler's can be in the LIST.
Type of Interrupts:
ASM interrupts:
Your Interrupt service routine is written in assembly.
DT_INTS-18 using ASM interrupts uses only 7 bytes of Ram.
DT_INTS runs ASM interrupts with very little overhead and greater control. ASM interrupts will always give the best performance.
You should not use any multiplication, division, modulus (remainder), shifts (<<,>>) greater than 1 or 90% of any other commands in an ASM interrupt.
But if you absolutely must ... then you will have to search through the list file to see if what you wrote uses any system variables, FSR's, TABLPTRx
or HW multiplier registers.
PicBasic Pro uses 24 to 26 bytes for System Variables. (can be more)
When using ASM interrupts ONLY, the INCLUDE ReEnterPBP.bas file is not needed...........Click the "Assembly INTs" button.
PBP interrupts:
Your Interrupt service routine is written in PBP.
ReEnterPBP must be used with PBP interrupts.
ReEnterPBP needs to save all of PBP's system variables (26 bytes)
Plus it uses another 8 bytes, just in case PBP creates more T? system vars.
If you need a few more bytes, and you're using PBP type handlers, you can reduce the MaxTvars constant in ReEnterPBP.
High Priority/Low Priority
DEFINE USE_LOWPRIORITY 1
Darrel's Example......Post
Interrupt Handlers Order of Execution:
The Interrupt Handlers are executed in the same Order they are listed in the INT_LIST macro.
If something needs to be done Immediately after the interrupt occurs, then it should be placed at the top of the list. This might include capturing a Timer value or turning an Output ON etc.
Any interrupt source can have either an ASM or a PBP type of Handler. In fact, a single interrupt source might have both. You might place an ASM handler at the top of the list, and then have a PBP handler further down the list. This way you can capture a value immediately, and then process it later when it's not critical. Just make sure that the first one does NOT reset the interrupt Flag, or the second one will not execute.
Example:
ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler CCP1_INT, Pre_SQ_wave, ASM, no INT_Handler TMR0_INT, int_handler, ASM, yes INT_Handler TMR1_INT, _T1_ovrFlow, PBP, yes INT_Handler CCP1_INT, _SQ_wave, PBP, yes endm INT_CREATE ; Creates the interrupt processor
ENDASM
Download the files here: (Right click and Save As)
- INTS-18 Version x.xx