int i=0
while (1)
{
//①L1、L2、…L8依次点亮
lights = 0x01
for (i=0i<7i++)
{
delay(500)
lights = lights <<1
}
delay(500)
//②L1、L2、…L8依次熄灭
lights = 0xfe
for (i=0i<7i++)
{
delay(500)
lights = (lights <<1) + 0x01
}
delay(500)
//③L1、L2、…L8全亮
lights = 0xff
delay(500)
//全灭
lights = 0x00
delay(500)
}
ORG 0000HAJMP MAIN
MAIN:
MOV P1,#05H
CALL DELAY
MOV P1,#0AH
CALL DELAY
MOV P1,#50H
CALL DELAY
MOV P1,#55H
CALL DELAY
MOV P1,#0AAH
CALL DELAY
MOV P1,#0FFH
CALL DELAY
MOV P1,#00H
CALL DELAY
AJMP MAIN
DELAY:
MOV R3,#1000
BC: MOV R2,#995
DEC R2
DJNZ R2,$
DJNZ R3,BC
RET
END
说明:该程序采用P1口作为发光二极管的控制,阳极接P1口,阴极接地即可
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)