//本程序?yàn)?005帶單片機(jī)課程設(shè)計(jì)時(shí)所寫,并有相關(guān)的硬件電路板//本程序在硬件上測(cè)試通過(guò)
//晶振為11.0592MHZ
//程序中用單片機(jī)的P1口的I/O引腳做按鍵
//用四位一體的共陰數(shù)碼管顯示
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;時(shí)
MOVR2,#0H;分
movr1,#0h;秒
MOVR6,#0H;標(biāo)志
movr7,#0h;標(biāo)志
MOV38h,#0H;標(biāo)志
mov39h,#0h;標(biāo)志
MOVTMOD,#10H
MOVTL1,#00H;50 mS 的時(shí)間常數(shù)
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
本文引用地址:http://www.ex-cimer.com/article/201611/321863.htmINT_T1:;INT_T1中斷服務(wù)子程序
PUSHDPH;保護(hù)現(xiàn)場(chǎng)
PUSHDPL
PUSHACC
PUSHPSW
CLRTR1
MOVTL1,#00H;50mS 定時(shí)常數(shù)
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;判斷時(shí)=23
MOVR3,#99H
HOUR:
MOVA,R3
ADDA,#1;時(shí)加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;恢復(fù)現(xiàn)場(chǎng)
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:;延時(shí)子程序
PUSH0;保存現(xiàn)場(chǎng)
PUSH1
MOV0,#1H
DELAY1: MOV1,#0FH
DJNZ1,$
DJNZ0,DELAY1
POP1;恢復(fù)現(xiàn)場(chǎng)
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
評(píng)論