LPC1768 -- How to use RTC

Publisher:独享留白1028Latest update time:2018-06-27 Source: eefocusKeywords:LPC1768  RTC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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


Keywords:LPC1768  RTC Reference address:LPC1768 -- How to use RTC

Previous article:LPC1768 clock detailed explanation
Next article:LPC1768 timer TIMER0

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号