单片机闪烁灯流水灯汇编代码大全 下载本文

单片机闪烁灯流水灯汇编代码大全

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