Hôm nay THIETKEMACHDIENTU.NET xin giới thiệu với bạn một số chương trình điều khiển led đơn đơn giản như sau:
1.Chương trình led sáng nhấp nháy port 1.
2.Chương trình Led sáng dần port 1
3.Chương trình led tắt dần port 1
4.Sáng dần tắt dần theo chiều ngược lại:
ORG 00H
MAIN:
MOV P1,#00H;led tắt hết
CALL DELAY
MOV P1,#0FFH;led sáng hết
CALL DELAY
JMP MAIN
DELAY:;CT tạo trễ
MOV R0,#50
LAP:
NOP
NOP
DJNZ R0,LAP
RET
END
•ORG 00H
MAIN:
•MOV P1,#00000000B;Trạng thái led tắt hết
•CALL DELAY
•MOV P1,#00000001B;Led p1.0 sáng
•CALL DELAY
•MOV P1,#00000011B;led p1.0,p1.1 sáng
•CALL DELAY
•MOV P1,#00000111B;led p1.0,p1.1,p1.2 sáng
•CALL DELAY
•MOV P1,#00001111B
•CALL DELAY
•MOV P1,#00011111B
•CALL DELAY
•MOV P1,#00111111B
•CALL DELAY
•MOV P1,#01111111B
•CALL DELAY
•MOV P1,#11111111B
•CALL DELAY
JMP MAIN
DELAY:
•MOV R0,#200
•LAP:
•MOV R1,#200
•LAP2:
•NOP
•NOP
•NOP
•DJNZ R1,LAP2
•DJNZ R0,LAP
•RET
END
ORG 00H
•MAIN:
•MOV P1,#11111111B;Trạng thái led sáng hết
•CALL DELAY
•MOV P1,#11111110B;Led p1.0 tắt
•CALL DELAY
•MOV P1,#11111100B;led p1.0 tắt,p1.1 tắt
•CALL DELAY
•MOV P1,#11111000B
•CALL DELAY
•MOV P1,#11110000B
•CALL DELAY
•MOV P1,#11100000B
•CALL DELAY
•MOV P1,#11000000B
•CALL DELAY
•MOV P1,#10000000B
•CALL DELAY
•MOV P1,#00000000B
•CALL DELAY
•JMP MAIN
•DELAY:
•MOV R0,#200
•LAP:
•MOV R1,#200
•LAP2:
•NOP
•NOP
•NOP
•DJNZ R1,LAP2
•DJNZ R0,LAP
•RET
•END
ORG 00H
5,Đèn giao thông không dùng led 7 đoạn:
MAIN:
CALL CON1
CALL CON2
JMP MAIN
CON1:;SANG DAN
MOV P1,#00000000B
CALL DELAY
MOV P1,#10000000B
CALL DELAY
MOV P1,#11000000B
CALL DELAY
MOV P1,#11100000B
CALL DELAY
MOV P1,#11110000B
CALL DELAY
MOV P1,#11111000B
CALL DELAY
MOV P1,#11111100B
CALL DELAY
MOV P1,#11111110B
CALL DELAY
MOV P1,#11111111B
CALL DELAY
RET
•CON2:;TAT DAN
•MOV P1,#11111111B
•CALL DELAY
•MOV P1,#01111111B
•CALL DELAY
•MOV P1,#00111111B
•CALL DELAY
•MOV P1,#00011111B
•CALL DELAY
•MOV P1,#00001111B
•CALL DELAY
•MOV P1,#00000111B
•CALL DELAY
•MOV P1,#00000011B
•CALL DELAY
•MOV P1,#00000001B
•CALL DELAY
•MOV P1,#00000000B
•CALL DELAY
•RET
•DELAY:
•MOV R0,#200
•LAP:
•MOV R1,#200
•LAP2:
•NOP
•NOP
•NOP
•DJNZ R1,LAP2
•DJNZ R0,LAP
•RET
•END
•
Phạm Văn Ngọc Anh- 01644326695
ORG 00H
•MAIN:
• MOV P2,#00100001B;P1.0 và p1.5=1
• CALL DELAY
• MOV P2,#00010010B;p1.2 và p1.4=1
• CALL DELAY1
• MOV P2,#00001100B;p1.3 và p1.4=1
• CALL DELAY2
•JMP MAIN
•DELAY:;CT trễ 2.2S
•MOV R0,#200
•LAP:
•MOV R1,#100
•LAP1:
•MOV R3,#100
•LAP2:
•NOP
•NOP
•NOP
•DJNZ R3,LAP2
•DJNZ R1,LAP1
•DJNZ R0,LAP
•RET
DELAY1:;CT trễ 1.1S
MOV R4,#220
LAP4:
MOV R5,#150
LAP5:
MOV R6,#50
LAP6:
NOP
NOP
NOP
DJNZ R6,LAP6
DJNZ R5,LAP5
DJNZ R4,LAP4
RET
DELAY2:;CT trễ 3.3S
MOV R0,#220
LAP7:
MOV R1,#100
LAP8:
MOV R2,#100
LAP9:
NOP
NOP
NOP
DJNZ R2,LAP9
DJNZ R1,LAP8
DJNZ R0,LAP7
RET
END
Đăng nhận xét