Darrell Taylor Timers 1 and 2

Discussion in 'The Projects Forum' started by ronbowalker, Dec 15, 2009.

  1. ronbowalker

    Thread Starter Member

    Jun 26, 2009
    23
    0
    My PIC16F819 has TIMER0, Timer1 and TIMER2. I am using TIMER1 as an interupt, and I now need to create another timed interupt. Can I use TIMER1 and TIMER2 without the two of them causing problems with each other?

    I am using this from Darrell Taylor:

    INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, ReloadTMR1, ASM, no ; MUST be first
    INT_Handler TMR1_INT, _T1handler, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM
    ------------------------------------
    @Freq = 10 ; Frequency of Interrupts in Hz
    @Prescaler = 8 ; Timers Prescaler setting
    T1CON = $00 ; $30 = Prescaler 1:8, TMR1 OFF
    ; $00=1:1, $10=1:2, $20=1:4, $30=1:8 -- Must match @Prescaler value
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
    GOSUB StartTimer ; Start the Timer
    ------------------------------------
    Main:

    My program goes here....

    Goto Main
    ---------------------------------------
    'This routine is Called on each TMR1 Interrupt
    T1handler:
    TICK = TICK + 1
    If TICK = 46 then
    TOCK = TOCK + 1
    TICK = 0
    ENDIF
    @ INT_RETURN
    '---[TMR1 reload - interrupt handler]-----------------------------------
    ASM ; Calculate Timer Reload Constant
    ReloadInst = 8 ; # of Intructions used to reload timer
    if ((Prescaler == 1)||(Prescaler == 2)||(Prescaler == 4)||(Prescaler == 8))
    MaxCount = 65536 + (ReloadInst / Prescaler)
    TimerReload = MaxCount - (OSC*1000000/4/Prescaler/Freq)
    if ((TimerReload < 0) || (TimerReload > (65535-ReloadInst)))
    error Invalid Timer Values - check "OSC", "Freq" and "Prescaler"
    endif
    else
    error Invalid Prescaler
    endif
    ENDASM
    @Timer1 = TMR1L ; map timer registers to a word variable
    Timer1 VAR WORD EXT
    TimerReload CON EXT ; Get the External Constant
    TMR1ON VAR T1CON.0 ; Alias the Timers ON/OFF bit
    ;---Reload Timer1------
    ASM
    ReloadTMR1
    MOVE?CT 0, T1CON, TMR1ON ; 1 stop timer
    MOVLW LOW(TimerReload) ; 1 Add TimerReload to the
    ADDWF TMR1L,F ; 1 value in Timer1
    BTFSC STATUS,C ; 1/2
    INCF TMR1H,F ; 1
    MOVLW HIGH(TimerReload) ; 1
    ADDWF TMR1H,F ; 1
    MOVE?CT 1, T1CON, TMR1ON ; 1 start timer
    INT_RETURN
    ENDASM
    ;---Start/Stop controls -----
    StartTimer:
    Timer1 = TimerReload ; Load Timer
    TMR1ON = 1 ; start timer
    RETURN
    StopTimer:
    TMR1ON = 0 ; stop timer
    RETURN

    What do I need to do to create a TIMER2?
    Do I do the same as the TIMER1 but change the verbiage to TIMER2, and create new .bas files?
     
Loading...