; *******************************
; Filename: ShieldDataLogger
; Date: 06/07/2012
; File Version: v2.00
; Written by: MS
; Function: Greenhouse Data logger
; Last Revision:
; Target PICAXE:My20M2Shield
; *******************************
#picaxe 20m2
symbol intemp = b.0
symbol outtemp = b.1
symbol key= b.2
symbol light = b.3
;symbol humid = b.4
symbol All_clear=%00000000
symbol line1=128 'Set up LCD line codes
symbol line2=192 'Start location for each line
symbol line3=148
symbol line4=212
symbol RTC=%11010000 'DS1307 Address
symbol MEM=%10100000 'EEprom Address
symbol MEM2=$8001 '2nd EEprom Address
symbol mintemp=MEM
symbol maxtemp=mintemp+2
symbol sun=b0
symbol baud=T2400 'Serial baud rate baud,N,8,1
pause 300 'Give system time to power up and stabilize?
serout c.0,baud,(255,1) 'switch backlight on
pause 200
Main:
gosub keys
gosub gettime
gosub convert
serout c.0,baud,(254,line1,b12,b13,"/",b14,b15,"/20",b16,b17," ",b10,b11,":",b8,b9,":",b19,b20," ")'display current date & time
gosub tempIn
gosub checkmin
gosub tempIn
gosub checkmax
serout c.0,baud, (254,line2,"Inside Temp:",b9,b7,b6,".",b5,b4,"c")'display local temp.
gosub tempOut
serout c.0,baud, (254,line3,"Outside Temp:",b9,b7,b6,".",b5,b4,"c")'display remote temp.
readadc light,sun
serout c.0,baud,(254,line4,"light value = ", #sun," ")
goto main
;JOBS
job1:
gosub clearlcd
serout c.0,baud,(254,line1,253,2)
i2cslave mem,i2cfast,i2cword
readi2c mintemp,(w10)
gosub checkpoint
serout c.0,baud(254,line3," Temp",b8,b7,b6,".",b5,b4,"c")
i2cread maxtemp,(w10)
gosub checkpoint
serout c.0,baud,(254,line4," Max Temp",b8,b7,b6,".",b5,b4,"c")
wait 3
return
job2:
gosub clearlcd
serout c.0,baud,(254,line1,253,3)
wait 2
return
job3:
gosub clearlcd
serout c.0,baud,(254,line1,253,4)
wait 2
return
job4:
gosub clearlcd
serout c.0,baud,(254,line1,253,5)
wait 2
return
;**************************************
;SubRounites
checkmin: 'record MIN & MAX temps in memory.
i2cslave MEM,i2cfast,i2cword
readi2c mintemp,(w12)
if w11<w12 then 'Check is w11 less then w12 in mem
writei2c mintemp,(w11)
endif
return
checkmax:
i2cslave MEM,i2cfast,i2cword
readi2c maxtemp,(w12)
if w11>w12 then 'Check is w11 more then w12 in mem
writei2c maxtemp,(w11)
endif
return
;--------------------------------------------
gettime:
i2cslave RTC,i2cslow,i2cbyte 'set up i2c DS1307 RTC
readi2c 0,(b0,b1,b2,b3,b4,b5,b6,b7) 'read Time and Date
return
convert:
bcdtoascii b0,b19,b20 'Secs Convert to ASCII
bcdtoascii b1,b8,b9 'Mins
bcdtoascii b2,b10,b11 'Hours
bcdtoascii b3,b21,b22 'DayOfWeek
bcdtoascii b4,b12,b13 'Date
bcdtoascii b5,b14,b15 'Month
bcdtoascii b6,b16,b17 'Year
return
;--------------------------------------------------
tempIn:
Readtemp12 intemp,w10 'read in result from ds18b20 and convert to 0.06 RES
w11=w10
let b9 =160 'Display space (32)
if w10 > 64655 then 'info - 55 degrees = 64656
let b9 =45 'Display - (45) MINUS
w10 = - w10 'info if - ie w1=1000 display - 10.00 C
endif
w10 = w10 * 50 / 8 'info + ie w1=8500 display 85.00 C
bintoascii w10,b8,b7,b6,b5,b4
if b8 = "0" then : b8 = " " :endif ' zero blanking b8
if b8 = " " and b7 = "0" then : b7 = " " :endif ' zero blanking b7
return
;--------------------------------------------------
tempOut:
Readtemp12 outtemp,w10 'read in result from ds18b20 and convert to 0.06 RES
let b9 =160 'Display space (32)
if w10 > 64655 then 'info - 55 degrees = 64656
let b9 =45 'Display - (45) MINUS
w10 = - w10 'info if - ie w1=1000 display - 10.00 C
endif
w10 = w10 * 50 / 8 'info + ie w1=8500 display 85.00 C
bintoascii w10,b8,b7,b6,b5,b4
if b8 = "0" then : b8 = " " :endif ' zero blanking b8
if b8 = " " and b7 = "0" then : b7 = " " :endif ' zero blanking b7
return
;---------------------------------------------------
keys:
readadc key,b11
if b11=0 then return:endif
if b11=113 then goto job1
if b11=69 then goto job2
if b11=28 then goto job3
if b11=46 then goto job4
return
;---------------------------------------------------
ClearLcd:
serout c.0,baud,(254,line1," ")
serout c.0,baud,(254,line2," ")
serout c.0,baud,(254,line3," ")
serout c.0,baud,(254,line4," ")
return
;----------------------------------------------------
checkpoint:
let b9 =160 'Display space (32)
if w10 > 64655 then 'info - 55 degrees = 64656
let b9 =45 'Display - (45) MINUS
w10 = - w10 'info if - ie w1=1000 display - 10.00 C
endif
w10 = w10 * 50 / 8 'info + ie w1=8500 display 85.00 C
bintoascii w10,b8,b7,b6,b5,b4
if b8 = "0" then : b8 = " " :endif ' zero blanking b8
if b8 = " " and b7 = "0" then : b7 = " " :endif ' zero blanking b7
return
;****************************************************