No.35884 作者:taoganzh 邮件:glhydc@163.com ID:12224 登陆:4次 文章数:6篇 最后登陆IP:220.173.130.180 最后登陆:2003/8/4 20:39:11 注册:2003/5/17 12:41:22 财富:141 发帖时间:2003/6/30 20:09:52 发贴者IP:220.173.119.55 标题:taoganzh:各位老师您们好!帮我看看此有关DS12887显示时间的程序好吗?十分感谢! 摘要:No.35884各位老师您们好!帮我看看此有关DS12887显示时间的程序好吗?十分感谢! 班主晚上好:不好意思,麻烦您,帮我看看此程序. 谢谢! 我仿真DS12887时读出的时标是88进制而不是60进制( 分秒),( 时)不是24进制. 设置B寄存器时我已设为时标BCD和二进制码都试过显示结果都一样,因为我用的是EasyScope 8052F仿真器仿真,他有10 .16.进制相互转换. 程序如下: /*文件名称:ds12c887.c 适用范围:时钟芯片ds12c887的驱动程序*/ #include <reg51.h> #include <absacc.h> #define uchar unsigned char /* 命令常量定义 */ #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 uchar chSecondsChannel _at_ 0x5f80; xdata uchar chMinutesChannel _at_ 0x5f82; xdata uchar chHoursChannel _at_ 0x5f84; xdata uchar chDofWChannel _at_ 0x5f86; xdata uchar chDateChannel _at_ 0x5f87; xdata uchar chMonthChannel _at_ 0x5f88; xdata uchar chYearChannel _at_ 0x5f89; xdata uchar chCenturyChannel _at_ 0x5f32; xdata uchar chRegA _at_ 0x5f8a; xdata uchar chRegB _at_ 0x5f8b; xdata uchar chRegC _at_ 0x5f8c; xdata uchar chRegD _at_ 0x5f8d; /* 函数声明部分 */ void StartDs12c887(void); void CloseDs12c887(void); void InitDs12c887(void); uchar GetSeconds(void); uchar GetMinutes(void); uchar GetHours(void); uchar GetDate(void); uchar GetMonth(void); uchar GetYear(void); uchar GetCentury(void); void SetTime(uchar chSeconds,uchar chMinutes,uchar chHours); void SetDate(uchar chDate,uchar chMonth,uchar chYear); /*函数功能:该函数用来启动时钟芯片工作 应用范围:仅在时钟芯片首次使用时用到一次 入口参数: 出口参数:*/ void StartDs12c887(void) { chRegA = CMD_START_DS12C887; } /*初始化DS12887 */ void InitDs12c887() { StartDs12c887(); chRegB = chRegB | MASK_SETB_SET; /* 禁止刷新 */ chRegB = chRegB & MASK_SETB_DM | MASK_SETB_2412 & MASK_CLR_DSE; /* 使用BCD码格式、24小时模式、不使用夏令时 */ chCenturyChannel = 0x21; /* 设置为21世纪 */ chRegB = chRegB & MASK_CLR_SET; /* 使能刷新 */ } /************************************************************* 函数功能:该函数用来从时钟芯片读取秒字节 应用范围: 入口参数: 出口参数: *************************************************************/ uchar GetSeconds(void) { return(chSecondsChannel); } /************************************************************* 函数功能:该函数用来从时钟芯片读取分字节 应用范围: 入口参数: 出口参数: *********** ......
>>返回讨论的主题
|