单片机闪烁灯流水灯汇编代码大全
参考程序:
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口灯左移第二次,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
单片机闪烁灯流水 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)