蜂鸣器播放生日快乐歌曲

合集下载

Arduino控制蜂鸣器播放音乐设计说明书

Arduino控制蜂鸣器播放音乐设计说明书

目录一、新媒体装置艺术1、作品原理介绍 (1)2、作品设计的意义 (1)3、作品的主要内容 (1)4、制作方法和流程 (1)5、成果 (9)6、价值和影响 (9)7、创新点 (10)二、结论8、技术方面 (10)9、艺术方面 (10)10、不足及展望 (11)11、谢辞 (11)设计说明书一、作品原理介绍:能感应到物体靠近并且低于50CM时,蜂鸣器发出音乐,并且小灯泡随着音乐节奏变化。

二、作品设计意义:将它应用到图书馆或者购物的地方,当人们靠近的时间能只能朗读出这一栏或者这一块区域有什么东西,能够更加让人们更快速的找到自己需要的东西,很大程度上节约的时间! 也可以应用到车上,当开车的人快要和前面或者后面的物体撞上的时候,会发出声音来提醒你,从而给生命和财产加上保护套。

三、作品主要内容:1、Arduino控制蜂鸣器播放音乐、小灯泡。

2、小灯泡跟随蜂鸣器的音乐节奏变化。

3、当物体离超声波低于50CM时发出指令,控制蜂鸣器、小灯泡。

四、制作方法和流程:adruino uno一块(其他Arduino板子也可,注意引脚就行),面保线若干条,蜂鸣器或小喇叭一个。

原理:首先讲下简单的乐理知识,知道音乐是怎么演奏出来的自然就可以通过代码来进行编排了。

1.演奏单音符的原理一首音乐由若干音符组成,每一个音符唯一对应一个频率。

如果我们知道了音符相对应的频率,再让 Arduino 按照这个频率输出到蜂鸣器或喇叭,蜂鸣器或喇叭就会发出相应频率下的声音。

Arduino官方网站给出了不同音符对应的不同频率的头文件,具体请见下文介绍。

2.音符演奏的持续时间每个音符都会播放一定的时间,这样才能构成一首优美的曲子,而不是每个音符都播放一样长的时间。

如何确定每个音符演奏的单位时间呢?我们知道,音符节奏分为1拍、1/2拍、1/4拍、1/8拍等等,我们规定一拍音符的时间为1;半拍为0.5;1/4拍为0.25;1/8拍为0.125……,所以我们可以为每个音符赋予这样的拍子播放出来,音乐就成了。

51单片机蜂鸣器播放音乐代码

51单片机蜂鸣器播放音乐代码

/*生日快乐歌曲*/#include <>#define uint unsigned int#define uchar unsigned charsbit beep = P1^5;uchar code SONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159, 212,212,106,126,159,169,190,119,119,126,159,142,159,0};uchar code SONG_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0};//延时void DelayMS(uint x){uchar t;while(x--) for(t=0;t<120;t++);}void PlayMusic(){uint i=0,j,k;while(SONG_LONG[i]!=0||SONG_TONE[i]!=0){ //播放各个音符,SONG_LONG 为拍子长度for(j=0;j<SONG_LONG[i]*20;j++){beep=~beep;//SONG_TONE 延时表决定了每个音符的频率for(k=0;k<SONG_TONE[i]/3;k++);}DelayMS(10);i++;}}void main(){beep=0;while(1){PlayMusic(); //播放生日快乐DelayMS(500); //播放完后暂停一段时间}}两只蝴蝶:#include <> // 这是单片机音乐代码生成器生成的代码#define uchar unsigned charsbit beepIO=P1^5; // 输出为可以修改成其它 IO 口uchar m,n;uchar code T[49][2]={{0,0},{0xF8,0x8B},{0xF8,0xF2},{0xF9,0x5B},{0xF9,0xB7},{0xFA,0x14},{0xFA,0x66},{0xFA,0 xB9},{0xFB,0x03},{0xFB,0x4A},{0xFB,0x8F},{0xFB,0xCF},{0xFC,0x0B},{0xFC,0x43},{0xFC,0x78},{0xFC,0xAB},{0xFC,0xDB},{0xFD,0x08},{0xFD,0x33},{0xFD,0 x5B},{0xFD,0x81},{0xFD,0xA5},{0xFD,0xC7},{0xFD,0xE7},{0xFE,0x05},{0xFE,0x21},{0xFE,0x3C},{0xFE,0x55},{0xFE,0x6D},{0xFE,0x84},{0xFE,0x99},{0xFE,0 xAD},{0xFE,0xC0},{0xFE,0x02},{0xFE,0xE3},{0xFE,0xF3},{0xFF,0x02},{0xFF,0x10},{0xFF,0x1D},{0xFF,0x2A},{0xFF,0x36},{0xFF,0x42},{0xFF,0x4C},{0xFF,0 x56},{0xFF,0x60},{0xFF,0x69},{0xFF,0x71},{0xFF,0x79},{0xFF,0x81}};uchar code music[][2]={{0,4},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8}, {21,4},{23,4},{21,4},{19,4},{16,4},{19,4},{14,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,24},{16,4},{19,4},{21,8}, {21,4},{23,4},{21,4},{19,4},{16,4},{19,4},{21,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8}, {21,4},{23,4},{21,4},{19,4},{16,4},{19,4},{14,24},{23,4},{26,4},{26,16},{26,4},{28,4},{26,4},{23,24},{21,4},{23,4},{21,8},{21,4}, {23,4},{21,4},{19,4},{16,4},{16,2},{19,2},{19,24},{0,20},{26,4},{26,4},{28,4},{31,4},{30,4},{30,4},{28,4},{23,4},{21,4},{21,4},{23,16},{ 0,4},{23,4},{23,4},{26,4},{28,8},{28,12},{16,4},{23,4},{21,4},{21,24},{23,4},{26,4},{26,4},{23,4},{26,8},{0,4},{31,8},{30,4},{28,4},{30,4},{2 3,8},{0,4},{28,4},{28,4},{30,4},{28,4},{26,4},{23,4},{21,8},{23,4},{21,4},{23,4 },{26,16},{0xFF,0xFF}};void delay(uchar p){uchar i,j;for(;p>0;p--)for(i=181;i>0;i--)for(j=181;j>0;j--);}void pause(){uchar i,j;for(i=150;i>0;i--)for(j=150;j>0;j--);}void T0_int() interrupt 1{beepIO=!beepIO;TH0=T[m][0]; TL0=T[m][1];}void main()uchar i=0;TMOD=0x01; EA=1; ET0=1;while(1){m=music[i][0];n=music[i][1];if(m==0x00){TR0=0;delay(n);i++;}else if(m==0xFF){TR0=0;delay(30);i=0;}else if(m==music[i+1][0]){TR0=1;delay(n);TR0=0;pause();i++;}else{TR0=1;delay(n);i++;}}}祝你平安:#include ""unsigned char Count;sbit _Speak =P1^5 ;unsigned char code SONG[] ={ //祝你平安0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20 ,0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20 ,0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20 ,0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20 ,0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10 ,0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20 ,0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20 ,0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20 ,0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10 ,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80 ,0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20 ,0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x200x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10 ,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x00};void Time0_Init(){TMOD = 0x01;IE = 0x82;TH0 = 0xD8;TL0 = 0xEF; //12MZ晶振,10ms}void Time0_Int() interrupt 1{TH0 = 0xD8;TL0 = 0xEF;Count++; //长度加1}/*-------------------------------------------------功能:1MS延时子程序-------------------------------------------------*/void Delay_xMs(unsigned int x){unsigned int i,j;for( i =0;i < x;i++ ){for( j =0;j<3;j++ );}}void Play_Song(unsigned char i){unsigned char Temp1,Temp2;unsigned int Addr;Count = 0; //中断计数器清0Addr = i * 217;while(1){Temp1 = SONG[Addr++];if ( Temp1 == 0xFF ) //休止符{TR0 = 0;Delay_xMs(100);}else if ( Temp1 == 0x00 ) //歌曲结束符{return;}else{Temp2 = SONG[Addr++];TR0 = 1;while(1){_Speak = ~_Speak;Delay_xMs(Temp1);if ( Temp2 == Count ){Count = 0;break;}}}}}/*-------------------------------------------------功能:主程序-------------------------------------------------*/ void main(){Time0_Init(); //定时器0中断初始化while(1){Play_Song(0); //播放}}。

51单片机蜂鸣器播放音乐代码(生日快乐 两只蝴蝶 祝你平安)精编版

51单片机蜂鸣器播放音乐代码(生日快乐 两只蝴蝶 祝你平安)精编版

/*生日快乐歌曲*/#include <reg51.h>#define uint unsigned int#define uchar unsigned charsbit beep = P1^5;uchar code SONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159, 212,212,106,126,159,169,190,119,119,126,159,142,159,0};uchar code SONG_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0};//延时void DelayMS(uint x){uchar t;while(x--) for(t=0;t<120;t++);}void PlayMusic(){uint i=0,j,k;while(SONG_LONG[i]!=0||SONG_TONE[i]!=0){ //播放各个音符,SONG_LONG 为拍子长度for(j=0;j<SONG_LONG[i]*20;j++){beep=~beep;//SONG_TONE 延时表决定了每个音符的频率for(k=0;k<SONG_TONE[i]/3;k++);}DelayMS(10);i++;}}void main(){beep=0;while(1){PlayMusic(); //播放生日快乐DelayMS(500); //播放完后暂停一段时间}}两只蝴蝶:#include <reg51.h> // 这是单片机音乐代码生成器生成的代码#define uchar unsigned charsbit beepIO=P1^5; // 输出为P1.5 可以修改成其它IO 口uchar m,n;uchar code T[49][2]={{0,0},{0xF8,0x8B},{0xF8,0xF2},{0xF9,0x5B},{0xF9,0xB7},{0xFA,0x14},{0xFA,0x66},{0xFA,0xB9},{0xFB,0x03 },{0xFB,0x4A},{0xFB,0x8F},{0xFB,0xCF},{0xFC,0x0B},{0xFC,0x43},{0xFC,0x78},{0xFC,0xAB},{0xFC,0xDB},{0xFD,0x08},{0xFD,0x33},{0xFD,0x5B},{0xFD,0x8 1},{0xFD,0xA5},{0xFD,0xC7},{0xFD,0xE7},{0xFE,0x05},{0xFE,0x21},{0xFE,0x3C},{0xFE,0x55},{0xFE,0x6D},{0xFE,0x84},{0xFE,0x99},{0xFE,0xAD},{0xFE,0xC0 },{0xFE,0x02},{0xFE,0xE3},{0xFE,0xF3},{0xFF,0x02},{0xFF,0x10},{0xFF,0x1D},{0xFF,0x2A},{0xFF,0x36},{0xFF,0x42},{0xFF,0x4C},{0xFF,0x56},{0xFF,0x60},{ 0xFF,0x69},{0xFF,0x71},{0xFF,0x79},{0xFF,0x81}};uchar code music[][2]={{0,4},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8},{21,4},{23,4},{21,4},{19 ,4},{16,4},{19,4},{14,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,24},{16,4},{19,4},{21,8},{21,4},{23,4},{21,4},{19 ,4},{16,4},{19,4},{21,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8},{21,4},{23,4},{21,4},{19 ,4},{16,4},{19,4},{14,24},{23,4},{26,4},{26,16},{26,4},{28,4},{26,4},{23,24},{21,4},{23,4},{21,8},{21,4},{23,4},{21,4},{19,4},{16 ,4},{16,2},{19,2},{19,24},{0,20},{26,4},{26,4},{28,4},{31,4},{30,4},{30,4},{28,4},{23,4},{21,4},{21,4},{23,16},{0,4},{23,4},{23,4},{26,4} ,{28,8},{28,12},{16,4},{23,4},{21,4},{21,24},{23,4},{26,4},{26,4},{23,4},{26,8},{0,4},{31,8},{30,4},{28,4},{30,4},{23,8},{0,4},{28,4},{28,4},{ 30,4},{28,4},{26,4},{23,4},{21,8},{23,4},{21,4},{23,4},{26,16},{0xFF,0xFF}};void delay(uchar p){uchar i,j;for(;p>0;p--)for(i=181;i>0;i--)for(j=181;j>0;j--);}void pause(){uchar i,j;for(i=150;i>0;i--)for(j=150;j>0;j--);}void T0_int() interrupt 1beepIO=!beepIO;TH0=T[m][0]; TL0=T[m][1];}void main(){uchar i=0;TMOD=0x01; EA=1; ET0=1;while(1){m=music[i][0];n=music[i][1];if(m==0x00){TR0=0;delay(n);i++;}else if(m==0xFF){TR0=0;delay(30);i=0;}else if(m==music[i+1][0]){TR0=1;delay(n);TR0=0;pause();i++;}else{TR0=1;delay(n);i++;}}}祝你平安:#include "reg52.h"unsigned char Count;sbit _Speak =P1^5 ;unsigned char code SONG[] ={ //祝你平安0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20, 0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20, 0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20, 0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20, 0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10, 0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20, 0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20, 0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20, 0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10, 0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80, 0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20, 0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20, 0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10, 0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x00};void Time0_Init(){TMOD = 0x01;IE = 0x82;TH0 = 0xD8;TL0 = 0xEF; //12MZ晶振,10ms}void Time0_Int() interrupt 1{TH0 = 0xD8;TL0 = 0xEF;Count++; //长度加1}/*-------------------------------------------------功能:1MS延时子程序-------------------------------------------------*/ void Delay_xMs(unsigned int x){unsigned int i,j;for( i =0;i < x;i++ ){for( j =0;j<3;j++ );}}void Play_Song(unsigned char i){unsigned char Temp1,Temp2;unsigned int Addr;Count = 0; //中断计数器清0Addr = i * 217;while(1){Temp1 = SONG[Addr++];if ( Temp1 == 0xFF ) //休止符{TR0 = 0;Delay_xMs(100);}else if ( Temp1 == 0x00 ) //歌曲结束符{return;}else{Temp2 = SONG[Addr++];TR0 = 1;while(1){_Speak = ~_Speak;Delay_xMs(Temp1);if ( Temp2 == Count ){Count = 0;break;}}}}}/*------------------------------------------------- 功能:主程序-------------------------------------------------*/ void main(){Time0_Init(); //定时器0中断初始化while(1){Play_Song(0); //播放}}。

播放生日快乐歌曲

播放生日快乐歌曲

安徽冶金科技职业学院实训报告课题名称播放生日快乐歌系部班级学生姓名指导教师年月日一、播放生日快乐歌的原理:通过80C51乐曲播放电路中,P1.7接发声器SOND,P1.0接启动键<K0>,按一次K0就播放一遍生日快乐歌<fosc=12MHz>;控制输出方波形频率用定时/计数器比延时程序更加准确,根据C音调、半周期和fosc=12MHz条件下选T0定时器方式0计算出来的;播放乐曲,除了控制频率,还有控制时间的问题,用T0方式0控制音频频率,T1方式1控制音符节拍,编制生日快乐歌曲音符序号数组s[26]和生日快乐歌曲音符节拍长度数组L[26],两数组序号具有对应关系。

例如:播放生日快乐歌第一个音符“5”,1/8拍,取4*50ms=200ms;遇休止符0;停止发音频,但仍当做一个音符,按其节拍长短控制定时时间。

当一个音符播放结束,T1停,转入下一个音符,中间间隔延时10ms。

设T1定时时间:50ms计算T1定时初值:T1(初值)=3CB0H因此:TH1=0x3c,TL1=0xb0三、生日快乐歌曲编程:#include <reg51.h> //包含访问sfr库函数reg51.hsbit K0=P1^0; //定义启动键K0为P1.0sbit SOND=P1^7; //定义发声器SOND为P1.7unsigned char i,j; //定义字符型循环变量i(音符序数)、j(50ms整倍数)unsigned char code th[22]={ //定义音符频率定时数组高8位(12MHz,定时方式0)0,196,202,208,211,216,220,224,226,229,232,233,236,238,240,241,242,244,244,246,2 67,248};unsigned char code tl[22]={ //定义音符频率定时数组低8位(12MHz,定时方式0)0,12,27,21,7,4,16,12,4,12,9,20,2,8,6,2,22,5,26,1,4,3};unsigned char s[26]={ //定义生日快乐歌曲音符序数数组12,12,13,12,15,14,12,12,13,12,16,15,12,12,19,17,15,14,13,0,18,18,17,15,16,15}; unsigned char L[26]={ //定义生日快乐歌曲音符节拍长度数组(50ms整倍数)4,4,8,8,8,16,4,4,8,8,8,16,4,4,8,8,8,8,16,8,4,4,8,8,8,16};void main(){ //主函数unsigned int t; //定义循环变量t(用于音符发声后间隙延时)TMOD=0x10; //T0定时器方式0,T1定时器方式1TH1=0x3c;TL1=0xb0; //置T1初值50msIP=0x02;IE=0x8a; //置T0为高优先级中断,T0、T1开中断while(1){ //无限循环while(K0==1); //等待按K0按下while(K0==0); //等待按K0释放for(i=0;i<26;i++){ //歌曲音符节拍循环if(s[i]==0) {SOND=0; //若歌曲音符序数为0,停止发声TR0=0;} //T0停止运行else {TH0=th[s[i]]; //否则,置T0初值高8位(音符方波半周期)TL0=tl[s[i]]; //置T0初值低8位(音符方波半周期)TR0=1;} //T0运行j=L[i];TR1=1; //置50ms计数器初值,T1运行while(TR1==1); //等待T1停止运行TR0=0;SOND=0; //T0停止运行,停止发声for(t=0;t<2000;t++);}}} //音符间隔延时为10msvoid t0() interrupt 1 { //T0中断函数SOND=~SOND; //输出取反(产音频方波)TH0=th[s[i]]; TL0=tl[s[i]];} //重置T0初值void t1() interrupt 3 { //T1中断函数TH1=0x3c;TL1=0xb0; //重置T1初值50msif((j--)==0) TR1=0;} //若50ms计数器减1为0,T1停止四、播放生日快乐歌的步骤和调试:A.创建keil项目:1)双击桌面keil软件2)打开keil的集成开发环境3)点击菜单栏项目project选新建new project4)选择保存路径,建立项目文件夹,给项目命名并保存。

51单片机蜂鸣器奏乐(生日快乐)

51单片机蜂鸣器奏乐(生日快乐)
mov 30h,#00h ;取简谱码指针
next: mov a,30h ;简谱码指针载入A
mov dptr,#table ;至table取简谱码
movc a,@a+dptr
mov r2,a ;取到的简谱码暂存于R2
jz end0 ;是否取到00(结束码)?
anl a,#0fh ;不是,则取低4位(节拍码)
dw 64684,64777,64820,64898
dw 64968,65030,65058,65110
dw 65157,65178,65217
table:
;1
db 82h,01h,81h,94h,84h,0b4h,0a4h,04h,82h,01h,81h,94h,84h,0c4h,0b4h,04h
mov 22h,a ;存入(22H).
rl a ;乘2
mov dptr,#table1 ;至table1取相对的高位字节计数值
m高位字节存入TH0
mov 21h,a ;取到的高位字节存入(21H)
mov a,22h ;再载入取的的音符码
inc 30h ;取简谱码指针加1
jmp next ;取下一个码
end0: clr tr0 ;停止timer0
jmp start0 ;重复循环
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;time0中断服务子程序用来产生相应的音调脉冲频率。
;4
db 82h,01h,81h,0f4h,0d4h,0b4h,0a4h,94h,0e2h,01h,0e1h,0d4h,0b4h,0c4h,0b4h,04h,00

单片机驱动蜂鸣器音乐生日快乐的播放程序

单片机驱动蜂鸣器音乐生日快乐的播放程序

单片机驱动蜂鸣器音乐生日快乐的播放程序;音乐生日快乐的播放;P1.6是喇叭输出端口,用杜邦线连接到J42插针 B1针脚,喇叭即播放音乐numtim equ 20hgewei equ 21hshiwei equ 22hscanled equ 23horg 000hjmp startorg 00bhjmp tim0org 100hstart:; JB P3.7,$ ;检测播放按键是否按下mov tmod,#00000001bmov ie,#10000010bmov numtim,#01h start0:mov 30h,#00hnext:mov a,30hmov dptr,#tablemovc a,@a+dptrmov r2,ajz end0anl a,#0fhmov r5,amov a,r2swap aanl a,#0fhjnz singclr tr0jmp d1sing: dec amov 22h,arl amov dptr,#table1movc a,@a+dptrmov th0,amov 21h,amov a,22hrl ainc amovc a,@a+dptrmov tl0,amov 20h,asupplies and get to use, the registration of company assets, record maintenance, maintenance of effective management; 2.6 cost management: preparation of the annual administrative budget, control administrative costs, determine the scope of cost-sharing, sharing the office expenses by month; 2.7 information management: responsible for documents,materials, information and publicity, communication links, and ensure promptly, ranking officers reporting; responsible for the collation and analysis of information, provide the basis for corporate decisions; corporate culture construction, planning, editing, internal publications;2.8 vehicle management: responsible for the management, repairs and maintenance of vehicles; 2.9 legal disputes: the company responsible for the handling of disputes; 2.10 other: maintaining normal working order, and security. General Manager General Manager job description 1, 1.1 develop strategies and plans: according to company strategic planning, establish the annual management plan, reported to the Board of Directors for approval; 1.2 decomposition measures: according to the Board of Directors issued the annual management plan, annual index of decomposition, through the Organization of coordination mandate incharge of the Department Organization and implementation, ensuring comprehensive implementation of annual indicators; 1.3 inspection: convenes the General Manager Office, throughsetb tr0d1:lcall delayinc 30hjmp nextend0:clr tr0jmp start0tim0:push accpush pswmov tl0,20hmov th0,21hcpl p1.6 ;由该口输出音频数据pop pswpop accretidelay: mov r7,#02hd2: mov r4,#187d3: mov r3,#248djnz r3,$djnz r4,d3djnz r7,d2djnz r5,delayrettable1: ;音乐码表dw 64260,64400,64524,64580 dw 64684,64777,64820,64898 dw 64968,65030,65058,65110 dw 65157,65178,65217table:db 82h,01h,81h,94h,84h db 0b4h,0a4h,04hdb 82h,01h,81h,94h,84hdb 0c4h,0b4h,04hdb 82h,01h,81h,0f4h,0d4hdb 0b4h,0a4h,94hdb 0e2h,01h,0e1h,0d4h,0b4hdb 0c4h,0b4h,04hdb 82h,01h,81h,94h,84hdb 0b4h,0a4h,04hdb 82h,01h,81h,94h,84hdb 0c4h,0b4h,04h supplies and get to use, the registration of company assets, record maintenance, maintenance of effective management;2.6 cost management: preparation of the annual administrative budget, control administrative costs, determine the scope of cost-sharing, sharing the office expenses by month; 2.7 information management: responsible for documents, materials, information and publicity, communication links, and ensure promptly, ranking officers reporting; responsible for the collation and analysis of information, provide the basis for corporate decisions; corporate culture construction, planning, editing, internal publications; 2.8 vehicle management: responsible for the management, repairs and maintenance of vehicles; 2.9 legal disputes: the company responsible for the handling of disputes; 2.10 other: maintaining normal working order, and security. General Manager General Manager job description 1, 1.1 develop strategies and plans: according to company strategic planning, establish the annual management plan, reported to the Board of Directors for approval; 1.2 decomposition measures: according to the Board of Directors issued the annual management plan, annual index of decomposition, through the Organizationof coordination mandate in charge of the Department Organization and implementation, ensuring comprehensive implementation of annual indicators; 1.3 inspection: convenes the General Manager Office, through db 82h,01h,81h,0f4h,0d4hdb 0b4h,0a4h,94hdb 0e2h,01h,0e1h,0d4h,0b4hdb 0c4h,0b4h,04hdb 00TABLE2:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90Hend另外的一个C文件。

3 蜂鸣器指导书

3 蜂鸣器指导书

6
北方蓝芯科技开发有限公司
NBC51-V4.0 使用手册
实验现象:控制蜂鸣器使之发出 7 种不同的音调。 扩展实验:尝试实现更多种音调。
7
北方蓝芯科技开发有限公司
Hale Waihona Puke NBC51-V4.0 使用手册
EX3.3、节拍实现
实验源程序: //***********************************************************************************/ /播放音调 //*********************************************************************************** void Play_jp() { uint Tone,Long; //定义音调变量 uint i,j,k; //定义 for(i=0;i<7;i++) //7 种音调循环 { Tone=SOUNDTONE[i]; //读取音调 Long=SOUNDLONG[i]; //读取节拍 for(j=0;j<Long;j++) //输出不同节拍 { BZ=0; //关闭蜂鸣器 for(k=0;k<Tone;k++); //Tone 的不同来区分 7 种音调 BZ=1; //打开蜂鸣器 for(k=0;k<Tone;k++); //Tone 的不同来区分 7 种音调 } } } //*********************************************************************************** //主函数 //*********************************************************************************** void main() { while(1) { Play_jp(); //播放 7 种音调 BZ=0; //关闭蜂鸣器 delay(10000); //关闭蜂鸣器时间 } } 硬件连接: IO 接口 模块接口 位数 J10_0 J18_BZ 1位

51单片机蜂鸣器播放音乐代码

51单片机蜂鸣器播放音乐代码

/*生日快乐歌曲*/#include <>#define uint unsigned int#define uchar unsigned charsbit beep = P1^5;uchar code SONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159, 212,212,106,126,159,169,190,119,119,126,159,142,159,0};uchar code SONG_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0};//延时!void DelayMS(uint x){uchar t;while(x--) for(t=0;t<120;t++);}void PlayMusic(){uint i=0,j,k;while(SONG_LONG[i]!=0||SONG_TONE[i]!=0){ //播放各个音符,SONG_LONG 为拍子长度%for(j=0;j<SONG_LONG[i]*20;j++){beep=~beep;//SONG_TONE 延时表决定了每个音符的频率for(k=0;k<SONG_TONE[i]/3;k++);}DelayMS(10);i++;}}~void main(){beep=0;while(1){PlayMusic(); //播放生日快乐DelayMS(500); //播放完后暂停一段时间}}两只蝴蝶:%#include <> // 这是单片机音乐代码生成器生成的代码#define uchar unsigned charsbit beepIO=P1^5; // 输出为可以修改成其它IO 口uchar m,n;uchar code T[49][2]={{0,0},{0xF8,0x8B},{0xF8,0xF2},{0xF9,0x5B},{0xF9,0xB7},{0xFA,0x14},{0xFA,0x66},{0xFA,0xB9},{0xFB,0x03 },{0xFB,0x4A},{0xFB,0x8F},{0xFB,0xCF},{0xFC,0x0B},{0xFC,0x43},{0xFC,0x78},{0xFC,0xAB},{0xFC,0xDB},{0xFD,0x08},{0xFD,0x33},{0xFD,0x5B},{0xFD,0x8 1},{0xFD,0xA5},{0xFD,0xC7},{0xFD,0xE7},{0xFE,0x05},{0xFE,0x21},{0xFE,0x3C},{0xFE,0x55},{0xFE,0x6D},{0xFE,0x84},{0xFE,0x99},{0xFE,0xAD},{0xFE,0xC0 },{0xFE,0x02},{0xFE,0xE3},{0xFE,0xF3},{0xFF,0x02},{0xFF,0x10},{0xFF,0x1D},{0xFF,0x2A},{0xFF,0x36},{0xFF,0x42},{0xFF,0x4C},{0xFF,0x56},{0xFF,0x60},{ 0xFF,0x69},{0xFF,0x71},{0xFF,0x79},{0xFF,0x81}};~uchar code music[][2]={{0,4},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8},{21,4},{23,4},{21,4},{19 ,4},{16,4},{19,4},{14,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,24},{16,4},{19,4},{21,8},{21,4},{23,4},{21,4},{19 ,4},{16,4},{19,4},{21,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8},{21,4},{23,4},{21,4},{19 ,4},{16,4},{19,4},{14,24},{23,4},{26,4},{26,16},{26,4},{28,4},{26,4},{23,24},{21,4},{23,4},{21,8},{21,4},{23,4},{21,4},{19,4},{16 ,4},{16,2},{19,2},{19,24},{0,20},{26,4},{26,4},{28,4},{31,4},{30,4},{30,4},{28,4},{23,4},{21,4},{21,4},{23,16},{0,4},{23,4},{23,4},{26,4} ,{28,8},{28,12},{16,4},{23,4},{21,4},{21,24},{23,4},{26,4},{26,4},{23,4},{26,8},{0,4},{31,8},{30,4},{28,4},{30,4},{23,8},{0,4},{28,4},{28,4},{ 30,4},{28,4},{26,4},{23,4},{21,8},{23,4},{21,4},{23,4},{26,16},{0xFF,0xFF}};void delay(uchar p){.uchar i,j;for(;p>0;p--)for(i=181;i>0;i--)for(j=181;j>0;j--);}void pause(){uchar i,j;for(i=150;i>0;i--)for(j=150;j>0;j--);/}void T0_int() interrupt 1{beepIO=!beepIO;TH0=T[m][0]; TL0=T[m][1];}void main(){uchar i=0;TMOD=0x01; EA=1; ET0=1;、while(1){m=music[i][0];n=music[i][1];if(m==0x00){TR0=0;delay(n);i++;}else if(m==0xFF){TR0=0;delay(30);i=0;}else if(m==music[i+1][0]){TR0=1;delay(n);TR0=0;pause();i++;}else.{TR0=1;delay(n);i++;}}}祝你平安:#include ""unsigned char Count;sbit _Speak =P1^5 ;unsigned char code SONG[] ={ //祝你平安0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20, 0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20, %0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20, 0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20, 0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10, 0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20, 0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20, 0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20, 0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10, 0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80, 0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20, 0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20,¥0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x00}; void Time0_Init(){TMOD = 0x01;IE = 0x82;TH0 = 0xD8;TL0 = 0xEF; //12MZ晶振,10ms}void Time0_Int() interrupt 1({TH0 = 0xD8;TL0 = 0xEF;Count++; //长度加1}/*-------------------------------------------------功能:1MS延时子程序-------------------------------------------------*/void Delay_xMs(unsigned int x){)unsigned int i,j;for( i =0;i < x;i++ ){for( j =0;j<3;j++ );}}void Play_Song(unsigned char i){unsigned char Temp1,Temp2;unsigned int Addr;!Count = 0; //中断计数器清0Addr = i * 217;while(1){Temp1 = SONG[Addr++];if ( Temp1 == 0xFF ) //休止符{TR0 = 0;Delay_xMs(100);}:else if ( Temp1 == 0x00 ) //歌曲结束符{return;}else{Temp2 = SONG[Addr++];TR0 = 1;while(1){._Speak = ~_Speak;Delay_xMs(Temp1);if ( Temp2 == Count ){Count = 0;break;}}}}}/*-------------------------------------------------功能:主程序-------------------------------------------------*/ void main(){Time0_Init(); //定时器0中断初始化while(1){Play_Song(0); //播放}}。

