1、蜂鸣器

2、所用元件 2n5771 at89c51 button cap cap-elec crystal res speaker

例图:

例图代码:

#include<REGX51.H> sbit BEEP=P2^0; void delay(unsigned int i) { while(i--); }
void main() { while(1) { BEEP=1; delay(1000); BEEP=0; delay(1000); } }
2、开关声控蜂鸣器

所用元件

例图:

 例图代码:
#include<REGX51.H> sbit BEEP=P2^0; sbit LED=P1^0; sbit SW=P3^0; unsigned char
count; void delay(unsigned int i) { while(i--); } void main() { while(1) {
if(SW==0) { for(count=200;count>0;count--) { BEEP=~BEEP; LED=~LED; delay(250);
} for(count=200;count>0;count--) { BEEP=~BEEP; LED=~LED; delay(500); } } } }
邮件:3391641349@qq.com

文章多处存在借鉴,如有侵权请联系修改删除

技术
今日推荐
PPT
阅读数 128
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信