蜂鸣片的构成、原理与辨别
蜂鸣片也叫压电陶瓷蜂鸣片,是压电陶瓷中应用最广的产品之一。蜂鸣片是压电蜂鸣器的主要部件。
蜂鸣片的构成
蜂鸣片由锆钛酸铅或铌镁酸铅压电陶瓷材料制成。在陶瓷片的两面镀上银电极,经极化和老化处理后,再与黄铜片或不锈钢片粘在一起。
蜂鸣片的原理
蜂鸣片是利用压电效应原理工作的,当对其施加交变电压时它会产生机械振动;反之,对其施加机械作用力时它也会产生电压信号。因此,可以将压电陶瓷蜂鸣片变通作为振动传感器使用。压电陶瓷蜂鸣片受到机械作用力时产生的电压信号很微弱,作振动传感器使用一般应连接电压放大器。
蜂鸣片的质量辨别
用机械万用表可以方便的检测蜂鸣片的好坏,方法是:
将万用表拨至25V档,左手拇指与食指轻轻捏住蜂鸣片的两面,右手持两只表笔,红笔接近薯片,黑笔横放在蜂鸣片的表面,然后左手拇指与食指用力压紧一下,随即放松,蜂鸣片上就先后产生两个极性相反的电压信号,使指针向右摆-回零-向左摆-回零,摆幅约0.1~0.15V。若交换表笔位置后重新试验,指针摆动的顺序为向左摆-回零-向右摆-回零。在压力相同的情况下,指针摆幅愈大,蜂鸣片的灵敏度越高,若指针不动,说明蜂鸣片内部漏电或受损。
图 9-8 蜂鸣器电路原理图
我们来看一下图 9-8 的电路,蜂鸣器电流依然相对较大,因此需要用三极管驱动,并且加了一个 100 欧的电阻作为限流电阻。此外还加了一个 D4 二极管,这个二极管叫做续流二极管。我们的蜂鸣器是感性器件,当三极管导通给蜂鸣器供电时,就会有导通电流流过蜂鸣器。而我们知道,电感的一个特点就是电流不能突变,导通时电流是逐渐加大的,这点没有问题,但当关断时,经“电源-三极管-蜂鸣器-地”这条回路就截断了,过不了任何电流了,那么储存的电流往哪儿去呢,就是经过这个 D4 和蜂鸣器自身的环路来消耗掉了,从而就避免了关断时由于电感电流造成的反向冲击。接续关断时的电流,这就是续流二极管名称的由来。
蜂鸣器经常用于电脑、打印机、万用表这些设备上做提示音,提示音一般也很简单,就是简单发出个声音就行,我们用程序简单做了个 4KHZ 频率下的发声和 1KHZ 频率下的发声程序,同学们可以自己研究下程序,比较下实际效果。
/************************************************************************
[文件名] C51音乐程序(八月桂花)
[功能] 通过单片机演奏音乐 /**********************************************************************/
#include <REG52.H>
#include <INTRINS.H>
//本例采用89C52, 晶振为11.0592MHZ
//关于如何编制音乐代码, 其实十分简单,各位可以看以下代码.
//频率常数即音乐术语中的音调,而节拍常数即音乐术语中的多少拍;
//所以拿出谱子, 试探编吧! sbit GPIO_Beep = P1^5 ;
unsigned char g_beat = 0; //节拍常数变量 unsigned char code music_tab[] ={
0x18, 0x30, 0x1C , 0x10, //格式为: 频率常数, 节拍常数, 频率常数, 节拍常数,
0x20, 0x40, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x10,
0x1C, 0x10, 0x18 , 0x40,
0x1C, 0x20, 0x20 , 0x20,
0x1C, 0x20, 0x18 , 0x20,
0x20, 0x80, 0xFF , 0x20,
0x30, 0x1C, 0x10 , 0x18,
0x20, 0x15, 0x20 , 0x1C,
0x20, 0x20, 0x20 , 0x26,
0x40, 0x20, 0x20 , 0x2B,
0x20, 0x26, 0x20 , 0x20,
0x20, 0x30, 0x80 , 0xFF,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x80,
0x20, 0x30, 0x1C , 0x10,
0x20, 0x10, 0x1C , 0x10,
0x20, 0x20, 0x26 , 0x20,
0x2B, 0x20, 0x30 , 0x20,
0x2B, 0x40, 0x20 , 0x15,
0x1F, 0x05, 0x20 , 0x10,
0x1C, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x30,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x40, 0x1C , 0x20,
0x20, 0x20, 0x26 , 0x40,
0x13, 0x60, 0x18 , 0x20,
0x15, 0x40, 0x13 , 0x40,
0x18, 0x80, 0x00
}; void int0() interrupt 1 //采用中断0 控制节拍
{ TH0 = 0xd8; TL0 = 0xef; g_beat--;
} void AudioFrequencyDelay (unsigned char m) //控制频率延时
{ unsigned i=3*m; while(--i);
} void BeepTone(unsigned char tone, unsigned char beat)
{ g_beat = beat; TR0 = 1; //开定时器1 while(g_beat != 0) //等待节拍完成, 通过P1口输出音频(可多声道哦!) { GPIO_Beep = ~GPIO_Beep; AudioFrequencyDelay(tone); } TR0 = 0; //关定时器1
} void Delay10ms(unsigned int c) //误差 0us
{ unsigned char a, b; //--c已经在传递过来的时候已经赋值了,所以在for语句第一句就不用赋值了--// for (;c>0;c--) { for (b=38;b>0;b--) { for (a=130;a>0;a--); } }
} void InitTimer0()
{ TMOD = 0x01; //选择16位计数器 TH0 = 0xd8; //(65535 - 10000) / 256 TL0 = 0xef; //(65535 - 10000) % 256 IE=0x82; //允许定时器T0中断和总中断
} void PlaySong()
{ unsigned char i=0; unsigned char tmpTone = 0; while(1) { tmpTone = music_tab[i]; if(tmpTone == 0x00) //如果碰到结束符 { return; } else if(tmpTone == 0xff) //若碰到休止符,延时100ms,继续取下一音符 { ++i; Delay10ms(10), TR0=0; continue; } else { unsigned char tone, beat; tone = music_tab[i++]; beat = music_tab[i++]; BeepTone(tone, beat); } }
} void main()
{ InitTimer0(); while(1) { PlaySong(); Delay10ms(300); }
}
2. 流水灯和蜂鸣器相结合:/*======================================================*/ /* 时间:2015年7月27日 21:34:44 */ /* :2015年7月29日 21:40:17 */ /* :2015年8月2日 18:15:38 */ /* 功能:流水灯1 + 蜂鸣器 */ /* 目的:51单片机学习 */ /* ^_^……! */ /*======================================================*/ #include <reg52.h> #include "commLib.h" #define SHIFT_LEFT 0 // 左移 #define SHIFT_RIGHT 1 // 右移 sbit beep = P2^3; // 蜂鸣器 int main(void) { char shiftFlag = SHIFT_LEFT; unsigned char led = 0xFE; while (1) { P1 = led; beep = 0; // 蜂鸣器发声 delay(50); beep = 1; // 蜂鸣器关闭 // 此时最左边的灯亮,0在最低位,所以要向高位移,即向左移 if (0xFE == led) { shiftFlag = SHIFT_LEFT; } // 此时最右边的灯亮,0在最高位,所以要向低位移,即向右移 else if (0x7F == led) { shiftFlag = SHIFT_RIGHT; } switch(shiftFlag) { // 左移 case SHIFT_LEFT: led = ccCrol(led, 1); break; // 右移 case SHIFT_RIGHT: led = ccCror(led, 1); break; } //延时100ms delay(50); } return 0; }
奏乐程序二:
#ifndef __MUSIC_H__
#define __MUSIC_H__
//*****************************Music******************************************************
//挥着翅膀的女孩
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};
//同一首歌
const 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 };
//两只蝴蝶
const 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 };
//***********************************************************************************
#endif
/**************************************************************************SOUND PLAY FOR 51MCUCOPYRIGHT (c) 2005 BY JJJ.-- ALL RIGHTS RESERVED --File Name: SoundPlay.hAuthor: Jiang Jian JunCreated: 2005/5/16Modified: NORevision: 1.0*******************************************************************************//*说明**************************************************************************曲谱存贮格式 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): 值越大速度越快;***************************************************************************/
#ifndef __SOUNDPLAY_H_REVISION_FIRST__
#define __SOUNDPLAY_H_REVISION_FIRST__//**************************************************************************
#include"music.h"#define SYSTEM_OSC 12000000 //定义晶振频率12000000HZ
#define SOUND_SPACE 4/5 //定义普通音符演奏的长度分率,//每4分音符间隔
sbit BeepIO = P1^5; //定义输出管脚
unsigned char value=0;
unsigned int code FreTab[12] = { 262,277,294,311,330,349,369,392,415,440,466,494 }; //原始频率表
unsigned char code SignTab[7] = { 0,2,4,5,7,9,11 }; //1~7在频率表中的位置
unsigned char code LengthTab[7]= { 1,2,4,8,16,32,64 };
unsigned char Sound_Temp_TH0,Sound_Temp_TL0; //音符定时器初值暂存
unsigned char Sound_Temp_TH1,Sound_Temp_TL1; //音长定时器初值暂存
//**************************************************************************
void InitialSound(void)
{BeepIO = 0;Sound_Temp_TH1 = (65535-(1/1200)*SYSTEM_OSC)/256; // 计算TL1应装入的初值 (10ms的初装值)Sound_Temp_TL1 = (65535-(1/1200)*SYSTEM_OSC)%256; // 计算TH1应装入的初值 TH1 = Sound_Temp_TH1;TL1 = Sound_Temp_TL1;TMOD |= 0x11;ET0 = 1;ET1 = 0;TR0 = 0;TR1 = 0;EA = 1;
}void BeepTimer0(void) interrupt 1 //音符发生中断
{static unsigned char i;BeepIO = !BeepIO;TH0 = Sound_Temp_TH0;TL0 = Sound_Temp_TL0;i++;if(i==100){i=0;value++;if(value==5)value=0;}}
//**************************************************************************
void Play(unsigned char *Sound,unsigned char Signature,unsigned Octachord,unsigned int Speed)
{unsigned int NewFreTab[12]; //新的频率表unsigned char i,j;unsigned int Point,LDiv,LDiv0,LDiv1,LDiv2,LDiv4,CurrentFre,Temp_T,SoundLength;unsigned char Tone,Length,SL,SH,SM,SLen,XG,FD;for(i=0;i<12;i++) // 根据调号及升降八度来生成新的频率表 {j = i + Signature;if(j > 11){j = j-12;NewFreTab[i] = FreTab[j]*2;}elseNewFreTab[i] = FreTab[j];if(Octachord == 1)NewFreTab[i]>>=2;else if(Octachord == 3)NewFreTab[i]<<=2;} SoundLength = 0;while(Sound[SoundLength] != 0x00) //计算歌曲长度{SoundLength+=2;}Point = 0;Tone = Sound[Point]; Length = Sound[Point+1]; // 读出第一个音符和它时时值LDiv0 = 12000/Speed; // 算出1分音符的长度(几个10ms) LDiv4 = LDiv0/4; // 算出4分音符的长度 LDiv4 = LDiv4-LDiv4*SOUND_SPACE; // 普通音最长间隔标准 TR0 = 0;TR1 = 1;while(Point < SoundLength){SL=Tone%10; //计算出音符 SM=Tone/10%10; //计算出高低音 SH=Tone/100; //计算出是否升半 CurrentFre = NewFreTab[SignTab[SL-1]+SH]; //查出对应音符的频率 if(SL!=0){if (SM==1) CurrentFre >>= 2; //低音 if (SM==3) CurrentFre <<= 2; //高音Temp_T = 65536-(50000/CurrentFre)*10/(12000000/SYSTEM_OSC);//计算计数器初值Sound_Temp_TH0 = Temp_T/256; Sound_Temp_TL0 = Temp_T%256; TH0 = Sound_Temp_TH0; TL0 = Sound_Temp_TL0 + 12; //加12是对中断延时的补偿 }SLen=LengthTab[Length%10]; //算出是几分音符XG=Length/10%10; //算出音符类型(0普通1连音2顿音) FD=Length/100;LDiv=LDiv0/SLen; //算出连音音符演奏的长度(多少个10ms)if (FD==1) LDiv=LDiv+LDiv/2;if(XG!=1) if(XG==0) //算出普通音符的演奏长度 if (SLen<=4) LDiv1=LDiv-LDiv4;elseLDiv1=LDiv*SOUND_SPACE;elseLDiv1=LDiv/2; //算出顿音的演奏长度 elseLDiv1=LDiv;if(SL==0) LDiv1=0;LDiv2=LDiv-LDiv1; //算出不发音的长度 if (SL!=0){TR0=1;for(i=LDiv1;i>0;i--) //发规定长度的音 {while(TF1==0);TH1 = Sound_Temp_TH1;TL1 = Sound_Temp_TL1;TF1=0;}}if(LDiv2!=0){TR0=0; BeepIO=0;for(i=LDiv2;i>0;i--) //音符间的间隔{while(TF1==0);TH1 = Sound_Temp_TH1;TL1 = Sound_Temp_TL1;TF1=0;}}Point+=2; Tone=Sound[Point];Length=Sound[Point+1];}BeepIO = 0;
}
//**************************************************************************
#endif
#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器
#include "SoundPlay.h"
#include"music.h"typedef unsigned int u16; //对数据类型进行声明定义
typedef unsigned char u8;void Delay1ms(unsigned int count)
{unsigned int i,j;for(i=0;i<count;i++)for(j=0;j<120;j++);
}void main()
{InitialSound();while(1){Play(Music_Girl,0,3,360);Delay1ms(500);Play(Music_Same,0,3,360);Delay1ms(500);Play(Music_Two,0,3,360);Delay1ms(500);}
}