0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

基于AT89C2051做的音乐门铃 附程序

454398 作者:工程师吴畏 2018-09-21 09:12 次阅读

家里门铃坏了一个多月了,一直没有时间去搞,过年前几天刚好有点时间,拆出来看看发现由于电池漏液造成了电路板多处被腐蚀,修也是麻烦了,所以索性就自己重新设计一个出来。这个门铃从电路设计,程序设计,调试及焊接都是我自己一手一脚完成,前后一共大概用了2天半时间。做出来的效果还是不错的。大家有兴趣可以试一下。

为了使门铃更有个性化,我采用的是单片机,用单片机来产生所需要的响声。其电路原理是控制单片机的IO口产生适当频率的方波,经过三极管放大后驱动自藕变压器的一次测,这时在变压器的二次测会产生相同频率的高压方波从而使压电陶瓷片发生形变,发出较大的门铃声。电源使用的是4节干电池,共6V,单片机电源是6V电源通过二极管降压0.7V后提供。

程序的原理就是通过控制单片机的计时器T1和T2来产生不同频率的PWM波,然后通过定义一个歌曲的数组,来控制不同音调,音高,音长,音高,音长。以下是曲谱的储存格式:

曲谱存贮格式 unsigned char code MusicName{音高,音长,音高,音长。..。, 0,0}; 末尾:0,0 表示结束(Important)

音高由三位数字组成:

个位是表示 1~7 这七个音符

十位是表示音符所在的音区:1-低音,2-中音,3-高音;

百位表示这个音符是否要升半音: 0-不升,1-升半音。

音长最多由三位数字组成:

个位表示音符的时值,其对应关系是:

|数值(n): |0 |1 |2 |3 | 4 | 5 | 6

|几分音符: |1 |2 |4 |8 |16 |32 |64 音符=2^n

十位表示音符的演奏效果(0-2): 0-普通,1-连音,2-顿音

百位是符点位: 0-无符点,1-有符点

调用演奏子程序的格式

Play(乐曲名,调号,升降八度,演奏速度);

|乐曲名 : 要播放的乐曲指针,结尾以(0,0)结束;

|调号(0-11) : 是指乐曲升多少个半音演奏;

|升降八度(1-3) : 1:降八度, 2:不升不降, 3:升八度;

|演奏速度(1-12000): 值越大速度越快;

由于门铃在没有按下时候CPU是没有工作任务的,所以在没有按下门铃时,我令CPU进入休眠状态,这样能够省下不少的电,使电池的工作寿命延长。当有人按下门铃时,就会产生外部中断INT0,使CPU退出休眠状态,进入全速运行状态,当歌曲演奏完毕,重新自动进入休眠状态。下面是主程序和中断服务程序

void main()

{

IT0=1; //外中断跳变产生中断

EX0=1;

EA=1; //打开总中断

InitialSound();

PCON |= 0x01;

while(1)

{

if(Play_music==1)

{

P1_7=0;

Play(Music_happynewyear,0,3,360);

P1_7=1;

Delay1ms(1500);

P1_7=0;

Play(Music_yingchun,0,3,360);

P1_7=1;

Play_music=0;

PCON |= 0x01;

}

}

}

void int0() interrupt 0 using 1

{

PCON &=~ 0x00;

Play_music=1;

}

电路原理图

由于当时快要过年了,所以我编了一首“新年好”和“迎春花”应一下节,其实所有歌都可以写,只要有乐谱就可以,这样你就可以把自己喜欢的歌编成程序烧入芯片,打造个性化的音乐门铃。下面我给出一些歌的编码,由于2051里面的flash容量有限,通常只能装下2首歌,所以如果想换歌时又要自己重新把代码替换烧入芯片。

//新年好

unsigned char code Music_happynewyear[]={ 0x15,0x03, 0x15,0x03, 0x15,0x02, 0x0F,0x02, 0x17,0x03,0x17,0x03, 0x17,0x02, 0x15,0x02, 0x15,0x03, 0x17,0x03,0x19,0x02,0x19,0x02, 0x18,0x03,0x17,0x03,0x16,0x01,0x16,0x03,0x17,0x03,0x18,0x02,0x18,0x02,0x17,0x03,0x16,0x03, 0x17,0x02, 0x15,0x02, 0x15,0x03, 0x17,0x03, 0x16,0x02, 0x0F,0x02, 0x11,0x03, 0x16,0x03, 0x15,0x01, 0x00,0x00 };

//迎春花

