Vũ Duy Khang - Đin A - CĐ 44 Page 1
Câu hi: Lp trình điề u khi n đèn nháy: “VI ĐIỀ U KHI N 89C51
Dùng đèn led điề u khi n đấ u ant chung, ti cng p1,p2 theo yêu cu sau:
1)Hin tng chttrái sang phi vi t c độ 1s/ ch.
2)Sáng dn tng kí tttrái sang phi vi t c độ 0,1s/ 1 kí t.
3)Sáng dn ttrái sang phi vi t c độ 0,1s /1 kí t.
4)Chp tt dòng chtrên 3 ln vi t c độ 0,5 s/1 ln.
1) Hin dn tng chttrái sang phi vi t c độ 1 giây/1 ch:
org 0h
mov tmod,#1
mov p1,#1
mov p2,#1
yeucau1:
mov p1,#11111100b
call delay1
mov p1,#11000000b
call delay1
mov p1,#00000000b
mov p2,#11111000b
lcall delay1
mov p2,#00000000b
Vũ Duy Khang - Đin A - CĐ 44 Page 2
call delay1
mov p1,#11111111b
mov p2,#11111111b
call delay1
jmp yeucau1
delay1: ;tao tre 1 giay
mov r7,#20
kt:
mov th0,#3ch
mov tl0,#0b0h
setb tr0
loop:
jnb tf0,loop
clr tr0
clr tf0
djnz r7,kt
ret
end
2) Hin dn tng kí tttrái sang phi vi t c độ 0,1 giây/1 kí t:
org 0h
mov tmod,#1
Vũ Duy Khang - Đin A - CĐ 44 Page 3
mov p2,#1
mov p1,#1
yeucau2:
mov p1,#11111110b
call delay01
mov p1,#11111100b
call delay01
mov p1,#11111000b
call delay01
mov p1,#11110000b
call delay01
mov p1,#11100000b
call delay01
mov p1,#11000000b
call delay01
mov p1,#10000000b
call delay01
mov p1,#00000000b
call delay01
mov p2,#11111110b
Vũ Duy Khang - Đin A - CĐ 44 Page 4
call delay01
mov p2,#11111100b
call delay01
mov p2,#11111000b
call delay01
mov p2,#11110000b
call delay01
mov p2,#11100000b
call delay01
mov p2,#11000000b
call delay01
mov p2,#10000000b
call delay01
mov p2,#00000000b
call delay01
mov p2,#11111111b
call delay01
mov p1,#1
jmp yeucau2
delay01:
mov r7,#2
Vũ Duy Khang - Đin A - CĐ 44 Page 5
kt:
mov th0,#3ch
mov tl0,#0b0h
setb tr0
loop:
jnb tf0,loop
clr tr0
clr tf0
djnz r7,kt
ret
end
3)Sáng dn ttrái sang phi vi t c độ 0,1s /1 kí t:
org 0h
mov p1,#1
mov p2,#1
mov tmod,#1
sangdon:
clr p2.7
call delay