1
编程语言及工具
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
单片机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
单片机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
单片机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
全部0条评论
快来发表一下你的评论吧 !