10924 views|4 replies

1782

Posts

0

Resources
The OP
 

DS1302 Real-time Clock Module [Copy link]

DS1302 Real-time Clock Module

[ Print ] [ Return ]


;////////////////////////////////////////////////

;This program implements the real-time clock module. Clock chip model: DS1302

;///////////////////////////////////////////////

T_CLK Bit P1.4 ; Real-time clock clock line pin
T_IO Bit P1.5 ; Real-time clock data line pin
T_RST Bit P1.6 ; Real-time clock reset line pin
; 40h--46h store "seconds, minutes, hours, days, months, weeks, and years"
second equ 40h

org 0000h
ajmp main
org 0030h
main:
mov dptr,#tab
mov 40h,#00 ;seconds
mov 41h,#05 ;minutes
mov 42h,#11 ;hours
mov 43h,#23 ;days
mov 44h,#05 ;months
mov 45h,#00 ;weeks
mov 46h,#04 ;years
lcall set1302
loop:
lcall get1302
lcall exchange
mov r4,#3
tt1:
lcall display
djnz r4,tt1
ajmp loop

exchange:
mov a,41h
mov b,#10h
div ab
mov 33h,a
mov a,b
mov 32h,a
mov a,40h
mov b,#10h
div ab
mov 31h,a
mov a,b
mov 30h,a
ret
display:
mov r7,#100
dd1:
mov a,30h
movc a,@a+dptr
mov p0,a
clr p2.0
lcall delay100us
setb p2.0

mov a,31h
movc a,@a+dptr
mov p0,a
clr p2.1
lcall delay100us
setb p2.1

mov a,32h
movc a,@a+dptr
mov p0,a
clr p2.2
lcall delay100us
setb p2.2

mov a,33h
movc a,@a+dptr
mov p0,a
clr p2.3
lcall delay100us
setb p2.3
djnz r7,dd1
ret


delay100us:
mov r5,#50
djnz r5,$
ret

tab: db 0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0f8h,80h,90h,88h,83h,0c6h,0a1h,86h,8eh
;**********************************************************
;Subroutine name: Set1302
;Function: Set the initial time of DS1302 and start timing.
;Call: RTInputByte
;Entry parameter: initial time: Second, Minute, Hour, Day, Month, Week.YearL (address continuous)
;Exit parameter: None
;Affected resources: AB R0 R1 R4 R7
;**********************************************************
Set1302:
CLR T_RST
CLR T_CLK
SETB T_RST
MOV B,#8EH ;Control register
LCALL RTInputByte
MOV B,#00H;WP=0 before write operation
LCALL RTInputByte
SETB T_CLK
CLR T_RST

MOV R0,#Second;
MOV R7,#7; Seconds, time, minute, day, month, week, year
MOV R1,#80H; Seconds write address
S13021: CLR T_RST
CLR T_CLK
SETB T_RST
MOV B,R1; Write seconds, time, minute, day, month, week, year address
LCALL RTInputByte
MOV A,@R0; Write seconds data
MOV B,A
LCALL RTInputByte
INC R0
INC R1
INC R1
SETB T_CLK
CLR T_RST
DJNZ R7,S13021
CLR T_RST
CLR T_CLK
SETB T_RST
MOV B,#8EH; Control register
LCALL RTInputByte
MOV B,#80H; Control, WP=1, write protection
LCALL RTInputByte
SETB T_CLK
CLR T_RST
RET

;**********************************************************
;Subroutine name: Get1302
;Function: Read time from DS1302
;Call: RTInputByte, RTOutputByte
;Input parameter: Time is stored in: Second, Minute, Hour, Day, Month, Week.YearL
;Output parameter: None
;Affected resources: AB R0 R1 R4 R7
;**************************************************************
Get1302:
MOV R0,#Second;
MOV R7,#7
MOV R1,#81H;Second address
G13021: CLRT_RST
CLR T_CLK
SETB T_RST
MOV B,R1;Seconds, hour, day, month, week, year address
LCALL RTInputByte
LCALL RTOutputByte
MOV @R0,A;Seconds
INC R0
INC R1
INC R1
SETB T_CLK
CLR T_RST
DJNZ 7,G13021
RET

;**********************************************************
;Function: write 1302 one byte (internal subroutine)
;**********************************************************
RTInputByte:
MOV R4,#8
Inbit1: MOV A,B
RRC A
MOV B,A
MOV T_IO,C
SETB T_CLK
CLR T_CLK
DJNZ R4,Inbit1
RET

;**********************************************************
;Function: read 1302 one byte (internal subroutine)
;**********************************************************
RTOutputByte:
MOV R4,#8
Outbit1: MOV C,T_IO
RRC A
SETB T_CLK
CLR T_CLK
DJNZ R4,Outbit1
RET
;/ ...

end


This post is from MCU

Latest reply

C is good, I really can't understand assembly  Details Published on 2008-10-14 18:58
 

1379

Posts

0

Resources
2
 
Not bad, not bad
This post is from MCU
 
 

2

Posts

0

Resources
3
 
Newbies come to learn
This post is from MCU
 
 
 

4

Posts

0

Resources
4
 
How do you check the time?
This post is from MCU
 
 
 

43

Posts

0

Resources
5
 
C is good, I really can't understand assembly
This post is from MCU
 
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list