I am back at trying to get RTCC working on a Pic. The chip is the 18f26J53. I have some old code where I am reading the time twice, the code loops till these two reads agree. Of course I didn't comment it and can't remember why I was doing this. I have been looking through the datasheet as to what would make me read twice and loop but just not seeing it. So of course I just figured I was nuts so decided to check microchip's library. Lo and behold, they are reading multiple times too. I have posted their code below.
Why are we both reading twice than looping? Where would I have come up with that idea?
EDIT: This is the on board RTCC.
Why are we both reading twice than looping? Where would I have come up with that idea?
EDIT: This is the on board RTCC.
Code:
void RtccReadTime(rtccTime* pTm)
{
rtccTimeDate rTD0, rTD1;
do
{
mRtccClearRtcPtr();
mRtccSetRtcPtr(RTCCPTR_MASK_HRSWEEK);
rTD0.b[4]=RTCVALL;
rTD0.b[5]=RTCVALH;
rTD0.b[6]=RTCVALL;
rTD0.b[7]=RTCVALH;
// read the user value
mRtccClearRtcPtr();
mRtccSetRtcPtr(RTCCPTR_MASK_HRSWEEK);
rTD1.b[4]=RTCVALL;
rTD1.b[5]=RTCVALH;
rTD1.b[6]=RTCVALL;
rTD1.b[7]=RTCVALH; // read the user value
}while(rTD0.f.sec!=rTD1.f.sec); // make sure you have the same sec
pTm->f.hour=rTD0.f.hour;
pTm->f.min=rTD0.f.min;
pTm->f.sec=rTD0.f.sec; // update user's data
}
Last edited: