#picaxe 40x2
#no_data
table 0,("JAN",0,"FEB",0,"MAR",0,"APR",0,"MAY",0,"JUN",0,"JUL",0,"AUG",0,"SEP",0,"OCT",0,"NOV",0,"DEC",0,0)
table 50,("MON",0,"TUE",0,"WEN",0,"THU",0,"FRI",0,"SAT",0,"SUN",0,0)
symbol usbon=b1 ' Data storage on or off
symbol pointer=b2 'setpointer and equipment selection in keypad
symbol marker =b3 'b5 interupt marker between program slots
symbol themode=b4 'program location pointer
'***********************
'*************************************
'TEMPRETURE
symbol vT = b9 ' the preset value for Temperature obtained from keypad
symbol vC=b10 'for setting night tempreture if diffrent tempreture required
symbol fr=b54
'*******************************
'Humidity
symbol vHl=b14 ' the preset value for RHidity minimum value via keypad
symbol vH = b15 ' the value maximum for RHidity via keypad
symbol RH=b16 ' RHidity value obtained from sensor
'*********************************************************************************************
'SETTING VARIABLES FOR DS1307
symbol datebcd=b19
symbol monthbcd=b20
symbol yearbcd=b21 'Variables from keypad converted at SetRTC to BCD
symbol daybcd=b22 'Loaded into the DS1307
symbol hourbcd=b23
symbol minbcd=b24
symbol secbcd=b25
'******************************************************************
'PICAXE VARIABLES FOR CONVERTED VALUES FROM I2C CLOCK
symbol sec =b26
symbol hour=b27
symbol mins=b28 'Read back variables from the DS1307 using the DS1307 as the
symbol day=b29 'Timer for the Data Logging and Display
symbol month=b30 'hour = hourbcd / 16 * $FA + hourbcd Hippy's solution for BCD to Dec conversion
symbol year=b31
symbol date=b32
symbol TD5=b42 symbol TD4=b43 symbol TD3=b44 symbol TD2=b45 symbol TD1=b46 symbol TD0=b47
symbol ii=b48
symbol Auto=b49
symbol optH=b55
symbol fsin=105
symbol mdptr=200
symbol rtnptr=201
symbol mtvl=211
symbol dyvl=212
symbol QT=34
symbol control=$10
hi2csetup i2cmaster, %11010000, i2cslow_8, i2cbyte
hi2csetup i2cslave, %11010000
hsersetup B9600_8, %0
pause 1000
upload:
bptr=1
poke fsin,bptr
bptr=0
peek mdptr, themode
poke rtnptr,theMode
main:
hsersetup B9600_8, %0
pause 500
if theMode=0 then:hserout 0,("page 3",QT,$FF,$FF,$FF) 'time and date settings for first power up or loss
elseif theMode=1 or themode=2 then:hserout 0, ("page 0",QT,$FF,$FF,$FF) 'operation settings for all variables
elseif themode=6 then: goto error 'clock not set warning page
endif
peek dyvl,ii 'day selection pointer updated in slots 1&2
if ii<50 then:ii=50:endif
poke dyvl,ii
peek mtvl,auto 'month selection pointer updated in slots 1&2
if auto>47 then:auto=0:endif
poke mtvl,auto
hserflag=0
pick:
pointer=0:marker=0
do
hserin 0,2 'variable settings and operation selection
if hserflag <>0 then : if hserptr < 2 then: pause 10 : endif :endif: get 0,pointer:get 1,marker
select case pointer
case "Q" if marker="A" then:hserout 0, ("page 1",$FF,$FF,$FF):theMode=1:gosub QTF:gosub HP:goto pick
else
hserout 0, ("page 2",$FF,$FF,$FF):theMode=2:gosub QTF:gosub HP:goto pick
endif
case "Z" if marker="X" then goto leave
case "R" if marker="T" then:gosub set_clock:pause 10:goto main:endif
case "T" if marker="M" then:@bptr=1:poke fsin,@bptr:hserout 0,("page 3",$FF,$FF,$FF):themode=0:gosub QTF:gosub HP:goto pick:endif
case "A" if marker="L" then:hserout 0,("page 4",$FF,$FF,$FF)themode=1:gosub QTF:gosub HP:goto pick:endif
case "H" if marker="P" then:goto pick endif 'removed gosub to fit forum size
case "!" if marker="!" then: theMode=1:poke mdptr,theMode:poke rtnptr,themode:poke fsin,themode:goto leave:endif
case "&" if marker="&" then: theMode=2:poke mdptr,theMode:poke rtnptr,themode:poke fsin,themode:goto leave:endif
endselect
pointer=pointer-65 'converts ascii capitals to 0 1 2 ect for the ongosub
if pointer<11 then
on pointer gosub n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10
endif
gosub QTF
gosub HP
pause 10
debug
loop
n0:'"A"
if marker="+" then
inc vT
elseif marker="-" then
dec VT
elseif marker="^" then
vT=vT+10
endif
if vT <0 or vT >200 then:vT=0:endif
hserout 0, ("svt.txt=",QT,#vT)
return
n1:'"B"
if marker="+" then
inc vC
elseif marker="-" then
dec vC
elseif marker="^" then
vC=vC+10
endif
if vC <0 or vC >200 then:vC=0:endif
hserout 0, ("svc.txt=",QT,#vC)
return
n2:'"C"
if marker="+" then
inc vHl
elseif marker="-" then
dec vHl
elseif Marker="^" then
vhl=vhl+10
endif
if vHl <0 or vHl >100 then:vHl=0:endif
hserout 0, ("svhl.txt=",QT,#vHl)
return
n3:'"D"
if marker="+" then
inc vH
elseif marker="-" then
dec vH
elseif marker="^" then
vH=vH+10
endif
if vH <0 or vH >100 then:vH =0:endif
hserout 0, ("svh.txt=",QT,#vH)
return
n4:'"E"
if marker="+" then
inc day
elseif marker="-" then
dec day
elseif marker="E" and day>=1 then 'entre value for clock
daybcd = day / 10 * 6 + day
elseif marker="E" and day<=0 then 'if enter pressed before any value
day=1
daybcd = day / 10 * 6 + day
endif
if day<1 or day>=7 then: day=1:endif
select case day
case 1 ii=50
case 2 ii=54
case 3 ii=58
case 4 ii=62
case 5 ii=66
case 6 ii=70
case 7 ii=74
endselect
bptr=ii
hserout 0, ("day.txt=",QT)
readtable bptr,ii
inc bptr
do until ii = 0
hserout 0, (ii)
readtable bptr,ii
inc bptr
loop
poke dyvl,ii
return
n5:'"F"
if marker="+" then
inc date
elseif marker="-" then
dec date
elseif marker="F" then
endif
'date = datebcd / 16 * $FA + datebcd
datebcd=date/10*6+date
hserout 0, ("date.txt=",QT,#date)
if date<0 or date>=31 then:date=0:endif
return
n6: '"G"
if marker="+" then
inc month
elseif marker="-" then
dec month
elseif marker="G" and month>=1 then
monthbcd=month/10*6+month
elseif marker="G" and month<=0 then
month=1
monthbcd=month/10*6+month
endif
if month<1 or month >12 then:month=1:endif
select case month
case 1 auto=0:case 2 auto=4:case 3 auto=8:case 4 auto=12
case 5 auto=16:case 6 auto=20:case 7 auto=24:case 8 auto=28
case 9 auto=32:case 10 auto=36:case 11 auto=40:case 12 auto=44
endselect
bptr=auto
hserout 0, ("mth.txt=",QT)
readtable bptr,auto
inc bptr
do until auto = 0
hserout 0, (auto)
readtable bptr,auto
inc bptr
loop
poke mtvl,auto
return
n7:'"H"
if marker="+" then
inc year
elseif marker="-" then
dec year
endif
if year=0 or year>200 then:year=1:endif
year=10+year
hserout 0, ("yr.txt=",QT,"20",#year)
year=year-10
yearbcd = year / 10 * 6 + year
return
n8:'"I"
if marker="+" then
inc hour
elseif marker="-" then
dec hour
endif
if hour<0 or hour>23 then:hour=0:endif
hserout 0, ("hr.txt=",QT,#hour)
hourbcd = hour / 10 * 6 + hour
return
n9:'"J"
if marker="+" then
inc mins
elseif marker="-" then
dec mins
endif
if mins<0 or mins>59 then:mins=0:endif
hserout 0, ("mins.txt=",QT,#mins)
minbcd = mins / 10 * 6 + mins
RETURN
N10:'"K"
if marker="+" then
inc fr
elseif marker ="-" then
dec fr
endif
if fr <0 or fr >200 then:fr=0:endif
hserout 0, ("fr.txt=",QT,#fr)
RETURN
set_clock:
themode=3
debug
hsersetup off 'only added to see if commands clash
secbcd=$14
hi2cout 0, (secbcd,minbcd,hourbcd,daybcd,datebcd,monthbcd,yearbcd,control) ' DS1307 RTC,0,1,2,3,4,5,6,7
pause 50
hi2cin 0, (TD0,TD1,TD3,TD4,TD5)
if TD0<>secbcd then:themode=6:endif
if TD1<>minbcd then:themode=6:endif
if TD2<>hourbcd then:themode=6:endif
if TD3<>daybcd then:themode=6:endif
if TD4<>datebcd then:themode=6:endif
if TD5<>monthbcd then:themode=6:endif
hsersetup B9600_8, %0 'only added due to hanging
if themode=6 then:hserout 0,("page 9",$FF,$FF,$FF):gosub QTF:gosub HP
else
hserout 0,("page 0",$FF,$FF,$FF):gosub QTF:gosub HP
endif
return
error:
pointer=0:marker=0
hsersetup B9600_8, %0
hserout 0, ("page 9",$FF,$FF,$FF)
do
get 0,pointer
get 1,marker
loop until pointer="T" and marker="M"
goto pick
QTF:
hserout 0,(QT,$ff,$ff,$ff) 'command for nextion
return
HP:
hserflag=0
hserptr=0
pointer=0
marker=0
return
leave:
hserflag=0
peek rtnptr,theMode
if theMode=1 then: Run 1:endif
if theMode=2 then: Run 2:endif
if theMode=0 then
hserout 0,("page 8",$ff,$ff,$ff)
endif
end
return
return