• PUDN用户
    了解作者
  • C/C++
    开发工具
  • 1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 47
    下载次数
  • 2007-11-06 19:47
    上传日期
ds12c887驱动程序,可以实现实时时钟,并且掉电数据也不丢失,采用总线接口
DS12887.rar
  • DS12887.H
    6.3KB
  • www.pudn.com.txt
    218B
内容介绍
/************************************************************/ /********* DS12887.H C51 driver ************/ /***********************--20071009 **********************/ /************************************************************/ #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; //------------------------------------------------------ void Set_Year(unsigned char Data); void Set_Month(unsigned char Data); void Set_Day(unsigned char Data); void Set_Hour(unsigned char Data); void Set_Minute(unsigned char Data); void Set_Second(unsigned char Data); //----------------------------------- unsigned char Get_Year(void); unsigned char Get_Month(void); unsigned char Get_Day(void); unsigned char Get_Hour(void); unsigned char Get_Minute(void); unsigned char Get_Second(void); //------------------------------------------------------ ////////////////////////////////////////////////////// bit Init_RTC(void); bit Second_Interrupt(void); unsigned char Read_RTC(unsigned char); void Write_RTC(unsigned char,unsigned char); unsigned char BCD_TO_DEC(unsigned char InData); unsigned char DEC_TO_BCD(unsigned char InData); //----------------------------------------------------- ///////////////////////////////////////// // 实现部分 RTC.C //////////////////////////////////////// //#include <reg52.h> #include<absacc.h rel='nofollow' onclick='return false;'> //#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); } //--------------------------------------------------- unsigned char BCD_TO_DEC(unsigned char InData) { unsigned char OutData=0; OutData=(InData>>4)*10+(InData&0x0f); return OutData; } //--------------------------------------------------- unsigned char DEC_TO_BCD(unsigned char InData) { unsigned char temp[2],OutData=0; temp[0]=InData/10; temp[1]=InData-10*temp[0]; temp[0]<<=4; OutData=temp[0]|temp[1]; return OutData; } //--------------------------------------------------- unsigned char Get_Year(void) { return BCD_TO_DEC( Read_RTC(YEAR_IN_RTC) ); } //--------------------------------------------------- unsigned char Get_Month(void) { return BCD_TO_DEC( Read_RTC(MONTH_IN_RTC) ); } //--------------------------------------------------- unsigned char Get_Day(void) { return BCD_TO_DEC( Read_RTC(DAY_IN_RTC) ); } //--------------------------------------------------- unsigned char Get_Hour(void) { return BCD_TO_DEC( Read_RTC(HOUR_IN_RTC) ); } //--------------------------------------------------- unsigned char Get_Minute(void) { return BCD_TO_DEC( Read_RTC(MINUTE_IN_RTC) ); } //--------------------------------------------------- unsigned char Get_Second(void) { return BCD_TO_DEC( Read_RTC(SECOND_IN_RTC) ); } //--------------------------------------------------- ///////////////////////////////////////////////////// //--------------------------------------------------- void Set_Year(unsigned char Data) { Write_RTC( YEAR_IN_RTC,DEC_TO_BCD(Data) ); } //--------------------------------------------------- void Set_Month(unsigned char Data) { Write_RTC( MONTH_IN_RTC,DEC_TO_BCD(Data) ); } //--------------------------------------------------- void Set_Day(unsigned char Data) { Write_RTC( DAY_IN_RTC,DEC_TO_BCD(Data) ); } //--------------------------------------------------- void Set_Hour(unsigned char Data) { Write_RTC( HOUR_IN_RTC,DEC_TO_BCD(Data) ); } //--------------------------------------------------- void Set_Minute(unsigned char Data) { Write_RTC( MINUTE_IN_RTC,DEC_TO_BCD(Data) ); } //--------------------------------------------------- void Set_Second(unsigned char Data) { Write_RTC( SECOND_IN_RTC,DEC_TO_BCD(Data) ); } //--------------------------------------------------- //--------------------------End of DS12887----------------------------
评论
    相关推荐
    • ds12c887.rar
      DS12c887电子时钟,1602液晶屏显示,
    • ds12c887.rar
      6位数码管显示时,分,秒 键盘可调时间ds12c887学习程序
    • ds12c887时钟.rar
      51单片机驱动DS12C887时钟芯片制作的LCD时钟,有温湿度,农历显示
    • ds12c887.zip
      实时时钟ds12c887驱动程序,atmega128平台测试通过
    • DS12c887.zip
      C51程序运用stc12c5a系列的单片机即可驱动,DS12c887时钟芯片的正常工作,利用共阴数码管显示。已测试完成。
    • RTC_DS12C887.zip
      使用keil编程,用51单片机和DS12C887芯片实现实时时钟
    • ds12c887.rar
      ds12c887 interfacing with 8051.the code just initialises ,reads and displays it in the serial port.
    • ds12c887.rar
      ds12c887 interfacing with 8051.the code just initialises ,reads and displays it in the serial port.
    • DS12C887.zip
      DS12C887是一款时钟芯片,精度高,误差小。驱动简单。
    • DS12C887程序
      DS12C887程序.可以助你一臂之力。C语言更能懂