学曲谱,请上曲谱自学网!

单片机音乐曲谱_单片机c语言音乐简谱代码

时间:2020-11-01 08:58:00编辑:刘牛来源:曲谱自学网

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接口

单片机曲谱_51单片机简谱编码

单管巴乌独奏曲谱_求巴乌或葫芦丝独奏《牧歌》的曲谱

热门曲谱

Copyright © 2014-2019 曲谱大全(www.qpzxw.com)曲谱自学网版权所有 备案号:皖ICP备2021004734号-1

版权声明:曲谱网所有曲谱及资料均为作者提供或网友推荐收集整理而来,仅供爱好者学习和研究使用,版权归原作者所有。

联系邮箱:qupudaquanhezuo@gmail.com