本文主要是介绍这是一个谱曲的代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
功能很简单,就是控制扬声器响的时间从而产生不同 的音节。
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit voice=P1^6;
uchar code sound[]={//0xff,0x40,0x10,0x40,0x10,0x39,0x10,0x40,0x10,0x60,0x10,0x33,0x10,0x00,// 0xff,0x40,0x20,0x40,0x20,0x48,0x20,0x40,0x20,0x60,0x20,0x33,0x20,0x00,// 0xff,0x40,0x30, 0x40,0x30, 0x39,0x30, 0x40,0x30, 0x60,0x30, 0x33,0x30,0x00,0xff,0x40,0x30,0x40,0x30,0x39,0x30,0x40,0x30,0x60,0x30,0x33,0x30,0x40,0x30,0x40,0x30,0x39,0x30,0x40,0x30,0x55,0x30,0x60,0x30,0x40,0x30,0x40,0x30,0x40,0x30,0x4c,0x30,0x60,0x30,0x33,0x30,0x39,0x30,0x48,0x30,0x48,0x30,0x4c,0x30,0x60,0x30,0x55,0x30,0x60,0x30,0x00,//《祝你生日快乐》};
uchar zdjs=0, jp;
del(yj);
void main(void){uint dpjs=0;uchar yj;TMOD=0x01,IE=0x82;TH0=0xd8, TL0=0xef;TR0=1;
while(1){ zdjs=0;dpjs++;yj=sound[dpjs]; dpjs++; jp=sound[dpjs];while(zdjs!=jp){ if(yj!=0xff){if(yj!=0){voice=!voice;del(yj);}else{dpjs=0; break;}}else{voice=0;del(jp);}}}}
time0() interrupt 1 using 1{TH0=0xd8, TL0=0xef;zdjs++;}
del(yj){uchar yj2=2;while(yj!=0){ while(yj2!=0){yj2--;}yj2=2;yj--; }}
这篇关于这是一个谱曲的代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!