基于AT89C2051做的音乐门铃

发布者:skyhcg最新更新时间:2023-08-23 来源: elecfans关键字:AT89C2051  音乐门铃  方波 手机看文章 扫描二维码
随时随地手机看文章

家里门铃坏了一个多月了,一直没有时间去搞,过年前几天刚好有点时间,拆出来看看发现由于电池漏液造成了电路板多处被腐蚀,修也是麻烦了,所以索性就自己重新设计一个出来。这个门铃从电路设计,程序设计,调试及焊接都是我自己一手一脚完成,前后一共大概用了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  音乐门铃  方波 引用地址:基于AT89C2051做的音乐门铃

上一篇:AT89C52单片机的SD卡读写设计原理
下一篇:基于STC89C52单片机的智能花盆设计案例

推荐阅读最新更新时间:2024-11-13 06:18

PWM方波产生51程序
PWMH DATA 30H ;高电平脉冲的个数 PWM DATA 31H ;PWM周期 COUNTER DATA 32H pwmhmin DATA 33H ORG 0000H AJMP MAIN ;ORG 0003H ;AJMP INT_X0 ;ORG 0013H ;AJMP INT_X1 ORG 000BH AJMP INT_T0 ORG 0100H MAIN: MOV SP,#60H ;给堆栈指针赋初值 mov ie,#87h MOV PWMH,#02H ; MOV COUNTER,#01H MOV PWM,#14H MOV TMOD,#02H ;定时器0在模式2
[单片机]
利用定时器使单片机输出方波
在P1^0口输出方波。 废话不多说,直接上代码。 #include reg52.h sbit FB = P1^0; void Init_ET_0()//定时器初始化函数 { TMOD = 0x01;//启用定时器 0 ,工作模式为 模式1 。 EA = 1;//开总中断 ET0 = 1;//开定时器开关 TR0 = 1;//启动定时器 TH0 = (65536 - 500)/256;//给高八位赋初值 TL0 = (65536 - 500)%256;//给低八位赋初值 } void Servoce_ET_0() interrupt 1 //定时器服务函数 { TH0
[单片机]
利用定时器使单片机输出<font color='red'>方波</font>
基于FM的双音频通信方案
  阐述双音频通信的基本工作原理;结合FM有线/无线遥控广播系统中的具体应用,介绍一种适合单片机系统的双音频通信方案,设计具体的硬件接口电路,说明其工作原理;给出应用于双音频的程序流程及在工作中应注意的一些问题。   1 遥控广播系统的基本原理   基本原理如图1所示。   遥控广播系统的通信是电话拨号收发的一种双音频通信方式,是一项可靠、成熟的通信技术。它取代了传统的电话拨号脉冲通信方式,成为现代电话通信拨号的主要通信方式。它对传输电路的要求低,传送的距离远,而且具有通用多种型号的双音频元器件以备选用,通过普通的电话就可以获得发送信号和编码。再经过FM捷变频立体声调频调制器的调制,采用立体声的两个声道,左声道输入广播音频信
[单片机]
基于FM的双音频通信方案
555方波三角波发生器 产生器电路图
如图所示为稳定的方波和三角波发生电路。该电路的特点是:方波和三角波的频率几乎相等,正、负向振幅对称;三角波的正、负斜率不受振幅变化的影响,而且正、负斜率可以分别调节。此外,调节基线电平时不会改变输出波形。运算放大器A2为积分器,它由运放A1的输出方波驱动。方波的振幅由两个齐纳二极管D1、D2固定在5V。电位器R3调节三角波的正斜率,R2调节三角波的负斜率,R5调节三角波的振幅。如果只需要相同的正、负斜率,则D3、D4和R2可以省掉。运算放大器A1为比较器。参考电压由电位器R4调节,R4决定输出的基线电平,但是不会影响振幅和斜率。最高工作频率由运算放大器的转换速率、最大输出电流以及二极管的开关速度决定。 三角波振幅: 方波振
[模拟电子]
555<font color='red'>方波</font>三角波发生器 产生器电路图
AT89S51与AT89C2051单片机引脚介绍
AT89C2051是精简版的51单片机,精简掉了P0口和P2口,只有20引脚,但其内部集成了一个很实用的模拟比较器,特别适合开发精简的51应用系统,毕竟很多时候我们开发简单的产品时用不了全部32个I/O口,用AT89C2051更合适,芯片体积更小,而且AT89C2051的工作电压最低为2.7V,因此可以用来开发两节5号电池供电的便携式产品。   本文以ATMEL公司生产的51系列家族的AT89S51和AT89C2051两种单片机来讲解,两种单片机是目前最常用的单片机,其中AT89S51为标准51单片机,当然其功能比早期的51单片机更强大,支持ISP在系统编程技术,内置硬件看门狗。。。        一、AT89S51单片机引脚介绍
[单片机]
AT89S51与<font color='red'>AT89C2051</font>单片机引脚介绍
时钟芯片DS1302+AT89C2051的红外遥控LED电子钟电路设计与制作
自制LED电子钟在很多电子报刊杂志上都可以见到,但大多数在断电后都要重新设置时间等参数,给使用带来很多不便。也有用后备电池作为备用电源的,但往往体积较大。本文介绍的LED电子钟克服了以往的弊端,而且采用了家电通用的红外遥控器进行控制,方便使用。有一路闹铃输出,可以通过遥控器设置闹铃时间及允许与否。 一.工作原理 DS1302为达拉斯公司的一种实时时钟芯片,主要特点是采用串行数据传输,可为掉电保护电源提供可编程的充电功能,并且可以关闭充电功能。采用普通32768 Hz 晶振 。 AT89C2051作为主控芯片,一是对接收到的红外遥控编码进行判断识别,并执行相应的处理;第二就是定期的读取时钟芯片DS1302中的时间并把小时和肥
[单片机]
时钟芯片DS1302+<font color='red'>AT89C2051</font>的红外遥控LED电子钟电路设计与制作
小广播
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件
随便看看

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved