CAC CHUONG TRINH SU DUNG NGAT
Nut nhan p3.2
Bai 1: LED DON
Nhấn lần 1 sáng dồn p1, nhân lần 2 chớp tắt p1, nhân lần 3 dừng
Tg EQU 20h
kQ EQOU 21h ckdl EOU 22h sldl EOU 23h
©ORG 0000h
LJMP main
org 0003h ; VETOR NGAT NGOAI 0
LƯMP ngatngoa10
:NGOÀI TẤT CẢ CAC NGAT
ma1n: MOV pl,f
> CHO PHEP NGAT NGOAI 0
SETB itWOs ; KÍCH MỨC THẤP
MOV RO, #008
SJMP $ ; KHONG LAM GI
ngatngoai0: INC RO
CUNE RO,#1,kt0
LCALL sangdon
kt0: CUNE RO,#2,kt1
LCALL choptat
kt1: CJUNE RO,#3,thoat
LCALL dung thoat: RETI
dung: MOV RO,#00h
MOV pl,#00h
CALL delay
LJMP main
sangdon: MOV pl1,#00h
LCALL delay
MOV ckdl,#8
Trang 2MOV kq,#00h
x11: MOV sldql,ckdl
MOV tg,#00h
SETB c x12: MOV A,tg
RLC A MOV tg,A ORL A,kq MOV pl1,A LCALL delay
DƯNZ sldl,x12
MOV kq,pl
DƯNZ ckdđl,x11
SJMP sangdon RETI
choptat: MOV pl1,#00h
CALL delay
MOV pl,#0ffh
CALL dela
delay:
del: MOV R6,#0ffh dell: MOV R5,#0ffh
DƯNZ R5,$
DINZ R6,dell DƯNZ R7,del
RETI
End
BÀI 2: ĐỘNG CƠ BƯỚC
Nhấn lần 1 quay thuận, nhắn lần 2 quay nghịch, nhân lần 3 dừng
ORG OO0OOOh LJMP main
org O003h
Trang 3main:
ngatngoa10:
ktO:
kt1:
thoat:
thuan:
x11:
ngich:
x1?:
LJMP ngatngoai0
org O030h
MOV ie, #81h
SETB itO
MOV RO, #00h
SƯMP §
INC RO CUNE RO,#1,kt0
LCALL thuan
CUNE RO,#2,kt1
LCALL ngich CUNE RO, #3,thoat LCALL dung
RET I
Š HE
MOV A,#00h RLC A
MOV p2,A LCALL delay JNB P2.3,x11
SJMP thuan
RET
MOV P2,#00H LCALL delay SETB c
MOV A,#00h RRC A
SWAP A MOV p2,A SWAP A LCALL delay
Trang 4JNB P2.0,x12
SJMP ngich
RET I
dung: MOV p2,#00h
MOV RO,#00h LCALL delay
LJMP main
delay: MOV R7,#3
DINZ RB,$
DJNZ Ro, dell DJNZ R/,del RETI
gee
a & lgq-©
¿
BÀI 3: LED 7 ĐOẠN
Nhấn lần 1 dém100 , nhân lần 2 đếm10, nhân lần 3 dừng
ORG OO0OOOh LJMP main
org O003h
LUMP ngatngoa10
org O030h
ma1n: MOV ie, #81h
SETB it0O
MOV RO, #00h
SJMP §
Trang 5ngatngoa10:
ktO:
kt1:
td0:
x11:
hex bcd:
bcd_ /doan:
INC RO CUNE RO,#1,kt0 MOV 70H, #101 LCALL td0 CUNE RO,#2,kt1 MOV 70H, #11 LCALL td0 CUNE RO, #3, THOAT LCALL dung
MOV R1,#00H
LCALL hex bcd LCALL bed /doan
LCALL delay hienth1i INC RI
MOV A,R1
MOV B, #10 DIV AB MOV 21H,B
MOV B, #10 DIV AB MOV 22H,B RETI
MOV DPTR, #bang
MOV A, 20h
MOVC A, @A+DPTR
Trang 6delay hienthi:
dell:
del:
hienthi:
DUNG:
MOV 25h,A
MOV A,21H MOVC A, @A+DPTR MOV 26H,A
MOV A,22H MOVC A, @A+DPTR MOV 27H,A
RETI
MOV R7,‡#2 MOV R6,#010h
LCALL hienthi
DJNZ Ro, del
DINZ R7,dell
RETLI
MOV P1,26H MOV P2,#02H LCALL delay MOV p2,#00h
MOV P1,27H MOV P2,#04H LCALL delay MOV p2,#00h RETI
MOV RO, #00H MOV P2,#00H LCALL DELAY LJMP MAIN
Trang 7THOAT : RETI
delay: MOV R4,#Offh
DƯNZ R4,5§
RETI bang: db
OcOh, Of9h, 0a4h, ObOh, 099h, 092h, 082h, 0OfF8h, O80h, 090h
End