All3Combined

Let's add all three of the previous examples into one program.
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:

; Initialize your Hardware and LCD first

LED1   VAR  PORTB.1
LED2   VAR  PORTB.2

INCLUDE "DT_INTS-18.bas"       ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas"    ; Include if using PBP interrupts
INCLUDE "Elapsed_INT-18.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

T0CON = %10010010             ; T0 = 16-bit, Prescaler 8
@    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)------
ToggleLED2:
    TOGGLE LED2
@ INT_RETURN

Code Size = 1356 bytes

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.

Page last modified on February 07, 2018, at 07:23 PM