ORG 0000H
CONT:MOV R2,#04H;循环灯数
MOV R4,#100
MOV A,#OFEH
NEXT:MOV P1,A
D: ACALL DELAY
DJNZ R4,D
RL A
MOV R5,#0AH
SHAN:CPL P1
ACALL DELAY
DJNZ R5,SHAN
DJNZ R2,NEXT
SJMP CONT
DELAY:MOV R3,#04H ;0.2秒延时
MOV TMOD,#01H
MOV TH0,#3CH
MOV TL0.#OBH
SETB TR0
L1: JBC TF0,L2
SJMP L1
L2: MOV TH0,#3CH
MOV TL0,#OBH
DJNZ R3,LP1
RET
END
c语言程序
按钮和喇叭都是高电平有效
#include
sbit
key=P1^0;
sbit
laba=P1^1;
void
delay(unsigned
char
c)
{
unsigned
char
i,j;
while(c--)
{
for(i=0;i<250;i++)
for(j=0;j<100;j++);
}
}
void
baojin()
{
laba=1;
delay(250);
laba=0;
}
void
main()
{
while(1)
{
if(key==1)
baojin();
}
}