音乐播放无法循环

2019-07-15 19:28发布

当歌曲播放完之后会出现一声一声的音调。而无法继续循环播放下面是我的程序 ,希望好心人资助一下。

#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit beep=P1^5;
uchar code tzdn[]={ //同桌的你[11]
0x56,0x56,0x32,0x42,0x52,0x76,0x66,0x56,0x52,0x22,0x32,0x46,0x16,0x26,0x04,
//前奏
0x52,0x52,0x52,0x52,0x32,0x42,0x56,0x86,0x62,0x62,0x62,0x62,0x42,0x62,0x56,
0x04,
//明天你是否会想起,昨天你写的日记
0x52,0x52,0x52,0x52,0x72,0x62,0x52,0x44,0x02,0x42,0x42,0x42,0x42,0x33,0x21,
0x16,0x02,
//明天你是否还惦记,曾经最爱哭的你
0x82,0x82,0x82,0x82,0x52,0x32,0x86,0x82,0xA4,0x92,0x92,0x92,0x93,0x81,0x72,
0x66,0x02,
//谁娶了多愁善感的你,谁看了你的日记
0x72,0x72,0x72,0x72,0x72,0x82,0x96,0x54,0x02,0x72,0x72,0x82,0x92,0x82,0x72,
0x16,0x02,
//谁把你的长发盘起,谁给你做的嫁衣
0x84,0x82,0x82,0x52,0x62,0x86,0xA6,0x94,0x92,0x92,0x82,0x72,0x66,0x74,0x72,
0x72,0x72,0x82,0x96,0x56,
//啦……,啦……,啦……
0x72,0x72,0x82,0x92,0x82,0x72,0x86,0x94,0x92,0x92,0x62,0x72,0x96,0xB6,0x94,
0x92,0x92,0x82,0x72,0x66,
//啦……,啦……,啦……
0x72,0x72,0x72,0x72,0x72,0x82,0x96,0x56,0x72,0x72,0x82,0x92,0x82,0x72,0x96,
0x86,0xff
//啦……,啦……,啦……,啦……
};
//----------------------------简谱音调对应的定时器初值---------------------------
//适合11.0592M的晶振
uchar code chuzhi[]={
         0xff,0xff,//占位
         0xFC,0x8E,//中央C调1-7
         0xFC,0xED,       
         0xFD,0x43,       
         0xFD,0x6A,       
         0xFD,0xB3,       
         0xFD,0xF3,       
         0xFE,0x2D,
         0xFE,0x47,        //高八度1-7          
         0xFE,0x76,
         0xFE,0xA1,
         0xFE,0xC7,       
         0xFE,0xD9,
         0xFE,0xF9,
         0xFF,0x16
         };

void delay1ms(uint z);   //延时1毫秒
void delay(uint z);                 //延时165毫秒,十六分音符;一拍是四分音符 =4十六分音符
void songtzdn();
uchar timeh,timel,k,temp;
void main()
{
        TMOD=0x01;                                        //定时器0工作在方式1
        TH0=0;
        TL0=0;
        ET0=1;
        EA=1;
        while(1)
        {
        songtzdn();                         
        delay1ms(1000);
        }                       
}
void songtzdn()
{
        uchar pl,i=0;
        while(1)
        {
                temp=tzdn[i];
                pl=temp/16;  //pl代表频率;取高四位
               
                if(pl!=0)
       
                {
                        timeh=chuzhi[pl*2];
                        timel=chuzhi[pl*2+1];
                }
                if (pl==0xff)
                {
                        TR0=0;
                        beep=1;
                        break;
                }
        delay(temp%16);                                          //取低四位,延时节拍时长
        TR0=0;
        beep=1;
        delay1ms(10);
        TR0=1;
        i++;               
        }
}
void time0() interrupt 1
{
        TH0=timeh;
        TL0=timel;
        beep=~beep;
}
void delay1ms(uint z)
{
        uchar x,y;
        for(x=z;x>0;x--)
                 for(y=112;y>0;y--);
}
void delay(uint z)                                        //延时165MS,即十六分音符
{        uint x,y;
        for(x=z;x>0;x--)
                 for(y=19000;y>0;y--);
}






友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。