?? smartclock_settime.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 + -