RTC实验步骤:
一、实时始终初始化
define TESTYEAR (0x99)
#define TESTMONTH (0x12)
#define TESTDAY (0x31)
#define TESTDATE (0x06) // SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
#define TESTHOUR (0x23)
#define TESTMIN (0x59)
#define TESTSEC (0x30)
#define TESTYEAR2 (0x00)
#define TESTMONTH2 (0x01)
#define TESTDAY2 (0x01)
#define TESTDATE2 (0x07) // SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
#define TESTHOUR2 (0x00)
#define TESTMIN2 (0x00)
#define TESTSEC2 (0x00)
void Rtc_Init(void)
{
rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset
rBCDYEAR = TESTYEAR;
rBCDMON = TESTMONTH;
rBCDDAY = TESTDAY; // SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
rBCDDATE = TESTDATE;
rBCDHOUR = TESTHOUR;
rBCDMIN = TESTMIN;
rBCDSEC = TESTSEC;
rRTCCON = 0x00;//读写禁止
}
二、显示当前时间
void Display_Rtc(void)
{
int year;
int month,day,weekday,hour,min,sec;
rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset
// Uart_Printf("This test should be excuted once RTC test(Alarm) for RTC initialization/n");
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("%4x,%2x,%2x,%s,%2x:%2x:%2x/n",year,month,day,date[weekday],hour,min,sec);
rRTCCON = 0x0; // R/W disable(for power consumption), 1/32768, Normal(merge), No reset
}
运行结果如下:
*************************************************************************
* 立泰电子工作室 *
* -S3C44B0X功能部件:RTC测试- *
* Version 1.11 *
* Email:rao_dali@263.net *
* UART Config--COM:115.2kbps,8Bit,NP,UART0 *
*------------------Begin to Start RTC test,OK? (Y/N)--------------------*
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:37
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:46
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:49
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:51
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:52
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:53
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:54
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:55
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:55
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:56
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:58
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:59
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
1999,12,31,FRI,23:59:59
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?1
2000, 1, 1,SAT, 0: 0: 2
1:RTC(display) 2:RTC(Alarm) 3:RTC Tick
Select the function to test?
注;此例是立宇泰的关于RTC测试的实验,此实验很简单没有太多要说明的地方,只要搞这行的应该很容易就能够清楚的。