Page 306 - Making PIC Microcontroller Instruments and Controllers
P. 306
soa ToGGNG DATA Fnoii A SOIAR COLIECIIB
As pmErammell for rhis expeiment, the clock is set to 0 t Jan, 2007 on sta up, and
after every power failure, lt can, of course, be set to any date and time you choose, and
it will not aflect the results of our experiments in that we are not using the exact lime/date
information as such, but rather the daily cycle of the collected daia. Even missing a day
or two of data would not adversely affect our effort.
We have no way of intervening to set lhe clock iflwhen there is a power iailure, so
we set the clock to the beginning of the year 200? on startup and whenever there is a
power failure. Later on, when the dala is analyzed, we car use the temperature data and
number of data points since the last night cycle to determine the approximate time of
js
day for each recovery. Fortunately, the exact time at which the readings are laken not
impo(ant ir this pa icular investigation.
Nole Therc is a ptur,ision.for a battery backlp far the clock on the I'AB'XI , atul a bst
tery could be pmviAed tu keep the clock Eoing d ring po\rer failurcs if this v/as desircd
However, chances are, the bafteies will rnt be easily aNailable in nnny parts ofthe less'
det,eloped worl(l wherc data mhf be 7athercd, so t')e shoud take that into consi.leration
The "date data' does not show up on the display but is sent to the computer along
with the other data as a matter of course during each transmission to the PC
The clock is seen as a set of memory locations by the MCU The ac$al locations will
depend on the clock cbip we select. For this application, we have selected the Nru6355
IC chip. The use of this chip is explained in some detail in Cbapter 7. We read the clock
bur rhe exacl acruai time is not ol;nFre\l beLau\e \ e do not ha\e a wa) lo reiel lo lhe cof-
rect time after a power failure. Our interest is in the time that has elapsed since the last sun-
rise and since the last power failwe. We can estimate the actual iime from the inldmation
gathered for the day if we know the lirst date that the data was collected. (The program
segment to read the IC is taten from a program on the microEngineering Labs Web site.)
The routrne to send the data to the computer look at the seconds value, and then every
minute, based on the changes in the registe(s, it sends the relevant information to the
computer lor storage.
The initialization code for the clock module is shown in Program 22 2
ii8iiiiil$lt*i.8: writins to the crock
; The alias Pins are as follows
CE VI* POREA.2
CI,K VAR PORTC.I
SDA'A VAR PORTC.3
IO VAl' PORTC.s
; allocate wariabLes
RTCYEIIR 1IAR BYTE
RTCIIOIf,IH 1IAR B'TE
RICDAIPE VAR EYTB
RTCDAY VAR BT4!E
RTCITR VAR BIEE
RTCMIN 1IAR BITE
RICSEC vaR AYIE ; set variables
(Contin edt

