89c51单片机。上的数码管编写汇编语言的问题。
如第一个显示0.熄灭以后第二个显示1. 展开
M EQU 004BH
N EQU 004CH
ORG 0000H
AJMP MAIN
ORG 0060H
MAIN: MOV R3,#06H
MOV N,#20H
MOV DPTR,#TABLE
L: MOVC A,@A+DPTR
MOV P2,A
CJNE R4,#06H,Q
MOV N,#20H
Q: MOV P1,N
LCALL DELAY
MOV A,N
RR A
MOV N,A
INC M
MOV R4,M
DJNZ R3,S
MOV M,#00H
MOV R3,#06H
S: MOV A,M
LCALL DELAY
AJMP L
ORG 0100H
DELAY: MOV R0,#00H
D1: MOV R1,#00H
D0: NOP
NOP
DJNZ R1,D0
DJNZ R0,D1
RET
ORG 0090H
TABLE: DB 0xc0,0xf9,0xa4,0xb0,0x99,0x92//,0x82,0xf8,0x80,0x90//编码范围:0-9
END
有些地方还可以优化的
2023-07-28 广告
AJMP MAIN
ORG 30H
MAIN:
MOV DPTR,#TAB
MOV P1,#0
MAIN1:
ACALL DISP
AJMP MAIN1
DISP:
MOV A,#0
MOVC A,@A+DPTR
MOV P2,A
SETB P1.0
ACALL DELAY
CLR P1.0
MOV A,#1
MOVC A,@A+DPTR
MOV P2,A
SETB P1.1
ACALL DELAY
CLR P1.1
MOV A,#2
MOVC A,@A+DPTR
MOV P2,A
SETB P1.2
ACALL DELAY
CLR P1.2
MOV A,#3
MOVC A,@A+DPTR
MOV P2,A
SETB P1.3
ACALL DELAY
CLR P1.3
MOV A,#4
MOVC A,@A+DPTR
MOV P2,A
SETB P1.4
ACALL DELAY
CLR P1.4
MOV A,#5
MOVC A,@A+DPTR
MOV P2,A
SETB P1.5
ACALL DELAY
CLR P1.5
RET
DELAY:
MOV R7,#250
MOV R6,#100
MOV R5,#10
DJNZ R5,$
DJNZ R6,$-4
DJNZ R7,$-8
RET
TAB:
DB 0C0H;0
DB 0F9H;1
DB 0A4H;2
DB 0B0H;3
DB 099H;4
DB 092H;5
END
JMP MAIN
ORG 30H
MAIN:
MOV 40H, #0C0H;0
MOV 41H, #0F9H;1
MOV 42H, #0A4H;2
MOV 43H, #0B0H;3
MOV 44H, #099H;4
MOV 45H, #092H;5
M2:
MOV R0, #40H
MOV R2, #6
MOV A, #1
M_LOOP:
MOV P1, #0
MOV P2, @R0
MOV P1, A
INC R0
RL A
CALL DELAY
DJNZ R2, M_LOOP
JMP M2
DELAY:
MOV R7, #250
MOV R6, #100
MOV R5, #10
DJNZ R5, $
DJNZ R6, $ - 4
DJNZ R7, $ - 8
RET
END
参考资料: 47okey的回答
AJMP XGC
ORG 0100H
XGC: MOV P2,#01
MOV A,#00H
MOV DPTR,#CB
MOVC A,@A+DPTR
MOV P0,A
LCALL CX
MOV P2,#02
MOV A,#01H
MOV DPTR,#CB
MOVC A,@A+DPTR
MOV P0,A
LCALL CX
MOV P2,#04
MOV A,#02H
MOV DPTR,#CB
MOVC A,@A+DPTR
MOV P0,A
LCALL CX
MOV P2,#08H
MOV A,#03H
MOV DPTR,#CB
MOVC A,@A+DPTR
MOV P0,A
LCALL CX
MOV P2,#10H
MOV A,#04H
MOV DPTR,#CB
MOVC A,@A+DPTR
MOV P0,A
LCALL CX
MOV P2,#20H
MOV A,#05H
MOV DPTR,#CB
MOVC A,@A+DPTR
MOV P0,A
LCALL CX
LJMP XGC
CB: DB 06H,5BH,3FH,6DH,06H,3FH
CX: MOV R7,#20
D1: MOV R6,#25
D2: NOP
NOP
NOP
DJNZ R6,D2
DJNZ R7,D1
RET
END