Tinh hinh la em viet ct ngat trong 8051, dung led de thay khi nao ngat; Viet cho TIMER0, TIMER1 ok roi;
lap them EX0 vao thi chuong trinh ko chay; du` ko co loi nao tren KEiL lun;
MOI NGUOI GIUP E VOI:
CODE day:
;===========Tên ch??ng trình ============
org 00h
nop
ljmp MAIN
org 03h ; Ng?t Ex0 <-- co; them no la khong chay
nop
cpl p1.3
reti
org 0bh ; Ng?t Timer0
nop
ljmp INT_TIMER0
org 1bh ; Ng?t Timer1
nop
ljmp INT_TIMER1
;===================================
; m a i n p r o g r a m
;===================================
org 50h
MAIN:
mov P1,#00h
mov R7,#00h
initialization_int:
setb ex0
setb ex0
setb et0
setb et1
setb px0
setb pt0
setb it0
setb ea
initialization_timer:
mov tmod,#00010010b
mov th0,#00h
mov tl0,#00h
mov th1,#00h
mov tl1,#00h
setb tr0
setb tr1
CPLP1_0:
cpl P1.0
mov a,r7
mov P0,a
lcall DELAY
ljmp CPLP1_0
INCR7:
inc r7
ret
DELAY:
mov r1,#0ffh
DELAY0:
mov r2,#0ffh
DELAY1:
djnz r2,DELAY1
djnz r1,DELAY0
ret
;===============================
;Ctrinh _ Ph?c v? ng?t
;===============================
INT_TIMER0:
clr tr0
cpl P1.1
setb tr0
Reti
INT_TIMER1:
clr tr1
cpl P1.2
lcall INCR7
clr tf1
setb tr1
reti
;==============================
End
lap them EX0 vao thi chuong trinh ko chay; du` ko co loi nao tren KEiL lun;
MOI NGUOI GIUP E VOI:
CODE day:
;===========Tên ch??ng trình ============
org 00h
nop
ljmp MAIN
org 03h ; Ng?t Ex0 <-- co; them no la khong chay
nop
cpl p1.3
reti
org 0bh ; Ng?t Timer0
nop
ljmp INT_TIMER0
org 1bh ; Ng?t Timer1
nop
ljmp INT_TIMER1
;===================================
; m a i n p r o g r a m
;===================================
org 50h
MAIN:
mov P1,#00h
mov R7,#00h
initialization_int:
setb ex0
setb ex0
setb et0
setb et1
setb px0
setb pt0
setb it0
setb ea
initialization_timer:
mov tmod,#00010010b
mov th0,#00h
mov tl0,#00h
mov th1,#00h
mov tl1,#00h
setb tr0
setb tr1
CPLP1_0:
cpl P1.0
mov a,r7
mov P0,a
lcall DELAY
ljmp CPLP1_0
INCR7:
inc r7
ret
DELAY:
mov r1,#0ffh
DELAY0:
mov r2,#0ffh
DELAY1:
djnz r2,DELAY1
djnz r1,DELAY0
ret
;===============================
;Ctrinh _ Ph?c v? ng?t
;===============================
INT_TIMER0:
clr tr0
cpl P1.1
setb tr0
Reti
INT_TIMER1:
clr tr1
cpl P1.2
lcall INCR7
clr tf1
setb tr1
reti
;==============================
End
Comment