Bài 2: Quét LED
- LED1 hiển thị số 1, Led 2 hiển thị số 2, Led 3 : số 3, Led 4 : số 4.
- Các Led sáng lần lượt 1,2,3,4
- Sư dụng ngắt
----------------------------------------
Sơ đồ thiết kế và mô phỏng trên Multisim (MultiMCU)
Mã:
ORG 00H
LJMP MAIN
ORG 003H
Lcall ngat1
reti
ORG 013H
Lcall ngat2
reti
MAIN:
LOOP: MOV IE,#85H
LCALL QUETLED
SJMP LOOP
QUETLED:
mov p0,#00
MOV P2,#1H
SETB P0.3
; ACALL DELAY
CLR P0.3
MOV P2,#2H
SETB P0.2
;ACALL DELAY
CLR P0.2
MOV P2,#3H
SETB P0.1
;ACALL DELAY
CLR P0.1
MOV P2,#4H
SETB P0.0
;ACALL DELAY
RET
ngat1:
MOV P0,#00
mov p2,#4h
SETB P0.3
ACALL DELAY
CLR P0.3
mov p2,#3h
SETB P0.2
ACALL DELAY
CLR P0.2
mov p2,#2h
SETB P0.1
ACALL DELAY
CLR P0.1
mov p2,#1h
SETB P0.0
ACALL DELAY
RET
ngat2:
mov p0,#00
mov p2,#0
mov p0,#5
call delay
mov p0,#0ah
call delay
ret
DELAY:
MOV R0,#03H
loop2: DJNZ R0,LOOP2
RET
END
--------------------------
Nguồn:
http://www.dieukhientudong.com/diend...=ST&f=7&t=931&
--------------------------