急求51单片机音乐程序(C语言),按键选择歌曲~~~各位大神。。拜托啦~

播放范玮琪的《最初的梦想》,《启程》,《左上角的心跳》,《黑白配》,《最重要的决定》,《如果的事》,《就是你》,《是非题》,《我们的纪念日》等。。。最好还有《爱情买卖》和一些励志的歌。。。。用的是STC89C54。。。应该不用担心会因为太多曲谱编码而放不下~~~
那个播放的程序。。。基本上会写。。。。重点是不会写那些歌曲的编码,不懂看曲谱。。。

可以加我哦1872376674

#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可播放第二首歌曲
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-10-31

会写程序,歌曲编码没有问题。网上有这种小工具,不懂曲谱也没有问题。

看下图,网上搜下需要歌曲的简谱,使用工具生成编码就行了。

第2个回答  2011-10-30
#include <reg51.h>
#include <intrins.h>

#define uchar unsigned char
#define uint unsigned int

uchar Count1,Count2;
bit flag;

sbit K1 = P1^4 ;
sbit K2 = P1^5 ;
sbit K3 = P1^6 ;
sbit K4 = P1^7 ;

sbit BEEP = P3^7 ; //蜂鸣器

/********************************************************
主函数
*********************************************************/
main()
{
P0=0xff;
P1=0xf0;
P2=0xff;
Count1=0x00;
Count2=0x00;
BEEP=1;
flag=0;
TMOD=0x01;
TH0=0xfc; TL0=0x66; //1ms定时
EA=1; ET0=1;

while(1)
{
if(K1==0)
{
while(K1==0);
TR0=1;
}
if(K2==0)
{
while(K2==0);
TR0=0;
}
}
}

/*********************************************************
Time0中断函数
**********************************************************/
void Time0(void) interrupt 1 using 0
{
TH0=0xfc; //1ms定时
TL0=0x66;
Count1++;
if(Count1==100)
{
Count2++;
if(Count2==4)
{
Count1=0;
Count2=0;
flag=~flag;
}
}
if(!flag)
{
BEEP=~BEEP;
P0=0x7e;
}
else P0=0xff;
}

/*********************************************************/
第3个回答  2011-11-01
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,本回答被提问者采纳

51单片机控制喇叭的程序(c语言)
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...

求一个用C语言编写的51单片机音乐程序代码。
sbit speaker=P2^2;unsigned char timer0h,timer0l,time;\/\/生日歌 code unsigned char sszymmh[]={5,1,1, 5,1,1, 6,1,2, 5,1,2, 1,2,2, 7,1,4,5,1,1, 5,1,1, 6,1,2, 5,1,2, 2,2,2, 1,2,4,5,1,1, 5,1,1, 5,2,2, 3,2,2, 1,2,2, 7,1,2,...

求51单片机蜂鸣器播放音乐的教程 C语言
BEEP=~BEEP; \/\/取反音乐输出IO }\/\/音乐符号串解释函数 \/\/入口:要解释的音乐符号串,输出的音调串,输出的时长串 changedata(uchar *song,uchar *diao,uchar *jie){ uchar i,i1,j;char gaodi; \/\/高低+\/-12音阶 uchar banyin;\/\/有没有半个升音阶 uchar yinchang;\/\/音长 uchar code jie7[...

跪求51单片机音乐盒汇编语言程序,急用!!!谢谢@@
;《两只老虎》播放数据 TAB: DB 0FBH,0F9H,08H,0FCH,066H,08H,0FCH,0C7H,08H,0FBH,0F9H,08H DB 0FBH,0F9H,08H,0FCH,066H,08H,0FCH,0C7H,08H,0FBH,0F9H,08H DB 0FCH,0C7H,08H,0FCH,0F3H,08H,0FDH,0A4H,10H,0FCH,0C7H,08H DB 0FCH,0F3H,08H,0FDH,04AH,08H,0F...

求89C51单片机播放音乐的C语言代码!
flag置0,准备frq递增 delayms(15);} } void timer0() interrupt 1 using 1 { TH0 = 0xfe;TL0 = frq;SPK = ~SPK;} void delayms(unsigned char ms)\/\/ 延时子程序 { unsigned char i;while(ms--){ for(i = 0; i < 120; i++);} } 这是蜂鸣器报警的代码 ...

如何编写51单片机音乐程序
参考程序:include<reg51.h> define uchar unsigned char define uint unsigned int sbit BEEP=P3^7;\/\/ 生日快乐歌的音符频率表,不同频率由不同的延时来决定 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,...

怎么用单片机编写音乐程序
单片机比如51系列都有定时器,因此可以利用它来控制扬声器按一定频率发声,以下就是一个例程,用按键的按下和抬起来模拟电子琴的控制程序。T0HEQU 30H T0L EQU 31H ORG 0000H LJMP MAIN ORG 000BH LJMP T0ISR ORG 0030H MAIN:MOV SP,#5FH MOV TMOD,#01H SETB ET0 SETB EA LOOP:MOV DPTR,...

如何编写51单片机音乐程序
其记数值的求法如:T=65536-N=65536-Fi\/2\/Fr。例:设K=65536,F=1000000=Fi=1 MHZ。求低音DO(26HZ),中音DO(523HZ),高音DO(1046HZ)的记数值。每个音符使用1个音节,字节的高四位代表音符的高低,低四位代表音符的节拍。如果1拍为0.4秒,1\/4拍为0.1秒,假设1\/4拍为 DELAY,则1拍为4...

求问,51单片机实现蜂鸣器播放音乐,并用按键控制音量大小,C语言怎么实现...
既然单独按键控制音量能实现,播放中应该也可以实现,只要巧妙利用中断或在节拍间隙读键也可以,只要安排得当就会播放调节两不误。

请高手帮忙解读一下51单片机音乐代码
sbit BEEP = P3^7; \/*用BEEP代替P3^7,即BEEP声明为P3的第7个I\/O端口*\/ \/*下面这几个有点遗忘了,呵呵*\/ \/*我们根据频率和延时来让机器唱起来的,相当于音乐曲谱里的音标与节拍*\/ uchar code SONG_TONE[]= { 212,212,190,212,159,169,212,212,190,212,142,159,212,212,106,126,...

相似回答