Code below works correctly (EP3 / 18F4685@8MHz) :
Code: Select all
program test_tmr0
sub procedure interrupt
if portb.0 = 1 then
portb.0 = 0
TMR0H = $00
TMR0L = $10
else
portb.0 = 1
TMR0H = $F0
TMR0L = $00
end if
INTCON.TMR0IF = 0 ' clear T0IF
end sub
main:
ADCON1 = $0F ' set AN pins to Digital I/O
T0CON = %10001000 ' TMR0 in 16 bit, no prescaler to TMR0
INTCON = $A0 ' enable TMRO interrupt
CMCON = 7 'Comparator OFF
TMR0L = $FE ' timer0 initial value
TMR0H = $FF
TRISB = 0 ' PORTB is output
PORTB = 0 ' initialize PORTB
while TRUE
nop
nop
wend
end.
Code: Select all
TMR0L = $10
TMR0H = $00
and
TMR0L = $00
TMR0H = $F0
This is may be a PIC limitation or specification ?
For 18F4685, TMR0L and TMR0H are located respectively at : FD6h / FD7h.
Now, rather than to initialise TMR0L/TMR0H separatly, I'd like to initialise Timer0 in one time by declaring an absolute variable.
But code below doesn't work either, :
Code: Select all
program test_tmr0
dim timer0 as word absolute $FD6
sub procedure interrupt
if portb.0 = 1 then
portb.0 = 0
timer0 = $0010
else
portb.0 = 1
timer0 = $F000
end if
INTCON.TMR0IF = 0 ' clear T0IF
end sub
main:
ADCON1 = $0F ' set AN pins to Digital I/O
T0CON = %10001000 ' TMR0 in 16 bit, no prescaler to TMR0
INTCON = $A0 ' enable TMRO interrupt
CMCON = 7 'Comparator OFF
TMR0L = $FE ' timer0 initial value
TMR0H = $FF
TRISB = 0 ' PORTB is output
PORTB = 0 ' initialize PORTB
while TRUE
nop
nop
wend
end.
Any ideas ?