the 1302 seems to have no defined por register settings, so why not write a couple of bytes to the rtc's ram when you set the time . on subsequent pic boot ups check the rtc ram for those bytes , if they are not set then run your settime code
the 1302 seems to have no defined por register settings, so why not write a couple of bytes to the rtc's ram when you set the time . on subsequent pic boot ups check the rtc ram for those bytes , if they are not set then run your settime code
I noticed you have "rtccontrol Var byte" but no value assigned to it, then used in the "gettime" sub-routine.
What is supposed to happen there?
I would also suggest using a button input to jump to "settime" so you only have to program once and just push the button to set the time while its running.
And add a While/Wend for the switch so it waits before going back or else it'll be continuously setting the time until you release the button.Code:' Main program loop - in this case, it only updates the LCD with the time mainloop: Gosub gettime ' Read the time from the RTC ' Display time on LCD Lcdout $fe, 1, hex2 rtcmonth, "/", hex2 rtcdate, "/" , hex2 rtcyear," " Lcdout $fe,$C0, hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec Pause 30 ' Do it about 3 times a second IF !switch THEN GOSUB settime Goto mainloop End
Code:settime: RST = 1 ' Ready for transfer Shiftout IO, SCLK, LSBFIRST, [$8e, 0] ' Enable write RST = 0 ' Reset RTC RST = 1 ' Ready for transfer ' Write all 8 RTC registers in burst mode Shiftout IO, SCLK, LSBFIRST, [$8e, 128] Shiftout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0] RST = 0 ' Reset RTC 'Shiftout IO, SCLK, LSBFIRST, [$8e, 128] WHILE !switch: WEND ' Wait until button is released Return
Louie
When a RTC is installed with battery backup the time only needs setting once. There are no routines within your code to utilise the settime: and by including the line
Shiftout IO, SCLK, LSBFIRST, [$8e, 128] writes are disabled.
Could I suggest you have two programs one to set the initial time which includes the settime:, without Shiftout IO, SCLK, LSBFIRST, [$8e, 128] line and a second program that does not include settime:.
You are stuck with a two stage programing process but the second program will not include the unused settime: code.
There are other alternatives as others have suggested one would be to read the date from the RTC and compare to the initial settings. What are the readings from the RTC before any time is set? Is the default reading on power up 01/01/00 for example. If so then simply test for the year being 00 and if it is set the time else skip over it.
Let me know what the default power up readings are and then I can help with the code.
Steve Earl www.datageo.co.uk
Hi Steve,
My apologies for the delay
Default Clock is:
01:01:00
00:00:80
Clock does not move
Regards,
Gavin
Gavin,
Gosub gettime before settime. Then if year =00 then settime also remove the disableing line "Shiftout IO, SCLK, LSBFIRST, [$8e, 128] "
Steve Earl www.datageo.co.uk
Yes we did, I was seeing if I could do a "one time" programming instead of 2, the rest is working 100%
Regards,
Gavin
Bookmarks