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

306   LOGGIIIG DAIA  FBOIII A SOIAB  COLTECTOR


                     Software


                     Nole  The solwarc listinls are v,ritten  as il the controLler  \')as a LAB Xi  boa
                    so that  a new boanl does  not haw to be created  to execute the  requirements ofthe
                    eryeriment-  A much more wn!1tile  slstem could be created if a new board was
                    desi!ne(]. Since  the major  ptoblem  wth  the LAB xl  is the  fact  that therc  a,e three
                    pots  atreadJ dttached  to the anaLog input lines, the circuit layout  for  this e.rperi'
                     ment must refect this.
                       The devices we  will be using are to be  attached as fbllows:

                       The temperatwe will be read from PORTA.5.
                       The clock uses the  Nru6355 chip and  is located as shown on  the LAB_Xl schematic
                       at  U6.
                       A32.786-KHz  c.ystal mustbe added  to the board at J5  to support the clock.

                       The fan switch will be  at PORTD.3.
                       The inteface fo the computer will  be the DBg connector on the board
                       The LCD display addresses will  be the standard  LCD adalresses for the bodrd.

                     The software for the solar collector has to peform  the following  functions:

                       Provide a clock function (with the hardware  addition)
                       Read  the temperature sensor

                       Make minor decisions  / Control the lan
                       Send the data  to the computer  periodically
                       Reco\er  frcm  po$  er oulage.  rutomalicalll

                       The hardware  needed to support these  functions is shown  on the wirjng diagran in
                     Figue 22.2,  with all the  pins  that will be used identified.
                       If there is no  battery  backup, the clock  must have an arbitrary  starting time  so tlte
                     recovery from apoweroutage  canbe effected  based on the datacollected  during  the
                     previous  and following day.  When the data  is analyzed, any reset/discontinuity  of
                     the clock  will indicate a  power  outage and the rcadings  will have to be  adjusted fbr
                     time ofday based on extrapolation  from the daily cycles.  Dr' Sun has  indicated that
                     these functions  are to be performed when the data is finally analyzed by his group
                     in Beijing.
                       Let's write the software as subroutines,  one for each  function Each of the sub
                     routines needs to have some  prcliminary  work done up  front during the setup  oflhe
                     program,  and this  is listed separateiy before  each subroutine.
                       First,let's setup the  LCD as we always do.  Then, we can call the  code oul as a sub-
                     routine  in the  program where we need it. See Progmm  22 1.
   299   300   301   302   303   304   305   306   307   308   309