⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 32musb.lst

📁 基于ateml89c51为核心处理器的mp3播放器程序。
💻 LST
📖 第 1 页 / 共 4 页
字号:
 448   1      }
 449          
 450          void Reserved()
 451          {
 452   1              printuf("Undefined Interrupt Occured : %x\n", UEPINT);
 453   1      }
 454          //END OF USB DISK
 455          //---------Edit by kent-------------------------------------------------------------
 456          void MP3FsInit(unsigned char NDIV, unsigned int RDIV, unsigned char MPCD, unsigned char AUCD)
 457          {       //!!!!!!!!!!!!!!!先清零!!!!!!!!!这个问题在调试的时候碰到了很多麻烦!!!!!!!!!!!!!!!!!!
 458   1              //例如先置5后置11时发现变成了0f,因为0101|1011=1111=F,因此总是不能改歌
 459   1              PLLNDIV = 0;
 460   1              PLLRDIV = 0;
 461   1              MP3CLK = 0;
 462   1              AUDCLK = 0;
 463   1      //PLL时钟的频率计算方法
 464   1              //      PLLclk=(OSCclk*(RDIV+1))/(int)(NDIV+1);
 465   1              //set PLL CLK
 466   1              PLLNDIV = 0x7f&NDIV;//set NDIV
 467   1              PLLCON  |= (0x3&RDIV) << 6;//set RDIV
 468   1              PLLRDIV = (0x3ff&RDIV) >> 2;
 469   1      //MP3时钟频率的计算方法
 470   1              //MP3CLK=PLLCLK/(int)(MPCD+1)负反馈
 471   1              MP3CLK |= MPCD;//0000 0010 MPCD=2
 472   1                          //必须通过计算得到最小 MP3CLK 24M
 473   1                                       
 474   1      //AUDCLK计算公式
 475   1              //AUDCLK=PLLCLK/(int)(AUCD+1)负反馈
 476   1              AUDCLK  |= AUCD;        //AUCD=4   必须通过计算得到 AUDCLK=12.288MHz              1a
 477   1      
 478   1      }
 479          
 480          void MP3Disable(void)
 481          {       PLLCON |= PLLRES;
 482   1              PLLCON &= (~PLLEN);
 483   1              MP3CON |= MSKREQ;
 484   1              MP3CON &= (~MPEN);
 485   1              AUDCON1 |= 0x20;
 486   1              AUDCON1 &= (~0x40);
 487   1              AUDCON1 &= (~0x01);
 488   1              AUDCON0 = 0x08;
 489   1              AUDCON1 = 0xB2;
C51 COMPILER V7.07   32MUSB                                                                11/26/2006 21:07:28 PAGE 9   

 490   1              AUDDAT = 0xFF;
 491   1      }
 492          //<<<------------------------by frank----------------------------------------------------
 493          
 494          
 495          /***Edit by kent***********************************************************/
 496          void PllInit(void)
 497          {
 498   1              if (FirstStart)
 499   1              {
 500   2                      AUXR1 = 0xf2;   //这两个寄存器的值在用Start Application和直接上电时不一样,前一种情况下MP3解码器才工作,
 501   2                      PLLCON = 0;     //这里强制将其置为与用Start Application按钮时一致
 502   2                      FirstStart = 0;
 503   2              }
 504   1              //锁相环时钟及MP3解码器时钟设置
 505   1              CKCON |= X2;            //0000 0001使能X2模式,增加处理速度,每个机器周期变成6个振荡周期即3个时钟周期
 506   1      
 507   1              PLLCON &= (~PLLRES);//Enable PLL
 508   1              PLLCON |= PLLEN;
 509   1      }
 510          
 511          void MP3Init(void)
 512          {
 513   1              
 514   1              //MP3音量及音效初始值
 515   1              MP3VOR = 0x0f;//0000 1111下同
 516   1              MP3VOL = 0x0f;
 517   1              MP3BAS = 0x0f;
 518   1              MP3MED = 0x0f;
 519   1              MP3TRE = 0x0f;
 520   1      
 521   1              //MP3CON自动上电为0011 1111
 522   1              MP3CON &= (~MSKREQ);    //允许产生MP3中断Clear to allow the MPREQ flag to generate a MP3 interrupt.
 523   1              MP3CON |= MPEN; //使能MP3解码器Set to enable the MP3 decoder.
 524   1      }
 525          
 526          void AudioInit()
 527          {       unsigned char i = 10;
 528   1      //音频解码器模式及时钟设置
 529   1              AUDCON0 = 0x77;//0111 0110
 530   1              //AUDCON1 = 0x41;//0100 0111
 531   1              AUDCON1 &= (~0xB0);//SRC=0,MSREQ=0,MUDRN=0
 532   1              AUDCON1 |= 0x01;
 533   1              while (i)i--;
 534   1              AUDCON1 |= 0x40;
 535   1      }
 536          
 537          void Init(void)
 538          {
 539   1              PllInit();
 540   1              MP3Init();
 541   1              AudioInit();
 542   1      }
 543          /*****Write by kent***************************************************************************************
             -/
 544          /*PlayInit()函数用来预检MP3歌曲的帧头并作相应的配置*/
 545          void PlayInit(unsigned char *SongName)
 546          {
 547   1                      int i = 0, j = 0, f = 0;
 548   1                      int k = 0;
 549   1                      unsigned int total_size;
 550   1                      //MP3Init();
C51 COMPILER V7.07   32MUSB                                                                11/26/2006 21:07:28 PAGE 10  

 551   1                      //分析MP3信息,可能会比较长,但是没有别的办法
 552   1                      //先要读出一部分文件内容,大小不能确定
 553   1                      //while(){
 554   1                      m = ReadSector(SongName, Page_Buf);//先读出512字节
 555   1                      ////for(k=0;k<64;k++)printuf("%x  ",Page_Buf[k]);
 556   1                      //when the first 3 bytes are 49 44 33 the next can be 03,this means ID3 V2.3
 557   1                              if (Page_Buf[0] == 0x49)
 558   1                                      if ((Page_Buf[1] == 0x44) && (Page_Buf[2] == 0x33))
 559   1                                      {
 560   2                                              //search the 7th-10th bytes,use the formular to calculate
 561   2                                              /*计算公式
 562   2                                              int total_size;
 563   2                                              total_size = (Size[0]&0x7F)*0x200000 +(Size[1]&0x7F)*0x4000 +(Size[2]&0x7F)*0x80 +(Size[3]&0x7F)
 564   2                                              */      
 565   2                                              total_size = (Page_Buf[6] & 0x7F) * 0x200000 + (Page_Buf[7] & 0x7F) * 0x4000 + (Page_Buf[8] & 0x7F) *
             - 0x80 + (Page_Buf[9] & 0x7F);
 566   2      
 567   2                                              while (total_size > 512)
 568   2                                              {
 569   3                                                      ReadSector(SongName, Page_Buf);
 570   3                                                      total_size -=512;
 571   3                                              }
 572   2      
 573   2                                              i = total_size;
 574   2                                              printuf("%x", total_size >> 8);
 575   2                                              printuf("%x\n", total_size & 0xFF);
 576   2                                              }
 577   1                              //else continue;
 578   1                              
 579   1                              //search whether the next 1.5bytes are 0xFFF,
 580   1                              //如果接下来是FFF则为MP3帧头,如果不是则为扩展标签头,需要加10个字节的量
 581   1                              if (Page_Buf[i] != 0xFF)
 582   1                                      i += 10;
 583   1                              //for(k=i;k<i+4;k++)printuf("%x  ",Page_Buf[k]);
 584   1                              //get MP3 information from FF FX XX XX 4bytes,and show that
 585   1                              if ((Page_Buf[i] == 0xFF) && (Page_Buf[i + 1] & 0xF0 == 0xF0))
 586   1                              {
 587   2                                      MP3_Framehead[0] = Page_Buf[i];
 588   2                                      MP3_Framehead[1] = Page_Buf[i + 1];
 589   2                                      MP3_Framehead[2] = Page_Buf[i + 2];
 590   2                                      MP3_Framehead[3] = Page_Buf[i + 3];
 591   2                              }
 592   1                                              //printu("The MP3 Framehead Bytes:");
 593   1                              printuf("%x", MP3_Framehead[0]);
 594   1                              printuf("%x", MP3_Framehead[1]);
 595   1                              printuf("%x", MP3_Framehead[2]);
 596   1                              printuf("%x\n", MP3_Framehead[3]);
 597   1                              //MP3初始化;
 598   1      
 599   1                              if (MP3_Framehead[1] & 0x08) 
 600   1                              {//MP3Disable();//MPEG I
 601   2                                      Init();
 602   2                                      switch ((MP3_Framehead[2] & 0x0C) >> 2) 
 603   2                                      {
 604   3                                              case 0x00 : MP3FsInit(24, 126, 3, 5); break;//Fs=44.1kHz
 605   3                                              case 0x01 : MP3FsInit(124, 575, 3, 4); break;//Fs=48kHz
 606   3                                              case 0x02 : MP3FsInit(124, 511, 3, 9); AUDCON0 = 0x76; break;//Fs=32kHz
 607   3                                              default : break;
 608   3                                      }
 609   2                                                                                      //PLLRegister=PLLCON;
 610   2                                                                                      //MP3Register=MP3CLK;
 611   2                                                                                      //AudioRegister=AUDCLK;                                                                         
C51 COMPILER V7.07   32MUSB                                                                11/26/2006 21:07:28 PAGE 11  

 612   2                              } 
 613   1                              else 
 614   1                              {//MP3Disable();                   //MPEG II
 615   2                                      Init();
 616   2                                      switch ((MP3_Framehead[2] & 0x0C) >> 2)
 617   2                                      {
 618   3                                              case 0x00 : MP3FsInit(24, 126, 3, 5); break;//Fs=22.05kHz
 619   3                                              case 0x01 : MP3FsInit(124, 575, 3, 9); break;//Fs=24kHz
 620   3                                              case 0x02 : MP3FsInit(124, 511, 3, 19); AUDCON0 = 0x76; break;//Fs=16kHz
 621   3                                              default : break;
 622   3                                      }
 623   2                                                                                      
 624   2                                                                                      //PLLRegister=PLLCON;
 625   2                                                                                      //MP3Register=MP3CLK;
 626   2                                                                                      //AudioRegister=AUDCLK;
 627   2                              }
 628   1                              //printu("The baud rate of now playing song is:");
 629   1                              printuf("%x \n", BaudRate[1-MP3_Framehead[1] & 0x07][3-MP3_Framehead[1] & 0x06][(MP3_Framehead[2] & 0xF
             -0) >> 4-1]);
 630   1                              //printu("kbps\n");
 631   1                                                              
 632   1                              DataRead = 0;//这句一定要加上
 633   1      }
 634          //播放MP3歌曲*******write by jingxiao*********************************************************************
             -****
 635          void PlayMP3(unsigned char *SongName)
 636          {
 637   1              int i =0;
 638   1      //      while ( 1 ) {
 639   1                      
 640   1                      while (MP3STA1&MPFREQ)
 641   1                      {//MP3解码器请求数据块
 642   2                              m = ReadSector(SongName, Page_Buf);//从当前歌曲中读取512字节
 643   2                              for (i=0; i<m; i++) 
 644   2                              {
 645   3                                      while (!(MP3STA1 & MPBREQ)) 
 646   3                                      {//MP3解码器请求数据字节
 647   4                                              while (!PlayState);  //暂停播放
 648   4                                              if (ChangeSong) 
 649   4                                              {//发生选曲
 650   5                                                      DataRead = 0;
 651   5                                                      ChangeSong = 0;
 652   5                                                      return;
 653   5                                              }
 654   4                                      } 
 655   3                                      MP3DAT = Page_Buf[i]; //向MP3解码器数据寄存器送入一个数据字节
 656   3                              }
 657   2      
 658   2                              if (m < 512) 
 659   2                              {//如果从歌曲中读出的数据不足512个字节则结束本歌曲播放
 660   3                                      NowPlaying++;
 661   3                                      MP3InitFlag = 1;
 662   3                                      return;
 663   3                              }
 664   2                      }
 665   1              
 666   1      }
 667          //***************************************************************************************************
 668          
 669          void KeyBoardInit()//<<<<<------------------------change by kent-------------------------------------
 670          {
 671   1              P1 = 0x0f;      //将端口1的低四位,即键盘对应的4位置1
C51 COMPILER V7.07   32MUSB                                                                11/26/2006 21:07:28 PAGE 12  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -