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

SOCKETS  IAND  UAI  i27
                                                                           U7


                  lilt9.idf]lti9il   Using  the DS1820  (Program  to read lemperalure  bv
                                  Labs)  (Cont ued)
                    micrcEngineering
                   ADCON1  =%OOOOO111           ;  set  PORTA and  PORTE to  digitaf
                    LOW PORTE.2                 ;  lcd  x/w  line  1ow  (v)
                    PAUSE  100                  ;  wait  for  1c.l  to  start
                    LCDOUT  $FE,  1,   \[EMP   IN  DEGREES C"   ;  display   siern-on  nessalre

                    ;  nainloop   to  read  the  tenperaiure   and  dispLav  on  tcd
                    UAINLOOP:
                    GOSUB INIT182O               ;  init   the  Ds 180 2
                    COIAIAnD  =  %11001100       ;  issue  skip  ron  conaand
                    GOSUs  WRrTE1820
                    CO!{DiAND  =  %01000100      ;  start   lemperature
                    GOSIIB  !rRrTE1820
                    PAUSE  2000                  ;  wait  2  seconds  for  converslon  to

                    GOSUB  INIT182O              ;  do  another  lnit
                             -
                    COMMAIiID  %L1OO11OO         ;  issue  skip  ron  comand
                    GOST'B  I'IRITE182O
                    COMMAND  =  %10111110        ;  read  lhe  tempetalure
                    GOSUB  WRTEE182O
                    GOSUB  RE]AD182O
                                                 ;  display   the  decinal   temperatu.e
                    LCDOUT  $FE,  1,  DEC (TE!'P >>  1),   \.4/   DEC  (IEMP.o  *   5),
                    \   DEGREES CZ
                    GOTO  MAINIOOP
                                                   inirialize   Ds1802 and  check  for

                    ITiIITIS2O:
                    LOW  DQ                        Set  lhe  data  pin  1ow ho  init
                    PAUSEUS  5OO
                                                   release  data  pin  {set  to  input
                                                   for  hish)
                    PAUSEUS  100
                    I F D Q = l T E E A !
                    I,CDOUE  SFE,  1,   'DS182O   NOT  PRESE!fT"  ;
                    PAUSE 500
                    GOTO  MAINI.OOP
                    ENDIF
                    PAUSEnS  400                   ldait  for  end  of  presence  pulse
                    RETURN
                                                   vrile   "comand"   byte  ho  the  ds1820
                    WRITE1820  !
                    F O R I = 1 T O 8              I  bits  Lo  a  byte
                      I F C O U M A N D - o = 0 t l t E N
                        GOSUB VTRITEO
                      EI"SE
                        GOST'B  IIRITEI
   132   133   134   135   136   137   138   139   140   141   142