51/AVR单片机技术驿站!  <在线翻译>     便利工具    特色网址   无弹窗、无插件的绿色站点...  英才招聘   学历查询  喜欢>>收藏我站 

当前位置:首页 > 单片机源码 > 详细内容
C51读写DS12887程序
作者:佚名  发布时间:2009/10/16  阅读次数:1417  字体大小: 【】 【】【
/////////////////////////////////////////
// 接口 RTC.h
////////////////////////////////////////

#include <reg52.h>
//*******DS12887 *******

#define YEAR_IN_RTC                       0
#define MONTH_IN_RTC                     1
#define DAY_IN_RTC                         2
#define HOUR_IN_RTC                       3
#define MINUTE_IN_RTC                   4
#define SECOND_IN_RTC                   5
#define SECOND_ALARM_IN_RTC 6
#define MINUTE_ALARM_IN_RTC 7
#define HOUR_ALARM_IN_RTC       8
#define RTC_SECONDS                     XBYTE[0xfe00]
#define RTC_SECONDS_ALARM       XBYTE[0xfe01]
#define RTC_MINUTES                     XBYTE[0xfe02]
#define RTC_MINUTES_ALARM     XBYTE[0xfe03]
#define RTC_HOURS                         XBYTE[0xfe04]
#define RTC_HOURS_ALARM         XBYTE[0xfe05]
#define RTC_DAYS                           XBYTE[0xfe07]  
#define RTC_MONTHS                       XBYTE[0xfe08]                                  
#define RTC_YEARS                         XBYTE[0xfe09]
#define DSA                                     XBYTE[0xfe0a]                           //DS12887 register A
#define DSB                                     XBYTE[0xfe0b]
#define DSC                                     XBYTE[0xfe0c]
#define DSD                                     XBYTE[0xfe0d]

sbit RTC_CS=P2^0;

bit Init_RTC(void);
bit Second_Interrupt(void);
unsigned char Read_RTC(unsigned char);
void Write_RTC(unsigned char,unsigned char);


/////////////////////////////////////////
// 实现部分 RTC.C
////////////////////////////////////////
#include <reg52.h>
#include<absacc.h>
#include<RTC.h>

unsigned char Read_RTC(unsigned char option)
{
    
   switch(option)
   {
       case YEAR_IN_RTC:return(RTC_YEARS);break;
       case MONTH_IN_RTC:return(RTC_MONTHS);break;
       case DAY_IN_RTC:return(RTC_DAYS);break;
       case HOUR_IN_RTC:return(RTC_HOURS);break;
       case MINUTE_IN_RTC:return(RTC_MINUTES);break;
       case SECOND_IN_RTC:return(RTC_SECONDS);break;
   }
}

void Write_RTC(unsigned char option,unsigned char j)
{
   switch(option)
   {
       case YEAR_IN_RTC:RTC_YEARS=j;break;
       case MONTH_IN_RTC:RTC_MONTHS=j;break;
       case DAY_IN_RTC:RTC_DAYS=j;break;
       case HOUR_IN_RTC:RTC_HOURS=j;break;
       case MINUTE_IN_RTC:RTC_MINUTES=j;break;
       case SECOND_IN_RTC:RTC_SECONDS=j;break;
       case SECOND_ALARM_IN_RTC:RTC_SECONDS_ALARM=j;break;
       case MINUTE_ALARM_IN_RTC:RTC_MINUTES_ALARM=j;break;
       case HOUR_ALARM_IN_RTC:RTC_HOURS_ALARM=j;break;

   }
}


bit Second_Interrupt(void)
{
       if( (DSC&0x20)==0x20 )return(1);
       return(0);
}


/*   initialize DS12887   */
bit Init_RTC(void)
{
       DSA=0x20;
       DSB=0x72;                                                                   //SET=0,*IE=disenable,SQW=disenable ,BCD,NO DSE
       DSC=0x00;
       ACC=DSD;

       //every second interrupt
       Write_RTC(HOUR_ALARM_IN_RTC,0xff);
       Write_RTC(MINUTE_ALARM_IN_RTC,0xff);
       Write_RTC(SECOND_ALARM_IN_RTC,0xff);
       //if(ACC&0x80)return(0); //when low bat return 0
       //return(1);
         /* DSB=0x82;                                                                     //set SET=1
   RTC_HOURS=0x23;
   RTC_MINUTES=0x12;
   RTC_SECONDS=0x30;
   DSB=0x02;
     */
   return(1);        
}    

我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[0]
    暂无已审核评论!

网站导航 管理登陆 ┊ 免责声明 问题反馈  友链说明
本站部分内容来自网络共享资源,如有冒犯您的权利请来信告之删除或纠正!
不得对本站进行复制、盗链或镜像,转载内容须获得同意或授权;欢迎友情链接、站务合作!

    我要报警 Alexa
 mcusy_cn#126.com (请把#改成@) 交流:522422171
本站学习交流群:138..158(高级群1-)、77930286(高级群2)、61804809(群3)
Copyright© MCUSY All Rights Reserved
本站网警备案号: WZ36040002485
  ICP备案证书号:粤ICP备09034963号