单片机蜂鸣器播放音乐代码生日快乐两只蝴蝶祝你平安

单片机蜂鸣器播放音乐代码生日快乐两只蝴蝶祝你平安

单片机蜂鸣器播放音乐代码生日快乐两只蝴蝶祝你平安/*生日快乐歌曲*/#include<reg51.h>#defineuintunsignedint#defineucharunsignedcharsbitbeep=P1^5;ucharcodeSONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159,212,212,106,126,159,169,190,119,119,126,159,142,159,0};ucharcodeSONG_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0};//延时voidDelayMS(uintx){uchart;while(x--)for(t=0;t<120;t++);}voidPlayMusic(){uinti=0,j,k;while(SONG_LONG[i]!=0||SONG_TONE[i]!=0){//播放各个音符,SONG_LONG为拍子长度for(j=0;j<SONG_LONG[i]*20;j++){beep=~beep;//SONG_TONE延时表决定了每个音符的频率for(k=0;k<SONG_TONE[i]/3;k++);}DelayMS(10);i++;}}voidmain(){beep=0;while(1){PlayMusic();//播放生日快乐DelayMS(500);//播放完后暂停一段时间}}两只蝴蝶:#include<reg51.h>//这是单片机音乐代码生成器生成的代码#defineucharunsignedcharsbitbeepIO=P1^5;//输出为P1.5可以修改成其它IO口ucharcodeT[49][2]={{0,0},{0xF8,0x8B},{0xF8,0xF2},{0xF9,0x5B},{0xF9,0xB7},{0xFA,0x14},{0xFA,0x66},{0xFA,0xB9},{ 0xFB,0x03},{0xFB,0x4A},{0xFB,0x8F},{0xFB,0xCF},{0xFC,0x0B},{0xFC,0x43},{0xFC,0x78},{0xFC,0xAB},{0xFC,0xDB},{0xFD,0x08},{0xFD,0x33},{0xFD,0x5B},{ 0xFD,0x81},{0xFD,0xA5},{0xFD,0xC7},{0xFD,0xE7},{0xFE,0x05},{0xFE,0x21},{0xFE,0x3C},{0xFE,0x55},{0xFE,0x6D},{0xFE,0x84},{0xFE,0x99},{0xFE,0xAD},{ 0xFE,0xC0},{0xFE,0x02},{0xFE,0xE3},{0xFE,0xF3},{0xFF,0x02},{0xFF,0x10},{0xFF,0x1D},{0xFF,0x2A},{0xFF,0x36},{0xFF,0x42},{0xFF,0x4C},{0xFF,0x56},{ 0xFF,0x60},{0xFF,0x69},{0xFF,0x71},{0xFF,0x79},{0xFF,0x81}};ucharcodemusic[][2]={{0,4},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8},{21,4} ,{23,4},{21,4},{19,4},{16,4},{19,4},{14,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,24},{16,4},{19,4},{21,8},{21,4} ,{23,4},{21,4},{19,4},{16,4},{19,4},{21,24},{23,4},{21,4},{23,16},{23,4},{21,4},{23,4},{21,4},{19,16},{16,4},{19,4},{21,8},{21,4} ,{23,4},{21,4},{19,4},{16,4},{19,4},{14,24},{23,4},{26,4},{26,16},{26,4},{28,4},{26,4},{23,24},{21,4},{23,4},{21,8},{21,4},{23,4} ,{21,4},{19,4},{16,4},{16,2},{19,2},{19,24},{0,20},{26,4},{26,4},{28,4},{31,4},{30,4},{30,4},{28,4},{23,4},{21,4},{21,4},{23,16},{0,4},{ 23,4},{23,4},{26,4},{28,8},{28,12},{16,4},{23,4},{21,4},{21,24},{23,4},{26,4},{26,4},{23,4},{26,8},{0,4},{31,8},{30,4},{28,4},{30,4},{23,8},{ 0,4},{28,4},{28,4},{30,4},{28,4},{26,4},{23,4},{21,8},{23,4},{21,4},{23,4},{26,16}, {0xFF,0xFF}};voiddelay(ucharp){uchari,j;for(;p>0;p--)for(i=181;i>0;i--)for(j=181;j>0;j--);}voidpause(){uchari,j;for(i=150;i>0;i--)for(j=150;j>0;j--);}voidT0_int()interrupt1{beepIO=!beepIO;TH0=T[m][0];TL0=T[m][1];}voidmain(){uchari=0;while(1){m=music[i][0];n=music[i][1];if(m==0x00){TR0=0;delay(n);i++;}elseif(m==0xFF){TR0=0;delay(30);i=0;}elseif(m==music[i+1][0]){TR0=1;delay(n);TR0=0;pause();i++;}else{TR0=1;delay(n);i++;}}}祝你平安:#include"reg52.h"unsignedcharCount;sbit_Speak=P1^5;unsignedcharcodeSONG[]={//祝你平安0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20, 0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20, 0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20, 0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20, 0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10, 0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20, 0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20, 0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20, 0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10, 0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80, 0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20, 0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20, 0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10, 0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x00};voidTime0_Init(){TMOD=0x01;IE=0x82;TH0=0xD8;TL0=0xEF;//12MZ晶振,10ms}voidTime0_Int()interrupt1{TH0=0xD8;TL0=0xEF;Count++;//长度加1}功能:1MS延时子程序-------------------------------------------------*/ voidDelay_xMs(unsignedintx){unsignedinti,j;for(i=0;i<x;i++){for(j=0;j<3;j++);}}voidPlay_Song(unsignedchari){unsignedcharTemp1,Temp2;unsignedintAddr;Count=0;//中断计数器清0Addr=i*217;while(1){Temp1=SONG[Addr++];if(Temp1==0xFF)//休止符{TR0=0;Delay_xMs(100);}elseif(Temp1==0x00)//歌曲结束符{return;}else{Temp2=SONG[Addr++];TR0=1;while(1){_Speak=~_Speak;Delay_xMs(Temp1);if(Temp2==Count){Count=0;break;}}}}}功能:主程序-------------------------------------------------*/ voidmain(){Time0_Init();//定时器0中断初始化while(1){Play_Song(0);//播放}}。

单片机蜂鸣器播放音乐代码生日快乐两只蝴蝶祝你平安

单片机蜂鸣器播放音乐代码生日快乐两只蝴蝶祝你平安

/生日快乐歌曲/ include<reg51.h>defineuintunsignedintdefineucharunsignedcharsbitbeep=P1^5;ucharcodeSONG_TONE={212;212;190;212;159;169;212;212;190;212;142;159;212;212;106;126;159;169;190;119;119;126;159;142;159;0};ucharcodeSONG_LONG={9;3;12;12;12;24;9;3;12;12;12;24;9;3;12;12;12;12;12;9;3;12;12;12;24;0};//延时voidDelayMSuintx{uchart;whilex--fort=0;t<120;t++;}voidPlayMusic{uinti=0;j;k;whileSONG_LONGi=0||SONG_TONEi=0{//播放各个音符;SONG_LONG为拍子长度forj=0;j<SONG_LONGi20;j++{//SONG_TONE延时表决定了每个音符的频率fork=0;k<SONG_TONEi/3;k++;}DelayMS10;i++;}}voidmain{beep=0;while1{PlayMusic;//播放生日快乐DelayMS500;//播放完后暂停一段时间}}两只蝴蝶:include<reg51.h>//这是单片机音乐代码生成器生成的代码defineucharunsignedcharsbitbeepIO=P1^5;//输出为P1.5可以修改成其它IO口ucharm;n;ucharcodeT492={{0;0};{0xF8;0x8B};{0xF8;0xF2};{0xF9;0x5B};{0xF9;0xB7};{0xFA;0x14};{0xFA;0x66};{0xFA;{0xFC;0x43};{0xFC;0x78};{0xFC;0xAB};{0xFC;0xDB};{0xFD;0x08};{0xFD;0x33};{0xFD; 0x5B};{0xFD;0x81};{0xFD;0xA5};{0xFD;0xC7};{0xFD;0xE7};{0xFE;0x05};{0xFE;0x21};{0xFE;0x3C};{0xFE;0x55};{0xFE;0x6D};{0xFE;0x84};{0xFE;0x99};{0xFE; 0xAD};{0xFE;0xC0};{0xFE;0x02};{0xFE;0xE3};{0xFE;0xF3};{0xFF;0x02};{0xFF;0x10};{0xFF;0x1D};{0xFF;0x2A};{0xFF;0x36};{0xFF;0x42};{0xFF;0x4C};{0xFF; 0x56};{0xFF;0x60};{0xFF;0x69};{0xFF;0x71};{0xFF;0x79};{0xFF;0x81}};ucharcodemusic2={{0;4};{23;4};{21;4};{23;16};{23;4};{21;4};{23;4};{21;4};{19;16};{16;4};{19;4};{21;8} ;{21;4};{23;4};{21;4};{19;4};{16;4};{19;4};{14;24};{23;4};{21;4};{23;16};{23;4};{21;4};{23;4};{21;4};{19;24};{16;4};{19;4};{21;8} ;{21;4};{23;4};{21;4};{19;4};{16;4};{19;4};{21;24};{23;4};{21;4};{23;16};{23;4};{21;4};{23;4};{21;4};{19;16};{16;4};{19;4};{21;8} ;{21;4};{23;4};{21;4};{19;4};{16;4};{19;4};{14;24};{23;4};{26;4};{26;16};{26;4};{28;4};{26;4};{23;24};{21;4};{23;4};{21;8};{21;4} ;{23;4};{21;4};{19;4};{16;4};{16;2};{19;2};{19;24};{0;20};{26;4};{26;4};{28;4};{31;4};{30;4};{30;4};{28;4};{23;4};{21;4};{21;4};{23;16}; {0;4};{23;4};{23;4};{26;4};{28;8};{28;12};{16;4};{23;4};{21;4};{21;24};{23;4};{26;4};{26;4};{23;4};{26;8};{0;4};{31;8};{30;4};{28;4};{30;4};{ 23;8};{0;4};{28;4};{28;4};{30;4};{28;4};{26;4};{23;4};{21;8};{23;4};{21;4};{23 ;4};{26;16};{0xFF;0xFF}};voiddelayucharpuchari;j;for;p>0;p--fori=181;i>0;i--forj=181;j>0;j--;}voidpause{uchari;j;fori=150;i>0;i--forj=150;j>0;j--;}voidT0_intinterrupt1 {beepIO=beepIO;TH0=Tm0;TL0=Tm1;}voidmain{uchari=0;TMOD=0x01;EA=1;ET0=1; while1{m=musici0;n=musici1;{TR0=0;delayn;i++;}elseifm==0xFF{TR0=0;delay30;i=0;}elseifm==musici+10{TR0=1;delayn;TR0=0;pause;i++;}else{TR0=1;delayn;i++;}}}祝你平安:include"reg52.h"unsignedcharCount;sbit_Speak=P1^5;unsignedcharcodeSONG={//祝你平安0x26;0x20;0x20;0x20;0x20;0x20;0x26;0x10;0x20;0x10;0x20;0x80;0x26;0x20;0x30;0x2 0;0x30;0x20;0x39;0x10;0x30;0x10;0x30;0x80;0x26;0x20;0x20;0x20;0x20;0x20;0x1c;0x2 0;0x20;0x80;0x2b;0x20;0x26;0x20;0x20;0x20;0x2b;0x10;0x26;0x10;0x2b;0x80;0x26;0x2 0;0x30;0x20;0x30;0x20;0x39;0x10;0x26;0x10;0x26;0x60;0x40;0x10;0x39;0x10;0x26;0x2 0;0x30;0x20;0x30;0x20;0x39;0x10;0x26;0x10;0x26;0x80;0x26;0x20;0x2b;0x10;0x2b;0x10x2b;0x20;0x30;0x10;0x39;0x10;0x26;0x10;0x2b;0x10;0x2b;0x20;0x2b;0x40;0x40;0x2 0;0x20;0x10;0x20;0x10;0x2b;0x10;0x26;0x30;0x30;0x80;0x18;0x20;0x18;0x20;0x26;0x2 0;0x20;0x20;0x20;0x40;0x26;0x20;0x2b;0x20;0x30;0x20;0x30;0x20;0x1c;0x20;0x20;0x2 0;0x20;0x80;0x1c;0x20;0x1c;0x20;0x1c;0x20;0x30;0x20;0x30;0x60;0x39;0x10;0x30;0x1 0;0x20;0x20;0x2b;0x10;0x26;0x10;0x2b;0x10;0x26;0x10;0x26;0x10;0x2b;0x10;0x2b;0x8 0;0x18;0x20;0x18;0x20;0x26;0x20;0x20;0x20;0x20;0x60;0x26;0x10;0x2b;0x20;0x30;0x2 0;0x30;0x20;0x1c;0x20;0x20;0x20;0x20;0x80;0x26;0x20;0x30;0x10;0x30;0x10;0x30;0x2 0;0x39;0x20;0x26;0x10;0x2b;0x10;0x2b;0x20;0x2b;0x40;0x40;0x10;0x40;0x10;0x20;0x1 0;0x20;0x10;0x2b;0x10;0x26;0x30;0x30;0x80;0x00};voidTime0_Init{TMOD=0x01;IE=0x82;TH0=0xD8;TL0=0xEF;//12MZ晶振;10msvoidTime0_Intinterrupt1{TH0=0xD8;TL0=0xEF;Count++;//长度加1}/-------------------------------------------------功能:1MS延时子程序-------------------------------------------------/ voidDelay_xMsunsignedintx{unsignedinti;j;fori=0;i<x;i++{forj=0;j<3;j++;}}voidPlay_Songunsignedchari{unsignedcharTemp1;Temp2;unsignedintAddr;Count=0;//中断计数器清0Addr=i217;Temp1=SONGAddr++;ifTemp1==0xFF//休止符{TR0=0;Delay_xMs100;}elseifTemp1==0x00//歌曲结束符{return;}else{Temp2=SONGAddr++;TR0=1;while1{_Speak=~_Speak;Delay_xMsTemp1;ifTemp2==Count{Count=0;break;}}}/-------------------------------------------------功能:主程序-------------------------------------------------/ voidmain{Time0_Init;//定时器0中断初始化while1{Play_Song0;//播放}}。

基于51单片机蜂鸣器发声的-C语言程序

基于51单片机蜂鸣器发声的-C语言程序

本例使用延时函数实精品文档按键发音/* 名称:按键发音说明:按下不同的按键会是SOUNDE 发出不同频率的声音。

现不同频率的声音输出,以后也可使用定时器*/#include<reg51.h>#define uchar unsigned char#define uint unsigned intsbit BEEP=P3A 7;sbit K 仁 P1A4;sbit K2=P1A5;sbit K3=P1A6;sbit K4=P1A7;// 延时void DelayMS(uint x){uchar t;while(x--) for(t=0;t<120;t++);}// 按周期 t 发音void Play(uchar t){uchar i;for(i=0;i<100;i++){BEEP=~BEEP;DelayMS(t);}BEEP=0;}void main(){P1=0xff;BEEP=0;while(1){if(K1==0) Play(1);if(K2==0) Play(2);if(K3==0) Play(3);if(K4==0) Play(4);}}精品文档播放音乐/* 名称:播放音乐说明:程序运行时播放生日快乐歌, 未使用定时器中断,所有频率完全用延时 实现*/#include<reg51.h>#define uchar unsigned char#define uint unsigned intsbit BEEP=P3A7;// 生日快乐歌的音符频率表,不同频率由不同的延时来决定uchar code SONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159,212,212,106,126,159, 169,190,119,119,126,159,142,159,0};// 生日快乐歌节拍表,节拍决定每个音符的演奏长短uchar code SONG_LONG[]= {9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0};// 延时void DelayMS(uint x){uchar t;while(x--) for(t=0;t<120;t++);}// 播放函数void PlayMusic(){ uint i=0,j,k; while(SONG_LONG[i]!=0||SONG_TONE[i]!=0){ //播放各个音符,SONG_LON为拍子长度for(j=0;j<SONG_LONG[i]*20;j++){BEEP=~BEEP;〃SONG_TON延时表决定了每个音符的频率for(k=0;k<SONG_TONE[i]/3;k++);} DelayMS(10);i++;}}void main(){BEEP=0;while(1){PlayMusic(); // 播放生日快乐DelayMS(500); // 播放完后暂停一段时间}精品文档。

蜂鸣器唱歌程序

蜂鸣器唱歌程序

蜂鸣器唱歌----生日快乐下面是我单片机入门的时候写的一个蜂鸣器唱歌的程序,用的是stc89c52的单片机和12MHZ的晶振。

它大致是这样工作的。

我们知道歌曲都是由最基本的音调和节拍组成的。

音调就是该音符的频率,节拍就是该音符持续的时间。

也就是说发出一个最基本的音我们需要两个参数,一个是频率,一个是节拍。

那么在单片机中如何产生这两个参数呢?首先我们需要知道该音符的频率,然后用单片机的I/O口不断地变高变低来产生这个频率。

比如 1 这个音在低音,中音,高音三种情况下会有3种频率,至于到底是哪种音,在歌曲的乐谱中会给出详细的标识。

现在我们假设1 这个音为低音,在d调(什么是d调?看文章尾附录)下频率为293hz,一个周期为T=1/293 s。

那么I/O口被置1和置0的时间各占一半也就是T/2。

然后算出相应的定时器初值,那么单片机就可以发出这个音了。

接下来就是一个音符要唱多久,那就要看这个音符占据多少个节拍了,同样在歌曲的乐谱中会给出详细的标示。

那么一拍是多长呢,下面有说明。

慢节奏一般600ms一拍,快节奏一般400ms一拍。

如果你要知道更准确的节拍时长,只有拿着乐谱去听歌了,记下唱一拍的时间就行了。

我用的是定时器0控制节拍长度,在每个音符开始时开启它,它是10ms 中断一次,并且让里面的计数值增加1。

如果我要唱一拍的话(假设为600ms),那么我只需要判断计数值是否达到60,如果达到那么就停止计时然后跳到下一拍。

以上就是蜂鸣器唱歌的基本原理了,希望能对你有所帮助。

#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit sound=P3^7;uint counter=0;uchar code FREQH[3][8]= //音符定时器初值,三个8度音的高八位{//注意每行起始都为0xff,因为音调中没有0 这个音,所以随便填了个数字,后面不不会引用它// 低音:// 1 2 3 4 5 6 7{0xff,0xf9, 0xfa, 0xfa, 0xfb, 0xfb, 0xfc, 0xfc},//中音://1 2 3 4 5 6 7{0xff,0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfe, 0xfe},//高音://1 2 3 4 5 6 7{0xff,0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xff, 0x00}//0x00};uchar code FREQL[3][8]= //音符定时器初值,三个8度音的低八位{// 低音:// 1 2 3 4 5 6 7{0xff,0x5b, 0x15, 0xb9, 0x04, 0x90, 0x0c, 0x79},//中音:// 1 2 3 4 5 6 7{0xff,0xac, 0x09, 0x5c, 0x82, 0xc8, 0x05, 0x3c},//高音://1 2 3 4 5 6 7{0xff,0x55, 0x84, 0xad, 0xc0, 0xe3, 0x02, 0x00}//0x00};uchar code MUSIC[]={//生日快乐//歌曲代码,每三个表示一个音符及节拍,第一个表示音符1234567,第二个表示音高,0表示低音,1表示中音,2表示高音,第三个表示节拍长度,1表示半拍,2表示一拍,以此类推。

蜡烛播放生日歌的原理

蜡烛播放生日歌的原理

蜡烛播放生日歌的原理
蜡烛播放生日歌的最核心部件是一枚微型芯片,它储存了生日歌的音频文件。

当蜡烛被点燃时,芯片会检测到烛火的高温,然后开始播放存储的生日歌音频。

那么,它是如何检测到烛火温度的呢?蜡烛芯中嵌入了一个微型热敏电阻,它的电阻值会随着温度的升高而增大。

芯片内置了一个简单的电路,通过电阻的大小变化来检测温度。

当烛火温度超过一定值时,电阻值变化明显,芯片就“知道”蜡烛被点燃了。

这与我们小时候使用的体温计原理类似,都是通过物质电阻随温度变化来检测温度。

那么芯片是如何播放储存的音频文件呢?芯片中集成了一个简单的音频解码芯片,以及一个微型的扬声器。

音频解码芯片将数字音频信号转换为模拟音频信号输出到扬声器。

扬声器则将电信号转换为机械振动,产生声音波传播到空气中。

我们就可以听到蜡烛“唱”生日歌了。

整个蜡烛的设计可谓机电结合,将热敏电阻、芯片、扬声器巧妙融合,应用控制论、信号处理等原理,实现了一个多学科交叉的系统。

虽然每个原件都很小巧,但整体协同工作时,就能实现我们想要的“会唱歌”功能。

蜡烛播放生日歌看似神奇,但其内在运作全靠科学原理。

正是电子学、热学、控制论等知识的巧妙应用,造就了这个朴实而富含创意的产品。

它让我们领略科学造福生活的魅力,为我们的生日增添一份小小的仪式感。

我用了大约2500字详细剖析了蜡烛播放生日歌的科学原理。

简单的创意往往最难得,希望这些知识可以启发你生活中的小创新。

如果你还有任何疑问,非常欢迎
你提出来一起讨论。

伊能静《生日快乐》歌词

伊能静《生日快乐》歌词

多么简单的一句话Happy Birthday
多么平凡的一句话Happy Birthday
从童年到成长人们说过了多少次
在这一瞬间我只想要对你说
拿著送你的礼物Happy Birthday
可以共舞的音乐盒Happy Birthday
从无知到长大不知舞伴换过多少次
在这一瞬间我只希望会是你
送你的音乐盒是去年就买好的
流出的音乐是你我都很熟悉的歌
Happy Birthday to You Happy Birthday to You
我总是站在角落悄悄望著你幻想将礼物送给你你会是什么心情和表情是否欢喜
多么简单的一句话Happy Birthday
多么平凡的一句话Happy Birthday
从童年到成长人们说过了多少次
在这一瞬间我只想要对你说
拿著送你的礼物Happy Birthday
可以共舞的音乐盒Happy Birthday
从无知到长大不知舞伴换过多少次
在这一瞬间我只希望会是你
我总是站在角落悄悄望著你幻想将礼物送给你你会是什么心情和表情是否欢喜
我从不想去真正独自拥有你也知道你从来不在意只想看看你微笑的表情默默是我对你的心情。

生日快乐歌韩语歌词

生日快乐歌韩语歌词

生日快乐歌(韩国版)(红字为中文发音)생일축하합니다(祝你生日快乐) 生意出卡哈米达,생일축하합니다(祝你生日快乐) 生意出卡哈米达지구에서우주에서(在地球在宇宙) 起鼓唉搜,屋脊唉搜,제일사랑합니다(我最爱你) 生意撒朗哈米达。

꽃보다더곱게(比花还香) 鼓不搭头估给,별보다더밝게(比星星还亮) 赔不搭头趴一给,사자보다용감하게(比狮子还勇敢) 撒咋不搭勇嘎妈给,해피버스데이투유(happy birthday to you)생일축하합니다(祝你生日快乐) 生意出卡哈米达,생일축하합니다(祝你生日快乐) 生意出卡哈米达,꽃다운내친구야(喜欢花的我的朋友呀) 五大欧内亲估呀,굴곡있게살아요(生活得很曲折) 硅谷gi`dei撒拉哟~생일축하합니다(祝你生日快乐) 生意出卡哈米达,생일축하합니다(祝你生日快乐) 生意出卡哈米达,지구에서우주에서(在地球在宇宙) 起鼓唉搜,屋脊唉搜,제일사랑합니다(我最爱你) 生意撒朗哈米达。

꽃보다더곱게(比花还香) 鼓不搭头估给,별보다더밝게(比星星还亮) 赔不搭头趴一给,사자보다용감하게(比狮子还勇敢) 撒咋不搭勇嘎妈给해피벌스데이투유(happy birthday to you)생일축하합니다(祝你生日快乐) 生意出卡哈米达,생일축하합니다(祝你生日快乐) 生意出卡哈米达,칼같은내친구야(像刀一样的朋友呀) 卡一嘎度内亲估呀폼나게사세요(生活得坚强些) 估姆那dei萨三哟~벌같은내친구야(像蜜蜂的朋友呀) 跑一考度内亲估呀톡쏘며살아요(生活得很塌实) 扑估苏~缪~撒拉哟~축하해요(祝贺) 出卡唉油~축하해(祝贺) 出卡唉~생일축하해(祝你生日快乐) 生意出卡唉~。

常用电子玩具电路实例精选

常用电子玩具电路实例精选

第一章声光类玩具电路2第一节摇声光圣诞树一、功能概述圣诞树是在庆祝圣诞节时用的一种装饰品,一般用杉、松、柏等塔形常绿树制成,树上挂有花彩、缎带、玩具和贺卡等节庆物品,也有饰以彩灯的,以增加节日气氛。

圣诞节时,许多场所都摆放有各式各样的圣诞树,它不仅为人们营造了浓郁的节日气氛,而且还为人们带来了一份祝福!声光圣诞树能够发出悦耳的《圣诞歌》乐曲,同时伴有红、绿、黄等颜色的彩灯闪亮。

一棵声光圣诞树能为圣诞之夜增添欢快的节日气氛,并为节日的居室增添艳丽的光彩。

二、电路工作原理声光圣诞树的电路包括声响电路和闪光电路两大部分:集成电路陨悦员、压电蜂鸣器月和电阻砸员等构成声响电路;陨悦圆、晶体管灾栽员~灾栽猿,以及发光二极管蕴耘阅员~蕴耘阅员缘等构成闪光电路。

闪光电路又是由功能相同、结构相同的三个相互独立电路部分组成,分别闪烁红、黄、绿三种颜色的光。

电源部分(猿灾)采用两节缘号电池供电。

其电路原理如图员鄄员所示。

电路工作过程如下。

当接通电源开关杂员后,陨悦员供电并且被触发开始工作,输出其事先存储好的音频信号(《圣诞歌》乐曲),驱动压电蜂鸣器月演奏《圣诞歌》乐曲。

与此同时,陨悦圆粤、陨悦圆月、砸圆、砸猿和悦员构成的多谐振荡器开始工作产生猿~源匀扎的脉冲方波,经电阻砸源和三极管灾栽员进行电流放大,控制发光二极管蕴耘阅员~蕴耘阅缘工作。

当脉冲方波处于高电平时,经灾栽员反向在其集电极出现低电平,此时发光二极管蕴耘阅员~蕴耘阅缘处于导通状态而发光;当脉冲方波处于低电平时,经灾栽员反向在其集电极出现高电平,此时发光二极管蕴耘阅员~蕴耘阅缘处于截止状态而不发光。

脉冲方波控制的发光二极管蕴耘阅员~蕴耘阅缘表现为时亮时灭的闪烁效果,其中砸缘为限流电阻。

另外,陨悦圆悦、陨悦圆阅、砸远、砸苑和悦圆构成的多谐振荡器及相应的二极管发光电路,陨悦圆耘、陨悦圆云、砸员园、砸员员和悦猿构成的多谐振荡器及相应的二第一章摇声光类玩具电路3第一节摇声光圣诞树4极管发光电路,二者的工作原理与上述的闪光电路完全相同。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档