單片機音樂代碼生成器
㈠ 單片機歌曲代碼
#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綠色版怎麼用
根據簡譜點擊音符和時長,也就是點一個間符,再點這個音符的時長,完成一個音符的輸入,輸完全部音符後點生成代碼,把代碼復制到程序中編譯就行