Tương tự như bài trước,chúng mình giới thiệu cho các bạn code lập trình quét 6 led từ 000000 -999999
[alert title="CODE MẪU" icon="info-circle"]
ORG 00
MAIN:
MOV R2,#0
LAPLED:MOV R1,#0
LAPLAI:MOV R0,#0
LAP:CALL HIENTHI
INC R0
CJNE R0,#100,LAP
INC R1
CJNE R1,#100,LAPLAI
INC R2
CJNE R2,#100,LAPLED
JMP MAIN
HIENTHI:
MOV R7,#100
QUET:
MOV P3,#00H
MOV A,R0
MOV B,#10
DIV AB
MOV DPTR,#MALED
MOVC A,@A+DPTR
MOV P2,A
CALL DELAY
SETB P3.4
CALL DELAY
CLR P3.4
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
SETB P3.5
CALL DELAY
CLR P3.5
CALL DELAY
MOV A,R1
MOV B,#10
DIV AB
MOV DPTR,#MALED
MOVC A,@A+DPTR
MOV P2,A
CALL DELAY
SETB P3.2
CALL DELAY
CLR P3.2
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
SETB P3.3
CALL DELAY
CLR P3.3
CALL DELAY
MOV A,R2
MOV B,#10
DIV AB
MOV DPTR,#MALED
MOVC A,@A+DPTR
MOV P2,A
CALL DELAY
SETB P3.0
CALL DELAY
CLR P3.0
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
SETB P3.1
CALL DELAY
CLR P3.1
CALL DELAY
RET
DJNZ R7,QUET
MALED:DB 11000000B,11111001B,10100100B,10110000B,10011001B,
10010010B,10000010B,11111000B,10000000B,10010000B
RET
DELAY:
MOV R4,#35
LAP1:
MOV R5,#20
LAPA:
NOP
NOP
NOP
NOP
DJNZ R5,LAPA
DJNZ R4,LAP1
RET
END
MAIN:
MOV R2,#0
LAPLED:MOV R1,#0
LAPLAI:MOV R0,#0
LAP:CALL HIENTHI
INC R0
CJNE R0,#100,LAP
INC R1
CJNE R1,#100,LAPLAI
INC R2
CJNE R2,#100,LAPLED
JMP MAIN
HIENTHI:
MOV R7,#100
QUET:
MOV P3,#00H
MOV A,R0
MOV B,#10
DIV AB
MOV DPTR,#MALED
MOVC A,@A+DPTR
MOV P2,A
CALL DELAY
SETB P3.4
CALL DELAY
CLR P3.4
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
SETB P3.5
CALL DELAY
CLR P3.5
CALL DELAY
MOV A,R1
MOV B,#10
DIV AB
MOV DPTR,#MALED
MOVC A,@A+DPTR
MOV P2,A
CALL DELAY
SETB P3.2
CALL DELAY
CLR P3.2
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
SETB P3.3
CALL DELAY
CLR P3.3
CALL DELAY
MOV A,R2
MOV B,#10
DIV AB
MOV DPTR,#MALED
MOVC A,@A+DPTR
MOV P2,A
CALL DELAY
SETB P3.0
CALL DELAY
CLR P3.0
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
SETB P3.1
CALL DELAY
CLR P3.1
CALL DELAY
RET
DJNZ R7,QUET
MALED:DB 11000000B,11111001B,10100100B,10110000B,10011001B,
10010010B,10000010B,11111000B,10000000B,10010000B
RET
DELAY:
MOV R4,#35
LAP1:
MOV R5,#20
LAPA:
NOP
NOP
NOP
NOP
DJNZ R5,LAPA
DJNZ R4,LAP1
RET
END
Đăng nhận xét