单片机的时钟电路
tiME20 EQU 7DH
ORG 0000H
AJMP MAIN
ORG 000BH
AJMP INTT0
org 0040h
MAIN:
mov p1,#55h
mov 7eh,#01h ;位选首地址
mov 70h,#11H ;时寄存器
mov 71h,#59H ;分寄存器
mov 72h,#50H ;秒寄存器
MOV IE,#82H
MOV TH0,#3CH
MOV TL0,#0B0H
MOV TMOD,#01H
SETB TR0
MOV TIME20,#20
loop:
mov r0,#70h
mov 7eh,#1 ;位选首地址
mov 7fh,#3 ;三个寄存器分成六个数码管显示.
acall display
ajmp loop
;;;;;;;;;;;;;;;;;;;;
display:
mov a,7eh
mov dptr,#1F01h
movx @dptr,a
rl a
mov 7eh,a ;送位选
mov dptr,#table
mov a,@r0
swap a
anl a,#0fh
movc a,@a+dptr
mov dptr,#1F00h
movx @dptr,a ;送段选
acall delay
mov a,7eh
mov dptr,#1F01h
movx @dptr,a
rl a
mov 7eh,a ;送位选
mov dptr,#table
mov a,@r0
anl a,#0fh
movc a,@a+dptr
mov dptr,#1F00h
movx @dptr,a ;送段选
acall delay
inc r0
djnz 7fh,display
ret
;;;;;;;;;;;;;;;;;;
delay:
mov r7,#50
del:mov r6,#50
djnz r6,$
djnz r7,del
ret
;;;;;;;;;;;;;;;;;;
INTT0:
PUSH ACC
PUSH PSW
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ TIME20,OUT
MOV TIME20,#20
MOV A,72H
ADD A,#01H ;秒寄存器+1
DA A
MOV 72H,A
CJNE A,#60H,OUT ;秒到了60否?
MOV 72H,#00H
MOV A,71H ;分寄存器+1
ADD A,#01H
DA A
MOV 71H,A
CJNE A,#60H,OUT ;分到了60否?
MOV 71H,#00H
MOV A,70H ;时寄存器+1
ADD A,#01H
DA A
CJNE A,#12H,OUT ;时到了12否?
MOV 70H,#00H
OUT:
POP PSW
POP ACC
RETI
table:
db 0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0f8h,80h,90h
end
0