Video demo
Code mã nguồn - Biên dịch bằng Keil c hoăc Pinnale 52
ORG 00H
BEGIN:
MOV P1,#00000000B
MOV P3,#00000000B
LCALL SANGDANTXD1
LCALL SANGDANDLT2
LCALL SANGDAN2BVG3
LCALL SANGDANGV2B4
LCALL SANGCHAYTXD1
LCALL SANGCHAYDLT2
LCALL SANGCHAY2BVG3
LCALL SANGCHAYGR2B4
LCALL SANGDONTXD1
LCALL SANGDONDLT2
LCALL SANGDON2BVG
LCALL SANGDONGR2B
SJMP BEGIN
RET
SANGDANTXD1:
MOV A,#00000000B
MOV P2,A
LCALL DELAY
QUAY1:
SETB C
RLC A
MOV P2,A
LCALL DELAY
CJNE A,#11111111B,QUAY1
RET
SANGDANDLT2:
MOV A,#00000000B
MOV P2,A
LCALL DELAY
QUAY2:
SETB C
RRC A
MOV P2,A
LCALL DELAY
CJNE A,#11111111B,QUAY2
RET
SANGDAN2BVG3:
MOV R0,#00000000B
MOV R1,#00000000B
MOV A,#00000000B
MOV P2,A
LCALL DELAY
QUAY3:
MOV A,R0
SETB C
RLC A
MOV R0,A
MOV A,R1
SETB C
RRC A
MOV R1,A
ORL A,R0
MOV P2,A
LCALL DELAY
CJNE A,#11111111B,QUAY3
RET
SANGDANGV2B4:
MOV R0,#00000000B
MOV R1,#00000000B
MOV A,#00000000B
MOV P2,A
QUAY4:
MOV A,R0
SETB C
RLC A
MOV R0,A
MOV A,R1
SETB C
RRC A
MOV R1,A
ANL A,R0
MOV P2,A
LCALL DELAY
CJNE A,#11111111B,QUAY4
RET
SANGCHAYTXD1:
MOV A,#00000001B
MOV P2,A
LCALL DELAY
QUAY5:
RL A
MOV P2,A
LCALL DELAY
CJNE A,#10000000B,QUAY5
RET
SANGCHAYDLT2:
MOV A,#10000000B
MOV P2,A
LCALL DELAY
QUAY6:
RR A
MOV P2,A
LCALL DELAY
CJNE A,#00000001B,QUAY6
RET
SANGCHAY2BVG3:
MOV R0,#10000000B
MOV R1,#00000001B
MOV A,#00000000B
MOV P2,A
LCALL DELAY
QUAY7:
MOV A,R0
RL A
MOV R0,A
MOV A,R1
RR A
MOV R1,A
ORL A,R0
MOV P2,A
LCALL DELAY
CJNE A,#00011000B,QUAY7
RET
SANGCHAYGR2B4:
MOV R0,#00001000B
MOV R1,#00010000B
MOV A, #00000000B
MOV P2,A
LCALL DELAY
QUAY8:
MOV A,R0
RL A
MOV R0,A
MOV A,R1
RR A
MOV R1,A
ORL A,R0
MOV P2,A
LCALL DELAY
CJNE A,#10000001B,QUAY8
RET
SANGDONTXD1:
BYTELUU1 EQU 20H
BYTEDICH1 EQU 22H
X EQU 24H
Y EQU 25H
LOOP: MOV BYTELUU1,#0
MOV X,#8
X0: MOV Y,X
MOV BYTEDICH1,#0
SETB C
X1: MOV A,BYTEDICH1
RLC A
MOV BYTEDICH1,A
ORL A,BYTELUU1
MOV P2,A
LCALL DELAY
DJNZ Y,X1
MOV BYTELUU1,P2
DJNZ X,X0
RET
SANGDONDLT2:
BYTELUU01 EQU 20H
BYTEDICH01 EQU 22H
T EQU 24H
Q EQU 25H
LOOP01: MOV BYTELUU01,#0
MOV T,#8
T00: MOV Q,T
MOV BYTEDICH01,#0
SETB C
T01:
MOV A,BYTEDICH01
RRC A
MOV BYTEDICH01,A
ORL A,BYTELUU01
MOV P2,A
LCALL DELAY
DJNZ Q,T01
MOV BYTELUU01,P2
DJNZ T,T00
RET
SANGDON2BVG:
MOV P2,#00000000B
LCALL DELAY
MOV P2,#10000001B
LCALL DELAY
MOV P2,#01000010B
LCALL DELAY
MOV P2,#00100100B
LCALL DELAY
MOV P2,#00011000B
LCALL DELAY
MOV P2,#10011001B
LCALL DELAY
MOV P2,#01011010B
LCALL DELAY
MOV P2,#00111100B
LCALL DELAY
MOV P2,#10111101B
LCALL DELAY
MOV P2,#01111110B
LCALL DELAY
MOV P2,#11111111B
LCALL DELAY
RET
SANGDONGR2B:
MOV P2,#00000000B
LCALL DELAY
MOV P2,#00011000B
LCALL DELAY
MOV P2,#01000010B
LCALL DELAY
MOV P2,#10000001B
LCALL DELAY
MOV P2,#10011001B
LCALL DELAY
MOV P2,#10100101B
LCALL DELAY
MOV P2,#11000011B
LCALL DELAY
MOV P2,#11011011B
LCALL DELAY
MOV P2,#11100111B
LCALL DELAY
MOV P2,#11111111B
LCALL DELAY
RET
DELAY:
MOV R2,#3
LAP:
MOV R3,#200
LAP1:
MOV R4,#200
DJNZ R4,$
DJNZ R3,LAP1
DJNZ R2,LAP
RET
END
Điện Tử | Tin Hock - echipkool.com - Chia sẻ kiến thức - Kết nối đam mê điện tử
0 Response to "Lập trình điều khiển 8 led đơn"
Đăng nhận xét