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

📄 smartclock_settime.c

📁 SmaRTclock Silicon labs Real Time Clock 實現
💻 C
字号:
//
// File Name:smaRTClock_SetTime.c
//----------------------------------------------------------------------------
// Project Name: SmaRTClock
// Module Name:  Set CAPTUREn Value
//----------------------------------------------------------------------------
//
// Company: Semiconductor Device Solution, Inc
// http://www.sdsi.com.tw/
//
// Engineer: Owen Chen
// Create Date: 11:00:30 03/25/2007 
// Revision:
//
// Description: Setting the smaRTClock Timer Value
//              Step1). Write the desired value  to the CAPTUREn registers
//              Step2). Write "1" to RTC0SET
//              Step3). Operation is complete when RTC0SET is cleared to "0"
//               
//                                           
// 
// Target Devcies: C8051F412
//
// Tool Chain: Tool chain: KEIL Eval 'c'
// Copyright Semiconductor Device Solution, Inc.All Rights Reserved

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <c8051f410.h>                 // SFR declarations

//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------

void RTC_Init(void);                       // smaRTClock Initialization
void CAPTURE_Set(void);

//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------

#define RTC_WAIT()                      while ( RTC0ADR & 0x80)   // Poll on the BUSY bit
#define RTC_WRITE( addr, dat )         { RTC_WAIT(); RTC0ADR = (addr)   ; RTC0DAT = dat; }

//-----------------------------------------------------------------------------
// Global VARIABLES
//-----------------------------------------------------------------------------

// RTC register address

enum {    CAPTURE0, CAPTURE1, CAPTURE2, CAPTURE3, CAPTURE4, CAPTURE5,   
          RTC0CN, 
          RTC0XCN,
          ALARM0, ALARM1, ALARM2, ALARM3, ALARM4, ALARM5,     
          RAMADDR,    
          RAMDATA
};

// 1 sec  0x00, 0x00, 0x01, 0x00, 0x00, 0x00 --> 10000
// 1 min  0x00, 0x00, 0x3C, 0x00, 0x00, 0x00 --> 3C0000
// 1 hour 0x00, 0x00, 0x10, 0x0E, 0x00, 0x00 --> E100000
// 1 day  0x00, 0x00, 0x80, 0x51, 0x01, 0x00 --> 151800000
// 1 week 0x00, 0x00, 0x80, 0x3A, 0x09, 0x00 --> 93A800000
// 1 year 0x00, 0x00, 0x50, 0xBC, 0x2F, 0x00 --> 2FBC500000


//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
//start main

void main()
{   
    
//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

     PCA0MD &= ~0x40;    // disable WDT temporarily 
          
     // Unlock
	 RTC0KEY   =  0xA5;              
	 RTC0KEY   =  0xF1;
	 
	 //CAPTURE_Set();
	 
	 
	 RTC_Init();        // RTC Initial

// Read Time
     
	 while(1)
	 	{

		   RTC_WRITE(RTC0CN, 0x91);		   

		}
			 
}

//-----------------------------------------------------------------------------
// smaRTClock Interface
//-----------------------------------------------------------------------------

void RTC_Init(void)
{
     
	 RTC_WRITE(RTC0CN, 0x90);	 // point to RTC0CN
	                             // smaRTClock Enable , smaRTClock Timer Run  

	 RTC_WRITE(RTC0XCN, 0x40);   // point to RTC0xCN
                                 // Crystal Mode

}

//-----------------------------------------------------------------------------
// Setting the smaRTClock Timer Value
//-----------------------------------------------------------------------------

void CAPTURE_Set(void)
{
     RTC_WRITE(CAPTURE0, 0x00);   // CAPTURE0

	 RTC_WRITE(CAPTURE1, 0x00);   // CAPTURE1

	 RTC_WRITE(CAPTURE2, 0x34);   // CAPTURE2

	 RTC_WRITE(CAPTURE3, 0x8D);   // CAPTURE3

	 RTC_WRITE(CAPTURE4, 0x07);   // CAPTURE4

	 RTC_WRITE(CAPTURE5, 0x46);   // CAPTURE5

	 RTC_WRITE(RTC0CN, 0x92);     // smaRTClock Set 

}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

⌨️ 快捷键说明

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