cfg_loop:
M_Clock:
'sec (& oscillator enable), Min, Hr, DoW, Day, Mo, Yr, Control register
'Year
YearRep:
'sertxd ("set clock YEAR Please Enter 00-99",cr,lf)
GoSub RTC_IR
b4 = b0
'Month
MonthRep:
'sertxd ("set clock MONTH Please Enter 01-12",cr,lf)
GoSub RTC_IR
If b0 < 1 OR b0 >18 then
gosub M_Error
goto MonthRep
Endif
b5 = b0
'Day
DayRep:
'sertxd ("set clock DAY Please Enter 01-29/30/31",cr,lf)
GoSub RTC_IR
If b0 < 1 OR b0 >49 then
gosub M_Error
goto DayRep
Endif
b6 = b0
'DoW # 1 - 7 sets first day of week - we don't care as we don't use this - just set to 1
'
'Hour
HourRep:
'sertxd ("set clock HOUR Please Enter 00-23",cr,lf)
GoSub RTC_IR
If b0 >35 then
gosub M_Error
Goto HourRep
Endif
b7 = b0
'Minute
MinRep:
'sertxd ("set clock MINUTE Please Enter 00-59",cr,lf)
GoSub RTC_IR
If b0 >89 then
gosub M_Error
goto MinRep
Endif
b8 = b0
'Second - highest bit must be 0 so oscillator is enabled
SecRep:
'sertxd ("set clock SECOND Please Enter 00-59",cr,lf)
GoSub RTC_IR
If b0 >89 then
gosub M_Error
goto SecRep
Endif
b9 = b0
'Control register
'%00010000 'bit 4 = 1 is square wave out at 1Hz
'
hi2csetup i2cmaster,RTC_0,i2cSlow_16,i2cbyte 'hi2c setup line only required once per POR
' S, M, H, Dow,D, M, Yr,Control
hi2cout 0, (b9,b8,b7,$01,b6,b5,b4,%00010000)
'Configure clock control register and set time/date - only required once per power up of Clock
'Ensure DOW matches Date
'$xx is the number you want for the date/time
' e.g. $07 (or $7) is the year 07, $10 is 10 for October
'Highest bit of secs must be 0 to enable oscillator - simplest to set seconds at $00
'If the set hour is from 1 to 23 then the hours will be in 24Hr mode
' as bit6 needs to be set to 1 to enable 12 hr mode ($4C or %01001100 for 12 hr/12 o'clock)
RTC_IR:
GoSub GetIR
b0 = b1 +"0"
GoSub GetIR
b1 = b1 +"0"
b0 = b0-$30*16+b1-$30
Return
GetIR:
IRIN [10000,cfg_loop],cfg_in, w1 'wait 2.5 secs for input
pause 1000
b1 =w1-11263 ' using modern remote which returns Sony remote number + 11263
if b1 =10 then let b1=0 :EndIf
Return