以下程序实现6位数码管,每一位依次循环显示0--9
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:
MOV P2,#0FEH
MOV A,#00H
MOV DPTR,#TAB
LOOP:
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
INC A
CJNE A,#0AH,LOOP
MOV A,P2
RL A
MOV P2,A
JB ACC.6,SS1
MOV P2,#0FEH
SS1:
CLR A
SJMP LOOP
DELAY:
MOV R1,#2
L1: MOV R2,#200
L2: MOV R3,#200
L3: DJNZ R3,L1
DJNZ R2,L2
DJNZ R1,L3
RET SJMP $
ORG 0080H
TAB:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
你的程序问题太多了,修改后如下,自己对照一下吧
ORG 0000H
LJMP START
ORG 0030H
START:MOV P2,#0FEH
MOV R6,#00H ;不能用A保存计数值,要用另一个寄存器
MOV DPTR,#TAB
SS: MOV A,R6 ;计数值送A
MOVC A,@A+DPTR ;A取出段码后发生变化,计数值就没有了
MOV P0,A
CALL DELAY
INC R6 ;计数值加1
CJNE R6,#0AH,SS
MOV R6,#0 ;回0重新计数
AJMP SS ;返回继续显示
DELAY:MOV R1,#5
L1: MOV R2,#200
L2: MOV R3,#200
L3: DJNZ R3,L3 ;改过
DJNZ R2,L2
DJNZ R1,L1 ;改过
RET
TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END
正确程序如下:
ORG 0000H
LJMP START
ORG 0030H
START:
MOV DPTR, #TAB
MOV R4, #0FEH
MOV R5, #0
SS:
MOV P2, R4
MOV A, R5
MOVC A, @A + DPTR
MOV P0, A
CALL DELAY
MOV A, R4
RL A
MOV R4, A
CJNE R4, #0FEH, SS
INC R5
CJNE R5, #10, SS
LJMP START
DELAY:
MOV R1, #2
L1: MOV R2, #200
L2: MOV R3, #200
L3: DJNZ R3, L3
DJNZ R2, L2
DJNZ R1, L1
RET
TAB:
DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END