收藏 分销(赏)

音乐代码.doc

上传人:w****g 文档编号:4143477 上传时间:2024-08-01 格式:DOC 页数:10 大小:69.50KB
下载 相关 举报
音乐代码.doc_第1页
第1页 / 共10页
音乐代码.doc_第2页
第2页 / 共10页
音乐代码.doc_第3页
第3页 / 共10页
音乐代码.doc_第4页
第4页 / 共10页
音乐代码.doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

1、挥着翅膀的女孩unsigned char code Music_Girl= 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x02, 0x18,0x03, 0x17,0x03, 0x15,0x02, 0x18,0x03, 0x17,0x03, 0x18,0x02, 0x10,0x03, 0x15,0x03, 0x16,0x02, 0x15,0x03

2、, 0x16,0x03, 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x1A,0x03, 0x1B,0x03, 0x1F,0x03, 0x1F,0x03, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x1F,0x03, 0x1F,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02, 0x1F,0x03, 0

3、x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03, 0x16,0x66, 0x17,0x04, 0x18,0x04, 0x18,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20

4、,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x1A,0x03, 0x1A,0x03, 0x1A,0x03, 0x1B,0x03, 0x1B,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x02, 0x17,0x03, 0x15,0x

5、17, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x04, 0x18,0x0E, 0x18,0x03, 0x17,0x04, 0x18,0x0E, 0x18,0x66, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x04, 0x1B,0x0E,

6、 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03, 0x16,0x66, 0x17,0x04, 0x18,0x04, 0x18,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03, 0x

7、19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x18,0x02, 0x18,0x03, 0x1A,0x03, 0x19,0x0D, 0x15,0x03, 0x15,0x02, 0x18,0x66, 0x16,0x02, 0x17,0x02, 0x15,0x00, 0x00,0x00;天空之城unsigned char code music_tab = 0x1c, 0x30, 0x19, 0x30, 0x18, 0x40, 0x19, 0x30,

8、0x18, 0x30, 0x13, 0x30, 0x19, 0x18,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

9、, 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,

10、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, 0x2

11、0, 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,0

12、x0e, 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,;示例#include #include /本例采用89C52, 晶振为11.0592MHZ /关于如何编制音乐代码, 其实十分简单,各位可以看以下代码. /频率常数即音乐术语中的音调,而节拍常数即音乐术语中的多少拍; /所以拿出谱子,

13、试探编吧! #define LED P0sbit Beep = P15 ; void delaya(unsigned int); unsigned char n=0; /n为节拍常数变量 unsigned char code music_tab = 0x1c, 0x30, 0x19, 0x30, 0x18, 0x40, 0x19, 0x30, 0x18, 0x30, 0x13, 0x30, 0x19, 0x18,0x26, 0x30, 0x26, 0x30, 0x1c, 0x40, 0x20, 0x30, 0x1c, 0x30, 0x18, 0x30, 0x20, 0x60,0x26, 0x3

14、0, 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,

15、 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, 0x1

16、3, 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,

17、 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, 0x3

18、0, 0x1c, 0x60, 0x1c, 0x30, 0x19, 0x30,0x1c,0xc0, 0x00,; void delaya(unsigned int x)unsigned int i;for(i=0;ix;i+); void int0() interrupt 1 /采用中断0 控制节拍 TH0=0xd8; TL0=0xef; n-; void delay (unsigned char m) /控制频率延时 unsigned i=3*m; while(-i); void delayms(unsigned char a) /豪秒延时子程序 while(-a); /采用while(-a)

19、 不要采用while(a-); 各位可编译一下看看汇编结果就知道了! void main() unsigned char p,m; /m为频率常数变量 unsigned char i=0; TMOD&=0x0f; TMOD|=0x01; TH0=0xd8;TL0=0xef; IE=0x82; play: while(1) a: p=music_tabi; if(p=0x00) i=0, delayms(1000); goto play; /如果碰到结束符,延时1秒,回到开始再来一遍 else if(p=0xff) i=i+1;delayms(100),TR0=0; goto a; /若碰到休止

