新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)閃爍燈流水燈匯編代碼大全

單片機(jī)閃爍燈流水燈匯編代碼大全

作者: 時(shí)間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
1、單片機(jī)AT89C51的P2口接8個(gè)發(fā)光二極管,讓這8個(gè)發(fā)光二極管顯示閃爍功能,即八燈亮2S,熄滅3S,如此循環(huán)。
參考程序:
ORG 0000H
start: MOV P1,#0H
CALL delay
MOV P1,#0FFH
CALL delay
CALL delay
LJMP start
delay:
MOV R7,#200
d2: MOV R6,#250
d1: DJNZ R6,d1
DJNZ R7,d2
RET
END
;200*250次*2*1us=1000ms=1s
2、單片機(jī)AT89C51的P1口接8個(gè)發(fā)光二極管,讓這8個(gè)發(fā)光二極管能夠雙燈左移之后再雙燈右移,
形成霹靂燈的效果,如此循環(huán)5次后全滅,延時(shí)0.5S。燈右移,形成霹靂燈的效果,
如此循環(huán)5次后全滅。延時(shí)0.5S。
參考程序1:
ORG 0000H
MOV A,#11111100B
start:
MOV P1,A
CALL delay
RL A
RL A
INC R0
CJNE R0,#4,start
MOV R0,#00H
s:
RR A
RR A
MOV P1,A
CALL delay
INC R0
CJNE R0,#4,s
MOV R0,#00H
LJMP start
delay: MOV R5,#100
k1: MOV R6,#250
k2: MOV R7,#250
k3: DJNZ R7,k3
DJNZ R6,k2
DJNZ R5,k1
RET
END
參考程序2:
ORG 0000H
MOV R0,#5
start:
MOV P2,#11111100B
CALL delay0_5s
MOV P2,#11110011B
CALL delay0_5s
MOV P2,#11001111B
CALL delay0_5s
MOV P2,#00111111B
CALL delay0_5s
MOV P2,#11001111B
CALL delay0_5s
MOV P2,#11110011B
CALL delay0_5s
MOV P2,#11111100B
CALL delay0_5s
DJNZ R0,start
MOV P2,#0FFH
SJMP $
delay0_5s:
MOV R7,#20
d3: MOV R6,#200
d2: MOV R5,#250
d1: NOP
NOP
DJNZ R5,d1
DJNZ R6,d2
DJNZ R7,d3
RET
END
3、單片機(jī)AT89C51的P2口接8個(gè)發(fā)光二極管,讓這8個(gè)發(fā)光二極管先交互閃爍5次,
然后雙燈左移之后再雙燈右移,如此循環(huán),形成流水燈的效果,延時(shí)0.5S。
ORG 0000H
MOV R0,#5
start:
MOV P1,#10101010B
CALL delay
MOV P1,#01010101B
CALL delay
DJNZ R0,start
MOV R0,#5
MOV A,#11111100B
s1: MOV P1,A
CALL delay
RL A
RL A
CJNE A,#11111100B,s1
s2: RR A
RR A
MOV P1,A
CALL delay
CJNE A,#11111100B,s2
JMP start
delay: MOV R5,#100
k1: MOV R6,#250
k2: MOV R7,#250
k3: DJNZ R7,k3
DJNZ R6,k2
DJNZ R5,k1
RET
END
4、單片機(jī)AT89C51的P1口和P2口分別接八個(gè)發(fā)光二極管,P2口八燈實(shí)現(xiàn)左移,延時(shí)0.5S,
要求左移第一次,P1.0對(duì)應(yīng)燈點(diǎn)亮,P2口燈左移第二次,P1.1對(duì)應(yīng)燈亮,如此延續(xù)下去,
直至左移八次后,所有燈全滅。
ORG 0000H
MOV R0,#11111110B
start: MOV A,#11111110B
MOV P2,A
s: CALL delay
RL A
MOV P2,A
CALL delay
CJNE A,#01111111B,s
MOV A,R0
MOV P1,A
RL A
MOV R0,A
JMP start
delay: MOV R5,#100
k1: MOV R6,#250
k2: MOV R7,#250
k3: DJNZ R7,k3
DJNZ R6,k2
DJNZ R5,k1
RET
END
5、單片機(jī)AT89C51的P2.0、P2.1和P2.2分別接按鈕開關(guān)PB1、PB2和PB3;P1.0接一個(gè)LED。按下PB1,
則LED亮;按下PB2則LED滅;按下PB3則LED閃爍。延時(shí)為0.1S。
原理圖:
參考程序:
ORG 0000H
MOV P2,#0FFH
s1: JNB P2.0,s3
JNB P2.1,s2
JNB P2.2,s4
JMP s1
s2: SETB P1.0
JMP s1
s3: CLR P1.0
JMP s1
s4: SETB P1.0
CALL delay
CLR P1.0
CALL delay
JNB P2.0,s3
JNB P2.1,s2
JMP s4
delay: MOV R5,#100
k1: MOV R6,#250
k2: MOV R7,#250
k3: DJNZ R7,k3
DJNZ R6,k2
DJNZ R5,k1
RET
END
6、單片機(jī)AT89C51的P2.0、P2.1和P2.2分別接按鈕開關(guān)PB1、PB2和PB3;P1口接8個(gè)LED。
按下PB1,則8個(gè)LED閃爍;按下PB2則8個(gè)LED單燈右移;按下PB3則8個(gè)LED單燈左移。延時(shí)為0.1S。
源代碼:
ORG 0
MOV P2,#0FFH
LOOP: JNB P2.0,LOOP_1
JNB P2.1,LOOP_2
JNB P2.2,LOOP_3
JMP LOOP
LOOP_1: MOV R0,#2
LOOP_1_1: MOV A,#10101010B
MOV P0,A
CALL D100MS
MOV A,#01010101B
MOV P0,A
CALL D100MS
MOV P0,#11111111B
DJNZ R0,LOOP_1_1
LOOP_1_2: JB P2.0,LOOP
JMP LOOP_1_2
LOOP_2: MOV A,#11111110B
MOV R0,#8
LOOP_2_1: MOV P0,A
RL A
CALL D100MS
DJNZ R0,LOOP_2_1
MOV P0,#11111111B
LOOP_2_2: JB P2.1,LOOP
JMP LOOP_2_2
LOOP_3: MOV A,#01111111B
MOV R0,#8
LOOP_3_1: MOV P0,A
RR A
CALL D100MS
DJNZ R0,LOOP_3_1
MOV P0,#11111111B
LOOP_3_2: JB P2.2,LOOP
JMP LOOP_3_2
D100MS: MOV R7,#250
D1: MOV R6,#200
DJNZ R6,$
DJNZ R7,D1
RET
END
7、單片機(jī)AT89C51的P2口分別接8個(gè)指撥開關(guān);P0口接8個(gè)LED。指撥開關(guān)閉合之前8個(gè)LED全亮,
閉合指撥開關(guān)P2.0,則P0.0所對(duì)應(yīng)的LED滅,以此類推。

上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: 單片機(jī)閃爍燈流水

評(píng)論


技術(shù)專區(qū)

關(guān)閉