功能:1MS延时子程序 -------------------------------------------------*/ void Delay_xMs(unsigned int x) { unsigned int i,j; for( i =0;i < x;i++ ) { for( j =0;j<2;j++ ); } } /*------------------------------------------------- 段曲目 功能:歌曲播放子程序i为播放哪一 -------------------------------------------------*/ void Play_Song(unsigned char i) { unsigned char Temp1,Temp2; unsigned int Addr; Count = 0; //中断计数器清0 Addr = i * 217; while(1) { if(!key1) { Delay_xMs(5); if(!key1) { kk++; if(kk>2)kk=0; } while(!key1); break; } else if(!key2) { while(!key2); break; //休止符 Delay_xMs(5); if(!key2) { flag=~flag; } } if(flag) { /* k=Addr;k++; if(k>=((i+1) * 217)) { flag=0; Addr = i * 217; } */ Temp1 = SONG[Addr++]; if (Temp1 == 0xFF) { TR0 = 0; Delay_xMs(100); } else if (Temp1 == 0x00) //歌曲结束符 { return; flag=0; } else { Temp2 = SONG[Addr++]; TR0 = 1; while(key1) { bee_Speak = ~bee_Speak; Delay_xMs(Temp1); if(Temp2 ==Count) { Count = 0; break; } } } } } }/*------------------------------------------------- 功能:按键切换歌 曲 -------------------------------------------------*/ /*unsigned char key1_sacn(void) 单键按下 //防抖 //k=0,1,2; //等待按键弹起 /*------------------------------------------------序 -------------------------------------------------*/ main() { unsigned char k; if(key1==0) //菜 { Delay_xMs(5); if(key1==0) { k++; if(k>2) k=0; } while(!key1); } return k; } */ 功能:主程 void { Time0_Init(); //定时器0中断初始化 Play_Song(kk); //播放//0改作1可播放第二首歌曲 while(1) { P2=kk; } }