您好,欢迎访问三七文档
当前位置:首页 > 金融/证券 > 金融资料 > 51音乐单片机播放三首歌程序
#includereg52.h#defineucharunsignedchar#defineuintunsignedintsbitKey1=P1^0;sbitKey2=P1^1;sbitKey3=P1^2;sbitKey4=P1^3;sbitRCK=P2^0;sbitDS=P2^2;sbitCLK=P2^1;sbitSpeak=P3^6;//蜂鸣器ucharstop_flage;uchartable[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//uchartable[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};ucharCOUNT_1=0,count=0,yimiao=0,j,i;//,stop=0ucharb=0,zhi;uintTable_1[3]={0,183,401};ucharshu=1;charm=1;ucharcodeSONG[]={//路边的野花不要采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,//祝你平安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,//天空之城0x1c,0x30,0x19,0x30,0x18,0x40,0x19,0x30,0x18,0x30,0x13,0x30,0x19,0x80,0x26,0x30,0x26,0x30,0x1c,0x40,0x20,0x30,0x1c,0x30,0x18,0x30,0x20,0x60,0x26,0x30,0x26,0x30,0x24,0x40,0x26,0x30,0x24,0x30,0x18,0x40,0x26,0x60,0x18,0x20,0x18,0x20,0x18,0x20,0x19,0x40,0x24,0x30,0x24,0x30,0x19,0x30,0x19,0x60,0x1c,0x30,0x19,0x30,0x18,0x40,0x19,0x30,0x18,0x30,0x13,0x30,0x19,0x60,0x26,0x30,0x26,0x30,0x1c,0x40,0x20,0x30,0x1c,0x30,0x18,0x30,0x20,0x80,0x26,0x30,0x24,0x30,0x24,0x30,0x18,0x30,0x19,0x20,0x19,0x30,0x18,0x30,0x15,0x20,0x15,0x20,0x13,0x20,0x18,0x40,0x18,0x30,0x19,0x30,0x1c,0x20,0x1c,0x20,0x19,0x30,0x20,0x30,0x1c,0x60,0x18,0x30,0x15,0x30,0x13,0x40,0x15,0x30,0x13,0x30,0x10,0x30,0x15,0x60,0x20,0x30,0x20,0x30,0x18,0x30,0x19,0x30,0x18,0x30,0x13,0x30,0x13,0x60,0x1c,0x20,0x19,0x20,0x18,0x30,0x19,0x30,0x15,0x20,0x15,0x20,0x18,0x40,0x20,0x30,0x20,0x30,0x12,0x30,0x13,0x30,0x15,0x30,0x18,0x30,0x13,0xc0,0x13,0x80,0x13,0x30,0x0e,0x80,0x10,0x30,0x10,0x30,0x13,0x20,0x15,0x20,0x18,0x40,0x18,0x30,0x15,0x30,0x18,0x20,0x15,0x20,0x15,0x30,0x10,0x30,0x13,0x60,0x13,0x30,0x0e,0x60,0x10,0x60,0x13,0x20,0x15,0x20,0x18,0x40,0x18,0x30,0x15,0x30,0x15,0x20,0x18,0x20,0x15,0x30,0x19,0x30,0x1c,0x60,0x1c,0x30,0x19,0x30,0x1c,0xc0,0x00,};voidDelay_xMs(uintx)//1ms0x30,0x1C,0x10,0x20,0x40,0x1C,0x10,{unsignedinti,j;for(i=0;ix;i++){for(j=0;j3;j++);}}voidDelay(uintdel){uinti,j;for(i=0;idel;i++)for(j=0;j=184;j++);}voidwrit_595(ucharx){uchardat,y;dat=x;for(y=0;y8;y++){CLK=0;if((dat&0x80)==0x80)DS=1;//串行数据输出elseDS=0;CLK=1;//移位输入时钟,上升沿输入dat=1;}RCK=0;//并行输出时钟RCK=1;}voidTime0_Init(){TMOD=0x11;IE=0x8A;TH0=0xDC;//10msTL0=0x00;TH1=0x4C;//50msTL1=0x00;}voidTime0_Int()interrupt1{TH0=0xDC;TL0=0x00;COUNT_1++;}voidTime1_Int()interrupt3{TH1=0x4C;//1msTL1=0x00;count++;if(count==20){yimiao++;count=0;writ_595(table[yimiao%10]);writ_595(table[yimiao/10]);writ_595(table[m+1]);}}voidPlay_Song(uchari){ucharTemp1,Temp2;//stop=0uintAddr;COUNT_1=0;//中断计数器清0if(i==0){Addr=Table_1[--shu];}if(i==1){Addr=Table_1[shu];}if(i==2){Addr=Table_1[++shu];}while(1){Temp1=SONG[Addr++];if(Temp1==0xFF)//休止符{TR0=0;Delay_xMs(100);}elseif(Temp1==0x00)//歌曲结束符{return;//stop=1;}else{Temp2=SONG[Addr++];TR0=1;while(1){Speak=~Speak;//十位Delay_xMs(Temp1);//各位while(stop_flage){if(Key2==0){Delay_xMs(200);if(Key2==0){stop_flage=0;TR1=1;while(Key2==0);}}}if(Key2==0)//暂停{Delay_xMs(200);if(Key2==0){stop_flage=1;TR1=0;while(Key2==0);}}if(Key3==0)//上一首{Delay_xMs(200);if(Key3==0){TR1=0;Delay_xMs(250);TR1=1;m--;//m=0;if(m=0){m=0;//while(Key3==0);}yimiao=0;Addr=Table_1[--shu];while(Key3==0);}}
本文标题:51音乐单片机播放三首歌程序
链接地址:https://www.777doc.com/doc-6434025 .html