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

2so   UIDERST NoI  G tHE  COUIIERS: COUNII|{G MARBLES



                     signal because  an intenupt can only be se! once.  The intenupt routine toggles  pin  B.4
                    up and down,  and since  pinB.4 is connected topin C.0,  the signal is fed to C.0.  We are
                     using  pin C.0 because  it is the only pin thal can be used as  an input for the Timer I reg-
                     ister  pair as indicatcd  in the data sheet.
                     IHE WORKING  PROGRAIU
                      Program  17.5 demonstmtes fundamental TMR I operation  as a counlcr lor the marbles.  As writ
                      ten  it counls the nunbcr of lines PORTB.0  is grounded- Displays show Lrs the following  things

                                  i
                          ' t \ t . O \ 6 g  s r o         s e a .  o d d  p o L s - .  - I  j o r  " r r  ' o
                          B  register        (too  fast  to  see,  add  pauses  if  you  ranr
                          TMR1L and  TMR1H registers

                        ltorking   connections   are
                          Connect  81  to  C0  to  feed  Tinerl   counter
                          Gromd  B0  Lo  increment   the  counter.
                                                   in Program 17.5.
                       The above ideas are implemented

                     riatiii!!iiii:!l?!!l:i   Basic marble countins  routineio count directlyto  theTimerl
                      counter register  pair  (The  wiring diagram lhis  program n Fig!re  17-5)
                                                        lor
                                                                     is
                      cL&dR                         ;  always  start  riLh  c1ear.  Good  habit.
                      DEFINE osc  4                 ;              -la   o   p..d.  (ood  holr'
                      DEFINE  ICD  DREG  PORTD      ;  de6ne  LCD connectioNs   dAtA  PORTB
                      DEFINE  LCD DBIT  4           i  4  brt  path
                      DEFrtitE LCD_RSREG PORTE      ;  register   Select  port
                      DEFrrlE  rJcD_RsBtt  0        ;  regisler   select   biL
                      DEFIAIE I,CD EREG PORTE       ,  enable  poTI
                      DEFINE tCD  EBIIr  L          ;  enable  bit
                      LOW POR1[E.2                  ;  sel  low  to  write   only
                      DEFINE  LCD-COM!4aI'IDUS 2000  ;  deLay  in  nicro   seconds
                      DEFINE  I,CD_DATAUS 50        ;  delay  in  nicro   seconds
                      .a.DcoN1-%00000111            ;  set  ADcoNl  for  diqilal   operation

                      IRIsA=%00000000
                      TRISB=%11110001
                      TRISC=%00001111
                      TRISE=%00000000
                      X  VAR  WORD

                      !E1CON=%o000 0011             ;  set  bils  to  conLrol  time.1.  Pae'e 56
                          ;  bitT=o   Not  used
                          ;  biL6=0   Not  ,rsed
                          ;  bit5=0   Prescalar=1
                          ;  bi!4=0   PrescaLar=
                          ;  bir3=0   osc  enable  bi!.   osc  off
   247   248   249   250   251   252   253   254   255   256   257