我用RTC实现日历功能,使用BCD编码,提供设置日期功能。在设置年份是,当增大或减小年份数值,都能写入RTCYEAR寄存器,
但是当设置月份和day时,有时出现,增加或者减小数值后,执行写入寄存器功能,写不进去(寄存器不变)。
int SetRTCDAY(unsigned char day)
{
RTCDAY = (day);//
return 1;
}
红色执行寄存器写入,但是执行后寄存器值不变?不知道为什么。
还有就是如下现象,不断减小day值,从0x30减 1,BCD码应该为0x29,下面程序计算的结果是正确的,当执行蓝色的寄存器写入
语句后,寄存器值变成了0x38. 不知道这是什么原因?
if(dayBCD == 0x01)
dayBCD = 0x31;
else if((dayBCD & 0x0F) == 0)
{
dayBCD -= 0x10;
dayBCD |= 0x09;
}
else
dayBCD--;
SetRTCDAY(dayBCD);
RTCCTL1里RTCBCD设置为 RTCBCD_H了么?
什么型号的cpu?什么类型的RTC?你是怎么读的?开发环境查看?
Because the system clock may in fact be asynchronous to the RTC_X clock source, special care must be
used when accessing the real-time clock registers.
When the counter clock is asynchronous to the CPU clock, any read from any RTCSEC,
RTCMIN, RTCHOUR, RTCDOW, RTCDAY, RTCMON, or RTCYEAR register while the
RTCRDY is reset may result in invalid data being read. To safely read the counting registers,
either polling of the RTCRDY bit or the synchronization procedure previously described can
be used. Alternatively, the counter register can be read multiple times while operating, and a
majority vote taken in software to determine the correct reading.