#include
sbit buzzer = P1^0 ;声明区
void delay(int) ;
void pulse_BZ(int,int,int);声明函数void main(void)
{
while(1)
{
pulse_BZ(500,1,1); 调用发声
delay(1000); 延时1000 X 0.5ms
pulse_BZ(500,1,1);
delay(1000);
pulse_BZ(500,1,1);
delay(1000);
pulse_BZ(200,1,1);
delay(1000);
pulse_BZ(200,1,1);
delay(1000);
}
}void delay(int x)
{
int i,j;
for(i=0;i
}void pulse_BZ(int count;int TH;int TL)
{
int i;
for(i=o;i
buzzer=1; //此程序段产生1HZ 信号
delay(TH);
buzzer=0;
delay(TL);
}
}
51单片机蜂鸣器
开关C语言程序:
sbit P2^0=KEY;
sbit P2^1=BEEP;
unsigned char KEYNUM=0;
void main()
{
while(1)
{
if(KEY==0)//开关按下;
{
KEYNUM++;
}
if(KEYNUM==1)//第一次按下;
{
BEEP=1; //蜂鸣器响
}
if(KEYNUM==2)/第二次按下;
{
BEEP=0; //蜂鸣器不响
KEYNUM=0;
}
}
}
51单片机,编写延时程序,控制蜂鸣器发声:
很简单的
#include
#define uchar unsigned char
#define uint unsigned int
sbit fengmingqi=P0^0; //声明IO口
void delay(uint x)//延时子函数
{
uint i,j;
for(i=x;i>0;i--)
for(j=50;j>0;j--);
}
void main(void)
{
while(1) //循环
{
fengmingqi=1; //p0.0口高电平,蜂鸣器发声
delay(500); //延时
fengmingqi=0; //p0.0口低电平,蜂鸣器不发声
delay(500); //延时
}
}
#include
sbit buzzer = P1^0 ;声明区
void delay(int) ;
void pulse_BZ(int,int,int);声明函数void main(void)
{
while(1)
{
pulse_BZ(500,1,1); 调用发声
delay(1000); 延时1000 X 0.5ms
pulse_BZ(500,1,1);
delay(1000);
pulse_BZ(500,1,1);
delay(1000);
pulse_BZ(200,1,1);
delay(1000);
pulse_BZ(200,1,1);
delay(1000);
}
}void delay(int x)
{
int i,j;
for(i=0;i
}void pulse_BZ(int count;int TH;int TL)
{
int i;
for(i=o;i
buzzer=1; //此程序段产生1HZ 信号
delay(TH);
buzzer=0;
delay(TL);
}
}
自己想
蜂鸣器是上点就响的,你两个响中间弄个延时就可以了赛