Page 233 - Making PIC Microcontroller Instruments and Controllers
P. 233
23o CREATIIIG ACCURAIE ll|tEnv![s WltH ll[ERS! IHE l|ETnO OIES
ilk!$$ffiiiiiillf$P! Metronome usinsrimer2 lcontinuectl
x vaR woRD ; se! up the variabLe
aDcot0-%00000111 , se! lhe aralos to Digital conrtol
, register
; needed for the 15F877A see noles
PAgsE 500 ; pause for LcD to start uP
r,cDottl SFE, L ; clear screen
oll II{IIERRUPT Goto INIt-RourrNE; te11s progxan wher:e !o qo on
; inLerrupt
T2coN.5=401111011 -n,erftpE erab e
; b i t 1 = 1
; b i t 2 = 0
; b i t 3 = 1
; bit 4=1 Prescaler
; biL 5=1 Prescaler
; b i t 6 = 1
P I E 1 . 1 = 0 i : n . e r r u p , e . € o e d
I N [ C O N . 6 . 1 i p e l n - L s r ' ] L e - ' l p t s r o o c . L r
x=0 ; sets the iniEial walue for x
ITAIN: ; the nain loop of lhe Progrd
LDOUT $FE, $80, "M€troDo@" i displd,/ Frst I ie
LDOUT $FE, $C0, DEC5 1( ; srite X to line 2 of the LCD
IF xE15 THEN ; check vatue of x
x=0
ToGGr,E PoREc.z ; toggle the speaker so we can
; hear it
ENDIF
GOTO MArN ; repeat loop
DISIELE , reqd insttuclion lo lhe conpiler
INf_ROD:rINE| i -nLerrLp. se-vice'oulinF
x=x+1 ; increnenl lhe counter
PIR1.1-0 ; clear the inlerrupt flag
RESUI'E ; go back to where you were
ENAILE ; reqd inslruction !o the conpiler
END ; all proerrans musr end with end
The Watchdos Timer
A fourth timer in the 16F877A is used as a watchdog timer. The furction of a watch-
dog timer is to provide an intenupt if a program hangs up and thereby fails to periodi-
cally reset the watchdog timer. The watchdog timer interupt flag is reset from time to