1、单片机AT89C51的P2口接8个发光二极管,让这8个发光二极管显现闪耀功用,即八灯亮2S,平息3S,如此循环。
参阅程序:
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、单片机AT89C51的P1口接8个发光二极管,让这8个发光二极管可以双灯左移之后再双灯右移,
构成响雷灯的作用,如此循环5次后全灭,延时0.5S。灯右移,构成响雷灯的作用,
如此循环5次后全灭。延时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、单片机AT89C51的P2口接8个发光二极管,让这8个发光二极管先交互闪耀5次,
然后双灯左移之后再双灯右移,如此循环,构成流水灯的作用,延时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、单片机AT89C51的P1口和P2口别离接八个发光二极管,P2口八灯完成左移,延时0.5S,
要求左移第一次,P1.0对应灯点亮,P2口灯左移第2次,P1.1对应灯亮,如此延续下去,
直至左移八次后,一切灯全灭。
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、单片机AT89C51的P2.0、P2.1和P2.2别离接按钮开关PB1、PB2和PB3;P1.0接一个LED。按下PB1,
则LED亮;按下PB2则LED灭;按下PB3则LED闪耀。延时为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、单片机AT89C51的P2.0、P2.1和P2.2别离接按钮开关PB1、PB2和PB3;P1口接8个LED。
按下PB1,则8个LED闪耀;按下PB2则8个LED单灯右移;按下PB3则8个LED单灯左移。延时为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、单片机AT89C51的P2口别离接8个指拨开关;P0口接8个LED。指拨开关闭合之前8个LED全亮,
闭合指拨开关P2.0,则P0.0所对应的LED灭,以此类推。
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qianrushi/yingjian/255590.html