Page 229 - Making PIC Microcontroller Instruments and Controllers
P. 229
246 CREAtll{O ACCUnITE INTERV LS WlTll IIMERS: IXE flEtROl{OMES
Like all the timers, Timerl is clocked by the crystal ftequency divided by 4 (or
Fosc/4). It can also be clocked by an extemal oscillator connected between PORTC.0
and PORTC.I. The selection between the intemal and extemal oscillators is made by
$har is in TICON. I rnd TlCON.I, fl. follow.:
TlCON.l=0 Selects tbe Fosc/4 signal
Tl CON.l= I Selects the external input between
PORTC.O and PORTC.I
T1CON.3=1 Also must be set ifTICON.l is set
The use of ?1CON to control Timerl is sunrmarized as follows:
Tl€€l+3 ltu1iise*-
T-l€€N5 N€ftsed:
T|CON.5 ) These 2 bits
TlCON.4 ) specify the prescalar
TlCON.3 Set to 1 to enable oscillator
T1CON.2 Set to 1 to selects external clock
Tl CON.1 Selects extemal clock when set to
I, internal clock when 0
TlCON.o Tums Timerl on when set to 1,
off when 0, becomes counter
USING TI ENI
The listing in Program 16.5 shows how Timerl can be used to create a metronome.
Conpare this to the listing for Time mentioned previously.
i:illiltliiiaii:lfl[:i Metronome usins rimerl
cIiEAR i clear
DEFINE OSC 4 ; oeme os -ll-Lor speeo
DEFINE LCD_DREG PORTD ; define LCD connecLions
DEFINE LcD DBIT 4 j 4 bit path
DEFINE I.D_RSREG PORTE ; selecI Ieg
DEFINE I,CD_RSBIT O ; select bit
DEFTNE t,cD EREG PORTE ; enable re€risLer
DEFINE IJCD_EBIT t i enable bit
Lovf PoRtE.2 ; nake ton for write only
(Continued)