起初我认为AC7802X的实时实钟会很难,我想留着以后再评吧。可是今天看了RTC说明突然开了悟了。
原来RTC只是个计数器。
我打开例程并没有发现RTC时钟的例程,到是有个秒中断例程,那也不要紧我把它的功能补全吧:
typedef struct
{
uint8_t year;
uint8_t mouth;
uint8_t day;
uint8_t hour;
uint8_t sec;
uint8_t min;
}rtc;
int main(void)
{
InitDelay(); /*! ÑÓʱº¯Êý³õʼ»¯ */
InitDebug(); /*! printfº¯Êý³õʼ»¯ */
GPIO_LedInit(); /*! GPIO_Led³õʼ»¯º¯Êý */
RTC_Timeout1s(); /*! RTC ³¬Ê±³¬Ê±1sº¯Êý³õʼ»¯ */
rtc rtcdata;
rtcdata.year=23;
rtcdata.mouth=8;
rtcdata.day=23;
rtcdata.hour=19;
rtcdata.min = 20;
rtcdata.sec = 19;
while (1)
{
if(g_timeoutFlag) /*! RTC ³¬Ê±±êÖ¾µ½ */
{
g_timeoutFlag = 0;
rtcdata.sec++;
if(rtcdata.sec == 60)
{
rtcdata.sec = 0;
rtcdata.min++;
}
if(rtcdata.min == 60)
{
rtcdata.hour++;
rtcdata.min=0;
}
if(rtcdata.hour==24)
{
rtcdata.day++;
rtcdata.hour=0;
}
if(rtcdata.day == 31)
{
rtcdata.mouth++;
rtcdata.day=0;
}
if(rtcdata.mouth == 12)
{
rtcdata.mouth =0;
rtcdata.year++;
}
//printf("RTC_Timeout1s Flag...\r\n");
printf("The Times is: %d, %d, %d, %d, %d, %d",rtcdata.year+2000,rtcdata.mouth,rtcdata.day,rtcdata.hour,rtcdata.min,rtcdata.sec);
}
}
}
编译运行结果如下:
总结一下RTC,这款RTC只能说是准RTC,要想断电保持住时间,本人认为不可能。因为没有地方加上3V电池。
|