单片机音乐代码生成器
㈠ 单片机歌曲代码
#include
"reg51.h"
#define
uint
unsigned
int
#define
uchar
unsigned
char
uchar
*
TABLE
;
code
uint
TABLE1
[15]={64260,64400,64524,64580,
64684,64777,64820,64898,
64968,65030,65058,65110,
65157,65178,65217};
code
uchar
SONG
[
]={
//1.
迟来的爱
};
code
uchar
SONG1
[
]={
//2.两只蝴蝶
};
code
uchar
SONG3
[
]={
//4.一个师傅三个徒弟
};
uchar
hjsz;
uchar
ljsz;
uchar
jpm;
uchar
yfm;
uchar
t0
=0;
uint
i=0;
sbit
Speaker
=P1^0;
uint
k;
void
Delay1()
{
for
(
k=0;k<20000;k++);
}
void
Lignt(
)
{
uchar
t;
for(t=0;t<10;t++)
{
P2=0xff;
Delay1();
P2=0x00;
Delay1();
}
}
void
Lignt1(
)
{
P2=0xaa;
Delay1();
P2=0x55;
Delay1();
}
void
Delay(uchar
t0)//延时
{
while(t0--)
//决定节拍
Lignt1();
}
void
Delay2(uchar
w0)//延时
{
while(w0--)
//决定节拍
Lignt();
}
void
T0Int()
interrupt
1//TIMER0
{
TL0
=
ljsz;
TH0
=
hjsz;
Speaker=!Speaker;
}
void
ExtInt0()
interrupt
0//INT0
{
if(t0>10)
t0=0;
i=0;
//
全局变量,指向歌谱的第1个
switch(t0++)
{
case
0
:
TABLE=SONG;break;
//选择第1首
case
1
:
TABLE=SONG1;break;//选择第2首
case
2
:
TABLE=SONG2;break;//选择第3首
case
3
:
TABLE=SONG3;break;//选择第4首
case
4
:
TABLE=SONG4;break;//选择第5首
case
5
:
TABLE=SONG5;break;//选择第6首
case
6
:
TABLE=SONG6;break;//选择第7首
case
7
:
TABLE=SONG7;break;//选择第8首
case
8
:
TABLE=SONG8;break;//选择第9首
case
9
:
TABLE=SONG9;break;//选择第10首
}
}
void
songsing()//发音程序
{
i=0;
while(TABLE[i])
{
jpm=TABLE[i]&0x0f;
//节拍值
yfm=(TABLE[i]>>0x04)&0x0f;//简谱值
if(yfm)
//简谱为1,取计数值
{
yfm=yfm-1;
hjsz=(uchar)(TABLE1[yfm]>>0x08);//取计数值高字节
TH0
=
hjsz;
ljsz=(uchar)(TABLE1[yfm]);
//取计数值低字节
TL0
=
ljsz;
TR0
=
1;
//启动TIMER0
}
else
TR0
=
0;
//简谱为0,不发音
Delay(jpm);
//节拍延时
i++;
}
}
void
main(void)
{
TMOD
=0X01;//设TIMER0在MODE1
TCON
=0X01;//外部中断INT0,下降沿触发
IE
=0x83;//开中断(INT0,TIMER0)
IP
=0x00;//设置中断优先级
TABLE=SONG0;
while(1)
{
Lignt(
);
songsing();//调用发音程序
TR0
=
0;//停止TIMER0
Delay2(1);
TABLE=SONG0;//
更改歌曲0
songsing();
}
}
㈡ 求单片机 音乐播放的c代码
^#include "reg52.h"
unsigned char Count;
sbit _Speak =P2^3 ; //讯响器控制脚
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,
};
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++ );
}
}
/*-------------------------------------------------
功能:歌曲播放子程序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)
{
_Speak = ~_Speak;
Delay_xMs(Temp1);
if ( Temp2 == Count )
{
Count = 0;
break;
}
}
}
}
}
/*-------------------------------------------------
功能:主程序
-------------------------------------------------*/
void main()
{
Time0_Init(); //定时器0中断初始化
while(1)
{
Play_Song(0); //播放
}
}
㈢ 单片机播放音乐里的音乐代码是怎么得到的有什么软件能将歌曲直接转换成16进制代码
把简谱中每个唱名对应的频率找出来,比如C调的1对应264Hz左右。
然后把这些回频率通过答公式转换成初值再换算成十六进制。
比如你用的是定时的工作方式1,则可以这位算:(假设晶振是12MHz)
X=2^16-10^6/(264*2)=63642因为要计算的是半周期对应的初值,所以频率就是2倍。
十六进制就是:F89A
好像没有什么软件吧,有的话告诉我一声哦。
㈣ 谁能告诉我如何将一段音乐编码成51单片机的代码了
请将音乐文件转成u律或者A律,用软件cooledit转,将文件拖到VC6.0下面专,你可以看到这个音频文件的内容,,其中开始的属一部分是文件头,,之后的就是音乐文件的内容. 将这个文件中的内容保存到51里面的一个BUFFER里面,然后就是51编程的事儿了,具体怎么出声,我没做过,但是知道部分原理吧.
㈤ 谁有单片机音乐 代码 生成器
我有,网络HI你了!
㈥ 单片机音乐代码
#include "reg51.h"
#define uint unsigned int
#define uchar unsigned char
uchar * TABLE ;
code uint TABLE1 [15]={64260,64400,64524,64580,
64684,64777,64820,64898,
64968,65030,65058,65110,
65157,65178,65217};
code uchar SONG [ ]={
//1. 迟来的爱
};
code uchar SONG1 [ ]={
//2.两只蝴蝶
};
code uchar SONG3 [ ]={
//4.一个师傅三个徒弟
};
uchar hjsz;
uchar ljsz;
uchar jpm;
uchar yfm;
uchar t0 =0;
uint i=0;
sbit Speaker =P1^0;
uint k;
void Delay1()
{
for ( k=0;k<20000;k++);
}
void Lignt( )
{ uchar t;
for(t=0;t<10;t++)
{
P2=0xff;
Delay1();
P2=0x00;
Delay1();
}
}
void Lignt1( )
{
P2=0xaa;
Delay1();
P2=0x55;
Delay1();
}
void Delay(uchar t0)//延时
{
while(t0--) //决定节拍
Lignt1();
}
void Delay2(uchar w0)//延时
{
while(w0--) //决定节拍
Lignt();
}
void T0Int() interrupt 1//TIMER0
{
TL0 = ljsz;
TH0 = hjsz;
Speaker=!Speaker;
}
void ExtInt0() interrupt 0//INT0
{
if(t0>10)
t0=0;
i=0; // 全局变量,指向歌谱的第1个
switch(t0++)
{
case 0 : TABLE=SONG;break; //选择第1首
case 1 : TABLE=SONG1;break;//选择第2首
case 2 : TABLE=SONG2;break;//选择第3首
case 3 : TABLE=SONG3;break;//选择第4首
case 4 : TABLE=SONG4;break;//选择第5首
case 5 : TABLE=SONG5;break;//选择第6首
case 6 : TABLE=SONG6;break;//选择第7首
case 7 : TABLE=SONG7;break;//选择第8首
case 8 : TABLE=SONG8;break;//选择第9首
case 9 : TABLE=SONG9;break;//选择第10首
}
}
void songsing()//发音程序
{
i=0;
while(TABLE[i])
{
jpm=TABLE[i]&0x0f; //节拍值
yfm=(TABLE[i]>>0x04)&0x0f;//简谱值
if(yfm) //简谱为1,取计数值
{
yfm=yfm-1;
hjsz=(uchar)(TABLE1[yfm]>>0x08);//取计数值高字节
TH0 = hjsz;
ljsz=(uchar)(TABLE1[yfm]); //取计数值低字节
TL0 = ljsz;
TR0 = 1; //启动TIMER0
}
else TR0 = 0; //简谱为0,不发音
Delay(jpm); //节拍延时
i++;
}
}
void main(void)
{
TMOD =0X01;//设TIMER0在MODE1
TCON =0X01;//外部中断INT0,下降沿触发
IE =0x83;//开中断(INT0,TIMER0)
IP =0x00;//设置中断优先级
TABLE=SONG0;
while(1)
{
Lignt( );
songsing();//调用发音程序
TR0 = 0;//停止TIMER0
Delay2(1);
TABLE=SONG0;// 更改歌曲0
songsing();
}
}
㈦ 求一个用C语言编写的51单片机音乐程序代码。
#include <reg52.h>
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, 6,1,2,
4,2,1, 4,2,1, 3,2,2, 1,2,2, 2,2,2, 1,2,4};
// 音阶频率表 高八位
code unsigned char FREQH[]={
0xF2,0xF3,0xF5,0xF5,0xF6,0xF7,0xF8,
0xF9,0xF9,0xFA,0xFA,0xFB,0xFB,0xFC,0xFC, //1,2,3,4,5,6,7,8,i
0xFC,0xFD,0xFD,0xFD,0xFD,0xFE,
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF,
} ;
// 音阶频率表 低八位
code unsigned char FREQL[]={
0x42,0xC1,0x17,0xB6,0xD0,0xD1,0xB6,
0x21,0xE1,0x8C,0xD8,0x68,0xE9,0x5B,0x8F, //1,2,3,4,5,6,7,8,i
0xEE,0x44, 0x6B,0xB4,0xF4,0x2D,
0x47,0x77,0xA2,0xB6,0xDA,0xFA,0x16,
};
void delay(unsigned char t)
{
unsigned char t1;
unsigned long t2;
for(t1=0;t1<t;t1++)
{
for(t2=0;t2<8000;t2++)
{
;
}
}
TR0=0;
}
void t0int() interrupt 1
{
TR0=0;
speaker=!speaker;
TH0=timer0h;
TL0=timer0l;
TR0=1;
}
void song()
{
TH0=timer0h;
TL0=timer0l;
TR0=1;
delay(time);
}
void main(void)
{
unsigned char k,i;
TMOD=1; //置CT0定时工作方式1
EA=1;
ET0=1;//IE=0x82 //CPU开中断,CT0开中断
while(1)
{
i=0;
while(i<75){ //音乐数组长度 ,唱完从头再来
k=sszymmh[i]+7*sszymmh[i+1]-1;
timer0h=FREQH[k];
timer0l=FREQL[k];
time=sszymmh[i+2];
i=i+3;
song();
}
}
}
㈧ 51music单片机音乐代码生成器怎么用
试了一下,感觉速度很正常,没有快很多的感觉。
这个软件应该是以12M晶振的51单片机为基础,针对那些以四分之一音符为一拍的音乐而设计的,如果晶振频率过快,或者音乐以二分之一音符为一拍的,那样设计结果都会比预想的快。
如果想让他慢下来有两个方法,一个是修改晶振频率,另一个就是找到程序中void delay(uchar p)函数,修改函数内i,j变量的类型并且修改循环的参数,让这个延时函数的时间变长。
符号的输入要看符号的含义了,这种软件不可能面面俱到的。
㈨ 51music 单片机音乐代码生成器 1.0绿色版怎么用
根据简谱点击音符和时长,也就是点一个间符,再点这个音符的时长,完成一个音符的输入,输完全部音符后点生成代码,把代码复制到程序中编译就行