So far I've shown one interrupt source being used at a time, but as I said in the first post, you can easily service Multiple Interrupt Sources. So what if we wanted to join the previous 3 examples into one program. NOT a problem!
To add more interrupt "Handlers", simply add them to the
INT_LIST, and create a subroutine for them.
Since both the Blinky Light, and Elapsed Timer used TMR1, lets move the Blinky Light over to TMR0. Elapsed will still use TMR1.
Code:
<font color="#000000"><b>LED1 </b><font color="#008000"><b>VAR </b></font><b>PORTD</b>.<b>0
LED2 </b><font color="#008000"><b>VAR </b></font><b>PORTD</b>.<b>1
</b><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">"DT_INTS-14.bas" </font><font color="#0000FF"><b><i>' Base Interrupt System
</i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">"ReEnterPBP.bas" </font><font color="#0000FF"><b><i>' Include if using PBP interrupts
</i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">"Elapsed_INT.bas" </font><font color="#0000FF"><b><i>' Elapsed Timer Routines
</i></b></font><font color="#008000"><b>ASM
</b></font><font color="#000080">INT_LIST macro </font><font color="#0000FF"><b><i>; IntSource, Label, Type, ResetFlag?
</i></b></font><font color="#000080">INT_Handler INT_INT, _ToggleLED1, PBP, yes
INT_Handler TMR0_INT, _ToggleLED2, PBP, yes
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE </font><font color="#0000FF"><b><i>; Creates the interrupt processor
</i></b></font><font color="#000080">INT_ENABLE INT_INT </font><font color="#0000FF"><b><i>; enable external (INT) interrupts
</i></b></font><font color="#000080">INT_ENABLE TMR0_INT </font><font color="#0000FF"><b><i>; enable Timer 0 interrupts
</i></b></font><font color="#000080">INT_ENABLE TMR1_INT </font><font color="#0000FF"><b><i>; Enable Timer 1 Interrupts
</i></b></font><font color="#008000"><b>ENDASM
</b></font><b>OPTION_REG </b>= <b>OPTION_REG </b>& <b>$80 </b>| <b>1 </b><font color="#0000FF"><b><i>; Set TMR0 Prescaler to 256, leave RBPU alone
</i></b></font><font color="#008000"><b>GOSUB </b></font><b>ResetTime </b><font color="#0000FF"><b><i>' Reset Time to 0d-00:00:00.00
</i></b></font><font color="#008000"><b>GOSUB </b></font><b>StartTimer </b><font color="#0000FF"><b><i>' Start the Elapsed Timer
</i></b></font><b>Main</b>:
<font color="#008000"><b>IF </b></font><b>SecondsChanged </b>= <b>1 </b><font color="#008000"><b>THEN
</b></font><b>SecondsChanged </b>= <b>0
</b><font color="#008000"><b>LCDOUT </b></font><b>$FE</b>,<b>$C0</b>, <font color="#008000"><b>DEC </b></font><b>Days</b>,<font color="#FF0000">"d-"</font>,<font color="#008000"><b>DEC2 </b></font><b>Hours</b>,<font color="#FF0000">":"</font>,<font color="#008000"><b>DEC2 </b></font><b>Minutes</b>,<font color="#FF0000">":"</font>,<font color="#008000"><b>DEC2 </b></font><b>Seconds
</b><font color="#008000"><b>ENDIF
GOTO </b></font><b>Main
</b><font color="#0000FF"><b><i>'---[INT - interrupt handler]---------------------------------------------------
</i></b></font><b>ToggleLED1</b>:
<font color="#008000"><b>TOGGLE </b></font><b>LED1
</b><font color="#000080">@ INT_RETURN
</font><font color="#0000FF"><b><i>'---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
</i></b></font><b>T0Count </b><font color="#008000"><b>VAR WORD
</b></font><b>ToggleLED2</b>:
<b>T0Count </b>= <b>T0Count </b>+ <b>1
</b><font color="#008000"><b>IF </b></font><b>T0Count </b>= <b>512 </b><font color="#008000"><b>THEN </b></font><b>T0Count </b>= <b>0 </b>: <font color="#008000"><b>TOGGLE </b></font><b>LED2
</b><font color="#000080">@ INT_RETURN
</font>
<font size=-2>Code Size = 711 Words</font>
Now we have all three interrupt sources working together in the same program.
LED1 responds to the external INT
LED2 flashes, timed by TMR0
and, the elapsed timer is maintained via TMR1
And, all of this is happening behind the scenes of your normal PBP program.
Bookmarks