unsigned char code Music_yingchun[]={ 0x1F,0x03, 0x1F,0x04, 0x1A,0x04, 0x20,0x04, 0x1F,0x04, 0x1A,0x03, 0x19,0x03, 0x19,0x04, 0x17,0x04, 0x1A,0x04, 0x19,0x04, 0x17,0x03, 0x20,0x04, 0x1F,0x04, 0x1B,0x04, 0x1A,0x04, 0x19,0x04, 0x18,0x04, 0x17,0x04, 0x16,0x04,

0x15,0x03, 0x17,0x04, 0x19,0x04, 0x1A,0x04, 0x1A,0x04,0x1A,0x04, 0x1A,0x04, 0x1A,0x03, 0x19,0x03, 0x1A,0x03,0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x02, 0x16,0x03, 0x17,0x01, 0x17,0x67, 0x19,0x04, 0x1A,0x03, 0x1F,0x03, 0x19,0x02, 0x19,0x03, 0x17,0x03, 0x16,0x67, 0x17,0x04, 0x16,0x03, 0x15,0x03,0x15,0x03, 0x10,0x02, 0x0F,0x03,0x10,0x01,0x10,0x01,0x17,0x03,0x19,0x03,0x17,0x67,0x16,0x04,0x17,0x03,0x19,0x03, 0x17,0x67, 0x16,0x04, 0x17,0x03, 0x19,0x03,0x19,0x03, 0x10,0x03, 0x15,0x01, 0x17,0x03, 0x1F,0x03, 0x1A,0x67, 0x19,0x04, 0x17,0x03, 0x1F,0x03, 0x1A,0x67, 0x19,0x04, 0x1F,0x67, 0x1F,0x04, 0x20,0x04, 0x1F,0x04, 0x1A,0x03, 0x19,0x01, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x04, 0x16,0x04, 0x19,0x03, 0x10,0x03, 0x15,0x17, 0x1F,0x03, 0x1F,0x02, 0x1A,0x04, 0x19,0x04, 0x1A,0x03, 0x1F,0x03, 0x17,0x17, 0x17,0x67, 0x19,0x04, 0x1A,0x03,0x1F,0x03, 0x19,0x02, 0x19,0x67, 0x17,0x04, 0x16,0x67,0x17,0x04, 0x16,0x03, 0x15,0x03, 0x15,0x03, 0x10,0x02, 0x0F,0x03, 0x10,0x01, 0x00,0x00 };

//挥着翅膀的女孩

unsigned char code Music_Girl[]={ 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x03,

0x16,0x03, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x18,0x03,0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x02, 0x18,0x03, 0x17,0x03, 0x15,0x02, 0x18,0x03, 0x17,0x03, 0x18,0x02,0x10,0x03, 0x15,0x03, 0x16,0x02, 0x15,0x03, 0x16,0x03,0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x1A,0x03, 0x1B,0x03, 0x1F,0x03, 0x1F,0x03, 0x17,0x03, 0x18,0x03,0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x1F,0x03, 0x1F,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03, 0x16,0x66, 0x17,0x04, 0x18,0x04, 0x18,0x03, 0x19,0x03,0x1F,0x03, 0x1B,0x03, 0x1F,0x66,0x20,0x03,0x21,0x03,0x20,0x03,0x1F,0x03,0x1B,0x03,0x1F,0x66,0x1F,0x03,0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66,0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x1A,0x03, 0x1A,0x03, 0x1A,0x03, 0x1B,0x03,0x1B,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x02, 0x17,0x03,0x15,0x17, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x18,0x03,

0x17,0x04, 0x18,0x0E, 0x18,0x03, 0x17,0x04, 0x18,0x0E,0x18,0x66, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66,0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03,0x1F,0x66, 0x1F,0x04, 0x1B,0x0E, 0x1B,0x03, 0x19,0x03,0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03,0x16,0x66,0x17,0x04,0x18,0x04,0x18,0x03,0x19,0x03,0x1F,0x03,0x1B,0x03,0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x18,0x02, 0x18,0x03, 0x1A,0x03, 0x19,0x0D, 0x15,0x03, 0x15,0x02,0x18,0x66, 0x16,0x02, 0x17,0x02, 0x15,0x00, 0x00,0x00};

//同一首歌

unsigned char code Music_Same[]={ 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x66, 0x18,0x03,

0x17,0x02, 0x15,0x02, 0x16,0x01, 0x15,0x02, 0x10,0x02,0x15,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x02, 0x18,0x66, 0x17,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x16,0x00, 0x17,0x01, 0x19,0x02, 0x1B,0x02, 0x1B,0x70, 0x1A,0x03, 0x1A,0x01, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x02, 0x1A,0x0D, 0x19,0x03, 0x17,0x00,0x18,0x66,0x18,0x03,0x19,0x02,0x1A,0x02,0x19,0x0C,0x18,0x0D,0x17,0x03,0x16,0x01, 0x11,0x02, 0x11,0x03, 0x10,0x03, 0x0F,0x0C,0x10,0x02, 0x15,0x00, 0x1F,0x01, 0x1A,0x01, 0x18,0x66, 0x19,0x03, 0x1A,0x01, 0x1B,0x02, 0x1B,0x03, 0x1B,0x03,0x1B,0x0C, 0x1A,0x0D, 0x19,0x03,0x17,0x00,0x1F,0x01,0x1A,0x01,0x18,0x66,0x19,0x03,0x1A,0x01,0x10,0x02,0x10,0x03, 0x10,0x03, 0x1A,0x0C, 0x18,0x0D, 0x17,0x03,0x16,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x70, 0x18,0x03, 0x17,0x02, 0x15,0x03, 0x15,0x03, 0x16,0x66, 0x16,0x03, 0x16,0x02, 0x16,0x03, 0x15,0x03, 0x10,0x02, 0x10,0x01, 0x11,0x01, 0x11,0x66, 0x10,0x03, 0x0F,0x0C, 0x1A,0x02, 0x19,0x02, 0x16,0x03, 0x16,0x03, 0x18,0x66,0x18,0x03, 0x18,0x02, 0x17,0x03, 0x16,0x03, 0x19,0x00, 0x00,0x00 };

