┊ 网站导航 ┊ 管理登陆 ┊ 免责声明 ┊ 问题反馈 ┊ 友链说明┊本站部分内容来自网络共享资源,如有冒犯您的权利请来信告之删除或纠正! 不得对本站进行复制、盗链或镜像,转载内容须获得同意或授权;欢迎友情链接、站务合作! ![]() ![]() ![]() ![]() ![]() ![]() 本站学习交流群:138..158(高级群1-满)、77930286(高级群2)、61804809(群3) Copyright© MCUSY All Rights Reserved 本站网警备案号: WZ36040002485 ICP备案证书号:粤ICP备09034963号 |
C51读写DS12887程序 2005-12-1 15:31:07 C51读写DS12887程序 已用于开发的无线电子衡器上 包括RTC.h及RTC.c ///////////////////////////////////////// // 接口 RTC.h //////////////////////////////////////// #i nclude <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 //////////////////////////////////////// #i nclude <reg52.h> #i nclude<absacc.h> #i nclude<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); }
┊ 网站导航 ┊ 管理登陆 ┊ 免责声明 ┊ 问题反馈 ┊ 友链说明┊本站部分内容来自网络共享资源,如有冒犯您的权利请来信告之删除或纠正! 不得对本站进行复制、盗链或镜像,转载内容须获得同意或授权;欢迎友情链接、站务合作! ![]() ![]() ![]() ![]() ![]() ![]() 本站学习交流群:138..158(高级群1-满)、77930286(高级群2)、61804809(群3) Copyright© MCUSY All Rights Reserved 本站网警备案号: WZ36040002485 ICP备案证书号:粤ICP备09034963号 |