C51单片机音乐程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include
sbit fmq=P3^6;
sbit start=P1^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); //1/2拍暂停,即1/2拍的0
else if(jiepai==2) delay(500); //1拍暂停,即1拍的0
else
{
for(jp=0;jp{
fmq=0;
for(pl=0;plfmq=1;
for(pl=0;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; //数组共有68个元素
if(start==0)
for(x=0;x{
yanzou(pinlv[x],jiepai[x]);
}
}

相关文档
最新文档