//两只蝴蝶

unsigned char code Music_Two[] ={ 0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,

0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x16,0x03,0x17,0x01, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x01, 0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x01, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x01, 0x16,0x03, 0x16,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0D, 0x15,0x00, 0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03, 0x1B,0x03, 0x1A,0x03, 0x17,0x0D,0x16,0x03,0x16,0x03,0x16,0x0D,0x17,0x01,0x17,0x03,0x17,0x03,0x19,0x03,0x1A,0x02,0x1A,0x02,0x10,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x19,0x02, 0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04, 0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03,

0x17,0x0D, 0x16,0x03, 0x17,0x03, 0x19,0x01, 0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03, 0x1B,0x03, 0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03, 0x16,0x03, 0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02, 0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x19,0x03, 0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04, 0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,

0x17,0x16, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x0F,0x02, 0x10,0x03, 0x15,0x00, 0x00,0x00 };

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • AT89C2051
    +关注

    关注

    7

    文章

    170

    浏览量

    66271
  • 音乐门铃
    +关注

    关注

    0

    文章

    19

    浏览量

    17635
收藏 人收藏

    评论

    相关推荐

    at89c2051实用程序

    at89c2051实用程序集这个包中提供了一些有实际应用价值的子程序供参考选用SUB1----X25045/43 看门狗/存储器与 89C2051接口子
    发表于 10-14 17:04

    at89c2051 问题

    哪位知道 at89c2051在仿真器通过的程序为什么烧写好后插如线路会出错啊?
    发表于 10-27 16:39

    AT89C2051烧写程序问题

    怎么用RF910烧写AT89C2051啊,引脚怎么连,比如单片机1脚链烧写器的那个脚啊
    发表于 09-14 09:09

    求下这个基于AT89C2051的仿真程序

    求下这个基于AT89C2051的仿真程序,大神
    发表于 12-11 12:33

    at89c2051程序

    at89c2051程序包中提供了一些有实际应用价值的子程序供参考选用SUB6----AT89C2051与上位机RS232通讯接口子程序
    发表于 10-14 17:03 248次下载
    <b class='flag-5'>at89c2051</b><b class='flag-5'>程序</b>

    AT89C2051单片机节日彩灯控制电路程序

    AT89C2051单片机节日彩灯控制电路程序 ;***************************************************;*   
    发表于 10-14 17:17 125次下载

    AT89C2051驱动步进电机的电路和源码

    AT89C2051
    发表于 01-09 15:17 8次下载

    AT89C2051单片机时钟程序源代码

    AT89C2051单片机时钟程序源代码:AT89C2051组成的时钟电路原理图
    发表于 03-06 10:14 204次下载

    AT89C2051单片机的比较器的应用

    AT89C2051单片机的比较器的应用 AT89C2051的一个特殊应用,用它的比较器做一个光强调节器,应用
    发表于 09-13 16:28 2607次阅读

    AT89C2051设计的快速充电器电路

    AT89C2051设计的快速充电器电路
    发表于 05-23 18:10 1478次阅读
    <b class='flag-5'>AT89C2051</b>设计的快速充电器电路

    AT89C2051实现对功放的自动控制

    AT89C2051实现对功放的自动控制
    发表于 01-08 14:14 7次下载

    基于AT89C2051单片机的GPS时钟系统

    基于AT89C2051单片机的GPS时钟系统
    发表于 02-07 16:14 34次下载

    基于AT89C2051单片机的无线门铃报警器

    本章向网友介绍一款集无线门铃和无线防盗报警器于一身的无线门铃报警器的制作,由于采用了AT89C2051单片机作为中央处理芯片,使得该系统的功能扩展比较方便,对于整个系统如需改变某种设置,只要更改相应的软件即可。
    发表于 03-18 14:13 24次下载
    基于<b class='flag-5'>AT89C2051</b>单片机的无线<b class='flag-5'>门铃</b>报警器

    AT89C2051中文数据资料

    AT89C2051中文数据资料分享。
    发表于 04-13 11:06 60次下载

    AT89C2051的数字时钟

    电子发烧友网站提供《带AT89C2051的数字时钟.zip》资料免费下载
    发表于 08-05 11:57 10次下载
    带<b class='flag-5'>AT89C2051</b>的数字时钟