51单片机题目: 要求:按下按钮时启动报警并且红灯闪烁,蜂鸣器报警,按钮松开,报警解除,绿灯闪烁。 100
下面附上代码,请高手直接修改完给我,谢谢!#include"reg51.h"voiddelay(unsignedinti);sbitK=P0^0;sbitbeep=P1^...
下面附上代码,请高手直接修改完给我,谢谢!
#include "reg51.h"
void delay(unsigned int i);
sbit K=P0^0;
sbit beep=P1^0;
sbit green=P1^1;
sbit red=P1^2;
void main()
{
green=0;
red=1;
while(1)
{
if(K==0)
{
delay(200);
if(K==0)
{
green=1;
red=0;
beep=0;
delay(100);
red=1;
beep=1;
}
}
else
green=0;
}
}
void delay(unsigned int i)
{
unsigned int k;
for(k=0;k<i;k++);
} 展开
#include "reg51.h"
void delay(unsigned int i);
sbit K=P0^0;
sbit beep=P1^0;
sbit green=P1^1;
sbit red=P1^2;
void main()
{
green=0;
red=1;
while(1)
{
if(K==0)
{
delay(200);
if(K==0)
{
green=1;
red=0;
beep=0;
delay(100);
red=1;
beep=1;
}
}
else
green=0;
}
}
void delay(unsigned int i)
{
unsigned int k;
for(k=0;k<i;k++);
} 展开
展开全部
void main()
{
green=0;
red=1;
while(1)
{
if(K==0)
{
delay(1000); /汪仔/延时约源瞎12ms
if(K==0)
{
green=1;
red=0;
beep=0;
delay(40000); //延时约0.5s
red=1;
beep=1;
}
}
else
{
green=!green;
delay(20000);//延时约0.25s
}
}
}
或者将delay(40000) 换困裂汪成while(k==0);//等待按键抬起
{
green=0;
red=1;
while(1)
{
if(K==0)
{
delay(1000); /汪仔/延时约源瞎12ms
if(K==0)
{
green=1;
red=0;
beep=0;
delay(40000); //延时约0.5s
red=1;
beep=1;
}
}
else
{
green=!green;
delay(20000);//延时约0.25s
}
}
}
或者将delay(40000) 换困裂汪成while(k==0);//等待按键抬起
追问
你这个我编译的时候有三处语法错误,target根本无法创立
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询