PDA

View Full Version : 18F2620 tmr0 and interrupts



astouffer
- 7th March 2009, 06:17
I'm having a bit of trouble converting the EZCLOCK1 code to a 18F2620.

http://www.picbasic.co.uk/forum/showthread.php?t=2129


OPTION_REG=%00000111 'weak pullups on, TMRO prescale = 256
INTCON=0 'interrupts off

Looking at the 18F2620 datasheet that would be changed to T0CON = %11000111 for prescale 256 and 8 bit timer enabled? INTCON=0 should stay the same.


TMR0=0 'Reset TMRO
INTCON.2= 0 'Clear TMRO overflow flag

Now here is what starts to confuse me. I'm not sure about TMR0 and the overflow flag is now called TMR0IF.


Main:
ClockLoop: IF INTCON.2=0 THEN ClockLoop ' Wait for TMRO overflow
INTCON.2=0 'Clear TMRO overflow flag

At this point how is the timer being enabled? The code works fine with a few minor changes on a 16F876A but this my first encounter with the 18F series. Any comments?


Adam

Darrel Taylor
- 7th March 2009, 06:43
At this point how is the timer being enabled?

On 16F's, TMR0 doesn't have an ON bit. It's always running.
On 18F's TMR0ON is T0CON.7, which you indicated as a 1. "T0CON = %11000111"

When using it as an 8-bit timer, the timers value is in TMR0L. On 16F's it's just TMR0.

And yeup, T0IF is now TMR0IF. There are also some 16F's that call it TMR0IF so it's always confusing.
But at least it's still INTCON.2 no matter what you call it.
<br>

astouffer
- 8th March 2009, 00:56
All is working as it should. Many thanks.


Adam