//本程序为2005带单片机课程设计时所写,并有相关的硬件电路板
//本程序在硬件上测试通过
//晶振为11.0592MHZ
//程序顶用单片机的P1口的I/O引脚做按键
//用四位一体的共阴数码管显现
org 0000h
ljmp start
ORG001BH;INT T1 进口地址
lJMPINT_T1
ORG0080H
start:
MOVSP,#60H
mov30h,#0
mov31h,#0
mov32h,#0
mov33h,#0
mov34h,#0
mov35h,#0
mov36h,#0
mov37h,#0
MOVR3,#0H;时
MOVR2,#0H;分
movr1,#0h;秒
MOVR6,#0H;标志
movr7,#0h;标志
MOV38h,#0H;标志
mov39h,#0h;标志
MOVTMOD,#10H
MOVTL1,#00H;50 mS 的时间常数
MOVTH1,#04CH
MOVR0,#10
movr4,#2
setb p2.7
SETBTR1
SETBET1
SETBEA;答应中止
loop:
lcall scankey
cjner7,#0ffh,wait1
lcall display2
sjmp loop
wait1:
CJNER6,#0FFH,wait
LCALLDISPLAY1
MOV 34H,30H
MOV 35H,31H
MOV 36H,32H
MOV 37H,33H
sjmp loop
wait:
lcall display
SJMPloop
INT_T1:;INT_T1中止服务子程序
PUSHDPH;维护现场
PUSHDPL
PUSHACC
PUSHPSW
CLRTR1
MOVTL1,#00H;50mS 守时常数
MOVTH1,#4CH
SETBTR1
DJNZR4,EXIT1
MOVR4,#2
mov a,30h
CJNEa,#09h,s0
MOV30h,#0
mov a,31h
CJNEa,#9H,s1
MOV31h,#0H
mov a,32h
CJNEa,#9H,s2
MOV32h,#0H
mov a,33h
CJNEa,#9H,s3
MOV33h,#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
DJNZR0,EXIT1;判别毫秒=0
MOVR0,#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:CJNER1,#59H,SECOND;判别秒=59
MOVR1,#99H
minute1:CJNER2,#59H,MINUTE;判别分=59
MOVR2,#99H
hour1:CJNER3,#23H,HOUR;判别时=23
MOVR3,#99H
HOUR:
MOVA,R3
ADDA,#1;时加1
DAA
MOVR3,A
mov a,38h
cjne a,#00,exit1
MINUTE:
MOVA,R2
ADDA,#1;分加1
DAA
MOVR2,A
mov a,39h
cjne a,#00,exit1
SECOND:
MOVA,R1
ADDA,#1;秒加1
DAA
MOVR1,A
EXIT1:
mov 38h,#0h
mov 39h,#0h
POPPSW;康复现场
POPACC
POPDPL
POPDPH
RETI;中止回来
DISPLAY:
MOVA,R3
ANLA,#0FH
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
;MOVP2,#0fbh
setb p2.0
clr p2.2
setb p2.1
setb p2.3
lcall delay
MOVA,R3
SWAPA
ANLA,#0FH
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
setb p2.0
clr p2.3
setb p2.2
setb p2.1
;MOVP2,#0f7h
lcall delay
MOVA,R2
ANLA,#0fH
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
setb p2.1
clr p2.0
setb p2.2
setb p2.3
;MOVP2,#0feh
lcall delay
MOVA,R2
SWAPA
ANLA,#0FH
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
setb p2.0
clr p2.1
setb p2.2
setb p2.3
;MOVP2,#0fdh
lcall delay
RET
display1:
MOVA,30h
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
MOVP2,#0feh
lcall delay
MOVA,31h
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
MOVP2,#0fdh
lcall delay
MOVA,32H
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
MOVP2,#0fbh
lcall delay
MOVA,33H
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
MOVP2,#0f7h
lcall delay
RET
display2:
MOVA,34h
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
MOVP2,#0feh
lcall delay
MOVA,35h
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
MOVP2,#0fdh
lcall delay
MOVA,36H
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
MOVP2,#0fbh
lcall delay
MOVA,37H
mov dptr,#ledseg
movc a,@a+dptr
MOVP0,A
MOVP2,#0f7h
lcall delay
RET
delay:;延时子程序
PUSH0;保存现场
PUSH1
MOV0,#1H
DELAY1: MOV1,#0FH
DJNZ1,$
DJNZ0,DELAY1
POP1;康复现场
POP0
RET
scankey:
setb p1.0
jbp1.0,p11
lcall delay
jbp1.0,p11
mov r6,#0ffh
mov r7,#0h
mov30h,#0
mov31h,#0
mov32h,#0
mov33h,#0
SJMP loop1
p11:
setb p1.1
jbp1.1,P12
lcall delay
jbp1.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: DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H ;0,1,2,3,4,5,6,7
DB7FH,6FH,77H,7CH,39H,5EH,79H,71H ;8,9,A,B,C,D,E,F
DB6DH,02H,08H,00H,59H,0FH,76H
end
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/moni/258355.html