导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→各位老师您们好!帮我看看此有关DS12887显示时间的程序好

* 35884: 各位老师您们好!帮我看看此有关DS12887显示时间的程序好吗?十分感谢!

   taoganzh 
taoganzh发表的帖子 

 各位老师您们好!帮我看看此有关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);
}

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

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

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

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

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

/************************************************************* 
函数功能:该函数用来从时钟芯片读取世纪字节
应用范围:
入口参数:
出口参数:
*************************************************************/ 

uchar GetCentury(void)
{
return(chCenturyChannel);


/************************************************************* 
函数功能:该函数用来设置时钟芯片的时间
应用范围:
入口参数:chSeconds、chMinutes、chHours是设定时间的压缩BCD码
出口参数:
*************************************************************/ 

void SetTime(uchar chSeconds,uchar chMinutes,uchar chHours)
{
chRegB = chRegB | MASK_SETB_SET; /* 禁止刷新 */
chSecondsChannel = chSeconds;
chMinutesChannel = chMinutes;
chHoursChannel = chHours;
chRegB = chRegB & MASK_CLR_SET; /* 使能刷新 */
}

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


void main() /* 主函数 */


uchar Seconds=10, Minutes=30, Hours=12 ;
uchar Date=29, Month=6, Year=03;
InitDs12c887();
SetTime(Seconds,Minutes,Hours) ;
SetDate(Date,Month,Year);
for(;;)
{

GetCentury();
GetYear();
GetMonth();
GetDate();
GetHours(); 
GetMinutes();
GetSeconds();

};



发表时间:2003年6月30日20:09:52

  
回复该帖

本主题共有 1 帖,分页:>>>>>该主题的所有内容[1]条

 *树形目录 只列出部分跟帖的标题以及简单的摘要信息 该主题的部分跟帖如下:

[上一篇帖子]:我也想要!各位大哥大姐,告诉我还有别的地方有或FTP一下吧(gingkgo_1217@yahoo.c
[下一篇帖子]:不要老是给别人推荐你的网站,还要找,直接告诉别人不就行了?其实简单的说:reti 是用于中