LPC210X real-time clock operation program

Publisher:BeaLaity0170Latest update time:2014-12-12 Source: 51heiKeywords:LPC210X Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/************************Initialize real-time clock********************************************/
void RTCInit(void)
{
  YEAR = 2011; // Initial year
  MONTH = 12; // Initial month
  DOM = 6; // Initialization date
  HOUR = 12;
  MIN = 59;
  SEC = 50;
//If the day of the week is used, initialize it correctly here: DOW = (value 0~6) 
 
  CIIR = 0x01; // Set the increment of the second value to generate an interrupt
  CCR = 0x11; // Use independent oscillator to start RTC. (0x01, 0x10, 0x13 are not displayed)
}
 
void SendTimeRtc(void) // incorrect week number
{
  U32 times;
  U8 bak;
  times = CTIME0; // Read complete clock register 0
 
/*
  bak = (times>>24)&0x07; // Get the value of the week
  Send_BUF[2] = bak/10+'0';
  Send_BUF[3] = bak%10+'0';  
 // Send_BUF[4] = ':';
 
  DataDisp(bak/10,2,0); //Display the day of the week Why is the day of the week incorrect?
  Delay(4);
  DataDisp(bak%10,3,0);
  Delay(2);*/
  bak = (times>>8)&0x3F; // Get the value of the score
  Send_BUF[0] = bak/10+'0';
  Send_BUF[1] = bak%10+'0';  
  Send_BUF[2] = ':';
 
  DataDisp(bak/10,0,0); //Display minutes
  Delay(4);
  DataDisp(bak%10,1,1);
  Delay(2);
 
  bak = times&0x3F; // Get the value of seconds
  Send_BUF[3] = bak/10+'0';
  Send_BUF[4] = bak%10+'0';  
  Send_BUF[5] = ' ';
 
  DataDisp(bak/10,2,0); //Display minutes
  Delay(4);
  DataDisp(bak%10,3,0);
  Delay(2);
}
After working for a long time, the week was always wrong. Finally I figured it out, it turned out that the clock was not initialized in RTCInit().
Remember: If you want to get the day of the week, the day of the week register must be initialized, and then ARM will automatically calculate the day of the week data.
Keywords:LPC210X Reference address:LPC210X real-time clock operation program

Previous article:ARM LPC210X GPIO operation related registers
Next article:ADC test program for LPC210X

Latest Microcontroller Articles
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号