The LPC internal RTC configuration is relatively straightforward, and its initialization method is as follows:
void Rtc_init (void)
{
pconp_bit. PCRTC = 1; Enable the peripheral clock for RTC
if (rtcccr_bit. Clken = = 0) {
RTCILR = 0;
RTCAMR = 0xFF;
Rtcciir = 0;
RTCCCR = 0;
Rtc_set_deftime ();
Rtc_start ();
}
}
Get the time function, where you need to create an RTC structure for storing time data.
typedef{
int8u U8_second;
int8u U8_minute;
int8u U8_hour;
int8u U8_daymonth;
int8u U8_dayweek;
int16u u16_dayyear;
int8u U8_month;
int16u u8_year;
}
void Rtc_get_time (rtc* pst_time)
{
pst_time->u8_year = rtcctime1_bit. YEAR-2000;
Pst_time->u8_month = Rtcctime1_bit. MON;
Pst_time->u16_dayyear = Rtcctime2_bit. Doy;
Pst_time->u8_dayweek = Rtcctime0_bit. DOW;
Pst_time->u8_daymonth = Rtcctime1_bit. DOM;
Pst_time->u8_hour = Rtcctime0_bit. HOUR;
Pst_time->u8_minute = Rtcctime0_bit. MIN;
Pst_time->u8_second = Rtcctime0_bit. SEC;
}
Also use the struct to initialize the time parameter
void Rtc_set_time (rtc* pst_time)
{
rtcsec_bit. SEC = pst_time->u8_second;
Rtcmin_bit. MIN = pst_time->u8_minute;
Rtchour_bit. HOUR = pst_time->u8_hour;
Rtcdom_bit. DOM = pst_time->u8_daymonth;
Rtcdow_bit. DOW = pst_time->u8_dayweek;
Rtcdoy_bit. Doy = pst_time->u16_dayyear;
Rtcmonth_bit. MON = pst_time->u8_month;
Rtcyear_bit. Year = Pst_time->u8_year +;
}
The configuration of RTC is completed by the above three functions.
void Testrtc (void)
{
rtc_get_time (&GETRTC);
static int8u Second = 0;
if (Second! = Getrtc.u8_second) {
Second = Getrtc.u8_second;
printf ("Current Data:%d-%d-%d\r\n", getrtc.u8_year+2000,getrtc.u8_month,getrtc.u8_daymonth);
printf ("Current time:%d:%d:%d\r\n", Getrtc.u8_hour,getrtc.u8_minute,getrtc.u8_second);
}
}
Test Result: The UART interface is printed on the PC computer serial monitor software.
Current DATA:2011-10-13
Current time:0:58:39
Current DATA:2011-10-13
Current time:0:58:40
Current DATA:2011-10-13
Current time:0:58:41
Current DATA:2011-10-13
Current time:0:58:42
Current DATA:2011-10-13
Current time:0:58:43
Current DATA:2011-10-13
Current time:0:58:44
Current DATA:2011-10-13
Current time:0:58:45
Current DATA:2011-10-13
Current time:0:58:56