c语言曲谱_单片机c语言音乐简谱代码
51单片机曲谱编写音乐程序,我看不懂曲谱,谁能教下我!
//《世上只有妈妈好》51单片机C语言程序和音乐采灯程序
//此程序在硬件上调试通过
//本程序的单片机晶振采用11.0592MHZ
//此程序的流水灯随音乐的节拍的快慢而动
#include
sbit speaker=P2^0; //接音频放大电路,
//sbit speaker=P3^2;
sbit sw=P3^0; //电后位后,sw合上后就开始放音乐,灯开始闪动,sw断开,音乐停 止, 灯也同时停止闪动
unsigned char timer0h,timer0l,time,led=1,j=0;
unsigned char flagd=0;
//世上只有妈妈好数据表
code unsigned char sszymmh[]={ 6,2,3, 5,2,1, 3,2,2, 5,2,2, 1,3,2, 6,2,1, 5,2,1,
6,2,4, 3,2,2, 5,2,1, 6,2,1, 5,2,2, 3,2,2, 1,2,1,
6,1,1, 5,2,1, 3,2,1, 2,2,4, 2,2,3, 3,2,1, 5,2,2,
5,2,1, 6,2,1, 3,2,2, 2,2,2, 1,2,4, 5,2,3, 3,2,1,
2,2,1, 1,2,1, 6,1,1, 1,2,1, 5,1,6, 0,0,0
} ;
// 音阶频率表 高八位
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;
time=1;
sw=1;
while(time)
{
if(sw)
{P1=0;i=0;continue;}
if(j==8)
{
//led=1;
j=0;flagd=~flagd;
if(flagd)
{
led=0x80;
}
else
{
led=1;
}
}
else
{
P1=~led;
if(flagd)
{
led=led>>1;
}
else
{
led=le d<<1;
}
j++;
}
k=sszymmh[i]+7*sszymmh[i+1]-1;
timer0h=FREQH[k];
timer0l=FREQL[k];
time=sszymmh[i+2];
i=i+3;
song();
}
}
}
求一个用C语言编写的51单片机音乐程序代码。
#include
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();
}
}
}
求单片机 音乐播放的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); //播放
}
}
51单片机简谱编码
// 8键电子琴C程序 自己根据音节做个与简谱对应的表就可以了。
#include
sbit SPEAKER = P3^7;
#define KEY P1
unsigned char MUSIC;
unsigned char STH0;
unsigned char STL0;
unsigned int code tab[]={
64021,64103,64260,64400,//低音3开始
64524,64580,64684,64777,
64820,64898,64968,65030,
65058,65110,65157,65178
};
void main(void){
TMOD=0x01;
ET0=1;
EA=1;
KEY = 0xff;
while(1){
if(KEY != 0xff){
switch (~KEY){//显示的列位置
case 0x01://
MUSIC = 7;
break;//
case 0x02://
MUSIC = 6;
break;//
case 0x04://
MUSIC = 5;
break;//
case 0x08://
MUSIC = 4;
break;//
case 0x10://
MUSIC = 3;
break;//
case 0x20://
MUSIC = 2;
break;//
case 0x40://
MUSIC = 1;
break;//
case 0x80://
MUSIC = 0;
break;//
}
STH0=tab[MUSIC]/256;
STL0=tab[MUSIC]%256;
TR0=1;
}else{
SPEAKER = 1;
TR0=0;
}
}
}
void t0(void) interrupt 1 using 0{
TH0=STH0;
TL0=STL0;
SPEAKER=~SPEAKER;
}
求几首单片机经典歌曲乐谱,及蜂鸣器驱动原理和 C语言程序。
#include
sbit fmq=P2^3;
//sbit start=P3^4;
void delay(unsigned int i)
{
unsigned char j;
while(i--)
{
for(j=0;j<115;j++);
}
}
void yanzou(unsigned char pinlv,unsigned int jiepai)
{
unsigned char pl;
unsigned int jp;
if(jiepai==1) delay(250);
else if(jiepai==2) delay(500);
else
{
for(jp=0;jp<jiepai;jp++)
{
fmq=0;
for(pl=0;pl<pinlv;pl++);
fmq=1;
for(pl=0;pl<pinlv;pl++);
}
}
}
void main()
{
unsigned char i,x;
unsigned char code pinlv[]={131,110,98, 87, 73, 87, 110,98, 131,0,110,98, 87, 73, 73, 65, 98, 87,87,87,73,65,73,65,55,58,65,73,65,87,110,98,87,73,110,131,110,98,87,65,73,73,0,87,65,65,73,82,87,98,87,73,131,110,98,0,110,98,87,73,65,55,58,65,73,87,65,65};
unsigned int code jiepai[]={110,131,147,494,196,165,131,294,440,1,131,147,165,588,196,440,294,660,330,165,196,880,588,220,262,124,110,196,220,330,131,147,495,196,262,220,131,147,165,220,784,392,2,660,660,220,196,175,330,588,495,196,110,131,147,2,131,147,330,392,440,524,247,220,196,165,880,880};
i=68;
for(x=0;x<i;x++)
{
yanzou(pinlv[x],jiepai[x]);
}
}
蜂鸣器为P3^4接口
热门曲谱
- 渡情笛子曲谱
曲谱自学网今天精心准备的曲谱是《渡情笛子曲谱》,下面是详解!
竹笛 我想学 渡情 请问是买A还是B调 的笛子 我还要...
竹笛的调和...
[详情]分类:曲谱大全时间:07:36 - c调口琴曲谱
曲谱自学网今天精心准备的曲谱是《c调口琴曲谱》,下面是详解!
求c调24孔口琴简谱大全
小弟求c调24孔口琴简谱大全,邮箱:zifuchen@st...
[详情]分类:曲谱大全时间:07:36 - 徳德玛歌曲谱
曲谱自学网今天精心准备的曲谱是《徳德玛歌曲谱》,下面是详解!
德德玛歌曲
1. 草原母亲河
[详情]分类:曲谱大全时间:07:36
2. 蓝蓝的马莲花
3. 阿妈的... - 京剧青衣曲谱
曲谱自学网今天精心准备的曲谱是《京剧青衣曲谱》,下面是详解!
京剧老旦唱段曲谱 与琴谱有什么区别
两者均属旦行。旦行包括:青...
[详情]分类:曲谱大全时间:07:35 - 诺言钢琴曲谱
曲谱自学网今天精心准备的曲谱是《诺言钢琴曲谱》,下面是详解!
洛洛历险记的片尾曲诺言的钢琴简谱(最好有前奏)
偶然听见这首歌觉得...
[详情]分类:曲谱大全时间:07:34 - 流行口琴曲谱
曲谱自学网今天精心准备的曲谱是《流行口琴曲谱》,下面是详解!
适合初学者的口琴简谱,要流行音乐的
我把爱铺成蓝天 ...
[详情]分类:曲谱大全时间:07:35 - 又见山里红曲谱
曲谱自学网今天精心准备的曲谱是《又见山里红曲谱》,下面是详解!
又见山里红简谱
分类:曲谱大全时间:07:31 - 钢琴流行曲谱
曲谱自学网今天精心准备的曲谱是《钢琴流行曲谱》,下面是详解!
有没有流行歌曲的钢琴简谱
樱花草,老人与海,爱转角等。谢谢。本人急...
[详情]分类:曲谱大全时间:07:29 - 古筝乡韵曲谱
曲谱自学网今天精心准备的曲谱是《古筝乡韵曲谱》,下面是详解!
古筝 乡韵
乡韵多难?既然云裳诉是它改的,乡韵应该也很难吧,特长生...
[详情]分类:曲谱大全时间:07:27 - 初学古琴曲谱
曲谱自学网今天精心准备的曲谱是《初学古琴曲谱》,下面是详解!
请问初学者如何识古琴谱,对谱怎么弹?
减字谱:
[详情]分类:曲谱大全时间:07:27
识谱还是比... - 一生无悔曲谱
曲谱自学网今天精心准备的曲谱是《一生无悔曲谱》,下面是详解!
基督教歌曲为福音一生无悔谱
基督教歌曲为福音一生无悔谱...
...[详情]分类:曲谱大全时间:07:26 - 手机曲谱软件
曲谱自学网今天精心准备的曲谱是《手机曲谱软件》,下面是详解!
在手机上怎么制作谱子
没试过用手机做谱子,效率太低了…
[详情]分类:曲谱大全时间:07:22
建... - 渴望主题曲谱
曲谱自学网今天精心准备的曲谱是《渴望主题曲谱》,下面是详解!
渴望的简谱
《渴望》的简谱是电视剧《渴望》录制的同名主题曲...
[详情]分类:曲谱大全时间:07:22 - 乐伶曲谱在哪
曲谱自学网今天精心准备的曲谱是《乐伶曲谱在哪》,下面是详解!
天涯明月刀ol乐伶曲谱怎么获得
首先你要学会第一职业 第二行里面...
[详情]分类:曲谱大全时间:07:21 - 天刀童话曲谱
曲谱自学网今天精心准备的曲谱是《天刀童话曲谱》,下面是详解!
天涯明月刀ol文士曲谱有哪些
笛曲·水云游 由身份技能点...
[详情]分类:曲谱大全时间:07:20 - 天刀曲谱弹琴
曲谱自学网今天精心准备的曲谱是《天刀曲谱弹琴》,下面是详解!
天涯明月刀乐伶怎么弹琴给别人加BUF
1:要想加BUF,首先游戏中...
[详情]分类:曲谱大全时间:07:20 - 天竺少女曲谱
曲谱自学网今天精心准备的曲谱是《天竺少女曲谱》,下面是详解!
天竺少女的古筝谱
- 绿岛小夜曲曲谱
曲谱自学网今天精心准备的曲谱是《绿岛小夜曲曲谱》,下面是详解!
绿岛小夜曲原唱晋秦歌词和谱曲
绿岛小夜曲原唱晋秦歌词和谱曲...[详情]
分类:曲谱大全时间:07:17 - 越剧曲谱下载
曲谱自学网今天精心准备的曲谱是《越剧曲谱下载》,下面是详解!
求越剧简谱
吴凤花的《狸猫换太子》拷寇部分,三次举起无情棒的曲谱,...
[详情]分类:曲谱大全时间:07:13 - 萨克斯曲谱简谱
曲谱自学网今天精心准备的曲谱是《萨克斯曲谱简谱》,下面是详解!
学萨克斯要学五线谱还是简谱
学萨克斯必须学五线谱。
[详情]分类:曲谱大全时间:07:37
其实...