So far I've shown one interrupt source being used at a time, but as I said in
the Introduction, 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.
Example 3:
LED1 VAR PORTD.0
LED2 VAR PORTD.1
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
INT_Handler TMR0_INT, _ToggleLED2, PBP, yes
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone
@ INT_ENABLE INT_INT ; enable external (INT) interrupts
@ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
GOSUB StartTimer ' Start the Elapsed Timer
Main:
IF SecondsChanged = 1 THEN
SecondsChanged = 0
LCDOUT $FE,$C0, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
ENDIF
GOTO Main
'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
TOGGLE LED1
@ INT_RETURN
'---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
T0Count VAR WORD
ToggleLED2:
T0Count = T0Count + 1
IF T0Count = 512 THEN T0Count = 0 : TOGGLE LED2
@ INT_RETURN
Code Size = 711 Words
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.