全新论坛MCU智学网上线,欢迎访问新论坛!稀缺资源、技术干货、参考设计、原厂资料尽在MCU智学网
更新自动建库工具PCB Footprint Expert 2023.13 Pro / Library Expert 破解版

时钟芯片ds12c887的驱动程序

[复制链接]
3802 1

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
/*************************************************************
文件名称:ds12c887.c
适用范围:时钟芯片ds12c887的驱动程序
*************************************************************/
#include <absacc.h>

/* 命令常量定义 */
#define CMD_START_DS12C887 0x20 /* 开启时钟芯片 */
#define CMD_START_OSCILLATOR 0x70 /* 开启振荡器,处于抑制状态 */
#define CMD_CLOSE_DS12C887 0x30 /* 关掉时钟芯片 */

/* 所有的置位使用或操作,清除使用与操作 */
#define MASK_SETB_SET 0x80 /* 禁止刷新 */
#define MASK_CLR_SET 0x7f /* 使能刷新 */
#define MASK_SETB_DM 0x04 /* 使用HEX格式 */
#define MASK_CLR_DM 0xfb /* 使用BCD码格式 */
#define MASK_SETB_2412 0x02 /* 使用24小时模式 */
#define MASK_CLR_2412 0xfd /* 使用12小时模式 */
#define MASK_SETB_DSE 0x01 /* 使用夏令时 */
#define MASK_CLR_DSE 0xfe /* 不使用夏令时 */

/* 寄存器地址通道定义 */
xdata char chSecondsChannel _at_ 0xdf00;
xdata char chMinutesChannel _at_ 0xdf02;
xdata char chHoursChannel _at_ 0xdf04;
xdata char chDofWChannel _at_ 0xdf06;
xdata char chDateChannel _at_ 0xdf07;
xdata char chMonthChannel _at_ 0xdf08;
xdata char chYearChannel _at_ 0xdf09;
xdata char chCenturyChannel _at_ 0xdf32;
xdata char chRegA _at_ 0xdf0a;
xdata char chRegB _at_ 0xdf0b;
xdata char chRegC _at_ 0xdf0c;
xdata char chRegD _at_ 0xdf0d;

/* 函数声明部分 */
void StartDs12c887(void);
void CloseDs12c887(void);
void InitDs12c887(void);
unsigned char GetSeconds(void);
unsigned char GetMinutes(void);
unsigned char GetHours(void);
unsigned char GetDate(void);
unsigned char GetMonth(void);
unsigned char GetYear(void);
unsigned char GetCentury(void);
void SetTime(unsigned char chSeconds,unsigned char chMinutes,unsigned char
chHours);
void SetDate(unsigned char chDate,unsigned char chMonth,unsigned char chYear);

/*************************************************************
函数功能:该函数用来启动时钟芯片工作
应用范围:仅在时钟芯片首次使用时用到一次
入口参数:
出口参数:
*************************************************************/
void StartDs12c887(void)
{
chRegA = CMD_START_DS12C887;
}

/*************************************************************
函数功能:该函数用来关闭时钟芯片
应用范围:一般用不到
入口参数:
出口参数:
*************************************************************/
void CloseDs12c887(void)
{
chRegA = CMD_CLOSE_DS12C887;
}

void InitDs12c887()
{
StartDs12c887();
chRegB = chRegB | MASK_SETB_SET; /* 禁止刷新 */
chRegB = chRegB & MASK_CLR_DM | MASK_SETB_2412 \
& MASK_CLR_DSE;

/* 使用BCD码格式、24小时模式、不使用夏令时 */
chCenturyChannel = 0x21; /* 设置为21世纪 */
chRegB = chRegB & MASK_CLR_SET; /* 使能刷新 */
}

/*************************************************************
函数功能:该函数用来从时钟芯片读取秒字节
应用范围:
入口参数:
出口参数:
*************************************************************/
unsigned char GetSeconds(void)
{
return(chSecondsChannel);
}

/*************************************************************
函数功能:该函数用来从时钟芯片读取分字节
应用范围:
入口参数:
出口参数:
*************************************************************/
unsigned char GetMinutes(void)
{
return(chMinutesChannel);
}

/*************************************************************
函数功能:该函数用来从时钟芯片读取小时字节
应用范围:
入口参数:
出口参数:
*************************************************************/
unsigned char GetHours(void)
{
return(chHoursChannel);
}

/*************************************************************
函数功能:该函数用来从时钟芯片读取日字节
应用范围:
入口参数:
出口参数:
*************************************************************/
unsigned char GetDate(void)
{
return(chDateChannel);
}
/*************************************************************
函数功能:该函数用来从时钟芯片读取月字节
应用范围:
入口参数:
出口参数:
*************************************************************/
unsigned char GetMonth(void)
{
return(chMonthChannel);
}

/*************************************************************
函数功能:该函数用来从时钟芯片读取年字节
应用范围:
入口参数:
出口参数:
*************************************************************/
unsigned char GetYear(void)
{
return(chYearChannel);
}

/*************************************************************
函数功能:该函数用来从时钟芯片读取世纪字节
应用范围:
入口参数:
出口参数:
*************************************************************/
unsigned char GetCentury(void)
{
return(chCenturyChannel);
}

/*************************************************************
函数功能:该函数用来设置时钟芯片的时间
应用范围:
入口参数:chSeconds、chMinutes、chHours是设定时间的压缩BCD码
出口参数:
*************************************************************/
void SetTime(unsigned char chSeconds,unsigned char chMinutes,unsigned char
chHours)
{
chRegB = chRegB | MASK_SETB_SET; /* 禁止刷新 */
chSecondsChannel = chSeconds;
chMinutesChannel = chMinutes;
chHoursChannel = chHours;
chRegB = chRegB & MASK_CLR_SET; /* 使能刷新 */
}

/*************************************************************
函数功能:该函数用来设置时钟芯片的日期
应用范围:
入口参数:chDate、chMonth、chYear是设定日期的压缩BCD码
出口参数:
*************************************************************/
void SetDate(unsigned char chDate,unsigned char chMonth,unsigned char chYear)
{
chRegB = chRegB | MASK_SETB_SET; /* 禁止刷新 */
chDateChannel = chDate;
chMonthChannel = chMonth;
chYearChannel = chYear;
chRegB = chRegB & MASK_CLR_SET; /* 使能刷新 */
}

举报

回复

1 个评论

zhjq4***  新手上路  发表于 2016-1-2 14:35:13  | 显示全部楼层
时钟芯片ds12c887的驱动程序
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

打开支付宝扫一扫,最高立得1212元红包
搜索

图文热点

更多

社区学堂

更多

客服中心

QQ:187196467 服务时间:周一至周日 8:30-20:30

关注我们

关于我们
关于我们
友情链接
联系我们
帮助中心
网友中心
购买须知
支付方式
服务支持
资源下载
售后服务
定制流程
关注我们
官方微博
官方空间
官方微信
快速回复 返回顶部 返回列表