1. 程序实现
5.1时钟设置
void Rtc_Init(void)
{
rRTCCON = 0x01; //RTC读写使能,选择BCD时钟、计数器,
//无复位,1/32768
rBCDYEAR = 0x05 ; //设定年
rBCDMON = 0x09 ; //设定月
rBCDDAY = 0x05 ; //设定日
rBCDDATE = 0x2 ; //设定星期
rBCDHOUR = 0x11 ; /设定小时
rBCDMIN = 0x23 ; //设定分钟
rBCDSEC = 0x12 ; //设定秒
rRTCCON = 0x0; //RTC读写禁止,选择BCD时钟、计数器,
//无复位,1/32768
}
5.2时钟显示
void Display_Rtc(void)
{
int year;
int month,day,weekday,hour,min,sec;
rRTCCON = 0x01; //RTC读写使能,选择BCD时钟、计数器,无复位,1/32768
while(1)
{
if (rBCDYEAR == 0x99) year = 0x1999;
else year = 0x2000 + rBCDYEAR;
month=rBCDMON;
day=rBCDDAY;
weekday=rBCDDATE;
hour=rBCDHOUR;
min=rBCDMIN;
sec=rBCDSEC;
if(sec!=0) break;
}
Uart_Printf("RTCTIME:%4x/%02x/%02x%s%02x:%02x:%02x\n",year,month,day,date[ weekday],hour,min,sec);
rRTCCON = 0x0; //RTC读写禁止,选择BCD时钟、计数器,无复位,1/32768
}
5.3主程序
void Main(void)
{
SetClockDivider(1, 1);
SetSysFclk(DFT_FCLK_VAL);
Port_Init();
Uart_Select(0);
Uart_Init(0, UART_BAUD);
Rtc_Init(); //实时时钟初始化
printf("s3c2410x RTC Test\n");
while(1)
{
Display_Rtc();
Delay(100);
}
}
阅读(973) | 评论(0) | 转发(0) |