时钟芯片DS1302文档格式.docx
《时钟芯片DS1302文档格式.docx》由会员分享,可在线阅读,更多相关《时钟芯片DS1302文档格式.docx(31页珍藏版)》请在冰豆网上搜索。
![时钟芯片DS1302文档格式.docx](https://file1.bdocx.com/fileroot1/2022-12/11/a479298e-bdd8-4edb-8a74-fd21a0e60e18/a479298e-bdd8-4edb-8a74-fd21a0e60e181.gif)
MOVA,#00H
MOVR0,#40H;
从40H单元开始
MOVR1,#40H;
清64个单元
M_CLEAR:
MOV@R0,A
INCR0
DJNZR1,M_CLEAR
MOV7FH,#0AH;
送熄灭符
SETBBEEP
LCALLTIME_DELAY;
调显示延时
LCALLPROSET;
DS1302初始化
MAIN1:
LCALLGET_TIME;
从DS1302读数据程序
LCALLCHULI;
实时时间数据处理
MOVR0,#TIME_DATA;
显示时、分、秒
LCALLDISP
MOVR0,#TIME_DATA
LCALLTIME_DISPLAY
LCALLSET_KEY;
键功能程序
LCALLCOMP;
实时时间与定时时间比较
JBK1,MAIN1
CALLBEEP_BL
MAIN2:
日期数据处理
MOVR0,#DATE_DATA
LCALLDISP;
显示年、月、日
JBK1,MAIN2
MAIN3:
LCALLDS_CHULI;
定时时间数据处理
MOVR0,#DS_DATA
LCALLDS_SP;
显示定时时间
LCALLDS_DISPLAY
JBK1,MAIN3
AJMPMAIN1
--------------------------------------------
中断服务子程序
300MS对闪动标记取反一次
INT_T0:
PUSHACC
PUSHPSW
MOVTL0,TIME_L
MOVTH0,TIME_H
INCT_CONU
MOVA,T_CONU
CJNEA,#06H,INT_END
MOVT_CONU,#00H
CPL0AH
INT_END:
POPPSW
POPACC
RETI
DS1302初始化子程序
(R0)=数据(R1)=地址
PROSET:
CLRRST;
DS1302复位
CLRSCLK
NOP
SETBRST
;
MOVR1,#80H;
写秒寄存器
MOVR0,#00H;
启动振荡器
LCALLWRITE
MOVR1,#82H;
写分寄存器
MOVR0,#58H
MOVR1,#84H;
写时寄存器
MOVR0,#80H
MOVR1,#90H;
写充电寄存器
MOVR0,#0ABH
LCALLWRITE
RET
===============================================
读时间、日期数据子程序
存放单元40H-46H
GET_TIME:
MOVR1,#81H;
读秒
LCALLREAD
MOV40H,R0
MOVR1,#83H;
读分
MOV41H,R0
MOVR1,#85H;
读时
MOV42H,R0
MOVR1,#87H;
读出日期
MOV43H,R0
MOVR1,#89H;
读出月份
MOV44H,R0
MOVR1,#8BH;
读出星期
MOV46H,R0
MOVR1,#8DH;
读出年
MOV45H,R0
================================================
写DS1302子程序
WRITE:
MOVA,R1
MOVR2,#08H
WRI_01:
RRCA;
传输地址到DS1302
NOP
MOVIO_DATA,C
SETBSCLK
DJNZR2,WRI_01
MOVA,R0
WRI_02:
传输数据到DS1302
DJNZR2,WRI_02
CLRRST
=================================================
读DS1302子程序
READ:
READ_01:
RRCA
NOP;
先传输地址到DS1302
DJNZR2,READ_01
SETBIO_DATA
CLRA
CLRC
READ_02:
MOVC,IO_DATA
再从DS1302接收数据
DJNZR2,READ_02
MOVR0,A
==============================================
实时时间、日期数据处理子程序
CHULI:
MOVA,40H;
处理秒数据
ANLA,#0FH
MOV50H,A
MOV70H,A
MOVA,40H
ANLA,#11110000B
SWAPA
MOV51H,A
MOV71H,A
---------------------------------------------
MOVA,41H;
处理分数据
MOV52H,A
MOV72H,A
MOVA,41H
MOV53H,A
MOV73H,A
MOVA,42H;
处理时数据
MOV54H,A
MOV74H,A
MOVA,42H
MOV55H,A
MOV75H,A
----------------------------------------------
MOVA,43H;
处理日数据
MOV60H,A
MOV76H,A
MOVA,43H
MOV61H,A
MOV77H,A
MOVA,44H;
处理月数据
MOV62H,A
MOV78H,A
MOVA,44H
MOV63H,A
MOV79H,A
MOVA,45H;
处理年数据
MOV64H,A
MOV7AH,A
MOVA,45H
MOV65H,A
MOV7BH,A
MOVA,46H;
处理周数据
MOV66H,A
MOV7CH,A
=============================================
实时时间、日期查表取数子程序
DISP:
MOVR0,#TIME_DATA
MOVR3,#06H
DISP1:
MOVA,@R0
MOVDPTR,#TAB_NU
MOVCA,@A+DPTR
DJNZR3,DISP1
====================================================
时间、日期显示子程序
TIME_DISPLAY:
MOVR0,#TIME_DATA;
取得显示单元首地址
MOVR1,#07FH;
从第一个数码管开始
MOVR2,#08H;
共8个数码管
DISLP:
MOVP0,@R0;
获得当前单元数据
MOVP2,A;
数码显示
JBACC.5,DISLP1;
第三位数码管显示-
MOVP0,#0f7H
JMPDISLP3
DISLP1:
JBACC.2,DISLP2;
第六位数码管显示-
DISLP2:
DISLP3:
MOVA,R1;
为下一个数准备
RRA;
下一个单元
MOVR1,A;
保存
LCALLDELAY;
为了保证数码管亮度,延时
DJNZR2,DISLP;
重复显示,直到全部数据刷新过
RET;
返回
DELAY:
MOVR4,#0AH
L15:
MOVR5,#64H
L16:
DJNZR5,L16
DJNZR4,L15
******************************************************
SET_KEY:
SETBK1;
增加键
SETBK2;
减少键
SETBK3;
选择键
SETBK4;
定时设定功能键
JBK4,KEY01
LCALLBEEP_BL
JMPDS_KEY;
进入定时值设定子程序
KEY01:
JBK2,KEY02
JMPSET_TIME;
进入时间设定子程序
KEY02:
JBK3,KEY03
CPL20H.0;
止闹标记取反
KEY03:
-----------------------------------------------------
DS_KEY:
CALLDS_DELAY
JNBK4,$
LCALLDSSET
实时时间设定子程序
K1为加键、K2为减键、K3为选择键
SET_TIME:
MOVR1,#8EH;
写保护寄存器
MOVR0,#00H;
允许写入
MOVR1,#80H;
MOVR0,#80H;
停止振荡器工作
SETBTR0
K001:
CALLTIME_DELAY;
校时
JNBK3,K001;
K3为位移键
K010:
CALLCHULI
JNB0AH,KH01
MOV54H,7FH;
送入熄灭符
MOV55H,7FH
JMPKH02
KH01:
MOV54H,74H;
送实时值
MOV55H,75H;
KH02:
CALLDISP
CALLTIME_DISPLAY
JNBK1,K011A
JNBK2,K011B
JNBK3,K002
JMPK010
K011A:
ADDA,#01H
DAA
MOV42H,A
XRLA,#24H
JNZK012A
MOV42H,#00H
K012A:
MOVR1,#84H;
MOVR0,42H
CALLTIME_DELAY
K011B:
XRLA,#00H
JZK012B
SETBC;
求补运算
ADDCA,#99H;
加99
SUBBA,#01H;
减去减数
ADDA,42H;
加被减数
DAA;
十进制调整
MOV42H,A;
JNZK012C
K012B:
MOV42H,#23H
K012C:
-------------------------------------------------
K002:
校分
JNBK3,K002;
K020:
JNB0AH,KM01
MOV52H,7FH;
MOV53H,7FH
JMPKM02
KM01:
MOV52H,72H;
MOV53H,73H;
KM02:
JNBK1,K021A
JNBK2,K021B
JNBK3,K003
JMPK020
K021A:
MOV41H,A
XRLA,#60H
JNZK022A
MOV41H,#00H
K022A:
MOVR1,#82H;
MOVR0,41H
---------------------------------------------------
K021B:
JZK022B
ADDA,41H;
MOV41H,A;
JNZK022C
K022B:
MOV41H,#59H
K022C:
K003:
CALLDATE_DELAY;
校日
JNBK3,K003;
K030:
JNB0AH,KR01
MOV60H,7FH;
MOV61H,7FH
JMPKR02
KR01:
MOV60H,76H;
MOV61H,77H;
KR02:
JNBK1,K031A
JNBK2,K031B
JNBK3,K004
JMPK030
K031A:
MOV43H,A
XRLA,#32H
JNZK032A
MOV43H,#00H
K032A:
MOVR1,#86H;
写日寄存器
MOVR0,43H
CALLDATE_DELAY
K031B:
JZK032B
ADDA,43H;
JNZK032C
K032B:
MOV43H,#31H
K032C:
K004:
校月
JNBK3,K004;
K040:
JNB0AH,KC01
MOV62H,7FH;
MOV63H,7FH
JMPKC02
KC01:
MOV62H,78H;
MOV63H,79H;
KC02:
JNBK1,K041A
JNBK2,K041B
JNBK3,K005
JMPK040
K041A:
MOV44H,A
XRLA,#13H
JNZK042A
MOV44H,#00H
K042A:
MOVR1,#88H;
写月寄存器
MOVR0,44H
K041B:
JZK042B
ADDA,44H;
MOV44H,A;
JNZK042C
K042B:
MOV44H,#12H
K042C:
-----------------------------------------------
K005:
校年
JNBK3,K005;
K050:
JNB0AH,KY01
MOV64H,7FH;
MOV65H,7FH
JMPKY02
KY01:
MOV64H,7AH;
MOV65H,7BH;
KY02:
MOVR0,#DATE_DA