51单片机《孤勇者》音谱
时间:2023-01-28 06:43:57 来源:哔哩哔哩
食用须知:
1.谱子是我自己打的,但总格式来自江科大自化协的[11-2] 蜂鸣器播放提示音&音乐_哔哩哔哩_bilibili。
2.由于单片机的生产厂家不同,有些IO口也不同,请以自己单片机的原理图为主,如果播放不出来,可以看看是不是蜂鸣器端口写错了。
(资料图)
3.代码用了模块化编程,Delay和Timer部分的代码未放出,可以自己去上述链接找一下。
主函数代码如下:
#include <REGX52.H>
#include "Delay.h"
#include "Timer0.h"
//蜂鸣器端口定义
sbit Buzzer=P2^5;
//播放速度,值为四分音符的时长(ms)
#define SPEED500
//音符与索引对应表,P:休止符,L:低音,M:中音,H:高音,下划线:升半音符号#
#define P0
#define L11
#define L1_2
#define L23
#define L2_4
#define L35
#define L46
#define L4_7
#define L58
#define L5_9
#define L610
#define L6_11
#define L712
#define M113
#define M1_14
#define M215
#define M2_16
#define M317
#define M418
#define M4_19
#define M520
#define M5_21
#define M622
#define M6_23
#define M724
#define H125
#define H1_26
#define H227
#define H2_28
#define H329
#define H430
#define H4_31
#define H532
#define H5_33
#define H634
#define H6_35
#define H736
//索引与频率对照表
unsigned int FreqTable[]={
0,
63628,63731,63835,63928,64021,64103,64185,64260,64331,64400,64463,64528,
64580,64633,64684,64732,64777,64820,64860,64898,64934,64968,65000,65030,
65058,65085,65110,65134,65157,65178,65198,65217,65235,65252,65268,65283,
};
//乐谱
unsigned char code Music[]={
//音符,时值,
//1
M2, 4+4+4+4,
M2, 2,
L7, 2,
M1, 2,
L6, 2,
M2, 2,
L7, 2,
M1, 2,
L6, 2,
M2, 2,
L7, 2,
M1, 2,
L6, 2,
M2, 2,
L7, 2,
M1, 2,
L6, 2,
M2, 2,
L7, 2,
M1, 2,
L6, 2,
M2, 2,
L7, 2,
M1, 2,
L6, 2,
M2, 2,
L7, 2,
M1, 2,
L6, 2,
M2, 2,
L7, 2,
M1, 2,
L6, 2,
M2, 2,
L7, 2,
M1, 2,
L6, 2,
M2, 2,
L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
P,2,
M6,1,
M7,1,
//又循环一轮结束
H3,1,
H2,1,
H2,2,
H2,1,
H2,1,
H1,1,
H3,1,
H3,1,
H2,1,
H2,2,
H2,1,
H1,1,
H1,1,
H1,1,
M6,2,
M6,2,
H1,2,
H3,2,
M7,4,
M7,2,
M7,1,
M7,1,
M6,1,
M6,3,
M6,4+4+4,
P,2,
M6,2,
H1,2,
H3,2,
M7,4,
M7,2,
M7,1,
M7,1,
M6,1,
M6,3,
M6,4+4,
P,2,
M6,1,
M7,1,
H3,1,
H2,1,
H2,2,
H2,1,
H1,1,
H1,1,
H3,2,
H2,1,
H2,2,
H2,1,
H1,1,
H1,1,
H1,1,
M6,4+4,
P,4,
P,4,
//片尾结束
0xFF//终止标志
};
unsigned char FreqSelect,MusicSelect;
void main()
{
Timer0Init();
while(1)
{
if(Music[MusicSelect]!=0xFF)//如果不是停止标志位
{
FreqSelect=Music[MusicSelect];//选择音符对应的频率
MusicSelect++;
Delay(SPEED/4*Music[MusicSelect]);//选择音符对应的时值
MusicSelect++;
TR0=0;
Delay(5);//音符间短暂停顿
TR0=1;
}
else//如果是停止标志位
{
TR0=0;
while(1);
}
}
}
void Timer0_Routine() interrupt 1
{
if(FreqTable[FreqSelect])//如果不是休止符
{
/*取对应频率值的重装载值到定时器*/
TL0 = FreqTable[FreqSelect]%256;//设置定时初值
TH0 = FreqTable[FreqSelect]/256;//设置定时初值
Buzzer=!Buzzer;//翻转蜂鸣器IO口
}
}
参考乐谱如下:
最新文章推荐
- 51单片机《孤勇者》音谱
- 天天简讯:崇义县气象台发布霜冻蓝色预警信号【IV级/一般】【2023-01-27】
- 全球今头条!山西应县木塔景区疑似提前关门赶人,当地文旅局:正在调查
- 川A大军返城!预计这些高速车流量最大 天天快资讯
- 形容女子的性格的句子(热门562句)
- 李希凡文集:《红楼梦》人物论_关于李希凡文集:《红楼梦》人物论简述
- 主线_关于主线的基本详情介绍
- 一切都在慢慢好起来——首都医护人员春节坚守一线见闻
- 焦点速看:记者实探冬奥后首个张家口雪季:旅游市场复苏恰逢其时,冰雪产业赋能经济发展|新春走基层
- 科幻小说改编游戏《蚂蚁帝国》2024年推出 虚幻引擎5制作
X 关闭
资讯中心
2022-08-15
2022-05-20
2021-10-18
2021-10-18
X 关闭
热点资讯
-
1
杏花绽放催热“赏花经济” 吸引了大量游客前来旅游
-
2
上海籍阳性夫妻内蒙古密接、次密接者出现初筛阳性情况
-
3
内蒙古二连浩特:市民非必要不出小区、不出城
-
4
重庆一名潜逃24年的持枪抢劫嫌犯落网
-
5
销售有毒、有害食品 郭美美获刑二年六个月
-
6
陕西新增6名确诊病例1名无症状感染者 西安全面开展排查管控
-
7
《加强建设中国风湿免疫病慢病管理》倡议书:建立基层医院独立风湿科
-
8
游客因未购物遭导游辱骂?九寨沟:相关部门已介入调查
-
9
郭美美再入狱!销售有毒有害食品获刑2年6个月
-
10
2020年黄河青海流域冰川面积和储量较十年前缩减
-
11
5名“摸金校尉”落网 内蒙古警方破获一起盗掘古墓葬案