Yep. So with a 16-bit timer, 1:1 prescaler, 20MHz osc, it will count up & roll-over in
200nS * 65,536, which = ~13.1mS.
If you can live with a few uS short of 1 second, then you can change the prescaler
to 1:256, and do something like this;
Code:
DEFINE OSC 20
TMR0_FLAG VAR INTCON.2 ' Timer0 over-flow flag bit
TMR0H = $B3 ' $B3B5 = 46,005
TMR0L = $B5
TMR0_FLAG = 0 ' clear TMR0 over-flow flag
T0CON = %10000111 ' 16-bit, 1:256 prescale, TMR0 ON
Main:
REPEAT ' just loop waiting for over-flow flag
@ NOP
UNTIL TMR0_FLAG = 1
TMR0_FLAG = 0 ' clear over-flow flag
TMR0H = $B3 ' reload for 1 second over-flow
TMR0L = $B5
TOGGLE PORTB.0
GOTO Main
Works out to roughly 0.999 seconds per toggle.
Bookmarks