Page 217 - Making PIC Microcontroller Instruments and Controllers
P. 217
2I4 CREATII{G ACCURATE INTENVALS WITH TIMEhS: THE IIIETEOIIOMES
intemal flags, which are addressed latcr as a part of the main loop, and then proceed-
ing with the program. So the interupt rcutine for each inteffupt just sets its own desig-
nated ffag, resets its intefiupt flag and ends. When the main loop sees this designated
flag, it lakes care of it as paft of the main routine, not the interr pt routine. In the mean
time, you can addrcss the next interupt flag. This gets compljcated in a hurry and the
program designer must guarantee that doing it this way will actually work. In other
words, this is not trivial, so ir is bcst avoided for now.)
Tirners are not the o y things thal create interruprs. External events can be used to
initiate an interxpt. PORIB has special signiEcance in the generation of these intenxpts.
See the datasheet.
Now lett look at each timer in greater detail.
TimerO
Timero is discussed on page 5 I ir the datasheel.
Basic description: Timero has 8 bits, runs all the lime, and sets its intenupt bit every
256 courts of Fosc/4 if the bit has been cleared. It can use an inlernal or extemal
signal (for counter use). It can count on a falling or rising edge. The frequency of
the intenupt can be modified with a prescalat and the register ilself can be read and
writtcn to.
The two registers that conirol Time are OP ON REG ard INTCON. The birs in
these registers affect Timer0 as follows:
OPTION RECISTER values
OPTION REG.O BitO )
OPTION_REG.I Bitl ) These 4 bits control the value
OPTION_REC.2 Bit2 ) of the Prescalar as Listed below
oPrIoN REG.3 Bir3 )
OPIION_REG.4 Bit4 Selects high to low transition ofclock when setto I
Selects low to hjgh transition ofclock when set to 0
OT/TION,REG.5 Bit5 Sclccts internal clock for timer when set to 0
Selecls exte.nal clock on TOCKI* lbr counter when
sel to I
€EFIEERE# Bi{6 |+st.u€€6t6e€itr€*ffe+(}
er+IeN:Rr€.?- Bi{+ Nblt}se++€-e€€{f€ffirtlplt{+ps'
*TOCK I is pin 6 on lhe PIC I6F37?A, ako kno{n I PORTA.,I
PORTA Pin .1 is tbe filth pin on PORT .