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

plC
                                                                             OF THE  ilCU
                              G MICBOCHIP
             26   UNDEBSTANDI            TECHNOLOGY'S 16FA77Ar A DESCRIPIION
                      Set up  the  pin used on ihe MCU for analog  mode

                      Select  the  pin to be  sed  for input
                      Select what the  excitation voltage  soxrce will bc  (inlernal  or erlcrnal)

                      On  rhe 16F877A. only l6 pins  can be used  with the POT command,  and these  l6 pirs
                    havc been  assigned lhe aliases  from PINo to PINI5 in thc lnclude  file BSIDEFS-BAS
                    (see  the  PBP marual).  For the 16F877A, these  are the  pins  on PORTB  (0 to 7) and
                    PORTC  (8  to 15). Other PIC  MCU have dillqent designations based  on their  pin  counts
                    See  pagc  26 of the PICBAS]C PRO nanual for more information
                       The POT command  is:
                      POT  Pin,  Scale,  NUBR



                                         qe
                       P,, is the  pir numbef  hdrc been  di.cr s.ing
                       S.?le  is the adjustmcnt forvarious  RC constanls.Ifthe  RC constant  is large, the  value
                       oI Scale sho ld be small. Scale  is detemincd experimen|ally  with a  potenliometef
                       in  place  ofthe  resistive load.  At the  low end o[ the  resistance, the value  ofscale shou]d
                       be 0, and at the  high end il shouldbe  255.
                       NMrli  is the  variable lhc result  will be  placcd in.

                       Values belween 5 and 50K ohms  may be read with a 0.1  uF capacitor,  as shown  in
                     the Conpiler manual  under the POT command.

                     Capacitance   Capacilance  can be measurcd by deternining  how  long i1 lakes to
                     charge a capacitor  through an accuralely  calibratcd resistor  or by sctting  up an oscilla
                     tor  with the two components  and ncasuring  the oscillalor  frequency.
                     yorfage  Vollage is measured by setting up an appropriate  dividing  network with  pre-
                     cision  resistors and  measurirg the  vollage across an approprraie  resrslance

                     Frequency  The PIC 16F877A  can neasurc  trequencies directly  (as  made  possible
                     by the compiler software).  Thc timers  and counlcrs  within the MCU are  used to sct the
                     mcJ.urelrenr inlen aL\  3nd  ('  'unrin!  \arJs."e.

                     Ree.ting  Siwitches  Swilches can  be read from thc  lines of any  port set  up as an input
                     port.  De-bouncjng  must be  perlbrmcd either in hardware or in soltware to avoid lalse
                     readlngs.  (The  BUTTON  comnand  provides  flexible de bouncing  capabilities.)
                       Make sure tha! other  hardware lhat  may be connecled to the  pins  does  not interlere
                     with the switch lunction  and iis detection.
                     Peading  Switches  in  a iltatix   Switches  armnged in a  matrix can be read by set
                     dng and  reading ihe rows and  columN in thc  matrix. The technique  activales one  row
                     ofbutlons at  a time by making  it high or low and then  seeing iI any of  the columns  have
                     been  affected. A detailed  desciption ofhow this is done  is in Chapler 5.
   34   35   36   37   38   39   40   41   42   43   44