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

FORIA   29



                    Configuring  and Controlling

                    the  Properties of the Pofts


                    The PIC 16F877A  provides  33 VO pins distributed across  five porls. Each of the  ports
                    has unique capabilities  built into it. The following section of this book discusses the  capa_
                    bilities of each of the  pots with special  attention to these  propeties.
                       These descriptions  are cufsory and  are designed to provide a quick and ready  refer-
                    ence. Refer to the actual datasheet for detailed  infomalion  on  these  polls. The dalasheet
                    provides  information at a level lhat cannot be  provided in a short  introductory text like
                    this. Refenhg  to the datasheets  frequently will  make  you comfortable with them in a
                     short time.




                     PORTA


                     PORTA is a 6 bit wide bidirectional port with both analog and digital capability

                     Note  The  general rule is that ifa  PIC de\)ice has  any analog inputs built  into it, it
                     will  come up as an analog input.lerice  on reset dntuor staftup.
                       The PIC 16F877A has analog capability  on PORTA  (and  PORTE) so it comes up as
                     an analog device  on statup and rcset.  lf you are  going to use  it as a digital device,  you
                     must set register  ADCON as needed.  The most common  \alne is ADCONI  to
                     q.0000A111  for vsirg  the LCD display.  This line of code will  be seen  in nany  of the
                     programs  in tlis book and  is explained in Chapter 5-  (7o00000111  all the analog
                                                                             sets
                     pins  to digital, but there are  many otherchoices.)
                       The  PIC 16F87?A supports external  access |o only six of the eight  pins  on  this  port.
                     Each of the six  pins  may be set to  function as an input or output  by appropriately  load-
                                           "0"
                     ing the TRISA register A   (zero)  in a bit in this register sets  the cofesponding pin
                     to function as an output, while a  "1"  (one)  sets  it to function as an input.
                       Thus, selting...

                      IRIsA=%o0U1000
                      (%  mcans this is a binary  numbel Wo wilt use this binary  notation throughout  this book because
                                                                                   bh, is on fte
                      it makes it easier to see  what eacb bit is being seito.  Bil7. the mosl significant
                                              is on the right.)
                      ieftibit  0, the leasl significant.
                       Would make lines A0,  A I  ,  and A2 outputs and  lines A3, A4, and A5 inputs.  The most
                     sienifcant  2 bits are igtrr,'ed (and  could be set to I s or 0s) because PORTA  has only
                     six activelines.  (However,  the  2 ignoredbits are used by the  processor  and  they can be
                     read when  necessary. You should  not set them. Again, see  lhe datasheet  for specific
                     details.)
                       As mentioned earlier,  the specilic functions (the uses the  pins are  put to) of the  pins
                     are  controlled with the  ADCONI  (the  first A-to-D  CONtrcl)  rcgister
   35   36   37   38   39   40   41   42   43   44   45