a series of include files that simplify the process of creating interrupt driven programs for PicBasic Pro using PIC16F & PIC12F'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 14-Bit Index in the left column lists the Named Interrupts

Files Placement

DT_INTS-14.bas and ReEnterPBP.bas should be placed in your working folder. The following INCLUDEs should be near the beginning of your program in most cases.

INCLUDE DT_INTS-14.bas ....for 14bit devises
INCLUDE ReEnterPBP.bas ....saves system variables


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.

NOTE: All command functions are assembly macros. If inside an ASM code block they should be indented. If stand alone, they should be preceded by the @ symbol and on the far left margin.


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

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
Darrel's Comments

Interrupt List (INI_LST)

The following block of code under INTerrupts Execution will establish the interrupt 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_LIST Headings

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? Yes or No If your not sure, say YES.

INTerrupts execution:

 INT_LIST     macro     ;IntSource      Label,    Type,    ResetFlag?
            INT_Handler   INT_INT    _ToggleLED1   PBP       Yes
            INT_CREATE              ; Creates the interrupt processor
            INT_ENABLE    INT_INT  ;enables external (INT) interrupts

NOTE: Make sure INT_Handler, INT_CREAT, and INT_ENABLE are indented if inside the ASM code block!
NOTE: PBP Labels in an ASM code block need underscore before the PBP Label.

Multiple interrupts may be used.

 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
            INT_CREAT              ; Creates the interrupt processor
            INT_ENABLE    INT_INT  ;enables external (INT) interrupts

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

PBP interrupts:

Your interrupt service routine is written is 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.

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.


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
    INT_CREATE               ; Creates the interrupt processor

Processor Specific


To use Instant Interrupts on PIC12F675 ... Open the DT_INTS-14.bas file and comment out the wsave lines. 675 doesn't have usable RAM in bank1,2,or 3.
Then open ReEnterPBP.bas file and comment the T?_save variables.


Wsave variables needed with the 683 are wsave at $20, and wsave1 at $A0
DT..11 Feb, 2012


The 628 has 4 banks, bank 3 doesn't have any General Purpose Registers in it. This causes one of the variable assignments to fail. It does have access memory that's common to all banks at $70 which can be used instead.

Open the DT_INTS-14.bas file, and at the top you should see this section...

wsave       var byte    $20     SYSTEM      ' location for W if in bank0\\
'wsave       var byte    $70     SYSTEM     ' alternate save location for W\\ 
                                            ' if using $70, comment out wsave1-3\\
' --- IF any of these three lines cause an error ?? -----------------\\
' ---   Comment them out to fix the problem ----\\
' -- It depends on which Chip you are using, as to which variables are needed --\\
wsave1      var byte    $A0     SYSTEM      ' location for W if in bank1\\
wsave2      var byte    $120    SYSTEM      ' location for W if in bank2\\
wsave3      var byte    $1A0    SYSTEM      ' location for W if in bank3\\
' ------------------------------------------------------------------------------\\
Comment out all the wsave? lines, and un-comment the 'wsave var byte $70

Page last modified on March 04, 2018, at 03:05 PM