1、智能仪表课程设计与制作实训项目之二简易WAVE音乐播放器一、设计要求用单片机设计并制作一个可以播放WAVE格式的音乐播放器。要求:1.在单片机内部内置4首WAVE格式音乐;2.用4个不同按键代表播放不同的音乐,当某个音乐播放的时候,按其他音乐按键没有任何效果;3.当音乐开始播放后,按停止按键可以终止当前的音乐播放;4.在音乐播放的同时,用8个LED灯表示音乐播放的音节。二、电路原理音节显示LED电路原理可参考图1-1。图1-1 音节显示LED原理图音乐播放部分电路图可以参考图1-2。图1-2 音乐播放部分电路参考原理图按键部分电路图可以参考图1-3。图1-3 按键部分电路参考原理图核心部分原理
2、图可以参考图1-4。图1-4 核心部分原理图电路也可自行设计。三、程序的设计1.misuc_code.h。WAVE音乐文件/*Music*uchar code song15=The Fairy Tale,Coral Sea,Meet,Love Transfer;/爱情呼叫转移uchar code Love= 0x0F,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x
3、16,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x67, 0x15,0x0E, 0x15,0x03, 0x10,0x03, 0x15,0x67, 0x16,0x0E, 0x16,0x03, 0x17,0x03, 0x17,0x66, 0x0F,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x19,0x03, 0x19,0x03, 0x17,
4、0x03, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x67, 0x16,0x0E, 0x16,0x03, 0x16,0x03, 0x16,0x67, 0x15,0x0E, 0x15,0x03, 0x10,0x03, 0x16,0x66, 0x0F,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x0
5、3, 0x19,0x0D, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x03, 0x1A,0x0D, 0x1A,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x67, 0x15,0x0E, 0x15,0x03, 0x10,0x03, 0x15,0x67, 0x16,0x0E, 0x16,0x03, 0x17,0x03, 0x19,0x66, 0x0F,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x03,
6、0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x1A,0x0D, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x67, 0x16,0x0E, 0x16,0x03, 0x16,0x03, 0x16,0x67, 0x15,0x0E, 0x15,0x03, 0x10,0x03, 0x15,0x66, 0x15,0x03, 0x1F,0x03, 0x1
7、B,0x03, 0x1F,0x03, 0x1A,0x03, 0x1F,0x67, 0x1A,0x0E, 0x1A,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x0D, 0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x1A,0x67, 0x1A,0x0E, 0x1A,0x03, 0x1A,0x03, 0x1A,0x67, 0x19,0x0E, 0x19,0x03, 0x1A,0x03, 0x19,0
8、x03, 0x17,0x0D, 0x17,0x16, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x1A,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x15,0x03, 0x15,0x03, 0x15,0x03, 0x1F,0x67, 0x1F,0x0E, 0x1F,0x03, 0x1F,0x03, 0x1F,0x67, 0x1A,0x0E
9、, 0x1A,0x03, 0x1F,0x03, 0x1A,0x66, 0x19,0x0D, 0x19,0x03, 0x15,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x0D, 0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x1A,0x67, 0x1A,0x0E, 0x1A,0x03, 0
10、x1A,0x03, 0x1A,0x67, 0x19,0x0E, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x0D, 0x17,0x16, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x0D, 0x15,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x1A,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x1F,0x15, 0x1F,0x03, 0x1A,0x03, 0x1F,0x03, 0x1A
11、,0x03, 0x19,0x0D, 0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x17,0x03, 0x16,0x0D, 0x16,0x03, 0x15,0x03, 0x10,0x03, 0x15,0x03, 0x15,0x03, 0x16,0x03, 0x15,0x00, 0x15,0x0B, 0x15,0x03, 0x1F,0x03, 0x1A,0x03, 0x1F,0x03, 0x20,0x03, 0x1F,0x0D, 0x1F,0x03, 0x1F,0x03, 0x20,0x03, 0x1F,0x
12、03, 0x1A,0x03, 0x1F,0x03, 0x21,0x03, 0x20,0x0D, 0x20,0x03, 0x1F,0x03, 0x1A,0x03, 0x1F,0x03, 0x20,0x02, 0x15,0x00, 0x00,0x00 ;/遇见uchar code Meet= 0x19,0x03, 0x17,0x0D, 0x17,0x02, 0x19,0x03, 0x16,0x0D, 0x16,0x02, 0x17,0x03, 0x16,0x0D, 0x16,0x03, 0x15,0x0D, 0x15,0x01, 0x15,0x03, 0x11,0x03, 0x10,0x03, 0
13、x11,0x03, 0x15,0x03, 0x11,0x0D, 0x15,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x00, 0x19,0x03, 0x17,0x0D, 0x17,0x02, 0x19,0x03, 0x16,0x0D, 0x16,0x02, 0x17,0x03, 0x16,0x0D, 0x16,0x03, 0x15,0x0D, 0x15,0x01, 0x15,0x03, 0x11,0x03, 0x10,0x03, 0x11,0x03, 0x15,0x03, 0x11,0x0D, 0x11,0x03, 0x15,0x03, 0x15
14、,0x0D, 0x16,0x03, 0x15,0x15, 0x19,0x03, 0x17,0x0D, 0x17,0x02, 0x19,0x03, 0x16,0x0D, 0x16,0x02, 0x17,0x03, 0x16,0x0D, 0x16,0x03, 0x15,0x0D, 0x15,0x01, 0x15,0x03, 0x11,0x03, 0x10,0x03, 0x11,0x03, 0x15,0x03, 0x11,0x0D, 0x11,0x03, 0x15,0x0D, 0x15,0x03, 0x16,0x03, 0x17,0x00, 0x19,0x03, 0x17,0x0D, 0x17,0x
15、02, 0x19,0x03, 0x20,0x0D, 0x20,0x02, 0x1F,0x03, 0x1B,0x0D, 0x1B,0x03, 0x1F,0x0D, 0x1F,0x01, 0x15,0x03, 0x11,0x03, 0x10,0x03, 0x11,0x03, 0x15,0x03, 0x11,0x0D, 0x11,0x03, 0x15,0x03, 0x15,0x0D, 0x16,0x03, 0x15,0x15, 0x19,0x03, 0x1A,0x03, 0x1B,0x03, 0x1F,0x02, 0x1B,0x03, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03,
16、 0x19,0x03, 0x1A,0x0D, 0x1A,0x03, 0x19,0x0D, 0x19,0x0C, 0x19,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x18,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x03, 0x17,0x0D, 0x17,0x16, 0x19,0x03, 0x1A,0x03, 0x1B,0x03, 0x1F,0x02, 0x1B,0x03, 0x1F,0x03, 0x20,0x03, 0x1F,0x03, 0x
17、20,0x03, 0x21,0x0D, 0x21,0x03, 0x19,0x0D, 0x19,0x0C, 0x19,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x18,0x02, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x16,0x0D, 0x16,0x03, 0x15,0x03, 0x11,0x03, 0x15,0x0D, 0x15,0x01, 0x00,0x00 ;/童话uchar code tale= 0x0F,0x67, 0x19,0x03, 0x18,0x03, 0x17,0x02, 0x17,0x03, 0x18,0x
18、04, 0x17,0x0E, 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x16,0x04, 0x15,0x18, 0x15,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02, 0x1A,0x03, 0x1A,0x04, 0x19,0x0E, 0x19,0x03, 0x16,0x03, 0x16,0x03, 0x18,0x04, 0x17,0x0E, 0x17,0x15, 0x15,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02, 0x1A,0x03,
19、 0x1A,0x04, 0x19,0x0E, 0x19,0x03, 0x16,0x03, 0x16,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x16,0x04, 0x15,0x0E, 0x15,0x02, 0x16,0x03, 0x17,0x03, 0x10,0x02, 0x10,0x03, 0x15,0x03, 0x15,0x02, 0x11,0x02, 0x15,0x14, 0x16,0x03, 0x17,0x03, 0x10,0x02, 0x10,0x03, 0x15,0x03, 0x15,0x0D, 0x11,0x03, 0x
20、11,0x0D, 0x15,0x03, 0x15,0x00, 0x00,0x00 ;/珊瑚海uchar code coral= 0x15,0x03, 0x15,0x03, 0x15,0x03, 0x11,0x03, 0x10,0x03, 0x11,0x03, 0x10,0x03, 0x0F,0x0D, 0x0F,0x0C, 0x0F,0x16, 0x15,0x03, 0x15,0x03, 0x15,0x03, 0x15,0x03, 0x16,0x03, 0x16,0x03, 0x0F,0x03, 0x18,0x67, 0x17,0x0E, 0x17,0x16, 0x17,0x03, 0x19,
21、0x03, 0x19,0x67, 0x15,0x0E, 0x15,0x16, 0x15,0x03, 0x17,0x03, 0x17,0x03, 0x10,0x0D, 0x10,0x16, 0x10,0x03, 0x15,0x03, 0x16,0x16, 0x17,0x03, 0x18,0x66, 0x17,0x03, 0x16,0x15, 0x1F,0x03, 0x1F,0x03, 0x1F,0x03, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1B,0x03, 0x1A,0x03, 0x19,0x0D, 0x19,0x03, 0x0F,0x03, 0x16,0x0
22、3, 0x17,0x0D, 0x17,0x16, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x16,0x0D, 0x17,0x03, 0x17,0x16, 0x17,0x03, 0x16,0x03, 0x16,0x67, 0x17,0x0E, 0x17,0x16, 0x0F,0x03, 0x17,0x03, 0x16,0x03, 0x16,0x0E, 0x17,0x03, 0x17,0x0E, 0x17,0x16, 0x0F,0x03, 0x16,0x03, 0x17,0x66,
23、0x18,0x03, 0x19,0x66, 0x17,0x03, 0x18,0x15, 0x0F,0x03, 0x16,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x15,0x03, 0x1A,0x0E, 0x19,0x03, 0x19,0x0E, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x03, 0x20,0x03, 0x20,0x03, 0x1F,0x0D, 0x1F,0x02, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1
24、B,0x03, 0x1A,0x0E, 0x19,0x03, 0x19,0x0E, 0x19,0x16, 0x19,0x67, 0x1B,0x03, 0x1B,0x03, 0x1F,0x0D, 0x1F,0x02, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1B,0x03, 0x1A,0x0E, 0x19,0x03, 0x19,0x0E, 0x19,0x16, 0x17,0x67, 0x1A,0x03, 0x1A,0x03, 0x15,0x0D, 0x15,0x02, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x1A,0x03, 0x1A,0
25、x0C, 0x1A,0x03, 0x19,0x03, 0x19,0x02, 0x0F,0x03, 0x16,0x03, 0x16,0x03, 0x17,0x0D, 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x15,0x03, 0x1A,0x04, 0x19,0x03, 0x19,0x0E, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x03, 0x20,0x03, 0x20,0x03, 0x1F,0x0D, 0x1F,0x02, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1B,0x03
26、, 0x1A,0x0E, 0x19,0x03, 0x19,0x0E, 0x19,0x16, 0x19,0x67, 0x1B,0x03, 0x1B,0x03, 0x1F,0x0D, 0x1F,0x02, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1B,0x03, 0x1A,0x0E, 0x19,0x03, 0x19,0x0E, 0x19,0x16, 0x17,0x67, 0x1A,0x03, 0x1A,0x03, 0x15,0x0D, 0x15,0x02, 0x1A,0x03, 0x19,0x03, 0x18,0x03, 0x17,0x03, 0x17,0x0E, 0
27、x16,0x03, 0x16,0x0E, 0x16,0x02, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x16,0x03, 0x16,0x04, 0x15,0x03, 0x15,0x0E, 0x15,0x0C, 0x15,0x15, 0x00,0x00 ;/*2.soundplay.h。播放音乐#ifndef _SOUNDPLAY_H_REVISION_FIRST_#define _SOUNDPLAY_H_REVISION_FIRST_#include#include#includesfr T2MOD = 0xC9;#define SYSTEM_OSC 120000
28、00#define SOUND_SPACE 4/5 sbit BeepIO = P35;sbit esc=P13;sbit pause=P12;uint code FreTab12 = 262,277,294,311,330,349,369,392,415,440,466,494 ; uchar code SignTab7 = 0,2,4,5,7,9,11 ; uchar code LengthTab7= 1,2,4,8,16,32,64 ;uchar Sound_Temp_TH0,Sound_Temp_TL0;uchar Sound_Temp_TH1,Sound_Temp_TL1;uchar
29、 temp1=0xfe;uchar bee,change;void InitialSound(void)BeepIO = 0;Sound_Temp_TH1 = (65535-(1/1200)*SYSTEM_OSC)/256;Sound_Temp_TL1 = (65535-(1/1200)*SYSTEM_OSC)%256;TH1 = Sound_Temp_TH1;TL1 = Sound_Temp_TL1;TMOD |= 0x11;ET0 = 1;ET1 = 0;TR0 = 0;TR1 = 0;EA = 1;T2MOD = 0xfd; CP_RL2 = 0; TL2 = 0xf0; TH2 = 0
30、xd8; RCAP2L = 0xf0; RCAP2H = 0xd8; C_T2 = 0; TR2 = 1; ET2 = 1;void BeepTimer0(void) interrupt 1BeepIO = !BeepIO;TH0 = Sound_Temp_TH0; TL0 = Sound_Temp_TL0;void timer2() interrupt 5TF2=0;bee+;if(esc=0) flag=4;if(pause=0) flag=3;if(bee=100)bee=0;change+;if(change=9&change=17&change25)temp1=temp1=25&ch
31、ange32)P0=P0;if(change=32)change=0;temp1=0xfe;void Play(uchar *Sound,uchar Signature,uchar Octachord,uint Speed)uint NewFreTab12;uchar i,j;uint Point,LDiv,LDiv0,LDiv1,LDiv2,LDiv4,CurrentFre,Temp_T,SoundLength;uchar Tone,Length,SL,SH,SM,SLen,XG,FD;for(i=0;i 11)j = j-12;NewFreTabi = FreTabj*2;elseNewF
32、reTabi = FreTabj;if(Octachord = 1)NewFreTabi=2;else if(Octachord = 3)NewFreTabi=2;SoundLength = 0;while(SoundSoundLength != 0x00)SoundLength+=2;Point = 0;Tone = SoundPoint;Length = SoundPoint+1; LDiv0 = 12000/Speed;LDiv4 = LDiv0/4; LDiv4 = LDiv4-LDiv4*SOUND_SPACE; TR0 = 0;TR1 = 1;while(Point = 2; if
33、 (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;SLen=LengthTabLength%10; XG=Length/10%10; FD=Length/100;LDiv=LDiv0/SLen; if (FD=1) LDiv=LDiv+LDiv/2;if(XG!=1)if
34、(XG=0) if (SLen0;i-) while(TF1=0);TH1 = Sound_Temp_TH1;TL1 = Sound_Temp_TL1;TF1=0;if(LDiv2!=0)TR0=0; BeepIO=0;for(i=LDiv2;i0;i-) while(TF1=0);TH1 = Sound_Temp_TH1;TL1 = Sound_Temp_TL1;TF1=0;if(flag=3)EA=0;TR2=0;TR1=0;while(!pause);EA=1;TR2=1;TR1=1;flag=0;if(flag=4)flag=0;Point=SoundLength;elsePoint+
35、=2; Tone=SoundPoint;Length=SoundPoint+1;flag=0;BeepIO = 0;temp1=0xfe;P0=0xff;bee=0;change=0;TR2 = 0; ET2 = 0;EA=0;ET0=0;ET1=0;TR0=0;TR1=0;#endif3.main.c。主函数#include#include#include#include/按键检测void detect()uchar temp;temp=P1;temp=temp&0x0f;if(temp!=0x0f)switch(temp)case 0x0e:while(temp!=0x0f)temp=P1
36、;temp=temp&0x0f;if(key=0)key=4;key-;flag=1;break;case 0x0d:while(temp!=0x0f)temp=P1;temp=temp&0x0f;key+;flag=2;if(key=4)key=0;break;case 0x0b:while(temp!=0x0f)temp=P1;temp=temp&0x0f;flag=3;break;case 0x07:while(temp!=0x0f)temp=P1;temp=temp&0x0f;flag=4;break;void main()while(1)detect();InitialSound()
37、;switch(key)case 0:Play(tale,0,3,300);break;case 1:Play(coral,0,3,300);break;case 2:Play(Meet,0,3,300);break;case 3:Play(Love,0,3,340);break;四、设计与制作报告1.设计任务2.硬件电路设计及描述对硬件电路分模块进行介绍,并介绍元件选择的依据。3.软件设计流程及描述程序分模块进行介绍,要有流程图及流程图的文字说明。4.源程序代码(要有注释)5.调试过程中出现的问题及解决方法先介绍你的调试过程,再介绍调试过程中出现的问题及解决方法。6.总结包括测试结果(电路所具有的功能和现象)、硬件操作说明(各数码管的意义,各按键的功能及操作)、心得体会等内容。7.参考文献。 (注:元器件查阅参考网址:, 单片机学习资料网址: 元件库存情况查询校园网。)
版权声明:以上文章中所选用的图片及文字来源于网络以及用户投稿,由于未联系到知识产权人或未发现有关知识产权的登记,如有知识产权人并不愿意我们使用,如有侵权请立即联系:2622162128@qq.com ,我们立即下架或删除。
Copyright© 2022-2024 www.wodocx.com ,All Rights Reserved |陕ICP备19002583号-1
陕公网安备 61072602000132号 违法和不良信息举报:0916-4228922