[求助] 关于430 RTC的一个问题,请赐教

mjl-0708   2012-10-15 14:42 楼主
我用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);

回复评论 (2)

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.
没工作,没女人老婆,没宽带 ,  没钱
点赞  2012-10-15 15:10
解决了吗
点赞  2016-5-4 15:09
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复