English
Language : 

PIC17C44 Datasheet, PDF (69/241 Pages) Microchip Technology – High-Performance 8-Bit CMOS EPROM/ROM Microcontroller
PIC17C4X
11.3 Read/Write Consideration for TMR0
Although TMR0 is a 16-bit timer/counter, only 8-bits at
a time can be read or written during a single instruction
cycle. Care must be taken during any read or write.
11.3.1 READING 16-BIT VALUE
The problem in reading the entire 16-bit value is that
after reading the low (or high) byte, its value may
change from FFh to 00h.
Example 11-1 shows a 16-bit read. To ensure a proper
read, interrupts must be disabled during this routine.
EXAMPLE 11-1: 16-BIT READ
MOVPF
MOVPF
MOVFP
CPFSLT
RETURN
MOVPF
MOVPF
RETURN
TMR0L, TMPLO
TMR0H, TMPHI
TMPLO, WREG
TMR0L
TMR0L, TMPLO
TMR0H, TMPHI
;read low tmr0
;read high tmr0
;tmplo −> wreg
;tmr0l < wreg?
;no then return
;read low tmr0
;read high tmr0
;return
11.3.2 WRITING A 16-BIT VALUE TO TMR0
Since writing to either TMR0L or TMR0H will effectively
inhibit increment of that half of the TMR0 in the next
cycle (following write), but not inhibit increment of the
other half, the user must write to TMR0L first and
TMR0H next in two consecutive instructions, as shown
in Example 11-2. The interrupt must be disabled. Any
write to either TMR0L or TMR0H clears the prescaler.
EXAMPLE 11-2: 16-BIT WRITE
BSF CPUSTA, GLINTD ; Disable interrupt
MOVFP RAM_L, TMR0L ;
MOVFP RAM_H, TMR0H ;
BCF CPUSTA, GLINTD ; Done, enable interrupt
11.4 Prescaler Assignments
Timer0 has an 8-bit prescaler. The prescaler assign-
ment is fully under software control; i.e., it can be
changed “on the fly” during program execution. When
changing the prescaler assignment, clearing the pres-
caler is recommended before changing assignment.
The value of the prescaler is “unknown,” and assigning
a value that is less then the present value makes it dif-
ficult to take this unknown time into account.
FIGURE 11-4: TMR0 TIMING: WRITE HIGH OR LOW BYTE
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
AD15:AD0
PC
PC+1
PC+2
PC+3
PC+4
ALE
TMR0L
T0
Fetch
Instruction
executed
TMR0H
T0+1
New T0 (NT0)
New T0+1
MOVFP W,TMR0L MOVFP TMR0L,W MOVFP TMR0L,W MOVFP TMR0L,W
Write to TMR0L Read TMR0L
Read TMR0L
Read TMR0L
(Value = NT0)
(Value = NT0) (Value = NT0 +1)
© 1996 Microchip Technology Inc.
DS30412C-page 69