DS1302-制作的電子時(shí)鐘程序分享
大小:0.1 MB 人氣: 2017-09-06 需要積分:0
推薦 + 挑錯(cuò) + 收藏(0) + 用戶評(píng)論(0)
標(biāo)簽:時(shí)鐘(129986)DS1302(49889)
DS1302-制作的電子時(shí)鐘程序分享
?;8位數(shù)碼管顯示?;P0 為段碼口、P2 為位碼口
?;晶振 11.0592M
?;時(shí)鐘芯片:DS1302
?;************** DS1302 端口位定義 **************
????????? IO_DATA? BIT? P1.1???? ; 數(shù)據(jù)傳送總線
????????? SCLK???? BIT? P1.0???? ; 時(shí)鐘控制總線
????????? RST????? BIT? P1.2???? ; 復(fù)位總線
????????? K1???? EQU? P1.4?????? ;獨(dú)立鍵
????????? K2???? EQU? P1.5
????????? K3???? EQU? P1.6
????????? K4???? EQU? P1.7
????????? BEEP?? EQU? P3.7?????? ;蜂鳴器
????????? RELAY? EQU? P1.3?????? ;繼電器
????????? T_CONU? EQU? 22H?????? ;中斷計(jì)數(shù)
????????? TIME_L? EQU? 23H?????? ;定時(shí)初值
????????? TIME_H? EQU? 24H
????????? TIME_DATA?? EQU? 50H?? ;顯示時(shí)間單元首地址
????????? DATE_DATA?? EQU? 60H?? ;顯示日期單元首地址
????????? DS_DATA???? EQU? 58H?? ;顯示定時(shí)時(shí)間單元首地址
;------------------------------------------------
????????? ORG 0000H
????????? AJMP MAIN
????????? ORG? 000BH
????????? AJMP? INT_T0
????????? ORG? 0100H
;------------------------------------------------
MAIN:
????????? MOV? TMOD,#01H??????? ;T0,方式1
????????? MOV? TIME_L,#00H????? ;50MS定時(shí)值
????????? MOV? TIME_H,#4CH
????????? MOV? T_CONU,#00H????? ;中斷次數(shù)
????????? MOV? IE,#82H????????? ;EA=1,ET0=1
????????? MOV? A,#00H
????????? MOV? R0,#40H????????? ;從40H單元開始
????????? MOV? R1,#40H????????? ;清64個(gè)單元
M_CLEAR:? MOV? @R0,A
????????? INC? R0
????????? DJNZ? R1,M_CLEAR
????????? MOV? 7FH,#0AH???????? ;送熄滅符
????????? SETB?? BEEP
????????? LCALL? TIME_DELAY???? ;調(diào)顯示延時(shí)
????????? LCALL? PROSET???????? ;DS1302初始化
MAIN1:
????????? LCALL? GET_TIME?????? ;從DS1302讀數(shù)據(jù)程序
????????? LCALL? CHULI????????? ;實(shí)時(shí)時(shí)間數(shù)據(jù)處理
????????? MOV? R0,#TIME_DATA??? ;顯示時(shí)、分、秒
????????? LCALL? DISP
????????? MOV? R0,#TIME_DATA
????????? LCALL? TIME_DISPLAY
????????? LCALL? SET_KEY??????? ;鍵功能程序
????????? LCALL? COMP?????????? ;實(shí)時(shí)時(shí)間與定時(shí)時(shí)間比較
????????? JB? K1,MAIN1
????????? CALL? BEEP_BL
MAIN2:
????????? LCALL? CHULI????????? ;日期數(shù)據(jù)處理
????????? MOV? R0,#DATE_DATA
????????? LCALL? DISP?????????? ;顯示年、月、日
????????? MOV? R0,#DATE_DATA
????????? LCALL? TIME_DISPLAY
????????? JB? K1,MAIN2
????????? CALL? BEEP_BL
MAIN3:
????????? LCALL? DS_CHULI??????? ;定時(shí)時(shí)間數(shù)據(jù)處理
????????? MOV? R0,#DS_DATA
????????? LCALL? DS_SP?????????? ;顯示定時(shí)時(shí)間
????????? MOV? R0,#DS_DATA
????????? LCALL? DS_DISPLAY
????????? JB? K1,MAIN3
????????? CALL? BEEP_BL
????????? AJMP? MAIN1
;--------------------------------------------
;中斷服務(wù)子程序
;300MS對(duì)閃動(dòng)標(biāo)記取反一次
;--------------------------------------------
INT_T0:
????????? PUSH? ACC
????????? PUSH? PSW
????????? MOV? TL0,TIME_L
????????? MOV? TH0,TIME_H
????????? INC? T_CONU
????????? MOV? A,T_CONU
????????? CJNE? A,#06H,INT_END
????????? MOV? T_CONU,#00H
????????? CPL? 0AH
INT_END:
????????? POP? PSW
????????? POP? ACC
????????? RETI
;--------------------------------------------
;DS1302 初始化子程序
; (R0)=數(shù)據(jù)? (R1)=地址
;--------------------------------------------
PROSET:
?????????? CLR?? RST??????????? ;DS1302復(fù)位
?????????? CLR?? SCLK
?????????? NOP
?????????? NOP
?????????? SETB? RST
????????? ;MOV? R1,#80H????????? ;寫秒寄存器
????????? ;MOV? R0,#00H????????? ;啟動(dòng)振蕩器
????????? ;LCALL WRITE
????????? ;MOV? R1,#82H????????? ;寫分寄存器
????????? ;MOV? R0,#58H
????????? ;LCALL WRITE
????????? ;MOV? R1,#84H????????? ;寫時(shí)寄存器
????????? ;MOV? R0,#80H
????????? ;LCALL WRITE
????????? MOV? R1,#90H????????? ;寫充電寄存器
????????? MOV? R0,#0ABH
????????? LCALL WRITE
????????? RET
;===============================================
;讀時(shí)間、日期數(shù)據(jù)子程序
;存放單元 40H - 46H
;===============================================
GET_TIME:
????????? MOV? R1,#81H????????? ;讀秒
????????? LCALL? READ
????????? MOV 40H,R0
????????? MOV? R1,#83H????????? ;讀分
????????? LCALL? READ
????????? MOV 41H,R0
????????? MOV? R1,#85H????????? ;讀時(shí)
????????? LCALL? READ
????????? MOV 42H,R0
????????? MOV? R1,#87H????????? ;讀出日期
????????? LCALL? READ
????????? MOV 43H,R0
????????? MOV? R1,#89H????????? ;讀出月份
????????? LCALL? READ
????????? MOV 44H,R0
????????? MOV? R1,#8BH????????? ;讀出星期
????????? LCALL? READ
????????? MOV 46H,R0
????????? MOV? R1,#8DH????????? ;讀出年
????????? LCALL? READ
????????? MOV 45H,R0
????????? RET
;================================================
;寫 DS1302 子程序
;================================================
WRITE:
????????? CLR? SCLK
????????? NOP
????????? NOP
????????? SETB? RST
????????? NOP
????????? MOV? A,R1
????????? MOV? R2,#08H
WRI_01:
????????? RRC? A??????????????? ;傳輸?shù)刂返紻S1302
????????? NOP
????????? NOP
????????? CLR? SCLK
????????? NOP
????????? NOP??????????
????????? MOV? IO_DATA,C
????????? NOP
????????? NOP?????????
????????? SETB? SCLK
????????? NOP
????????? NOP
????????? DJNZ? R2,WRI_01
????????? CLR? SCLK
????????? NOP
????????? NOP
????????? MOV? A,R0
????????? MOV? R2,#08H
WRI_02:
????????? RRC? A?????????? ;傳輸數(shù)據(jù)到DS1302
????????? NOP
????????? CLR? SCLK
????????? NOP
????????? NOP
????????? MOV? IO_DATA,C
????????? NOP
????????? NOP
????????? SETB? SCLK
????????? NOP
????????? NOP
????????? DJNZ? R2,WRI_02
????????? CLR? SCLK
????????? NOP
????????? NOP
????????? CLR? RST
????????? NOP
????????? NOP
????????? RET
;=================================================
;讀 DS1302 子程序
;=================================================
READ:
????????? CLR?? SCLK
????????? NOP
????????? NOP
????????? SETB? RST
????????? NOP
????????? NOP
????????? MOV? A,R1
????????? MOV? R2,#08H
READ_01:
????????? RRC? A
????????? NOP?????????????? ;先傳輸?shù)刂返紻S1302
????????? MOV? IO_DATA,C
????????? NOP
????????? NOP
????????? SETB? SCLK
????????? NOP
????????? NOP
????????? CLR? SCLK
????????? NOP
????????? NOP
????????? DJNZ? R2,READ_01
????????? NOP
????????? NOP
????????? SETB? IO_DATA
????????? CLR? A
????????? CLR? C
????????? MOV? R2,#08H
READ_02:
????????? CLR? SCLK
????????? NOP
????????? NOP?????????
????????? MOV? C,IO_DATA
????????? NOP
????????? NOP?????????
????????? RRC? A??????????????? ;再?gòu)腄S1302接收數(shù)據(jù)
????????? NOP
????????? NOP??????????
????????? SETB? SCLK
????????? NOP
????????? NOP??????????
????????? DJNZ? R2,READ_02
????????? MOV? R0,A
????????? CLR? RST
????????? RET
;==============================================
;實(shí)時(shí)時(shí)間、日期數(shù)據(jù)處理子程序
;==============================================
?CHULI:
????????? MOV A,40H?????????????? ;處理秒數(shù)據(jù)
????????? ANL A,#0FH
????????? MOV 50H,A
????????? MOV 70H,A
????????? MOV A,40H
????????? ANL A,#11110000B
????????? SWAP A
????????? MOV 51H,A
????????? MOV 71H,A
;---------------------------------------------
????????? MOV A,41H?????????????? ;處理分?jǐn)?shù)據(jù)
????????? ANL A,#0FH
????????? MOV 52H,A
????????? MOV 72H,A
????????? MOV A,41H
????????? ANL A,#11110000B
????????? SWAP A
????????? MOV 53H,A
????????? MOV 73H,A
;---------------------------------------------
????????? MOV A,42H?????????????? ;處理時(shí)數(shù)據(jù)
????????? ANL A,#0FH
????????? MOV 54H,A
????????? MOV 74H,A
????????? MOV A,42H
????????? ANL A,#11110000B
????????? SWAP A
????????? MOV 55H,A
????????? MOV 75H,A
;----------------------------------------------
????????? MOV A,43H?????????????? ;處理日數(shù)據(jù)
????????? ANL A,#0FH
????????? MOV 60H,A
????????? MOV 76H,A
????????? MOV A,43H
????????? ANL A,#11110000B
????????? SWAP A
????????? MOV 61H,A
????????? MOV 77H,A
;---------------------------------------------
????????? MOV A,44H?????????????? ;處理月數(shù)據(jù)
????????? ANL A,#0FH
????????? MOV 62H,A
????????? MOV 78H,A
????????? MOV A,44H
????????? ANL A,#11110000B
????????? SWAP A
????????? MOV 63H,A
????????? MOV 79H,A
;---------------------------------------------
????????? MOV A,45H?????????????? ;處理年數(shù)據(jù)
????????? ANL A,#0FH
????????? MOV 64H,A
????????? MOV? 7AH,A
????????? MOV A,45H
????????? ANL A,#11110000B
????????? SWAP A
????????? MOV 65H,A
????????? MOV 7BH,A
;----------------------------------------------
????????? MOV A,46H?????????????? ;處理周數(shù)據(jù)
????????? MOV 66H,A
????????? MOV 7CH,A
????????? RET
;=============================================
;實(shí)時(shí)時(shí)間、日期查表取數(shù)子程序
;=============================================
DISP:???? ;MOV? R0,#TIME_DATA
????????? MOV R3,#06H
DISP1:??? MOV A,@R0
????????? MOV DPTR,#TAB_NU
????????? MOVC A,@A+DPTR
????????? MOV @R0,A
????????? INC R0
????????? DJNZ R3,DISP1
????????? RET
;====================================================
;時(shí)間、日期顯示子程序
;====================================================
TIME_DISPLAY:
????????? ;MOV? R0,#TIME_DATA????? ;取得顯示單元首地址
????????? MOV? R1,#07FH????????? ;從第一個(gè)數(shù)碼管開始
????????? MOV? R2,#08H?????????? ;共8個(gè)數(shù)碼管
DISLP:??? MOV? P0,@R0??????????? ;獲得當(dāng)前單元數(shù)據(jù)
????????? MOV? A,R1
????????? MOV? P2,A???????????? ;數(shù)碼顯示
????????? JB? ACC.5,DISLP1????? ;第三位數(shù)碼管顯示 -
????????? MOV? P0,#0BFH
????????? JMP? DISLP3
DISLP1:?? JB? ACC.2,DISLP2????? ;第六位數(shù)碼管顯示 -
????????? MOV? P0,#0BFH
????????? JMP? DISLP3
DISLP2:?? INC? R0
DISLP3:?? MOV? A,R1????????????? ;為下一個(gè)數(shù)準(zhǔn)備
????????? RR? A????????????????? ;下一個(gè)單元
????????? MOV? R1,A????????????? ;保存
????????? LCALL? DELAY?????????? ;為了保證數(shù)碼管亮度,延時(shí)
????????? DJNZ? R2,DISLP??????? ;重復(fù)顯示,直到全部數(shù)據(jù)刷新過
????????? RET?????????????????? ;返回
DELAY:
????????? MOV? R4,#0AH
? L15:??? MOV? R5,#64H
? L16:??? DJNZ? R5,L16
????????? DJNZ? R4,L15
????????? RET
;******************************************************
SET_KEY:
???????? SETB? K1???????????? ;增加鍵
???????? SETB? K2???????????? ;減少鍵
???????? SETB? K3???????????? ;選擇鍵
???????? SETB? K4???????????? ;定時(shí)設(shè)定功能鍵
???????? NOP
???????? JB? K4,KEY01
???????? LCALL? BEEP_BL
???????? JMP? DS_KEY????????? ;進(jìn)入定時(shí)值設(shè)定子程序
KEY01:?? JB? K2,KEY02
???????? LCALL? BEEP_BL
???????? JMP? SET_TIME??????? ;進(jìn)入時(shí)間設(shè)定子程序
KEY02:?? JB? K3,KEY03
???????? LCALL? BEEP_BL
???????? CPL? 20H.0????????? ;止鬧標(biāo)記取反
KEY03:?? RET
;-----------------------------------------------------
DS_KEY:
???????? CALL? DS_DELAY
???????? JNB? K4,$??????????
???????? LCALL? DSSET
???????? CALL? DS_DELAY
???????? RET
;==============================================
;實(shí)時(shí)時(shí)間設(shè)定子程序
;K1為加鍵、K2為減鍵、K3為選擇鍵
;==============================================
SET_TIME:
???????? MOV? R1,#8EH????????? ;寫保護(hù)寄存器
???????? MOV? R0,#00H????????? ;允許寫入
???????? LCALL WRITE
???????? MOV? R1,#80H????????? ;寫秒寄存器
???????? MOV? R0,#80H????????? ;停止振蕩器工作
???????? LCALL WRITE
???????? SETB? TR0
K001:??? CALL TIME_DELAY?????? ;校時(shí)
???????? JNB K3,K001?????????? ;K3為位移鍵
K010:
???????? CALL? CHULI
???????? JNB? 0AH,KH01
???????? MOV? 54H,7FH????????? ;送入熄滅符
???????? MOV? 55H,7FH
???????? JMP? KH02
?KH01:?? MOV? 54H,74H????????? ;送實(shí)時(shí)值
???????? MOV? 55H,75H????????? ;送實(shí)時(shí)值
?KH02:?? MOV? R0,#TIME_DATA
???????? CALL? DISP
???????? MOV? R0,#TIME_DATA
???????? CALL? TIME_DISPLAY
???????? JNB? K1,K011A
???????? JNB? K2,K011B
???????? JNB? K3,K002
???????? JMP? K010
K011A:
???????? MOV? A,42H
???????? ADD A,#01H
???????? DA A
???????? MOV 42H,A
???????? XRL? A,#24H
???????? JNZ K012A
???????? MOV? 42H,#00H
K012A:?? MOV? R1,#84H?????????? ;寫時(shí)寄存器
???????? MOV? R0,42H
???????? LCALL WRITE
???????? CALL? TIME_DELAY
???????? JMP? K010
K011B:
???????? MOV? A,42H
???????? XRL? A,#00H
???????? JZ? K012B
???????? SETB? C????????????? ;求補(bǔ)運(yùn)算
???????? CLR? A
???????? ADDC? A,#99H???????? ;加99
???????? SUBB? A,#01H???????? ;減去減數(shù)
???????? ADD?? A,42H????????? ;加被減數(shù)
???????? DA A???????????????? ;十進(jìn)制調(diào)整
???????? MOV 42H,A??????????? ;
???????? XRL? A,#00H
???????? JNZ K012C
K012B:?? MOV? 42H,#23H
K012C:?? MOV? R1,#84H?????????? ;寫時(shí)寄存器
???????? MOV? R0,42H
???????? LCALL WRITE
???????? CALL? TIME_DELAY
???????? JMP? K010
;-------------------------------------------------
K002:??? CALL TIME_DELAY?????? ;校分
???????? JNB K3,K002??????????? ;K3為位移鍵
K020:??? CALL? CHULI
???????? JNB? 0AH,KM01
???????? MOV? 52H,7FH????????? ;送入熄滅符
???????? MOV? 53H,7FH
???????? JMP? KM02
?KM01:?? MOV? 52H,72H????????? ;送實(shí)時(shí)值
???????? MOV? 53H,73H????????? ;送實(shí)時(shí)值
?KM02:?? MOV? R0,#TIME_DATA
???????? CALL? DISP
???????? MOV? R0,#TIME_DATA
???????? CALL? TIME_DISPLAY
???????? JNB? K1,K021A
???????? JNB? K2,K021B
???????? JNB? K3,K003
???????? JMP? K020
K021A:
???????? MOV? A,41H
???????? ADD? A,#01H
???????? DA A
???????? MOV? 41H,A
???????? XRL? A,#60H
???????? JNZ? K022A
???????? MOV? 41H,#00H
K022A:?? MOV? R1,#82H?????????? ;寫分寄存器
???????? MOV? R0,41H
???????? LCALL WRITE
???????? CALL? TIME_DELAY
???????? JMP? K020
;---------------------------------------------------
K021B:
???????? MOV? A,41H
???????? XRL? A,#00H
???????? JZ? K022B
???????? SETB? C????????????? ;求補(bǔ)運(yùn)算
???????? CLR? A
???????? ADDC? A,#99H???????? ;加99
???????? SUBB? A,#01H???????? ;減去減數(shù)
???????? ADD?? A,41H????????? ;加被減數(shù)
???????? DA A???????????????? ;十進(jìn)制調(diào)整
???????? MOV 41H,A??????????? ;
???????? XRL? A,#00H
???????? JNZ K022C
K022B:?? MOV? 41H,#59H
K022C:?? MOV? R1,#82H?????????? ;寫分寄存器
???????? MOV? R0,41H
???????? LCALL WRITE
???????? CALL? TIME_DELAY
???????? JMP? K020
;---------------------------------------------------
K003:??? CALL DATE_DELAY?????? ;校日
???????? JNB K3,K003??????????? ;K3為位移鍵
K030:??? CALL? CHULI
???????? JNB? 0AH,KR01
???????? MOV? 60H,7FH????????? ;送入熄滅符
???????? MOV? 61H,7FH
???????? JMP? KR02
?KR01:?? MOV? 60H,76H????????? ;送實(shí)時(shí)值
???????? MOV? 61H,77H????????? ;送實(shí)時(shí)值
?KR02:?? MOV? R0,#DATE_DATA
???????? CALL? DISP
???????? MOV? R0,#DATE_DATA
???????? CALL? TIME_DISPLAY
???????? JNB? K1,K031A
???????? JNB? K2,K031B
???????? JNB? K3,K004
???????? JMP? K030
K031A:
???????? MOV? A,43H
???????? ADD? A,#01H
???????? DA A
???????? MOV? 43H,A
???????? XRL? A,#32H
???????? JNZ? K032A
???????? MOV? 43H,#00H
K032A:??? MOV? R1,#86H?????????? ;寫日寄存器
???????? MOV? R0,43H
???????? LCALL WRITE
???????? CALL? DATE_DELAY
???????? JMP? K030
K031B:
???????? MOV? A,43H
???????? XRL? A,#00H
???????? JZ? K032B
???????? SETB? C??????????????? ;求補(bǔ)運(yùn)算
???????? CLR? A
???????? ADDC? A,#99H?????????? ;加99
???????? SUBB? A,#01H?????????? ;減去減數(shù)
???????? ADD?? A,43H??????????? ;加被減數(shù)
???????? DA A?????????????????? ;十進(jìn)制調(diào)整
???????? MOV 43H,A
???????? XRL? A,#00H
???????? JNZ K032C
K032B:?? MOV? 43H,#31H
K032C:?? MOV? R1,#86H?????????? ;寫日寄存器
???????? MOV? R0,43H
???????? LCALL WRITE
???????? CALL? DATE_DELAY
???????? JMP? K030
;------------------------------------------------
K004:??? CALL DATE_DELAY??????? ;校月
???????? JNB K3,K004??????????? ;K3為位移鍵
K040:??? CALL? CHULI
???????? JNB? 0AH,KC01
???????? MOV? 62H,7FH?????????? ;送入熄滅符
???????? MOV? 63H,7FH
???????? JMP? KC02
?KC01:?? MOV? 62H,78H?????????? ;送實(shí)時(shí)值
???????? MOV? 63H,79H?????????? ;送實(shí)時(shí)值
?KC02:?? MOV? R0,#DATE_DATA
???????? CALL? DISP
???????? MOV? R0,#DATE_DATA
???????? CALL? TIME_DISPLAY
???????? JNB? K1,K041A
???????? JNB? K2,K041B
???????? JNB? K3,K005
???????? JMP? K040
K041A:
???????? MOV? A,44H
???????? ADD? A,#01H
???????? DA A
???????? MOV? 44H,A
???????? XRL? A,#13H
???????? JNZ? K042A
???????? MOV? 44H,#00H
K042A:?? MOV? R1,#88H?????????? ;寫月寄存器
???????? MOV? R0,44H
???????? LCALL WRITE
???????? CALL? DATE_DELAY
???????? JMP? K040
K041B:
???????? MOV? A,44H
???????? XRL? A,#00H
???????? JZ? K042B
???????? SETB? C????????????? ;求補(bǔ)運(yùn)算
???????? CLR? A
???????? ADDC? A,#99H???????? ;加99
???????? SUBB? A,#01H???????? ;減去減數(shù)
???????? ADD?? A,44H????????? ;加被減數(shù)
???????? DA A???????????????? ;十進(jìn)制調(diào)整
???????? MOV 44H,A??????????? ;
???????? XRL? A,#00H
???????? JNZ? K042C
K042B:?? MOV? 44H,#12H
K042C:?? MOV? R1,#88H??????? ;寫月寄存器
???????? MOV? R0,44H
???????? LCALL WRITE
???????? CALL? DATE_DELAY
???????? JMP? K040
;-----------------------------------------------
K005:???? CALL DATE_DELAY?????? ;校年
???????? JNB K3,K005??????????? ;K3為位移鍵
K050:??? CALL? CHULI
???????? JNB? 0AH,KY01
???????? MOV? 64H,7FH????????? ;送入熄滅符
???????? MOV? 65H,7FH
???????? JMP? KY02
?KY01:?? MOV? 64H,7AH????????? ;送實(shí)時(shí)值
???????? MOV? 65H,7BH????????? ;送實(shí)時(shí)值
?KY02:?? MOV? R0,#DATE_DATA
???????? CALL? DISP
???????? MOV? R0,#DATE_DATA
???????? CALL? TIME_DISPLAY
???????? JNB? K1,K051A
???????? JNB? K2,K051B
???????? JNB? K3,K008
???????? JMP? K050
K051A:
???????? MOV? A,45H
???????? ADD? A,#01H
???????? DA A
???????? MOV? 45H,A
???????? XRL? A,#9AH
???????? JNZ? K052A
???????? MOV? 45H,#00H
K052A:?? MOV? R1,#8CH???????? ;寫年寄存器
???????? MOV? R0,45H
???????? LCALL WRITE
???????? CALL? DATE_DELAY
???????? JMP?? K050
K051B:
???????? MOV? A,45H
???????? XRL? A,#00H
???????? JZ? K052B
???????? SETB? C????????????? ;求補(bǔ)運(yùn)算
???????? CLR? A
???????? ADDC? A,#99H???????? ;加99
???????? SUBB? A,#01H???????? ;減去減數(shù)
???????? ADD?? A,45H????????? ;加被減數(shù)
???????? DA A???????????????? ;十進(jìn)制調(diào)整
???????? MOV? 45H,A??????????? ;
???????? XRL? A,#00H
???????? JNZ? K052C
K052B:?? MOV? 45H,#99H
K052C:?? MOV? R1,#8CH???????? ;寫年寄存器
???????? MOV? R0,45H
???????? LCALL WRITE
???????? CALL? DATE_DELAY
???????? JMP?? K050
;-------------------------------------------------
K008:??? JNB K3,K008
???????? MOV? R1,#80H????????? ;寫秒寄存器
???????? MOV? R0,#00H????????? ;啟動(dòng)振蕩器工作
???????? LCALL WRITE
???????? MOV? R1,#8EH????????? ;寫保護(hù)寄存器
???????? MOV? R0,#80H????????? ;禁止寫入
???????? LCALL WRITE
???????? CALL? DATE_DELAY
???????? CLR? 0AH
???????? CLR? TR0
???????? CALL? BEEP_BL
???????? RET
;===================================================
;定時(shí)時(shí)間設(shè)定子程序
;K1為加鍵、K2為減鍵、K3為選擇鍵
;===================================================
DSSET:
???????? SETB? TR0
DS01:??? LCALL DS_DELAY??????? ;定時(shí)分設(shè)定
???????? JNB? K4,$
DS010:?? CALL? DS_CHULI
???????? JNB? 0AH,DS01_1
???????? MOV? 58H,7FH????????? ;送入熄滅符
???????? MOV? 59H,7FH
???????? JMP? DS01_2
DS01_1:? MOV? 58H,70H???????? ;送實(shí)時(shí)值
???????? MOV? 59H,71H???????? ;送實(shí)時(shí)值
DS01_2:? MOV? R0,#58H
???????? LCALL? DS_SP
???????? MOV? R0,#58H
???????? LCALL? DS_DISPLAY
???????? JNB? K1,DS01A??????? ;加鍵
???????? JNB? K2,DS01B??????? ;減鍵
???????? JNB? K3,DS02
???????? JMP? DS010
DS01A:??????????????????????? ;加
????????? MOV? A,48H
????????? ADD A,#01H
????????? DA A
????????? MOV 48H,A
????????? XRL? A,#60H
????????? JNZ DS011
????????? MOV? 48H,#00H
DS011:??? LCALL DS_DELAY
????????? JMP? DS010
DS01B:??? MOV? A,48H????????? ;判48H是否為0
????????? XRL? A,#00H
????????? JZ? DS012
????????? SETB? C????????????? ;減
???????? CLR? A?????????????? ;求補(bǔ)運(yùn)算
???????? ADDC? A,#99H???????? ;加99
???????? SUBB? A,#01H???????? ;減去減數(shù)
???????? ADD?? A,48H????????? ;加被減數(shù)
???????? DA A???????????????? ;十進(jìn)制調(diào)整
???????? MOV 48H,A??????????? ;
???????? XRL? A,#00H
???????? JNZ? DS013
DS012:?? MOV? 48H,#59H
DS013:?? CALL? DS_DELAY
???????? JMP? DS010
;----------------------------------------------
DS02:???? LCALL DS_DELAY????? ;定時(shí)時(shí)設(shè)定
????????? JNB? K3,$
DS020:
???????? CALL? DS_CHULI
???????? JNB? 0AH,DS02_1
???????? MOV? 5AH,7FH????????? ;送入熄滅符
???????? MOV? 5BH,7FH
???????? JMP? DS02_2
DS02_1:? MOV? 5AH,72H????????? ;送實(shí)時(shí)值
???????? MOV? 5BH,73H????????? ;送實(shí)時(shí)值
DS02_2:? MOV? R0,#58H
???????? LCALL? DS_SP
???????? MOV? R0,#58H
???????? LCALL? DS_DISPLAY
???????? JNB? K1,DS02A
???????? JNB? K2,DS02B
???????? JNB? K3,DS03
???????? JMP? DS020
DS02A:??? MOV? A,49H????????? ;加
????????? ADD? A,#01H
????????? DA A
????????? MOV? 49H,A
????????? XRL? A,#24H
????????? JNZ? DS021
????????? MOV? 49H,#00H
DS021:??? LCALL DS_DELAY
????????? JMP? DS020
DS02B:??? MOV? A,49H?????????? ;判49H是否為0
????????? XRL? A,#00H
????????? JZ? DS022
????????? SETB? C????????????? ;減
????????? CLR? A?????????????? ;求補(bǔ)運(yùn)算
????????? ADDC? A,#99H???????? ;加99
????????? SUBB? A,#01H???????? ;減去減數(shù)
????????? ADD?? A,49H????????? ;加被減數(shù)
????????? DA A???????????????? ;十進(jìn)制調(diào)整
????????? MOV 49H,A??????????? ;
????????? XRL? A,#00H
????????? JNZ? DS023
DS022:??? MOV? 49H,#23H
DS023:??? CALL? DS_DELAY
????????? JMP? DS020
;-------------------------------------------
DS03:???? CALL DS_DELAY
????????? JNB? K3,$
DS030:??? CALL? DS_CHULI
????????? JNB? 0AH,DS03_1
????????? MOV? 5CH,7FH???????? ;送入熄滅符
????????? JMP? DS03_2
DS03_1:?? MOV? 5CH,74H???????? ;送實(shí)時(shí)值
DS03_2:?? MOV? R0,#58H?????????
????????? LCALL? DS_SP
????????? MOV? R0,#58H
????????? LCALL? DS_DISPLAY
????????? JNB K3,DS04
????????? JNB? K1,DS03A
????????? JMP? DS030
DS03A:??? CPL? 20H.1????????????? ;報(bào)警標(biāo)記取反
????????? JNB? 20H.1,DS031
????????? MOV? 4AH,#01H?????????? ;報(bào)警標(biāo)記=1,允許報(bào)警
????????? AJMP? DS032
DS031:??? MOV? 4AH,#00H?????????? ;報(bào)警標(biāo)記=0,禁止報(bào)警
DS032:??? LCALL DS_DELAY
????????? JMP? DS030
;--------------------------------------------
DS04:???? CLR? TR0
????????? CLR? 0AH
????????? CALL? BEEP_BL
????????? LCALL DS_DELAY
????????? RET
;=============================================
;定時(shí)時(shí)間數(shù)據(jù)處理子程序
;=============================================
DS_CHULI:
????????? MOV A,48H?????????????? ;處理分?jǐn)?shù)據(jù)
????????? ANL A,#0FH
????????? MOV 58H,A
????????? MOV 70H,A
????????? MOV A,48H
????????? ANL A,#0F0H
????????? SWAP A
????????? MOV 59H,A
????????? MOV 71H,A
????????? MOV A,49H?????????????? ;處理時(shí)數(shù)據(jù)
????????? ANL A,#0FH
????????? MOV 5AH,A
????????? MOV 72H,A
????????? MOV A,49H
????????? ANL A,#0F0H
????????? SWAP A
????????? MOV 5BH,A
????????? MOV 73H,A
????????? MOV A,4AH????????????? ;處理定時(shí)標(biāo)記
????????? ANL A,#01H
????????? MOV 5CH,A
????????? MOV? 74H,A
????????? RET
;==================================================
;定時(shí)時(shí)間查表取數(shù)子程序
;==================================================
DS_SP:??? ;MOV R0,#58H
????????? MOV R3,#05H
DS_SP1:?? MOV A,@R0
????????? MOV DPTR,#TAB_NU
????????? MOVC A,@A+DPTR
????????? MOV @R0,A
????????? INC R0
????????? DJNZ R3,DS_SP1
????????? RET
;==================================================
;定時(shí)時(shí)間顯示子程序
;==================================================
DS_DISPLAY:
????????? ;MOV? R0,#58H????????? ;取得設(shè)定顯示單元首地址
????????? MOV? R1,#07FH????????? ;從第一個(gè)數(shù)碼管開始
????????? MOV? R2,#07H?????????? ;共7個(gè)數(shù)碼管
DSPLAY:?? MOV? P0,@R0??????????? ;獲得當(dāng)前單元數(shù)據(jù)
????????? MOV? A,R1
????????? MOV? P2,A????????????? ;數(shù)碼顯示
????????? JB? ACC.5,DSLP1??????? ;第三位數(shù)碼管顯示“-”
????????? MOV? P0,#0BFH
????????? JMP? DSLP3
DSLP1:??? JB? ACC.2,DSLP2??????? ;第六位數(shù)碼管顯示“-”
????????? MOV? P0,#0BFH
????????? JMP? DSLP3
DSLP2:??? INC? R0
DSLP3:??? MOV? A,R1????????????? ;為下一個(gè)數(shù)準(zhǔn)備
????????? RR? A????????????????? ;下一個(gè)單元
????????? MOV? R1,A????????????? ;保存
????????? LCALL? DELAY
????????? DJNZ? R2,DSPLAY??????? ;重復(fù)顯示,直到全部數(shù)據(jù)刷新過
????????? RET??????????????????? ;返回
;====================================================
;實(shí)時(shí)時(shí)間與設(shè)定時(shí)間比較子程序
;20H.0 止鬧標(biāo)記,=0,允許,=1,禁止。
;20H.1 報(bào)警標(biāo)記,=1,允許,=0,禁止。
;====================================================
COMP:???? JNB? 20H.1,COMP1
????????? MOV? R0,#TIME_DATA
????????? LCALL? TIME_DISPLAY
????????? MOV? A,42H???????????? ;實(shí)時(shí)時(shí)間與設(shè)定時(shí)間比較
????????? CJNE? A,49H,COMP1????? ;先比較時(shí)后比較分
????????? MOV A,41H
????????? CJNE? A,48H,COMP1
????????? JB?? 20H.0,COMP2?????? ;20H.0=1,止鬧開關(guān),關(guān)
????????? ;LCALL? BEEP_BL
????????? CLR? RELAY???????????? ;繼電器吸合1分鐘
????????? JMP? COMP3
COMP1:??? CLR? 20H.0
COMP2:??? SETB? RELAY
COMP3:??? RET
;====================================================
;鍵延時(shí)子程序
;多次調(diào)用顯示程序做鍵延時(shí)
;====================================================
DS_DELAY:
????????? MOV? R6,#0AH???????? ;設(shè)定定時(shí)時(shí)間,鍵延時(shí)用
?DS_KK:
????????? LCALL? DS_CHULI
????????? MOV? R0,#DS_DATA
????????? LCALL? DS_SP
????????? MOV? R0,#DS_DATA
????????? LCALL? DS_DISPLAY
????????? DJNZ? R6,DS_KK
????????? RET
TIME_DELAY:??????????????????? ;設(shè)定時(shí)間,鍵延時(shí)用
????????? MOV? R6,#0AH
TIME_KK:
????????? LCALL? CHULI
????????? MOV? R0,#TIME_DATA
????????? LCALL? DISP
????????? MOV? R0,#TIME_DATA
????????? CALL? TIME_DISPLAY
????????? DJNZ? R6,TIME_KK
????????? RET
DATE_DELAY:??????????????????? ;設(shè)定日期,鍵延時(shí)用
????????? MOV? R6,#0AH
DATE_KK:
????????? LCALL? CHULI
????????? MOV? R0,#DATE_DATA
????????? LCALL? DISP
????????? MOV? R0,#DATE_DATA
????????? CALL? TIME_DISPLAY
????????? DJNZ? R6,DATE_KK
????????? RET
;====================================================
;蜂鳴器響一聲子程序 (適用交流蜂鳴器)
;====================================================
BEEP_BL:
???????? MOV? R6,#100
?BL2:??? CALL? DEX1
???????? CPL? BEEP
???????? DJNZ? R6,BL2
???????? MOV? R5,#10
???????? CALL? DELAY_BL
???????? RET
?DEX1:?? MOV? R7,#180
?DE2:??? NOP
???????? DJNZ? R7,DE2
???????? RET
DELAY_BL:??????????????????? ;(R5)*延時(shí)10MS
???????? MOV? R6,#50
?DL1:??? MOV? R7,#100
???????? DJNZ? R7,$
???????? DJNZ? R6,DL1
???????? DJNZ? R5,DELAY_BL
???????? RET
;*************************************************************
TAB_NU: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H ;0-9
??????? DB 0FFH ;滅
??????? DB 88H,83H,0C6H,0A1H,86H,8EH ;A-F? 《 共陽數(shù)碼管 》
;*************************************************************
??????? END
?
非常好我支持^.^
(0) 0%
不好我反對(duì)
(0) 0%
下載地址
DS1302-制作的電子時(shí)鐘程序分享下載
相關(guān)電子資料下載
- STM32H7時(shí)鐘I/O響應(yīng)頻率和定時(shí)器最高頻率的測(cè)試方法 43
- STM32 RTC Alarm的使用 35
- 對(duì)于波形和電平不標(biāo)準(zhǔn)的時(shí)鐘信號(hào)一般應(yīng)進(jìn)行怎樣的處理? 20
- 時(shí)鐘精度PPM設(shè)置仿真錯(cuò)誤簡(jiǎn)析 21
- FPGA引入光芯片設(shè)計(jì)是未來矩陣計(jì)算新模式? 39
- SV線程的使用和控制 121
- 炫酷好玩的像素時(shí)鐘&音樂頻譜,合宙ESP32-C3開發(fā)板創(chuàng)意DIY分享 122
- 飛秒激光器在醫(yī)學(xué)上的應(yīng)用 97
- 快來!炫酷好玩的像素時(shí)鐘&音樂頻譜,合宙ESP32-C3開發(fā)板創(chuàng)意DIY分享 36
- 國(guó)內(nèi)首座入級(jí)CCS觀測(cè)塔|賽思5G同步設(shè)備賦能「同濟(jì)·海一號(hào)」開展海底科學(xué)觀 153