The LPC internal RTC configuration is relatively simple, 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 to store 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 this structure to initialize the time parameters
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 + 2000;
}
The above three functions complete the RTC configuration.
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 results: Printed on the PC serial port monitoring software through the UART interface.
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
Previous article:LPC1768 clock detailed explanation
Next article:LPC1768 timer TIMER0
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- [RVB2601 creative application development] + light intensity detection
- 【DIY Creative LED】Effect Demonstration
- [GD32450I-EVAL] USART and DMA variable length reception
- ESP32-S3 Technical Reference Manual Latest Manual
- 【DSP】TMS320F28035 ADC routine (software trigger + query)
- Ask for help either
- STEVAL-MKI109V3 Unico-GUI cannot connect, prompting The adapter board has not been recognized
- [Xianji HPM6750 Review] +LVGL modified the touch screen, but failed, there was a problem with the touch
- 【GD32L233C-START review】+ external LCD screen debugging
- Leisure