//本程序为2005带单片机课程设计时所写,并有相关的硬件电路板
//本程序在硬件上测试通过
//晶振为11.0592MHZ
//程序中用单片机的P1口的I/O引脚做按键
//用四位一体的共阴数码管显示
org 0000h
ljmp start
ORG 001BH ;INT T1 入口地址
lJMP INT_T1
ORG 0080H
start:
MOV SP,#60H
mov 30h,#0
mov 31h,#0
mov 32h,#0
mov 33h,#0
mov 34h,#0
mov 35h,#0
mov 36h,#0
mov 37h,#0
MOV R3,#0H ;时
MOV R2,#0H ;分
mov r1,#0h ;秒
MOV R6,#0H ;标志
mov r7,#0h ;标志
MOV 38h,#0H ;标志
mov 39h,#0h ;标志
MOV TMOD,#10H
MOV TL1,#00H ;50 mS 的时间常数
MOV TH1,#04CH
MOV R0,#10
mov r4,#2
setb p2.7
SETB TR1
SETB ET1
SETB EA ;允许中断
loop:
lcall scankey
cjne r7,#0ffh,wait1
lcall display2
sjmp loop
wait1:
CJNE R6,#0FFH,wait
LCALL DISPLAY1
MOV 34H,30H
MOV 35H,31H
MOV 36H,32H
MOV 37H,33H
sjmp loop
wait:
lcall display
SJMP loop
INT_T1: ;INT_T1中断服务子程序
PUSH DPH ;保护现场
PUSH DPL
PUSH ACC
PUSH PSW
CLR TR1
MOV TL1,#00H ;50mS 定时常数
MOV TH1,#4CH
SETB TR1
DJNZ R4,EXIT1
MOV R4,#2
mov a,30h
CJNE a,#09h,s0
MOV 30h,#0
mov a,31h
CJNE a,#9H,s1
MOV 31h,#0H
mov a,32h
CJNE a,#9H,s2
MOV 32h,#0H
mov a,33h
CJNE a,#9H,s3
MOV 33h,#0H
s3:
mov a,33h
add a,#1
mov 33h,a
s2:
mov a,32h
add a,#1
mov 32h,a
s1:
mov a,31H
add a,#1
mov 31H,a
s0:
mov a,30H
add a,#1
mov 30H,a
DJNZ R0,EXIT1 ;判断毫秒=0
MOV R0,#10 ;DELAY 1 SECOND
cpl p2.7
mov a,38h
cjne a,#0ffh,next1
ljmp hour1
next1:
mov a,39h
cjne a,#0ffh,next2
ljmp minute1
next2: CJNE R1,#59H,SECOND ;判断秒=59
MOV R1,#99H
minute1:CJNE R2,#59H,MINUTE ;判断分=59
MOV R2,#99H
hour1:CJNE R3,#23H,HOUR ;判断时=23
MOV R3,#99H
HOUR:
MOV A,R3
ADD A,#1 ;时加1
DA A
MOV R3,A
mov a,38h
cjne a,#00,exit1
MINUTE:
MOV A,R2
ADD A,#1 ;分加1
DA A
MOV R2,A
mov a,39h
cjne a,#00,exit1
SECOND:
MOV A,R1
ADD A,#1 ;秒加1
DA A
MOV R1,A
EXIT1:
mov 38h,#0h
mov 39h,#0h
POP PSW ;恢复现场
POP ACC
POP DPL
POP DPH
RETI ;中断返回
DISPLAY:
MOV A,R3
ANL A,#0FH
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
;MOV P2,#0fbh
setb p2.0
clr p2.2
setb p2.1
setb p2.3
lcall delay
MOV A,R3
SWAP A
ANL A,#0FH
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
setb p2.0
clr p2.3
setb p2.2
setb p2.1
;MOV P2,#0f7h
lcall delay
MOV A,R2
ANL A,#0fH
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
setb p2.1
clr p2.0
setb p2.2
setb p2.3
;MOV P2,#0feh
lcall delay
MOV A,R2
SWAP A
ANL A,#0FH
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
setb p2.0
clr p2.1
setb p2.2
setb p2.3
;MOV P2,#0fdh
lcall delay
RET
display1:
MOV A,30h
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
MOV P2,#0feh
lcall delay
MOV A,31h
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
MOV P2,#0fdh
lcall delay
MOV A,32H
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
MOV P2,#0fbh
lcall delay
MOV A,33H
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
MOV P2,#0f7h
lcall delay
RET
display2:
MOV A,34h
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
MOV P2,#0feh
lcall delay
MOV A,35h
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
MOV P2,#0fdh
lcall delay
MOV A,36H
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
MOV P2,#0fbh
lcall delay
MOV A,37H
mov dptr,#ledseg
movc a,@a+dptr
MOV P0,A
MOV P2,#0f7h
lcall delay
RET
delay: ;延时子程序
PUSH 0 ;保存现场
PUSH 1
MOV 0,#1H
DELAY1: MOV 1,#0FH
DJNZ 1,$
DJNZ 0,DELAY1
POP 1 ;恢复现场
POP 0
RET
scankey:
setb p1.0
jb p1.0,p11
lcall delay
jb p1.0,p11
mov r6,#0ffh
mov r7,#0h
mov 30h,#0
mov 31h,#0
mov 32h,#0
mov 33h,#0
SJMP loop1
p11:
setb p1.1
jb p1.1,P12
lcall delay
jb p1.1,p12
mov r6,#0h
mov r7,#0h
sjmp loop1
p12:
SETB P1.2
JB P1.2,p13
lcall delay
jb p1.2,p13
mov r7,#0ffh
sjmp loop1
p13:
setb p1.3
jb p1.3,p14
lcall delay
jb p1.3,p14
mov 38h,#0ffh
sjmp loop1
p14:
setb p1.4
jb p1.4,loop1
lcall delay
jb p1.4,loop1
mov 39h,#0ffh
sjmp loop1
loop1:
ret
LEDSEG: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H ;'0,1,2,3,4,5,6,7'
DB 7FH,6FH,77H,7CH,39H,5EH,79H,71H ;'8,9,A,B,C,D,E,F'
DB 6DH,02H,08H,00H,59H,0FH,76H
end