Page 232 - Making PIC Microcontroller Instruments and Controllers
P. 232

tHE t|lrERz DeOGFtt



                     1100           13
                     I 1 0 1        t4
                     1110           l 5

                     1 1 1 1        16

                     @
                     PIEI.I  and INTCON.6  control the intenupt enable bit
                     The interrupt flag is located  at PIRI.1.
                     Like all the timers, Timer2 is clocked by the crystal frequoncy  divjded by 4 (or
                   Fosc/4).  It can rotbe used with an external oscillator
                     The timer is controlled by T2CON.2  and  is on when this bit is set to 1.








                   The listing in Program  16.6 shows how Timer2 can be used  to create a meuonome.
                   Compare this to the listings for Timelo and Timerl mentioned  prcviously.


                   iPtlCiSIF.;Iry   Me onome usins rimer2
                    ;  Like  we  did  for: TIMERO,  f,I st  1et  us  se!  up  lhe  LCD
                    CI,EAR                           always  starC  wiLh  clear
                    DEFTNE  OSC  {                   def,ne  oscillalor   speed
                    DEFINE  !,CD_DREG  PORIID        def,ne  LcD  conneclions
                    DEFINE  I,CD_DBIT  4
                    DEFINE  I,CD_RSREG  PORITE
                    DEFINE  I,CD_RSBIT   O
                    DEFINE  ',CD_ER3G  PORTE         enable  register
                    DEFTNE  T,CD_EBIT   1
                    NOW PORTE.2                      nake  low  for  wrile   only
                    ;  Set  Lhe  port  direclions.   We
                    ;  PORTE as  oulpuls
                    ;  even  lhough   PORTE  has  only   3  lines,   The other  5  lines  will

                                             ' '  - -      r  s p 6 a < a r


                    TRJSC  -  %11111011                           fne  speaKer
                                                     to  an  outpuC  line
                    rRIsD -  200000000               set  all  PoRTD lines  to
                    rRrsE  =  %00000000              set  all  PoRTE lines  ro
                    PORIE.2=0
   227   228   229   230   231   232   233   234   235   236   237