20、符,延时100ms,继续取下一音符 else m=music_tabi+, n=music_tabi+; /取频率常数 和 节拍常数 TR0=1; /开定时器1 while(n!=0) Beep=Beep,delay(m); /等待节拍完成, 通过P1口输出音频(可多声道哦!) TR0=0; /关定时器1 LED=music_tabi ;delayms(100); 、#include sbit buzzer=P37; unsigned char timer0h,timer0l,time; /生日歌code unsigned char sszymmh=5,1,1, 5,1,1, 6,1,2, 5

21、,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

22、,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 t

23、1; unsigned long t2; for(t1=0;t1t;t1+) for(t2=0;t28000;t2+) ; TR0=0; void t0int() interrupt 1 TR0=0; buzzer=!buzzer; 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开中断

24、while(1) i=0; while(i75) /音乐数组长度 ,唱完从头再来 k=sszymmhi+7*sszymmhi+1-1; timer0h=FREQHk; timer0l=FREQLk; time=sszymmhi+2; i=i+3; song(); #include#define uchar unsigned char#define uint unsigned int /必不可少的定义头文件sbit BEEP=P37;uchar code SONG_TONE=212,212,190,212,159,169,212,212,190,212,142,159,212,212,106,1

25、26,159,169,190,119,119,126,159,142,159,0;/生日快乐歌的音符频率表,不同频率由不同的延时来决定uchar code SONG_LONG=9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0;/生日快乐歌节拍表,节拍决定每个音符的演奏长短void DelayMS(uint x)/延时uchar t;while(x-) for(t=0;t120;t+);void PlayMusic()/播放函数uint i=0,j,k;while(SONG_LONGi!=0|SONG_TON

26、Ei!=0)for(j=0;jSONG_LONGi*20;j+)/播放各个音符,SONG_LONG 为拍子长度BEEP=BEEP;/SONG_TONE 延时表决定了每个音符的频率for(k=0;kSONG_TONEi/3;k+);DelayMS(10);i+; void main()BEEP=0;while(1)PlayMusic(); /播放生日快乐DelayMS(500);/播放完后暂停一段时间#include#define uchar unsigned char#define uint unsigned int /必不可少的定义头文件sbit BEEP=P37;uchar code SO

27、NG_TONE=212,212,190,212,159,169,212,212,190,212,142,159,212,212,106,126,159,169,190,119,119,126,159,142,159,0;/生日快乐歌的音符频率表,不同频率由不同的延时来决定uchar code SONG_LONG=9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0;/生日快乐歌节拍表,节拍决定每个音符的演奏长短void DelayMS(uint x)/延时uchar t;while(x-) for(t=0;t1

28、20;t+);void PlayMusic()/播放函数uint i=0,j,k;while(SONG_LONGi!=0|SONG_TONEi!=0)for(j=0;jSONG_LONGi*20;j+)/播放各个音符,SONG_LONG 为拍子长度BEEP=BEEP;/SONG_TONE 延时表决定了每个音符的频率for(k=0;kSONG_TONEi/3;k+);DelayMS(10);i+; void main()BEEP=0;while(1)PlayMusic(); /播放生日快乐DelayMS(500);/播放完后暂停一段时间#include#define uchar unsigned

29、 char#define uint unsigned intsbit BEEP=P37;/生日快乐歌的音符频率表,不同频率由不同的延时来决定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,142,159,0;/生日快乐歌节拍表,节拍决定每个音符的演奏长短uchar code SONG_LONG=9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12

30、,24,0;/延时void DelayMS(uint x)uchar t;while(x-) for(t=0;t120;t+);/播放函数void PlayMusic()uint i=0,j,k;while(SONG_LONGi!=0|SONG_TONEi!=0) /播放各个音符,SONG_LONG 为拍子长度for(j=0;jSONG_LONGi*20;j+)BEEP=BEEP;/SONG_TONE 延时表决定了每个音符的频率for(k=0;kSONG_TONEi/3;k+);DelayMS(10);i+;void main()BEEP=0;while(1)PlayMusic(); /播放生日快乐DelayMS(500); /播放完后暂停一段时间

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
百度文库年卡

猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服