?? pcf8563.h
字號:
/*
* 文件名 : PCF8563.H
* 作 者 : li.yao
* 日 期 : 2005年 02月 28日,星期一
* 描 述 : PCF8563實時時鐘芯片的API函數(shù)庫,僅供外部函數(shù)調(diào)用。
*/
#ifndef _RTC_PCF8563_
#define _RTC_PCF8563_
// 數(shù)據(jù)結(jié)構(gòu)
typedef struct { // (BCD CODE.)
unsigned char sec; // 0 -- 59 Seconds.
unsigned char min; // 0 -- 59 Minutes.
unsigned char hour; // 0 -- 23 Hours.
unsigned char day; // 1 -- 31 Days.
unsigned char week; // 0 -- 6 0 = Sunday.
unsigned char month; // 1 -- 12 Month.
unsigned int year; // BASE_YEAR -- BASE_YEAR + 199 Years.
}TIME;
// 宏定義函數(shù)
/*
* 函數(shù)名 : void OpenAlarm(void);
* 參數(shù)表 : none
* 返回值 : none
* 功 能 : 打開鬧鐘報警器 AIE = 1 ,軟件清AF為0。
*/
#define OpenAlarm( ) { SetPCF8563(0x01, GetPCF8563(0x01) | 0x02); }
/*
* 函數(shù)名 : void SetAlarm(unsigned char type, unsigned char ch);
* 參數(shù)表 : type: 要讀的時間類型。
* 0x09: minute; 0x0A: hour; 0x0B: day; 0x0C: week;
* ch: 要設(shè)置的時間值(BCD格式)。
* 返回值 : none
* 功 能 : 設(shè)置鬧鐘報警。例如:SetAlarm(0x0A, 23); // 在晚上11點報警。
*/
#define SetAlarm(type, ch) { SetPCF8563(type, ch + 0x80); }
/*
* 函數(shù)名 : void CloseAlarm(void);
* 參數(shù)表 : none
* 返回值 : none
* 功 能 : 關(guān)閉鬧鐘報警器 AIE = 0 。
*/
#define CloseAlarm( ) { SetPCF8563(0x01, GetPCF8563(0x01) & 0xFD); }
/*
* 函數(shù)名 : void OpenTimer(void);
* 參數(shù)表 : none
* 返回值 : none
* 功 能 : 打開定時器中斷 TIE = 1 ,軟件清TF為0。
*/
#define OpenTimer( ) { SetPCF8563(0x01, GetPCF8563(0x01) | 0x01); }
/*
* 函數(shù)名 : void SetTimer(unsigned char freq, unsigned char count);
* 參數(shù)表 : freq: 設(shè)置定時器的時鐘頻率。
* 0x00: 4096Hz; 0x01: 64Hz; 0x02: 1Hz; 0x03: 1/60Hz;
* count: 設(shè)置定時器的計數(shù)值。0x00 ~ 0xFF;
* 返回值 : none
* 功 能 : 設(shè)置定時器的定時值。
*/
#define SetTimer(freq, count) { SetPCF8563(0x0E, freq + 0x80); SetPCF8563(0x0F, count); }
/*
* 函數(shù)名 : void CloseTimer(void);
* 參數(shù)表 : none
* 返回值 : none
* 功 能 : 關(guān)閉定時器中斷 TIE = 0 。
*/
#define CloseTimer( ) { SetPCF8563(0x01, GetPCF8563(0x01) & 0xFE); }
/*
* 函數(shù)名 : void OpenClkOut(unsigned char count);
* 參數(shù)表 : count: 設(shè)置輸出的頻率。
* 0x00: 32.768kHz; 0x01: 1024Hz; 0x02: 32Hz; 0x03: 1Hz;
* 返回值 : none
* 功 能 : 打開時鐘引腳的輸出。
*/
#define OpenClkOut(count) { SetPCF8563(0x0D, count + 0x80); }
/*
* 函數(shù)名 : void CloseClkOut(void);
* 參數(shù)表 : none
* 返回值 : none
* 功 能 : 關(guān)閉時鐘引腳的輸出。
*/
#define CloseClkOut( ) { SetPCF8563(0x0D, 0x00); }
/*
* 函數(shù)名 : void IntOutput(unsigned char type);
* 參數(shù)表 : type: 中斷類型。
* 0x00: 低電平有效;0x01: 跳沿有效,輸出一個脈沖,不用對AF和TF清零。
* 返回值 : none
* 功 能 : 選擇中斷的觸發(fā)類型。
*/
#define IntOutput(type) \
{ \
if (type > 0) \
SetPCF8563(0x01, GetPCF8563(0x01) | 0x08); \
else \
SetPCF8563(0x01, GetPCF8563(0x01) & 0xF7); \
} \
// 函數(shù)聲明
unsigned char GetPCF8563(unsigned char addr);
void SetPCF8563(unsigned char addr, unsigned char ch);
unsigned char SetClock(TIME *time);
unsigned char GetClock(TIME *time);
#endif
// 文件結(jié)束
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -