;定时器定时一秒,一个数码管秒个位加1,同时八个LED灯循环流动
很简单的题目,只能写很简单的程序:
ORG 0000H
JMP START
ORG 000BH
INC R2
RETI
START:
SETB TR0
MOV IE, #82H
MOV R3, #127
LP: MOV R4, #0
DP: MOV A, R4
MOV DPTR, #TAB
MOVC A, @A + DPTR
MOV P3, A
MOV P0, R3
MOV A, R3
RR A
MOV R3, A
CJNE R2, #122, $ ;定时 999424us
MOV R2, #0
INC R4
CJNE R4, #10, DP
JMP LP
TAB:
DB 0C0H,0F9H,0A4H,0B0H, 99H
DB 92H, 82H, 0F8H, 80H, 90H
END
ORG 0000H
LJMP BEGIN
ORG 000BH
LJMP T0ISR
ORG 0030H
;---------------------------------------
BEGIN:
MOV SP,#5FH
MOV TMOD,#01H
MOV TH0,#3CH
MOV TL0,#0B0H
MOV A,#0
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P1,A
SETB TR0
SETB ET0
SETB EA
MOV R2,#0
MOV R4,#0
MOV R7,#0
SJMP $
T0ISR:
CLR TR0
MOV TH0,#3CH
MOV TL0,#0B0H
SETB TR0
INC R7
CJNE R7,#10,T01
T01:
JC T0E
MOV R7,#0
INC R2
INC R4
CJNE R2,#10,T02
T02:
JC LP
MOV R2,#0
LP:
MOV A,R2
MOV DPTR,#TABLE
MOVC A,@A+DPTR ;找到相应位显示代码
MOV P1,A
CJNE R4,#9,T03
T03:
JC LEDDIS
MOV R4,#1
LEDDIS:
MOV A,#0FFH
CLR C
PUSH 04H
LEDDIS1:
RLC A
DJNZ R4,LEDDIS1
MOV P0,A
POP 04H
T0E:
RETI
TABLE: ; 共阴极数码管显示代码表
DB 3FH,06H,5BH,4FH,66H ;01234
DB 6DH,7DH,07H,7FH,6fh ;56789
END
本回答被提问者和网友采纳