#include <AT89X52.H>
unsigned char Count;
sbit bee_Speak =P3^0 ; //蜂鳴器器控制腳
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,
//路邊的野花不要采
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,
//天空之城
0x1c,0x30,0x19,0x30,0x18,0x40,0x19,0x30,0x18,0x30,0x13,0x30,0x19,0x80,
0x26,0x30,0x26,0x30,0x1c,0x40,0x20,0x30,0x1c,0x30,0x18,0x30,0x20,0x60,
0x26,0x30,0x26,0x30,0x24,0x40,0x26,0x30,0x24,0x30,0x18,0x40,0x26,0x60,
0x18,0x20,0x18,0x20,0x18,0x20,0x19,0x40,0x24,0x30,0x24,0x30,0x19,0x30,
0x19,0x60,0x1c,0x30,0x19,0x30,0x18,0x40,0x19,0x30,0x18,0x30,0x13,0x30,
0x19,0x60,0x26,0x30,0x26,0x30,0x1c,0x40,0x20,0x30,0x1c,0x30,0x18,0x30,
0x20,0x80,0x26,0x30,0x24,0x30,0x24,0x30,0x18,0x30,0x19,0x20,0x19,0x30,
0x18,0x30,0x15,0x20,0x15,0x20,0x13,0x20,0x18,0x40,0x18,0x30,0x19,0x30,
0x1c,0x20,0x1c,0x20,0x19,0x30,0x20,0x30,0x1c,0x60,0x18,0x30,0x15,0x30,
0x13,0x40,0x15,0x30,0x13,0x30,0x10,0x30,0x15,0x60,0x20,0x30,0x20,0x30,
0x18,0x30,0x19,0x30,0x18,0x30,0x13,0x30,0x13,0x60,0x1c,0x20,0x19,0x20,
0x18,0x30,0x19,0x30,0x15,0x20,0x15,0x20,0x18,0x40,0x20,0x30,0x20,0x30,
0x12,0x30,0x13,0x30,0x15,0x30,0x18,0x30,0x13,0xc0,0x13,0x80,0x13,0x30,
0x0e,0x80,0x10,0x30,0x10,0x30,0x13,0x20,0x15,0x20,0x18,0x40,0x18,0x30,
0x15,0x30,0x18,0x20,0x15,0x20,0x15,0x30,0x10,0x30,0x13,0x60,0x13,0x30,
0x0e,0x60,0x10,0x60,0x13,0x20,0x15,0x20,0x18,0x40,0x18,0x30,0x15,0x30,
0x15,0x20,0x18,0x20,0x15,0x30,0x19,0x30,0x1c,0x60,0x1c,0x30,0x19,0x30,
0x1c,0xc0,0x00,
};
void Time0_Init()
{
TMOD = 0x01;
IE = 0x82;
TH0 = 0xDC;
TL0 = 0x00; //11.0592MZ晶振,10ms
}
void Time0_Int() interrupt 1
{
TH0 = 0xDC;
TL0 = 0x00;
Count++; //長度加1
}
/*-------------------------------------------------
功能:1MS延時子程序
-------------------------------------------------*/
void Delay_xMs(unsigned int x)
{
unsigned int i,j;
for( i =0;i < x;i++ )
{
for( j =0;j<2;j++ );
}
}
/*-------------------------------------------------
功能:歌曲播放子程序i為播放哪壹段曲目
-------------------------------------------------*/
void Play_Song(unsigned char i)
{
unsigned char Temp1,Temp2;
unsigned int Addr;
Count = 0; //中斷計數器清0
Addr = 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)
{
bee_Speak = ~bee_Speak;
Delay_xMs(Temp1);
if ( Temp2 == Count )
{
Count = 0;
break;
}
}
}
}
}
/*-------------------------------------------------
功能:主程序
-------------------------------------------------*/
void main()
{
Time0_Init(); //定時器0中斷初始化
while(1)
{
Play_Song(0); //播放//0改作1可播放第二首歌曲
}
}