⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtc.txt

📁 C8051实时时钟开发程序
💻 TXT
字号:
void RTC_Init(void)
{
	 RTC0KEY = 0xA5;                     // Unlock the RTC interface
	RTC0KEY = 0xF1;
	RTC0ADR = 0x06;                     // Point to RTC0CN
	RTC0DAT = 0x80;                     // Enable the RTC
	
	while ((RTC0ADR & 0x80) == 0x80);   // Poll on the BUSY bit
	RTC0ADR = 0x07;    // Point to RTC0XCN
	RTC0DAT = 0x40;    // Set the RTC for crystal mode, AGCEN
                                      // disabled, and BIASX2 disabled

	while ((RTC0ADR & 0x80) == 0x80);   // Poll on the BUSY bit
	RTC0ADR |= 0x80;
  	while ((RTC0ADR & 0x80) == 0x80);   // Poll on the BUSY bit
	
	 // Wait until the clock is valid
  	while ((RTC0DAT & 0x10) == 0x00)
	 {
     		RTC0ADR |= 0x80;D 
     		while ((RTC0ADR & 0x80) == 0x80);Jdqei
  	}
}


LONG RTC_Read(void)
{
	LONG s_counts_temp;
	s_counts_temp.l = 0;
	 while ((RTC0ADR & 0x80) == 0x80);   // Poll on the BUSY bit

	RTC0ADR &= 0xF0;
  	RTC0ADR |= 0x06;

	RTC0DAT = 0xD9;    // Initiate the transfer to the CAPTUREn
                           // registers
	while ((RTC0ADR & 0x80) == 0x80);   // Poll on the BUSY bit
// Poll on the RTC0CAP bit until it indicates the transfer to the CAPTUREn
// registers is complete
  RTC0ADR = 0x86;                     // Disable autoreads
  while ((RTC0ADR & 0x80) == 0x80);   // Poll on the BUSY bit
  while ((RTC0DAT & 0x01) == 0x01))
{
 	RTC0ADR |= 0x80;
    	 while ((RTC0ADR & 0x80) == 0x80);
  
}

RTC0ADR = 0x42;                     // Target the capture registers
                                      // the MSB of CAPTURE1 equals 1 sec
                                      // at 32.768 kHz
                                      // re-enable autoreads

RTC0ADR |= 0x80;

 while ((RTC0ADR & 0x80) == 0x80);   // Poll on the BUSY bit

 // CAPTURE2
  s_counts_temp.byte[3] = RTC0DAT;
while ((RTC0ADR & 0x80) == 0x80);   // Poll on the BUSY bit

// CAPTURE
  s_counts_temp.byte[2] = RTC0DAT;

while ((RTC0ADR & 0x80) == 0x80);   // Poll on the BUSY bit
// CAPTURE4Y
  s_counts_temp.byte[1] = RTC0DAT;

while ((RTC0ADR & 0x80) == 0x80);   // Poll on the BUSY bit
// CAPTURE
  s_counts_temp.byte[0] = RTC0DAT;

return s_counts_temp;               // Number of seconds
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -