導航:首頁 > 操作系統 > 51單片機生日歌流程圖

51單片機生日歌流程圖

發布時間:2024-08-18 19:40:45

⑴ 求一個用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();
}
}
}

⑵ 單片機的蜂鳴器演奏 生日歌

你一個分也沒給,不想給你說,還是做下好人吧!
要想用模擬歌聲首先要定義1234567不同的音符,做個h文件放這里,,你後做其他的歌曲可以共享。這里網上可以找到,我給你一個。。然後建立個歌曲主程序,根據歌譜子,結合你的音符定義給他他編碼,把編的碼放到一個數組裡面然後輸出就好了,,下面我給你一首歌作為例子,,我也沒做個你那個什麼生日歌,你自己去編碼吧,,有譜子很好編碼的
/**************************************************************************

SOUND PLAY FOR 51MCU

COPYRIGHT (c) 2005 BY JJJ.
-- ALL RIGHTS RESERVED --

File Name: SoundPlay.h
Author: Jiang Jian Jun
Created: 2005/5/16
Modified: NO
Revision: 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__

//**************************************************************************

#define SYSTEM_OSC 12000000 //定義晶振頻率12000000HZ
#define SOUND_SPACE 4/5 //定義普通音符演奏的長度分率,//每4分音符間隔
sbit BeepIO = P3^7; //定義輸出管腳

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 //音符發生中斷
{
BeepIO = !BeepIO;
TH0 = Sound_Temp_TH0;
TL0 = Sound_Temp_TL0;
}
//**************************************************************************
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;
}
else
NewFreTab[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;
else
LDiv1=LDiv*SOUND_SPACE;
else
LDiv1=LDiv/2; //算出頓音的演奏長度
else
LDiv1=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"

void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}

//*****************************Music******************************************************

//同一首歌
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 };

//***********************************************************************************
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);
}
}

⑶ 哪位好心人給我一個51單片機C語言讓蜂鳴器唱生日歌的程序啊,謝謝啦!!

//此程序在硬體上調試通過

//本程序的單片機晶振採用11.0592M

#include<reg51.h>

sbitspeaker=P1^2;

unsignedchartimer0h,timer0l,time;

//生日歌

codeunsignedcharsszymmh[]={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};

//音階頻率表高八位

codeunsignedcharFREQH[]={

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,

};

//音階頻率表低八位

codeunsignedcharFREQL[]={

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,

};

voiddelay(unsignedchart)

{

unsignedchart1;

unsignedlongt2;

for(t1=0;t1<t;t1++)

{

for(t2=0;t2<8000;t2++)

{

;

}

}

TR0=0;

}

voidt0int()interrupt1

{

TR0=0;

speaker=!speaker;

TH0=timer0h;

TL0=timer0l;

TR0=1;

}

voidsong()

{

TH0=timer0h;

TL0=timer0l;

TR0=1;

delay(time);

}

voidmain(void)

{

unsignedchark,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();

}

}

}

P12接J31的7腳,我在板子上已經測試過了,用的是89S52

花時間編的,希望你能採納

⑷ 求: 用51單片機c語言操作使蜂鳴器奏出「祝你生日快樂」音樂的全部程序!

#include <REGX51.H>
unsigned char num1=0;
unsigned char num2=0;
//sbit P34 = P3^4; //定義用來軟體復位

//**************************************************************************

#define SYSTEM_OSC 12000000//11059200// //定義晶振頻率12000000HZ
#define SOUND_SPACE 4/5 //定義普通音符演奏的長度分率,//每4分音符間隔
//sbit BeepIO = P3^4; //定義輸出管腳
sbit BeepIO = P1^5; //定義輸出管腳

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 code led[8]= { 0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01 };
unsigned char Sound_Temp_TH0,Sound_Temp_TL0; //音符定時器初值暫存
unsigned char Sound_Temp_TH1,Sound_Temp_TL1; //音長定時器初值暫存
//**************************************************************************

//生日快樂
unsigned char code Music_birth[]={ 0x0F,0x03, 0x0F,0x03, 0x10,0x02, 0x0F,0x02, 0x15,0x02,
0x11,0x01, 0x0F,0x02, 0x0F,0x02, 0x10,0x02, 0x0F,0x02,
0x16,0x02, 0x15,0x01, 0x0F,0x03, 0x0F,0x03, 0x19,0x02,
0x17,0x02, 0x15,0x02, 0x11,0x0C, 0x10,0x02, 0x18,0x03,
0x18,0x03, 0x17,0x02, 0x15,0x02, 0x16,0x02, 0x15,0x0B,
0x00,0x00 };

void InitialSound(void)
{
BeepIO = 1;
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; //兩個定時器都工作在16位計數/計時器模式
ET0 = 1;
ET1 = 0;
TR0 = 0;
TR1 = 0;
EA = 1;
}

void BeepTimer0(void) interrupt 1 using 1 //音符發生中斷
{
BeepIO = !BeepIO;
TH0 = Sound_Temp_TH0;
TL0 = Sound_Temp_TL0;
}
//**************************************************************************
void Play(unsigned char *Sound,unsigned char Signature,unsigned Octachord,unsigned int Speed)
{
unsigned int NewFreTab[12]; //新的頻率表
unsigned char i,j,k,l;
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;
}
else
NewFreTab[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是對中斷延時的補償
//音樂彩燈的閃爍
k=l;
k=Temp_T%8;
if(k==l) k=k+2;
P0=led[k];

}
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;
else
LDiv1=LDiv*SOUND_SPACE;
else
LDiv1=LDiv/2; //算出頓音的演奏長度
else
LDiv1=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=1;
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 = 1;
}
//**************************************************************************
void delay() //為了顯示的延遲
{
unsigned int j;
// for (i=0;i<50;i++)
for (j=0;j<30;j++);
}

void main()
{
IT0=1; IT1=1; //外部中斷下降沿觸發
EX0=1;EX1=1;
EA=1; //開總中斷

InitialSound();
Play(Music_birth,4,2,300);
}

⑸ 怎麼把歌曲用單片機C語言程序進行播放,急急急急~~~~~~

#include <reg51.h> //包括一個51標准內核的頭文件
#define uchar unsigned char //定義一下方便使用
#define uint unsigned int

sbit BEEP=P3^6; //喇叭輸出腳
uchar th0_f; //在中斷中裝載的T0的值高8位
uchar tl0_f; //在中斷中裝載的T0的值低8位

/***************** 延時 1ms *******************/
void delay_1ms(unsigned int t)
{
unsigned char i,j;
for(t;t>0;t--)
{
for(i=34;i>0;i--)
for(j=13;j>0;j--);
}
}

//T0的值,及輸出頻率對照表
static code freq[36][2] = {
0xA9,0xEF, //00220HZ ,1 //0
0x93,0xF0, //00233HZ ,1# //1
0x73,0xF1, //00247HZ ,2 //2
0x49,0xF2, //00262HZ ,2# //3
0x07,0xF3, //00277HZ ,3 //4
0xC8,0xF3, //00294HZ ,4 //5
0x73,0xF4, //00311HZ ,4# //6
0x1E,0xF5, //00330HZ ,5 //7
0xB6,0xF5, //00349HZ ,5# //8
0x4C,0xF6, //00370HZ ,6 //9
0xD7,0xF6, //00392HZ ,6# //10
0x5A,0xF7, //00415HZ ,7 //11
0xD8,0xF7, //00440HZ 1 //12
0x4D,0xF8, //00466HZ 1# //13
0xBD,0xF8, //00494HZ 2 //14
0x24,0xF9, //00523HZ 2# //15
0x87,0xF9, //00554HZ 3 //16
0xE4,0xF9, //00587HZ 4 //17
0x3D,0xFA, //00622HZ 4# //18
0x90,0xFA, //00659HZ 5 //19
0xDE,0xFA, //00698HZ 5# //20
0x29,0xFB, //00740HZ 6 //21
0x6F,0xFB, //00784HZ 6# //22
0xB1,0xFB, //00831HZ 7 //23
0xEF,0xFB, //00880HZ `1 //24
0x2A,0xFC, //00932HZ `1# //25
0x62,0xFC, //00988HZ `2 //26
0x95,0xFC, //01046HZ `2# //27
0xC7,0xFC, //01109HZ `3 //28
0xF6,0xFC, //01175HZ `4 //29
0x22,0xFD, //01244HZ `4# //30
0x4B,0xFD, //01318HZ `5 //31
0x73,0xFD, //01397HZ `5# //32
0x98,0xFD, //01480HZ `6 //33
0xBB,0xFD, //01568HZ `6# //34
0xDC,0xFD, //01661HZ `7 //35
};

static code music1[464] = { // 《隱形的翅膀》
36,36,36,36,36,36,36,36,36,36,36,36,8,8,12,12, //每一
16,16,16,16,16,16,19,19,16,16,16,16,14,14,12,12, //次都在徘徊
12,12,12,12,12,12,9,9,8,8,8,36,9,9,12,12, //孤單中堅強 每一
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //次就算很受傷
19,19,16,16,14,14,12,12,14,14,14,36,21,21,19,19, //也不閃淚光 我知
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //道我一直有雙
16,16,14,14,12,12,14,14,9,9,9,36,8,8,9,9, //隱形的翅膀 帶我
12,12,12,12,12,12,16,16,14,14,14,14,16,14,14,14, //飛 飛過絕
12,12,12,12,12,12,12,12,12,12,12,36,8,8,12,12, //望 不去
16,16,16,16,16,16,19,19,16,16,16,16,14,14,12,12, //想他們擁有
12,12,12,12,12,12,9,9,8,8,8,36,8,8,12,12, //美麗的太陽 我看
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //見每天的夕陽
19,19,16,16,14,14,12,12,14,14,14,36,21,21,19,19, //也會有變化 我知
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //道我一直有雙
16,16,14,14,12,12,14,14,9,9,9,36,8,8,9,9, //隱形的翅膀 帶我
12,12,12,12,12,12,14,16,14,14,14,14,16,16,12,12, //飛 給我希
12,12,12,12,12,12,12,12,12,12,12,36,16,16,19,19, //望 我終
24,24,24,24,24,36,24,24,24,24,24,24,21,21,19,19, //於看到所有
21,21,24,24,16,16,14,14,12,12,12,36,12,12,12,12, //夢想都開花 追逐
12,12,24,24,24,24,21,21,19,19,16,16,14,14,12,12, //的年輕歌聲多嘹
14,14,14,14,14,14,14,14,14,14,14,36,16,16,19,19, //亮 我終
24,24,24,24,24,36,24,24,24,24,24,24,21,21,19,19, //於翱翔用心
21,21,24,24,16,16,14,14,12,12,12,36,12,12,12,12, //凝望不害怕 哪裡
12,12,24,24,24,24,21,21,19,19,16,16,14,14,12,12, //會有風就飛多遠
12,12,12,12,12,12,12,12,12,12,36,36,16,16,19,19, //吧 隱形
24,24,24,24,24,36,24,24,23,23,23,23,21,21,19,19, //的翅膀讓夢
21,21,24,24,16,16,14,14,12,12,12,36,12,12,12,12, //恆久比天長 留一
12,12,24,24,24,24,21,21,19,19,16,16,14,14,14,14, //個願望讓自己
14,14,14,14,12,12,12,12,12,12,12,12,12,12,12,36, //想像... ...
};

static code music2[336] = { // 《北京歡迎你》
16,16,19,19,16,16,14,14,16,16,14,14,16,16,16,36, //迎接另一個晨曦
16,16,14,14,9,9,12,12,16,16,14,14,14,14,14,36, //帶來全新空氣
14,14,12,12,9,9,12,12,14,14,16,16,19,19,14,14, //氣息改變情味不變
16,16,21,21,19,19,9,9,14,14,12,12,12,12,12,36, //茶香飄滿情誼
16,16,19,19,16,16,14,14,16,16,14,14,16,16,16,36, //我家大門常打開
16,16,14,14,9,9,12,12,16,16,14,14,14,14,14,36, //開放懷抱等你
14,14,12,12,9,9,12,12,14,14,16,16,19,19,14,14, //擁抱過就有了默契
16,16,21,21,19,19,9,9,14,14,12,12,12,12,12,36, //你會愛上這里
14,14,12,12,9,9,12,12,14,14,16,16,19,19,14,14, //不管遠近都是客人
16,16,21,21,19,19,19,19,16,16,16,16,16,16,16,36, //請不用客氣
14,14,16,16,14,14,12,12,19,19,21,21,14,14,14,36, //相約好了在一起
9,9,16,16,14,14,14,14,12,12,12,12,12,12,12,36, //我們歡迎你
36,36,36,36,36,36,36,36,16,16,16,16,19,19,19,19, //北京
24,24,19,19,21,21,21,21,36,36,21,21,19,19,16,16, //歡迎你 為你開
16,16,19,19,19,19,19,19,19,19,19,36,16,16,19,19, //天闢地 流動
21,21,24,24,26,26,24,24,19,19,16,16,14,14,19,19, //中的魅力充滿著朝
16,16,16,16,16,16,16,16,16,16,16,36,16,16,19,19, //氣 北京
24,24,19,19,21,21,21,21,36,36,24,24,26,26,24,24, //歡迎你 在太陽
19,19,16,16,19,19,23,23,21,21,21,21,36,36,16,16, //下分享呼吸 在
14,14,16,16,19,19,28,28,26,26,26,26,26,26,23,23, //黃土地刷新成
24,24,24,24,24,24,24,24,24,24,24,24,24,24,36,36, //績
};

static code music3[444] = { // 《仙劍奇俠傳》
28,28,26,26,28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
28,28,28,28,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,24,24,23,23,21,21,21,21,21,21,21,21,
21,21,21,21,28,28,26,26,36,36,36,36,28,28,26,26,
21,21,21,21,24,24,26,26,28,28,28,28,28,28,28,28,
28,28,31,31,28,28,24,24,26,26,26,26,26,26,26,26,
21,21,21,21,24,24,28,28,26,26,26,26,24,24,24,24,
21,21,21,21,21,21,21,21,21,21,21,21,36,36,36,36,
28,28,26,26,28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
28,28,28,28,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,28,24,23,23,21,21,21,21,21,21,21,21,
21,21,21,21,28,28,26,26,36,36,36,36,28,28,26,26,
28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
16,16,16,16,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,28,24,23,23,21,21,21,21,21,21,21,21,
21,21,21,21,23,23,23,23,23,23,23,23,23,23,23,23,
21,21,21,21,24,24,26,26,28,28,28,28,28,28,28,28,
31,33,31,31,28,28,24,24,26,26,26,26,26,26,26,26,
21,21,21,21,24,24,28,28,26,26,26,26,24,24,24,24,
21,21,21,21,21,21,21,21,21,21,21,21,36,36,36,36,
28,28,26,26,28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
28,28,28,28,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,28,24,23,23,21,21,21,21,21,21,21,21,
23,23,23,23,23,23,23,23,23,23,23,23,21,21,19,19,
21,21,21,21,21,21,21,21,36,36,36,36,36,36,36,36,
};

static code music4[448] = { // 《笑傲江湖》
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,16,16,19,19,21,21,16,16,16,16,16,16,16,36,
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,16,16,19,19,21,19,16,16,16,16,36,16,16,14,
12,12,12,12,14,14,16,16,14,14,14,14,14,14,14,12,
9,9,9,12,14,14,16,16,19,19,19,21,19,19,16,14,
12,12,12,14,14,14,16,16,14,14,14,14,14,12,12,12,
9,9,9,12,14,16,16,19,21,21,21,21,21,21,21,36,
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,16,16,19,19,21,19,16,16,16,16,16,16,16,36,
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,14,16,19,19,21,19,16,16,16,16,36,16,16,14,
12,12,12,12,14,14,16,16,14,14,14,14,14,14,14,12,
9,9,9,12,14,14,16,16,19,19,19,21,19,19,16,14,
12,12,12,14,14,14,16,16,14,14,14,14,14,12,12,12,
9,9,9,12,14,16,16,19,21,21,21,21,21,21,21,36,
14,14,14,14,14,16,16,14,12,12,12,12,12,9,9,12,
14,14,14,14,14,16,16,14,12,12,9,9,36,12,9,12,
14,14,14,14,14,16,16,14,12,12,12,12,36,12,9,12,
14,14,14,14,14,19,19,16,16,16,16,16,16,16,16,36,
9,9,9,9,36,9,9,9,14,14,14,14,14,14,16,14,
12,12,12,12,36,12,12,14,9,9,9,9,9,9,7,7,
9,9,9,9,36,9,7,7,4,4,4,4,36,4,7,7,
2,2,2,2,36,2,2,2,4,4,4,4,4,4,4,36,
9,9,9,9,9,9,9,9,14,14,14,14,14,14,16,16,
12,12,12,12,12,12,14,14,9,9,9,9,12,9,
7,7,7,7,7,7,9,9,4,4,4,2,4,4,7,7,
9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
};

//定時中斷0,用於產生唱歌頻率
timer0() interrupt 1
{
TL0=tl0_f;TH0=th0_f; //調入預定時值
BEEP=~BEEP; //取反音樂輸出IO
P2=~P2;
}

//音階聲音自動輸出試驗
void main(void) // 主程序
{
uint i;
TMOD = 0x01; //使用定時器0的16位工作模式
TR0 = 1;
ET0 = 1;
EA = 1;
while(1)
{
for(i=0;i<336;i++) //播放音樂
{
if(music2[i] == 36) //空音
{
TR0 = 0;
delay_1ms(190);
TR0 = 1;
}
else
{
tl0_f=freq[music2[i]][0]; //置一個音符的值
th0_f=freq[music2[i]][1];
delay_1ms(190);
}
}
TR0 = 0;
delay_1ms(3000);
TR0 = 1;
}
}

⑹ 求助「基於stc51單片機的生日快樂歌」

其實很容易的呢。
找一個單片機最小系統板或者開發板,然後接好蜂鳴器電路。
在網上找一個蜂鳴器奏樂的常式,改好I/O,就可以奏樂了。
再找一個蜂鳴器走也的輔助軟體,輸入生日歌的簡譜,就可以奏生日歌了。

閱讀全文

與51單片機生日歌流程圖相關的資料

熱點內容
怎麼設置個性化文件夾圖標 瀏覽:388
基金投資與入門技巧pdf 瀏覽:891
十六進制文件反編譯成c語言 瀏覽:579
程序員手術裸辭 瀏覽:251
編譯生成錯誤是什麼原因 瀏覽:965
我命令你停下用英語怎麼說 瀏覽:75
rtk文件夾不正確怎麼辦 瀏覽:926
java方法簽名 瀏覽:83
java程序員加薪申請書 瀏覽:600
女孩子如何嫁給程序員 瀏覽:657
安卓的動畫響應為什麼卡 瀏覽:835
怎麼把axure放到伺服器上 瀏覽:847
元柱體的鋼材理論重量的便捷演算法 瀏覽:467
地平線4如何加密 瀏覽:277
淘寶游戲解壓神器 瀏覽:706
androidurl視頻 瀏覽:842
app什麼播放器好 瀏覽:13
網路機頂盒伺服器地址 瀏覽:568
程序員常用軟體下載網站 瀏覽:441
美顏照app哪個好用 瀏覽:287