Hi Tony,
The reason your Seconds field isn't updating is because you cannot just flip the WriteEnable bit (RTCCFG.5). You have to send an unlock sequence first (see 15.2.7 WRITE LOCK pg. 167 of the datasheet). You have to write $55, then $AA to EECON2 then the immediate next instruction can flip the RTCWREN bit. This is best done in raw assembler, and you should ensure that you are not interrupted during the sequence or else it fails. The result is returned in BCD format, and you need to read the register twice to ensure consistency in case you accidentally read it during a rollover.
The RTCC clock output enable " (dont know what this is ?) " allows you to turn on or off the RTCC output pin. This can be configured to be a 32kHz Clock output, a 1 Hz output, or an alarm match output.
The module I wrote works well and is tested in a production environment. The sample program may look complex, but that's only because it demonstrates pretty much every feature. At a basic level your program can be:
Code: Select all
Include "IntRTCC.bas"
Include "usart2.bas"
include "convert.bas" ' For dec to str conversions
Dim Time As TTime ' Create a structure to hold the time
USART2.SetBaudrate(br4800)
Time.Hour = 10 ' put in some default time to the Time structure
Time.Minute = 20
Time.Second = 30
IntRTCC.Write(Time) ' write them into the RTCC registers
IntRTCC.RTCEnable(true) ' start the RTCC running
While true
IntRTCC.Read(Time) ' Read out
USART2.Write(DecToStr(Time.Hour, 2),":",DecToStr(Time.Minute,2),":",DecToStr(Time.Second,2), " ", 13) ' Send via USART2
wend
I haven't tested on that particular device, but it all looks compatible. If you have any questions about it please feel free to ask.
Best Regards,
Rangerbob (Nathan)