;==============================================
; Ten chuong trinh : DK do sang den LED bang nut bam.
; Nguoi thuc hien : Kyle Ray
; Ngay thuc hien : 01/05/2012 - 20h18'
; Phien ban : 1.0
; Mo ta phan cung : Dung AT89C51 - thach anh 12MHz
; : LED noi voi P2
; : Nut 1 <=> p1.1
; : Nut 2 <=> p1.2
; : Nut ON/OFF <=> p1.0
; Yeu cau: An ON/OFF DC hoat dong.
; An 1 LED 2 sang.
; An 2 LED 3 sang.
;----------------------------------------------------------------
; Hoan thanh : 01/05/2012 - 20h48'
; Kiem tra : ...
; Nguoi kiem tra : ...
;----------------------------------------------------------------
; Chu thich : Bam xung o tan so 500Hz. Mac dinh
; ban dau xung muc cao (30%) t_on = 600us.
;Sau moi lan an UP hoac DOWN thi t_on tang hoac giam 50us.
;==============================================
;
;-----------------------------------------------
; DINH NGHIA CAC KY HIEU ;
;-----------------------------------------------
LED1 data p2.0
Led2 data p2.1
Led3 data p2.2
ON_OFF bit p1.0
1 bit p1.1
2 bit p1.2
VAR equ 30h
value equ -39
;-----------------------------------------------
;-----------------------------------------------
org 0h
main: ;bat dau chuong trinh
mov p2.0, #0h ;tat LED
mov r1, #28
mov VAR, #12 ;nap gia tri t_on ban dau = 6ms
acall kt_on ;goi ct cho phim ON/OFF duoc an
t_on:
mov LED, #0ffh
jb UP, next ;ko an UP => nhay den next
acall delay_100ms ;goi ct tao tre 100ms de chong rung phim
jnb UP, $ ;cho nha phim
inc VAR ;tang bien dem
mov r0, VAR
cjne r0, #40, next ;VAR<20 => nhay den next
mov VAR, #39 ;giu khong cho VAR vuot qua 20
acall delay_50us
next: jb ON_OFF, next_1 ;ko an ON_OFF => nhay den next_1
acall delay_100ms
jnb ON_OFF, $
sjmp main
next_1:
acall delay_50us
djnz VAR, next
;-----------------------------------------------
t_off:
mov LED, #0h
clr c ;xoa co nho
mov a, #40
subb a, VAR ;thoi gian t_off duoc luu vao acc
jnc next_2 ;nhay den next_2 neu khong nho (c=0)
cpl a ;lay bu 1 acc
inc a ;tang acc len 1 de tao bu 2
next_2:
jb DOWN, next_3 ;nhay den next_3 neu DOWN ko dc an
acall delay_100ms
jnb DOWN, $
dec VAR ;giam VAR di 1 dv de T = const = 20ms
inc a
mov r1, a
mov r0, VAR
cjne r0, #0, next_3
inc VAR ;giu cho VAR ko bi am
next_3:
jb ON_OFF, next_4
acall delay_100ms
jnb ON_OFF, $
sjmp main
next_4:
acall delay_50us
djnz r1, next_3
sjmp t_on
;-----------------------------------------------
; CHUONG TRINH CON ;
;-----------------------------------------------
kt_on:
jb ON_OFF, $ ;cho den khi ON_OFF dc bam
acall delay_100ms
jnb ON_OFF, $
ret
;----------------
delay_50us:
mov tmod, #01h ;chon timer 0, che do 16 bits
mov th0, #high value
mov tl0, #low value
setb tr0
jnb tf0, $ ;cho o day den khi tran
clr tr0
clr tf0
ret
;----------------
delay_100ms:
push 5
push 6
push 7
mov r7, #100
mov r6, #2
mov r5, #248
djnz r5, $
djnz r6, $-4
djnz r7, $-8
pop 7
pop 6
pop 5
ret
;-----------------------------------------------
;-----------------------------------------------
end
; Ten chuong trinh : DK do sang den LED bang nut bam.
; Nguoi thuc hien : Kyle Ray
; Ngay thuc hien : 01/05/2012 - 20h18'
; Phien ban : 1.0
; Mo ta phan cung : Dung AT89C51 - thach anh 12MHz
; : LED noi voi P2
; : Nut 1 <=> p1.1
; : Nut 2 <=> p1.2
; : Nut ON/OFF <=> p1.0
; Yeu cau: An ON/OFF DC hoat dong.
; An 1 LED 2 sang.
; An 2 LED 3 sang.
;----------------------------------------------------------------
; Hoan thanh : 01/05/2012 - 20h48'
; Kiem tra : ...
; Nguoi kiem tra : ...
;----------------------------------------------------------------
; Chu thich : Bam xung o tan so 500Hz. Mac dinh
; ban dau xung muc cao (30%) t_on = 600us.
;Sau moi lan an UP hoac DOWN thi t_on tang hoac giam 50us.
;==============================================
;
;-----------------------------------------------
; DINH NGHIA CAC KY HIEU ;
;-----------------------------------------------
LED1 data p2.0
Led2 data p2.1
Led3 data p2.2
ON_OFF bit p1.0
1 bit p1.1
2 bit p1.2
VAR equ 30h
value equ -39
;-----------------------------------------------
;-----------------------------------------------
org 0h
main: ;bat dau chuong trinh
mov p2.0, #0h ;tat LED
mov r1, #28
mov VAR, #12 ;nap gia tri t_on ban dau = 6ms
acall kt_on ;goi ct cho phim ON/OFF duoc an
t_on:
mov LED, #0ffh
jb UP, next ;ko an UP => nhay den next
acall delay_100ms ;goi ct tao tre 100ms de chong rung phim
jnb UP, $ ;cho nha phim
inc VAR ;tang bien dem
mov r0, VAR
cjne r0, #40, next ;VAR<20 => nhay den next
mov VAR, #39 ;giu khong cho VAR vuot qua 20
acall delay_50us
next: jb ON_OFF, next_1 ;ko an ON_OFF => nhay den next_1
acall delay_100ms
jnb ON_OFF, $
sjmp main
next_1:
acall delay_50us
djnz VAR, next
;-----------------------------------------------
t_off:
mov LED, #0h
clr c ;xoa co nho
mov a, #40
subb a, VAR ;thoi gian t_off duoc luu vao acc
jnc next_2 ;nhay den next_2 neu khong nho (c=0)
cpl a ;lay bu 1 acc
inc a ;tang acc len 1 de tao bu 2
next_2:
jb DOWN, next_3 ;nhay den next_3 neu DOWN ko dc an
acall delay_100ms
jnb DOWN, $
dec VAR ;giam VAR di 1 dv de T = const = 20ms
inc a
mov r1, a
mov r0, VAR
cjne r0, #0, next_3
inc VAR ;giu cho VAR ko bi am
next_3:
jb ON_OFF, next_4
acall delay_100ms
jnb ON_OFF, $
sjmp main
next_4:
acall delay_50us
djnz r1, next_3
sjmp t_on
;-----------------------------------------------
; CHUONG TRINH CON ;
;-----------------------------------------------
kt_on:
jb ON_OFF, $ ;cho den khi ON_OFF dc bam
acall delay_100ms
jnb ON_OFF, $
ret
;----------------
delay_50us:
mov tmod, #01h ;chon timer 0, che do 16 bits
mov th0, #high value
mov tl0, #low value
setb tr0
jnb tf0, $ ;cho o day den khi tran
clr tr0
clr tf0
ret
;----------------
delay_100ms:
push 5
push 6
push 7
mov r7, #100
mov r6, #2
mov r5, #248
djnz r5, $
djnz r6, $-4
djnz r7, $-8
pop 7
pop 6
pop 5
ret
;-----------------------------------------------
;-----------------------------------------------
end
Comment