Câu hỏi: Lập trình điều khiển đèn nháy: “VI ĐIỀU KHIỂN 89C51”Dùng đèn led điều khiển đấu anốt chung, tại cổng p1,p2 theo yêu cầu sau: 1Hiện từng chữ từ trái sang phải với tốc độ 1s/ chữ.
Trang 1Câu hỏi: Lập trình điều khiển đèn nháy: “VI ĐIỀU KHIỂN 89C51”
Dùng đèn led điều khiển đấu anốt chung, tại cổng p1,p2 theo yêu cầu sau:
1)Hiện từng chữ từ trái sang phải với tốc độ 1s/ chữ.
2)Sáng dần từng kí tự từ trái sang phải với tốc độ 0,1s/ 1 kí tự.
3)Sáng dồn từ trái sang phải với tốc độ 0,1s /1 kí tự.
4)Chớp tắt dòng chữ trên 3 lần với tốc độ 0,5 s/1 lần.
1) Hiện dần từng chữ từ trái sang phải với tốc độ 1 giây/1 chữ:
org 0hmov tmod,#1mov p1,#1mov p2,#1yeucau1:
mov p1,#11111100bcall delay1
mov p1,#11000000bcall delay1
mov p1,#00000000bmov p2,#11111000blcall delay1
mov p2,#00000000b
Trang 2call delay1mov p1,#11111111bmov p2,#11111111bcall delay1
jmp yeucau1
mov r7,#20kt:
mov th0,#3chmov tl0,#0b0hsetb tr0
loop:
jnb tf0,loopclr tr0
clr tf0djnz r7,ktret
end2) Hiện dần từng kí tự từ trái sang phải với tốc độ 0,1 giây/1 kí tự:
org 0hmov tmod,#1
Trang 3mov p2,#1mov p1,#1
yeucau2:
mov p1,#11111110bcall delay01
mov p1,#11111100bcall delay01
mov p1,#11111000bcall delay01
mov p1,#11110000bcall delay01
mov p1,#11100000bcall delay01
mov p1,#11000000bcall delay01
mov p1,#10000000bcall delay01
mov p1,#00000000bcall delay01
mov p2,#11111110b
Trang 4call delay01mov p2,#11111100bcall delay01
mov p2,#11111000bcall delay01
mov p2,#11110000bcall delay01
mov p2,#11100000bcall delay01
mov p2,#11000000bcall delay01
mov p2,#10000000bcall delay01
mov p2,#00000000bcall delay01
mov p2,#11111111bcall delay01
mov p1,#1jmp yeucau2delay01:
mov r7,#2
Trang 5mov th0,#3chmov tl0,#0b0hsetb tr0
loop:
jnb tf0,loopclr tr0
clr tf0djnz r7,ktret
end
3)Sáng dồn từ trái sang phải với tốc độ 0,1s /1 kí tự:
org 0hmov p1,#1mov p2,#1mov tmod,#1sangdon:
clr p2.7call delay
Trang 6setb p2.7clr p2.6call delaysetb p2.6clr p2.5call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2call delaysetb p2.2clr p2.1call delaysetb p2.1clr p2.0call delay
Trang 7setb p2.0clr p1.7call delaysetb p1.7clr p1.6call delaysetb p1.6clr p1.5call delaysetb p1.5clr p1.4call delaysetb p1.4clr p1.3call delaysetb p1.3clr p1.2call delaysetb p1.2clr p1.1call delay
Trang 8setb p1.1clr p1.0call delay ;;;;;;;;;;;;;;;;;;;
clr p2.7call delaysetb p2.7clr p2.6call delaysetb p2.6clr p2.5call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2call delaysetb p2.2
Trang 9clr p2.1call delaysetb p2.1clr p2.0call delaysetb p2.0clr p1.7call delaysetb p1.7clr p1.6call delaysetb p1.6clr p1.5call delaysetb p1.5clr p1.4call delaysetb p1.4clr p1.3call delaysetb p1.3
Trang 10clr p1.2call delaysetb p1.2clr p1.1call delay ;;;;;;;;;;;;;;;;;;;;
clr p2.7call delaysetb p2.7clr p2.6call delaysetb p2.6clr p2.5call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2
Trang 11call delaysetb p2.2clr p2.1call delaysetb p2.1clr p2.0call delaysetb p2.0clr p1.7call delaysetb p1.7clr p1.6call delaysetb p1.6clr p1.5call delaysetb p1.5clr p1.4call delaysetb p1.4clr p1.3
Trang 12call delaysetb p1.3clr p1.2
clr p2.7call delaysetb p2.7clr p2.6call delaysetb p2.6clr p2.5call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2call delay
Trang 13setb p2.2clr p2.1call delaysetb p2.1clr p2.0call delaysetb p2.0clr p1.7call delaysetb p1.7clr p1.6call delaysetb p1.6clr p1.5call delaysetb p1.5clr p1.4call delaysetb p1.4clr p1.3call delay ;;;;;;;;;;;;
Trang 14clr p2.7call delaysetb p2.7clr p2.6call delaysetb p2.6clr p2.5call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2call delaysetb p2.2clr p2.1call delaysetb p2.1
Trang 15clr p2.0call delaysetb p2.0clr p1.7call delaysetb p1.7clr p1.6call delaysetb p1.6clr p1.5call delaysetb p1.5clr p1.4call delay ;;;;
clr p2.7call delaysetb p2.7clr p2.6call delaysetb p2.6clr p2.5
Trang 16call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2call delaysetb p2.2clr p2.1call delaysetb p2.1clr p2.0call delaysetb p2.0clr p1.7call delaysetb p1.7clr p1.6
Trang 17call delaysetb p1.6clr p1.5call delay ;;;;;;;;;;;
clr p2.7call delaysetb p2.7clr p2.6call delaysetb p2.6clr p2.5call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2call delay
Trang 18setb p2.2clr p2.1call delaysetb p2.1clr p2.0call delaysetb p2.0clr p1.7call delaysetb p1.7clr p1.6call delay ;;;;;;;;;;;;;;;;;
clr p2.7call delaysetb p2.7clr p2.6call delaysetb p2.6clr p2.5call delaysetb p2.5
Trang 19clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2call delaysetb p2.2clr p2.1call delaysetb p2.1clr p2.0call delaysetb p2.0clr p1.7
clr p2.7call delaysetb p2.7clr p2.6
Trang 20call delaysetb p2.6clr p2.5call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2call delaysetb p2.2clr p2.1call delaysetb p2.1clr p2.0
clr p2.7call delay
Trang 21setb p2.7clr p2.6call delaysetb p2.6clr p2.5call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2call delaysetb p2.2clr p2.1call delay ;;;;;;;;;;
clr p2.7call delaysetb p2.7
Trang 22clr p2.6call delaysetb p2.6clr p2.5call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delaysetb p2.3clr p2.2call delay ;;;;;;;;;
clr p2.7call delaysetb p2.7clr p2.6call delaysetb p2.6clr p2.5
Trang 23call delaysetb p2.5clr p2.4call delaysetb p2.4clr p2.3call delay ;;;;;
clr p2.7call delaysetb p2.7clr p2.6call delaysetb p2.6clr p2.5call delaysetb p2.5clr p2.4call delay ;;;;;;;;;
clr p2.7call delaysetb p2.7
Trang 24clr p2.6call delaysetb p2.6clr p2.5call delay ;;;;;;;;;;
clr p2.7call delaysetb p2.7clr p2.6call delay ;;;;;;;;;;;
clr p2.7call delaymov p2,#1mov p1,#1jmp sangdon
mov r7,#2kt:
mov th0,#3chmov tl0,#0b0hsetb tr0
Trang 25jnb tf0,loopclr tr0
clr tf0djnz r7,ktret
end
4)Chớp tắt dòng chữ trên 3 lần với tốc độ 0,5 s/1 lần:
org 0hmov tmod,#1mov p1,#1mov p2,#1yeucau4:
choptat:
call tatcall delay05call batcall delay05call tat
call delay05
Trang 26call batcall delay05call tat
call delay05call batcall delay05
tat:
mov p1,#11111111bmov p2,#11111111bret
bat:
mov p1,#00000000bmov p2,#00000000bret
delay05: ;tao tre 0.5 giay
mov r6,#10kt:
mov th0,#3chmov tl0,#0b0hsetb tr0
Trang 27jnb tf0,loopclr tr0
clr tf0djnz r6,ktret
end5)Mạch phần cứng đấu anốt chung: