资源描述:
《时钟芯片ds12c887使用说明》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、汇编程序:ORG0000HAJMPSTARTSTART:ACALLSETTIME;设置初始时间LOOP:ACALLGETTIME;循环读取当前时间AJMPLOOP;SETTIME:MOVDPTR,#7D0AH;DS12C887的A寄存器MOVA,#20HMOVX@DPTR,A;打开DS12C887的内部晶振并使RTC(实时时钟)记录时间INCDPTR;DS12C887的B寄存器MOVA,#08HMOVX@DPTR,A;设十进制BCD码,24小时制,不定时MOVDPTR,#7D0DH;DS12C887的D寄存器MOVXA,@DPTR;如果D寄存器的
2、第7位为0,表示电池耗尽JNBACC.7,ERRORMOVDPTR,#7D00H;DS12C887的秒单元MOVA,#00HMOVX@DPTR,A;写入秒MOVDPTR,#7D02H;DS12C887分单元MOVA,#21HMOVX@DPTR,A;写入分MOVDPTR,#7D04H;DS12C887时单元MOVA,#03HMOVX@DPTR,A;写入时MOVDPTR,#7D06H;DS12C887星期单元MOVA,#03HMOVX@DPTR,A;写入星期MOVDPTR,#7D07H;DS12C887日单元MOVA,#20HMOVX@DPTR,A;
3、写入日MOVDPTR,#7D08H;DS12C887月单元MOVA,#07HMOVX@DPTR,A;写入月MOVDPTR,#7D09H;DS12C887年单元MOVA,#05HMOVX@DPTR,A;写入年时间ERROR:RETGETTIME:MOVDPTR,#7D0AHMOVXA,@DPTRJBACC.7,GETTIME;REGISTERA的UIP位=0时才可以读数据MOVDPTR,#7D00HMOVXA,@DPTRMOVR2,A;SECONDSACALLDISPLAYMOVDPTR,#7D02HMOVXA,@DPTRMOVR1,AACALLD
4、ISPLAY;MINUTESMOVDPTR,#7D04HMOVXA,@DPTRMOVR0,A;HOURSACALLDISPLAYACALLDELAYRETDISPLAY:MOVDPTR,#TABMOVSCON,#00HMOVR3,AANLA,#0FHMOVCA,@A+DPTRMOVSBUF,AJNBTI,$CLRTIMOVA,R3SWAPAANLA,#0FHMOVCA,@A+DPTRMOVSBUF,AJNBTI,$CLRTIRETDELAY:MOVR4,#0FHDE1:MOVR5,#0FFHDJNZR5,$DJNZR4,DE1RETTAB:DB0
5、3H,9FH,25H,0DH,99H,49H,41H,1FH,01H,09H,11H,0C1H,63H,85H,61H,71HENDC语言源程序:#include"reg52.h"#include"absacc.h"#defineDSAXBYTE[0x7F0A]//12c887寄存器A地址#defineDSBXBYTE[0x7F0B]//B地址#defineDSDXBYTE[0x7F0D]//D地址#defineDS_HXBYTE[0x7F04]//时地址#defineDS_MXBYTE[0x7F02]//分地址#defineDS_SXBYTE[
6、0x7F00]//秒地址#defineDS_WXBYTE[0x7F06]//星期地址#defineDS_DXBYTE[0x7F07]//日地址#defineDS_MoXBYTE[0x7F08]//月地址#defineDS_YXBYTE[0x7F09]//年地址codeunsignedcharLED_code_tab[]={/*显示段笔划abcdefgh;0=亮*/0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,/*0,1,2,3,4,5,6,7*/0x01,0x09,0x11,0xc1,0x63,0x85,0x61
7、,0x71,0xff/*8,9,A,b,C,d,E,F,全灭*/};sbitSet=P1^0;//设置时间标志位sbitSet_h=P1^1;//设置小时sbitSet_m=P1^2;//设置分钟sbitSet_s=P1^3;//设置秒钟codestructtime{intYear;//当前时间年intMonth;//当前时间月intDay;//当前时间日intWeek;//当前时间星期intHour;//当前时间时intMinutes;//当前时间分intSeconds;//当前时间秒inta_Hour;//报警时间时inta_Minutes;
8、//报警时间分inta_Seconds;//报警时间秒};structtimetime_n;//保存当前时间的结构体structtime