ORG 00H
MAIN:
CALL CTA;goi chuong trinh con
CALL CTB
CALL CTC
CALL CTD
JMP MAIN
CTA:;sang nhap nhay 2 port
MOV R2,#5;vong lap nhap nhay 5 lan
LAP:
MOV P2,#00H;port 2 tat
MOV P3,#00H;port 3 tat
CALL DELAY
MOV P2,#0FFH;port 2 sang
MOV P3,#0FFH;port 3 sang
CALL DELAY
DJNZ R2,LAP
RET
CTB:;sang 1 led chay
MOV R2,#5
QUAY:
;SANG DUOI SANG PHAI
MOV A,#10000000B;thiet lap bit p2.7 sang
LAP1:
MOV P3,#00H;xoa port 3 tranh nhieu
MOV P2,A
CALL DELAY
RR A;lenh quay phai bit thanh ghi A 1 cu chay dan sang phai
CJNE A,#10000000B,LAP1;kiem tra
MOV P2,#00H
MOV A,#10000000B
LAP2:
MOV P3,A
CALL DELAY
RR A
CJNE A,#10000000B,LAP2
;SANG DUOI SANG TRAI
MOV A,#00000001B
LAP11:
MOV P3,A
CALL DELAY
RL A
CJNE A,#00000001B,LAP11
MOV P2,#00H
MOV A,#10000000B
LAP22:
MOV P3,#00H
MOV P2,A
CALL DELAY
RL A
CJNE A,#10000000B,LAP22
DJNZ R2,QUAY
RET
CTC:;sang dan 1 led lan luot tung port
MOV A,#00H;Thiet lap thanh ghi A bang 0
LAP3:
SETB C;thiet lap bit co nho len 1
RRC A;quay phai co co nho
MOV P2,A
CALL DELAY
CJNE A,#0FFH,LAP3
MOV A,#00H
LAP4:
SETB C
RRC A
MOV P3,A
CALL DELAY
CJNE A,#0FFH,LAP4
RET
CTD:;sang dan 2 pot cung luc
MOV R0,#00H
MOV R1,#00H
LAP5:
SETB C
MOV A,R0
RRC A
MOV R0,A
MOV P2,R0
CALL DELAY
SETB C
MOV A,R1
RRC A
MOV R1,A
MOV P3,R1
CALL DELAY
CJNE R1,#0FFH,LAP5
RET
DELAY:;chuong trinh tao tre
MOV R3,#200
LOOP:
MOV R4,#250
LOOP2:
DJNZ R4,LOOP2
DJNZ R3,LOOP
RET
END
Đăng nhận xét