#picaxe 18m2
symbol loop_time=b1
symbol temp=b2
symbol light=b3
symbol sec=b4
symbol mins=b5
symbol hour=b6
symbol day=b7
symbol date=b8
symbol month=b9
symbol year=b10
symbol control=$10
symbol QT=34'34=" in ascii netion requires the commands to be sent in ("t1.txt="") the picaxe does not allow "" so suplliment it with 34 the ascii value
#Define ToBin(bcd) bcd / 16 * $FA + bcd 'Hippys coding for converting BCD to binary
#Define ToBcd(bin) bin / 10 * 6 + bin 'Hippys coding for converting binary to BCD
ent:
HI2CSETUP I2CMASTER, %11010000, I2CSLOW, I2CBYTE'ds1307 i2c address
hsersetup B9600_8, %0'setup for hser commands see manual not look for background
mins=0:hour=0:day=0:date=0:month=0:year=0'add your own time and dates in BCD
gosub set_clock
hserout 0,("page0",$FF,$FF,$FF)
do
do
hi2cin 1,(mins)
pause 50
loop until loop_time<>mins'gives a 1 minute cycle for reads
gosub display
loop
set_clock:
sec=30
sec=ToBcd(sec)
mins = ToBcd(mins)
hour= ToBcd(hour)
day = ToBcd(day)
date = ToBcd(date)
month = ToBcd(month)
year = ToBcd(year)
hi2cout 0,(sec,mins,hour,day,date,month,year,control)
pause 50
hi2cin 0, (b11,b12,b13,b14,b15,month,year)
if b11<>mins or b12<>hour or b13<>day or b14<>date then
hserout 0, ("t1.txt=",QT,"ERROR"):gosub QTF'check wiring power cycle
endif
return
display:
hi2cin 0,(sec,mins,hour,day,date,month,year)
loop_time=mins
hour = ToBin(hour)
mins = ToBin(mins)
sec = ToBin(sec)
date=ToBin(date)
month=ToBin(month)
year=ToBin(year)
hserout 0, ("t0.txt=",QT,#date,"/",#month,"/","20",#year)
gosub QTF
if hour>12 then:hour=hour-12:endif
if hour<10 and mins<10 then
hserout 0, ("t1.txt=",QT,"0",#hour,":","0",#mins) 'rtc clock hour
elseif hour<10 and mins>=10 then
hserout 0, ("t1.txt=",QT,"0",#hour,":",#mins) 'rtc clock hour
elseif hour>=10 and mins<10 then
hserout 0, ("t1.txt=",QT,#hour,":","0",#mins)
endif
gosub QTF
readtemp C.0,temp
readadc C.1,light
'save to eeprom at this point set the i2c address then read, write
hserout 0, ("t2.txt=",QT,"Temprature= ",#temp):gosub QTF
hserout 0, ("t3.txt=",QT,"Light value= ",#light):gosub QTF
'reset the clock HI2CSETUP I2CMASTER, %11010000, I2CSLOW, I2CBYTE
pause 20
return
QTF:
hserout 0,(QT,$ff,$ff,$ff)
return