單片機(jī)報(bào)警器聲音產(chǎn)生的方法
START: JB P1.7,START
JNB FLAG,NEXT
MOV R2,#200
DV: CPL P1.0
LCALL DELY500
LCALL DELY500
DJNZ R2,DV
CPL FLAG
NEXT: MOV R2,#200
DV1: CPL P1.0
LCALL DELY500
DJNZ R2,DV1
CPL FLAG
SJMP START
DELY500: MOV R7,#250
LOOP: NOP
DJNZ R7,LOOP
RET
END
7. C語言源程序
#include
#include
bit flag;
unsigned char count;
void dely500(void)
{
unsigned char i;
for(i=250;i>0;i--)
{
_nop_();
}
}
void main(void)
{
while(1)
{
if(P1_7==0)
{
for(count=200;count>0;count--)
{
P1_0=~P1_0;
dely500();
}
for(count=200;count>0;count--)
{
P1_0=~P1_0;
dely500();
dely500();
}
}
}
}
評(píng)論