I am using this bit of code to call an external eeprom write routine.
expecting to store data at 29 minutes and 59 minutes past the hour.
In essence it works, but looking at the eeprom dump it is timed at 20 minutes past, and not 29.
The 59 minute seems ok.
Any ideas please
Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Note HourHi=b11,HourLo=b12,MinHi=b7,MinLo=b8
check_it:
if b7=2 or b7=5 and b8=9 Then
If flag = 0 Then gosub count_it
flag = 1
Else flag = 0
End If
return
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
In essence it works, but looking at the eeprom dump it is timed at 20 minutes past, and not 29.
The 59 minute seems ok.
I can only guess that the reason is buried somewhere somewhere in the complete code.Next Address is 224
Start Date 20/12
Time Low High
19:20 0 0
19:59 17 18
20:20 18 20
20:59 18 20
21:20 18 19
21:59 17 18
22:20 17 18
22:59 15 18
23:20 14 15
23:23 14 14
23:59 12 14
00:20 11 12
00:59 10 11
01:20 10 10
Code:
'08m2 Min/Max with reset and log
'Working 05/12/11
'modified and checked 09/12/11
#picaxe08M2
#No_Data
init:
symbol MINTEMP = b1
symbol MAXTEMP = b2
symbol NOWTEMP = b4
symbol LCD= c.0
symbol DEG= c.4
symbol WIPEIT= pinc.3
Symbol flag=w13
Symbol address=w12
let address=8
serout LCD,N2400,(254,1,254,1) 'clear screen
pause 200
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
gosub wipe
hi2csetup i2cmaster, %10100000, i2cslow, i2cword 'set up eeprom
hi2cout 0,(address)
pause 100
hi2cout 1,(b9,b10,b2,b3)
pause 100
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Main:
'if WIPEIT=1 then gosub wipe ' Reset values to zero
gosub timeit 'Get current time
gosub check_it
gosub disp1
gosub get_temp
gosub check 'check for neg values & display
goto main ' Doit again
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
get_temp:
ReadTemp DEG, NOWTEMP Read 0, MINTEMP
Read 1, MAXTEMP
Read 2,b5:Read 3,b6:read 4,b7
Read 5,b8:read 6,b9:read 7,b10
If MINTEMP = 0 And MAXTEMP = 0 Then
MINTEMP = 255
End If
If NOWTEMP < MINTEMP Then
MINTEMP = NOWTEMP
Write 0, MINTEMP
End If
If NOWTEMP > MAXTEMP Then
MAXTEMP = NOWTEMP
Write 1, MAXTEMP
End If
return
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
timeit:
i2cslave %11010000, i2cslow, i2cbyte
readi2c 0,(b0,b1,b2,b3,b4,b5,b6)
pause 100
b11=b2/16 'hour MSD
b12=b2 & $0F 'hour LSD
b7=b1/16 'min MSD
b8=b1 & $0F 'min LSD
b9=b4/16 'day MSD
b10=b4 & $0F 'day LSD
b2=b5/16
b3=b5 & $0F
b0=b6/16:b4=b6 & $0F
return
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
check:
if NOWTEMP > 127 then neg2
serout LCD,N2400,(254,192,"Temp ",#NOWTEMP,$df,"C ")
pause 5000
serout LCD,N2400,(254,128," ")
goto checkmin
neg2:
let NOWTEMP = NOWTEMP - 128 ‘ adjust neg value
serout LCD,N2400,(254,128,"Temp -",#NOWTEMP,$df)
checkmin:
if MINTEMP > 127 then neg3 'test negative
serout LCD,N2400,(254,128,"Lo ",#MINTEMP,$df," ")
goto checkmax
neg3:
let MINTEMP = MINTEMP - 128 'adjust neg value
serout LCD,N2400,(254,128,"Lo -",#MINTEMP,$df)
checkmax:
if MAXTEMP > 127 then neg4 'test for negative
serout LCD,N2400,(254,136,"Hi ",#MAXTEMP,$df)
goto fini
neg4:
let MAXTEMP = MAXTEMP - 128 ' adjust neg value
serout LCD,N2400,(254,136,"Hi -",#MAXTEMP,$df)
fini:
serout LCD,N2400,(254,192,"R/S ",#b11,#b12,":",#b7,#b8," Z= ",#address)
pause 5000
serout LCD,N2400,(254,1,254,1)
return
''''''''''''''''''''''''''''''''''''''''''''''''''''''
wipe:
gosub timeit
write 0,0:write 1,0
write 2,b11:write 3,b12:write 4,b7
write 5,b8:write 6,b0:write 7,b4
return
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
disp1:
serout LCD,N2400,(254,128,#b11,#b12,":",#b7,#b8," ") 'H/M
serout LCD,N2400,(254,136,#b9,#b10,"/",#b2,#b3,"/",#b0,#b4)
return
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
count_it:
Read 0, MINTEMP:pause 100
Read 1, MAXTEMP:pause 100
hi2csetup i2cmaster, %10100000, i2cslow, i2cword 'set up eeprom
hi2cin 0,(address) 'get next address from location zero
pause 200
hi2cout address,(b11,b12,b7,b8,mintemp,maxtemp) ' HH MM
pause 200
let address=address+8
pause 200
hi2cout 0, (address) 'and write it to location zero
pause 200
gosub wipe
return
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Note HourHi=b11,HourLo=b12,MinHi=b7,MinLo=b8
check_it:
if b7=2 or b7=5 and b8=9 Then
If flag = 0 Then gosub count_it
flag = 1
Else flag = 0
End If
return
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Last edited: