Quote Originally Posted by Michael Wakileh View Post
I've been wondering what it would take...or if anyone has managed to change the Timereload (External Constant), to a variable that can be altered in the main program...
Actually, I would like to load this value from eeprom on startup, but I am at a loss for how to go about this short of learning asm...


Code:
;---Reload Timer1------   (T1 asm interrupt handler)
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
I'm sure there are a number of ways to do it, but a direct translation of that routine might look like this ...
Code:
TimerReload VAR WORD BANK0

ASM
ReloadTMR1
    MOVE?CT  0, T1CON, TMR1ON     ;  1     stop timer
    MOVF     _TimerReload,w       ;  1     Add TimerReload to the 
    ADDWF    TMR1L,F              ;  1     value in Timer1
    BTFSC    STATUS,C             ;  1/2
    INCF     TMR1H,F              ;  1
    MOVF     _TimerReload + 1,w   ;  1
    ADDWF    TMR1H,F              ;  1
    MOVE?CT  1, T1CON, TMR1ON     ;  1     start timer
  INT_RETURN
ENDASM
Then TimerReload is a PBP word variable.
You can calculate it or read it from EEPROM as desired.