microman171
Member
Hey guys,
I have recently got my VDRIVE working, and am ready to start using it for data logging. My problem starts with my real time clock (DS1307); The number of bytes changes.
I have written my code to turn the BCD from the RTC into binary, and when turned into ASCII for writing to the VDRIVE, the number can either be single or double digit. The VDRIVE reads this as either one or two bytes.
How can I tell the VDRIVE how many bytes to write?
I was thinking padding with zeros, but I wouldn't know how to go about it.
While writing this, I thought of sending null bytes. Or maybe printing the CR at the start of the data, and then having extra bytes at the end in the form of spaces. These spaces would just get cut off if they weren't needed / wont fit.
Hopefully my code copies okay...
Thanks,
I have recently got my VDRIVE working, and am ready to start using it for data logging. My problem starts with my real time clock (DS1307); The number of bytes changes.
I have written my code to turn the BCD from the RTC into binary, and when turned into ASCII for writing to the VDRIVE, the number can either be single or double digit. The VDRIVE reads this as either one or two bytes.
How can I tell the VDRIVE how many bytes to write?
I was thinking padding with zeros, but I wouldn't know how to go about it.
While writing this, I thought of sending null bytes. Or maybe printing the CR at the start of the data, and then having extra bytes at the end in the form of spaces. These spaces would just get cut off if they weren't needed / wont fit.
Hopefully my code copies okay...
Code:
' microLOG
' Main Box
' Daniel Collins
symbol first_byte = b0
symbol point = b1
symbol temp = b2
symbol loopcounter = b3
Setup:
hsersetup b9600_4, %01
hi2csetup i2cmaster, %11010001, i2cslow, i2cbyte
Init:
pause 100
init_lcd:
sertxd ("Writing to LCD",CR,LF)
serout 0, n600, ("*L", $80, " micr")
pause 50
serout 0, n600, ("*L", "oLOG ")
sertxd ("Setting up VDRIVE",CR,LF)
init_vdrive:
sertxd ("<sent> E",CR,LF)
hserout 0, ("E",CR)
gosub get_response
if first_byte <> "E" then init_vdrive
pause 10
gosub get_time
gosub write_power
Main:
serin [200, skip], 2, n600, (":Q"), b4, b5
sertxd ("HOPE",#b4," ",#b5,CR,LF)
gosub get_time
gosub openwriteclose
skip:
readadc 0, b14
if b14 > 40 then gosub buttons
serout 1, n600, (":E")
goto main
get_time:
sertxd ("Getting Time")
hi2cin 6, (b13)
let b13 = bcdtobin b13
hi2cin 5, (b12)
let b12 = bcdtobin b12
hi2cin 4, (b11)
let b11 = bcdtobin b11
hi2cin 2, (b10)
let b10 = bcdtobin b10
hi2cin 1, (b9)
let b9 = bcdtobin b9
hi2cin 0, (b8)
let b8 = bcdtobin b8
sertxd (#b13," ",#b12," ",#b11," ",#b10," ",#b9," ",#b8,CR,LF)
return
get_response:
pause 1000
sertxd ("<Response> ")
point = 0
get point, first_byte
do
get point, temp
sertxd (temp)
inc point
loop while temp <> CR
sertxd (LF)
sertxd (CR,LF)
hserptr = 0
return
buttons:
inc b6
if b14 < 160 then gosub DS1
if b14 = 0 then return endif
if b14 < 230 then gosub DS2
if b14 > 240 then gosub DS3
return
DS1:
sertxd ("Button 1 was Pressed",CR,LF)
b14 = 0
return
DS2:
sertxd ("Button 2 was Pressed",CR,LF)
b14 = 0
return
DS3:
sertxd ("Button 3 was Pressed",CR,LF)
b14 = 0
return
openwriteclose:
sertxd ("<Sent> Check Drive",CR,LF)
hserout 0,(CR)
gosub get_response
if first_byte <> "D" then openwriteclose
sertxd ("<Sent> Open file",CR,LF)
hserout 0,("opw data.csv",CR)
gosub get_response
sertxd ("<Sent> write to file",CR,LF)
hserout 0,("wrf ",$00,$00,$00,$12,CR,#b13,"/",#b12,"/",#b11," ",#b10,":",#b9,":",#b8,",",#b4,",",#b5,",",#b6,$0A,CR)
gosub get_response
sertxd ("<Sent> Close file",CR,LF)
hserout 0,("clf data.csv",CR)
gosub get_response
return
write_power:
sertxd ("Writing power-on time",CR,LF)
sertxd ("<Sent> Check Drive",CR,LF)
hserout 0,(CR)
gosub get_response
if first_byte <> "D" then openwriteclose
sertxd ("<Sent> Open file",CR,LF)
hserout 0,("opw data.csv",CR)
gosub get_response
sertxd ("<Sent> write to file",CR,LF)
hserout 0,("wrf ",$00,$00,$00,$12,CR,#b13,"/",#b12,"/",#b11," ",#b10,":",#b9,":",#b8," POWER",$0A,CR)
gosub get_response
sertxd ("<Sent> Close file",CR,LF)
hserout 0,("clf data.csv",CR)
gosub get_response
return
Last edited: