LPC1768--How to use RTC

Source: Internet
Author: User
Tags current time min
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.