English
Language : 

PIC16F818_13 Datasheet, PDF (62/178 Pages) Microchip Technology – 18/20-Pin Enhanced Flash Microcontrollers with nanoWatt Technology
PIC16F818/819
EXAMPLE 7-3: IMPLEMENTING A REAL-TIME CLOCK USING A TIMER1 INTERRUPT SERVICE
RTCinit
RTCisr
BANKSEL
MOVLW
MOVWF
CLRF
MOVLW
MOVWF
CLRF
CLRF
MOVLW
MOVWF
BANKSEL
BSF
RETURN
BANKSEL
BSF
BCF
INCF
MOVF
SUBLW
BTFSS
RETURN
CLRF
INCF
MOVF
SUBLW
BTFSS
RETURN
CLRF
INCF
MOVF
SUBLW
BTFSS
RETURN
CLRF
RETURN
TMR1H
0x80
TMR1H
TMR1L
b’00001111’
T1CON
secs
mins
.12
hours
PIE1
PIE1, TMR1IE
TMR1H
TMR1H, 7
PIR1, TMR1IF
secs, F
secs, w
.60
STATUS, Z
seconds
mins, f
mins, w
.60
STATUS, Z
mins
hours, f
hours, w
.24
STATUS, Z
hours
; Preload TMR1 register pair
; for 1 second overflow
; Configure for external clock,
; Asynchronous operation, external oscillator
; Initialize timekeeping registers
; Enable Timer1 interrupt
; Preload for 1 sec overflow
; Clear interrupt flag
; Increment seconds
; 60 seconds elapsed?
; No, done
; Clear seconds
; Increment minutes
; 60 seconds elapsed?
; No, done
; Clear minutes
; Increment hours
; 24 hours elapsed?
; No, done
; Clear hours
; Done
TABLE 7-2: REGISTERS ASSOCIATED WITH TIMER1 AS A TIMER/COUNTER
Address Name Bit 7 Bit 6 Bit 5
Bit 4
Bit 3
Bit 2 Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
0Bh,8Bh, INTCON GIE PEIE TMR0IE
10Bh,18Bh
INTE
RBIE TMR0IF INTF RBIF 0000 000x 0000 000u
0Ch
PIR1
— ADIF
—
—
SSPIF CCP1IF TMR2IF TMR1IF -0-- 0000 -0-- 0000
8Ch
PIE1
— ADIE
—
—
SSPIE CCP1IE TMR2IE TMR1IE -0-- 0000 -0-- 0000
0Eh
TMR1L Holding Register for the Least Significant Byte of the 16-bit TMR1 Register
xxxx xxxx uuuu uuuu
0Fh
TMR1H Holding Register for the Most Significant Byte of the 16-bit TMR1 Register
xxxx xxxx uuuu uuuu
10h
T1CON — — T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON --00 0000 --uu uuuu
Legend: x = unknown, u = unchanged, - = unimplemented, read as ‘0’. Shaded cells are not used by the Timer1 module.
DS39598F-page 62
 2001-2013 Microchip Technology Inc.