I have a ProStart board and wanted to put an RTC with it. I found an Adafruit Arduino shield with RTC and MMC socket.
The RTC is a DS1307 which uses the I2C protocol for data transfer. The timeclock portion uses packed BCD to send/store data values.
Using ArmBasic has presented a challenge as there are '0's in the data stream, so many of the string functions can't be used.
'
Has anyone got ideas or experience along these lines? I think I have some BCD routines working, they are standalone though.
Getting them into and out of strings for display on an LCD/terminal isn't working. Maybe I need to revert to RXD / TXD for the
display part. Some of the stock I2C.bas routines appear to exit on a '0' value.
'
'TIA, olzeke51 aka. Gary
P.S. "simple" is in the mind of the dreamer !!!
Simple event logger
Re: Simple event logger
RTCs (real time clocks),.....I have created a short set of routines to simulate a
one-second time source{unfortunately it hogs the cpu for that time). You could
adjust it to compensate for other program functions. OR possibly use short routines
with a global variable for tracking [ie start = timer // if timer - start > xx then set global //
exit - until the global is 1 second.]
'
I am just going to check my event monitor AD pin every second so waiting is no issue
I may only print the time (to a future LCD?!?) every 5 minutes, but will print the
"event change" time.
*****************program listing **************** file is also attached****************
'***********************************************************
'
'these short routines will use the ARMBasic 'wait()' statement as a basic 1 second time source
'depending on how much printing there is - the value of the wait{millisecs] will need to be adjusted
'24 hour clock {ex-Navy!!]
'nn day is referred to as nn th (no 1st or 2nd, etc.-just all 'th')
'no day rollover check for end-of-the-month
'no bounds checks for improper values
'the "OO" are capital letter o's !!
'
' by Gary aka. olzeke51 on Coridium forum Aug 13,2014
'
'**********************************************************
'
dim rtc$(7) as string
dim rtc(7) as byte
dim choice, r_index, secs, mins, hours, days
dim secs$(1), mins$(1), hours$(1), days$(1) as string '2byte strings for printing
'
'
RTC_read_time:
print days$;"th ";hours$;":";mins$;":";secs$
return
'
'
SUB pretty_string (byref data$ as string)
if len(data$) = 1 then data$ = "O" + data$
END SUB
'
'
RTC_update_time:
wait(998) 'this is the value to adjust for program/print delays
secs = secs+1
secs$=str(secs)
gosub pretty_string (secs$)
if secs > 59
secs = 0
secs$=str(secs)
gosub pretty_string (secs$)
mins = mins +1
mins$=str(mins)
gosub pretty_string(mins$)
if mins > 59
mins = 0
mins$="OO"
hours = hours +1
hours$=str(hours)
gosub pretty_string(hours$)
if hours > 23
hours = 0
hours$="OO"
days = days +1
days$=str(days)
'not going to figure out day rollover here
endif
endif
endif
if secs = 0 then call RTC_read_time
if secs = 30 then call RTC_read_time
return
'
' *****************
Main:
'
print "starting Main:"
'
RTC_clear:
rtc$(0)= "D"
rtc$(1) = "D"
rtc$(2)= "H"
rtc$(3) = "H"
rtc$(4)= "M"
rtc$(5) = "M"
rtc$(6)= "S"
rtc$(7) = "S"
'
if choice = 2 then goto SetTime
MakeChoice:
choice = 0
print "1 for setting time, 2 to force time setting, else <enter> to monitor clock"
debugin choice
print "choice was ", choice
select case choice
case 2
goto RTC_clear
case 1
goto SetTime
case else
goto Status
endselect
print choice, " is not one of the choices"
wait (3000)
goto MakeChoice
SetTime:
r_index = 0
if rtc$(r_index) = "D" then
for r_index = 0 to 6 step 2
print chr(rtc$(r_index));" ? enter value"
debugin choice
rtc(r_index) = choice
next
endif
'
days=rtc(0)
days$=str(days)
' to pretty up your days do a gosub pretty_day routine
hours=rtc(2)
hours$=str(hours)
gosub pretty_string(hours$)
mins=rtc(4)
mins$=str(mins)
gosub pretty_string(mins$)
secs=rtc(6)
secs$=str(secs)
gosub pretty_string(secs$)
'
done:
print "time is set"
call RTC_read_time
'
print "now entering Monitor mode"
Status:
'
while 1
call RTC_update_time 'updates every second, prints every 30 seconds
loop
'
end
*************************
have fun !!!