今天移植代码发现rtc的这个函数,在设置年月日的时候成功,但是时分秒一直无法设置成功
void RTC_InitTime( UINT16 y, UINT16 mon, UINT16 d, UINT16 h, UINT16 m, UINT16 s )
{
UINT32 t;
UINT16 year, month, day, sec2, t32k;
UINT8V clk_pin;
year = y;
month = mon;
day = 0;
while ( year > BEGYEAR )
{
day += YearLength( year-1 );
year--;
}
while ( month > 1 )
{
day += monthLength( IsLeapYear( y ), month-2 );
month--;
}
day += d-1;
sec2 = (h%24)*1800+m*30+s/2;
t32k = (s&1)?(0x8000):(0);
t = sec2;
t = t<<16 | t32k;
do{
clk_pin = (R8_CK32K_CONFIG&RB_32K_CLK_PIN);
}while( (clk_pin != (R8_CK32K_CONFIG&RB_32K_CLK_PIN)) || (!clk_pin) );
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R32_RTC_TRIG = day;
R8_RTC_MODE_CTRL |= RB_RTC_LOAD_HI;
R32_RTC_TRIG = t;
R8_RTC_MODE_CTRL |= RB_RTC_LOAD_LO;
R8_SAFE_ACCESS_SIG = 0;
}
经过测试,发现在设置时分秒之前,重新开关一下
R8_SAFE_ACCESS_SIG = 0;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
能够解决该异常.
修改如下图所示:
|