?? smartclock_alarm.c
字號:
//
// File Name:smaRTClock_Alarm.c
//----------------------------------------------------------------------------
// Project Name: SmaRTClock
// Module Name: Alarm Setting
//----------------------------------------------------------------------------
//
// Company: Semiconductor Device Solution, Inc
// http://www.sdsi.com.tw/
//
// Engineer: Owen Chen
// Create Date: 19:51:30 03/25/2007
// Revision: 1.01
//
// Description: Setting a smaRTClock Alarm
// Step1). Disable smaRTClock Alarm Events (RTC0AEN = 0).
// Step2). Set ALARMn registers to the desired value.
// Step3). Enable smaRTClock Alarm Events (RTC0AEN = 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
typedef unsigned char uchar;
//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void RTC_Init(void); // smaRTClock Initialization
void ALARM_Set(void);
void Interrupt_Init(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
//-----------------------------------------------------------------------------
uchar data ALARM_data[6] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
// RTC register address
enum { CAPTURE0, CAPTURE1, CAPTURE2, CAPTURE3, CAPTURE4, CAPTURE5,
RTC0CN,
RTC0XCN,
ALARM0, ALARM1, ALARM2, ALARM3, ALARM4, ALARM5,
RAMADDR,
RAMDATA
};
//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
//start main
void main()
{
//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------
PCA0MD &= ~0x40; // disable WDT temporarily
// Unlock
RTC0KEY = 0xA5;
RTC0KEY = 0xF1;
ALARM_Set(); // Setting ALARM Time
Interrupt_Init();
// Read Time
while(1)
{
RTC_WRITE(RTC0CN, 0x91);
}
}
//-----------------------------------------------------------------------------
// Setting the smaRTClock Alarm
//-----------------------------------------------------------------------------
void ALARM_Set(void)
{
// Disable smaRTClock Allarm
RTC_WRITE(RTC0CN, 0x90); // point to RTC0CN
// smaRTClock Enable, smaRTClock Timer Run
// smaRTCLock Alarm Disable
// Setting ALARMn register
RTC_WRITE(ALARM0, ALARM_data[0]); // ALARM0
RTC_WRITE(ALARM1, ALARM_data[1]); // ALARM1
RTC_WRITE(ALARM2, ALARM_data[2]); // ALARM2
RTC_WRITE(ALARM3, ALARM_data[3]); // ALARM3
RTC_WRITE(ALARM4, ALARM_data[4]); // ALARM4
RTC_WRITE(ALARM5, ALARM_data[5]); // ALARM5
RTC_WRITE(RTC0CN, 0x98); // point to RTC0CN
// smaRTClock Enable, smaRTClock Timer Run
// smaRTCLock Alarm Enable
RTC_WRITE(RTC0XCN, 0x40); // point to RTC0XCN
// Crystal Mode
}
//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------
void Interrupt_Init()
{
EIE1 = 0x02; // EIE1: Extended Interrupt Enable 1
// Enable smaRTClock Interrupt
IE = 0x80; // Enable each interrupt
}
//-----------------------------------------------------------------------------
// smaRTClock interrupt ISR
//-----------------------------------------------------------------------------
//
// Description:
//
//-----------------------------------------------------------------------------
void smaRTClock_ISR(void) interrupt 8
{
}
//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -