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

56   GONTROLLI G  THE  OUTPUT AI{D READIIIG THE II{PUI


                                 I
                    Control       ing    the    Digital
                    and  Analog Settings


                    ADCON1 =  Analog to Digital  CONtrol  register#1.
                      The ADCONI=7.00000111  statement, or one lil(e it, is needed ior the 16F877A
                    because any PIC MCU processor  that has any analog capabilities at all comes up in the
                    analog mode  on reset  and startup. This particular  instruction puts  all the analog  pins on
                    po(s A and  E into the digital mode. Since we need or  y PORTE and PORTD for con
                    trolling the LCD, none of PORIA needs to be in digital mode. I am showing E 000001 I I
                    because all the examples used by nicroEngineering Labs in all their literature and on
                    their Web site use and suggest  singthisvalue. See datasheet for more detajled  infor-
                    mation.  (The  use of this register is  also discussed  in greater  detail in Chapter 9.) If you
                    want 1o tum  just the three available lines on PORTE to digital, you can use any binary
                    value  from  010 to 111 inclusive.
                      The conlrol of the A-to D conversion capability is managed by the 4 low bits of
                    ADCONI. For our  purposes,  bit 0 and bit 3 are not relevant. See  page  112 oI t}te
                    datasheet for detailed information on this.
                                                               "don't
                      Bit 0 is not relevant to the LCD operation  (it is a   care" bit).
                      Bit  I  and  2 must be set to 1 to make the two pots  (A and E) digital.
                                                                   "don't
                      Bit 3 is not relevant to the LCD operation  (it,  too, is a   care" bit).
                      So ADCON I =  '/.000001  I  0 or %0000011 I would be adeouate for our work.  (We  could
                    also have done  this in decimal  format  with ADCON 1=6 or with ADCON1  =7.)



                    Writing  Binary,  Hex, and Decimal

                    Values to the  LCD


                    The value of numbers written to the LCD can  be specified  with  prefixes  that determine
                    if the value wiil be  display  as a binary, a hexadecimal, or a decimal  value.  See the PBP
                    manual for details.

                      BIN specifies that the display will be binar).

                      HEX specifies ihat the display will be  in hexadecimal  format.
                      DEC specines that lhe display will  be in decimal format.
                                            "NMBR"
                      In hogram 5.5, the value of    is set to 170 arbitrd dly (actually  because it alter-
                    nates ls and 0s in binary fonmt). Any number below or equal to 255 could have  been  used.
                    Using BIN8 instead of BIN displays all 8 bits. Using  Hex2 instead  ofHEX  displays both
                    hex digits. DEC5 can display all fivl. decimal digits because we are limited to 16 bits
   61   62   63   64   65   66   67   68   69   70   71