📄 pcf8563.h
字号:
/*
* 文件名 : PCF8563.H
* 作 者 : li.yao
* 日 期 : 2005年 02月 28日,星期一
* 描 述 : PCF8563实时时钟芯片的API函数库,仅供外部函数调用。
*/
#ifndef _RTC_PCF8563_
#define _RTC_PCF8563_
// 数据结构
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;
// 宏定义函数
/*
* 函数名 : void OpenAlarm(void);
* 参数表 : none
* 返回值 : none
* 功 能 : 打开闹钟报警器 AIE = 1 ,软件清AF为0。
*/
#define OpenAlarm( ) { SetPCF8563(0x01, GetPCF8563(0x01) | 0x02); }
/*
* 函数名 : void SetAlarm(unsigned char type, unsigned char ch);
* 参数表 : type: 要读的时间类型。
* 0x09: minute; 0x0A: hour; 0x0B: day; 0x0C: week;
* ch: 要设置的时间值(BCD格式)。
* 返回值 : none
* 功 能 : 设置闹钟报警。例如:SetAlarm(0x0A, 23); // 在晚上11点报警。
*/
#define SetAlarm(type, ch) { SetPCF8563(type, ch + 0x80); }
/*
* 函数名 : void CloseAlarm(void);
* 参数表 : none
* 返回值 : none
* 功 能 : 关闭闹钟报警器 AIE = 0 。
*/
#define CloseAlarm( ) { SetPCF8563(0x01, GetPCF8563(0x01) & 0xFD); }
/*
* 函数名 : void OpenTimer(void);
* 参数表 : none
* 返回值 : none
* 功 能 : 打开定时器中断 TIE = 1 ,软件清TF为0。
*/
#define OpenTimer( ) { SetPCF8563(0x01, GetPCF8563(0x01) | 0x01); }
/*
* 函数名 : void SetTimer(unsigned char freq, unsigned char count);
* 参数表 : freq: 设置定时器的时钟频率。
* 0x00: 4096Hz; 0x01: 64Hz; 0x02: 1Hz; 0x03: 1/60Hz;
* count: 设置定时器的计数值。0x00 ~ 0xFF;
* 返回值 : none
* 功 能 : 设置定时器的定时值。
*/
#define SetTimer(freq, count) { SetPCF8563(0x0E, freq + 0x80); SetPCF8563(0x0F, count); }
/*
* 函数名 : void CloseTimer(void);
* 参数表 : none
* 返回值 : none
* 功 能 : 关闭定时器中断 TIE = 0 。
*/
#define CloseTimer( ) { SetPCF8563(0x01, GetPCF8563(0x01) & 0xFE); }
/*
* 函数名 : void OpenClkOut(unsigned char count);
* 参数表 : count: 设置输出的频率。
* 0x00: 32.768kHz; 0x01: 1024Hz; 0x02: 32Hz; 0x03: 1Hz;
* 返回值 : none
* 功 能 : 打开时钟引脚的输出。
*/
#define OpenClkOut(count) { SetPCF8563(0x0D, count + 0x80); }
/*
* 函数名 : void CloseClkOut(void);
* 参数表 : none
* 返回值 : none
* 功 能 : 关闭时钟引脚的输出。
*/
#define CloseClkOut( ) { SetPCF8563(0x0D, 0x00); }
/*
* 函数名 : void IntOutput(unsigned char type);
* 参数表 : type: 中断类型。
* 0x00: 低电平有效;0x01: 跳沿有效,输出一个脉冲,不用对AF和TF清零。
* 返回值 : none
* 功 能 : 选择中断的触发类型。
*/
#define IntOutput(type) \
{ \
if (type > 0) \
SetPCF8563(0x01, GetPCF8563(0x01) | 0x08); \
else \
SetPCF8563(0x01, GetPCF8563(0x01) & 0xF7); \
} \
// 函数声明
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
// 文件结束
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -