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

📄 mp3_player.lst

📁 mp3c程序源码
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   MP3_PLAYER                                                            11/18/2005 21:31:23 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE MP3_PLAYER
OBJECT MODULE PLACED IN MP3_PLAYER.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE MP3_PLAYER.C LARGE BROWSE

line level    source

   1          /*  Copyright (C) 1996-2005 Brilliant Ideal Electronics. All rights reserved.
   2                  MP3_Player+USB_Disk V3.0 Edit by JMBIE STUDIO 2005.07
   3          */
   4          
   5          
   6          #include "AT89C51SND1_REG.H"
   7          #include "MP3_PLAYER.H"
   8          #include "UDISK_DEF.H"
   9          #include "FILE_SYS.H"
  10          #include "MCU_UART.H"
  11          #include "LCD.H"
  12          
  13          
  14          
  15          int RDCOUNT = 0;
  16          unsigned char data MP3_Framehead[4]; 
  17          
  18          unsigned char SONG[88];  //Not more than 8 songs
  19          unsigned char data CurrentFun = SELECTSONG;
  20          unsigned char data PlayState = STOP;
  21          unsigned char data NowPlaying = 0;
  22          unsigned char data NumofSong = 0;
  23          unsigned char data MP3InitFlag= 1;
  24          unsigned char data ChangeSong = 0; 
  25          
  26          unsigned char data KeyState = 0,KeyState1 = 0; 
  27          
  28          
  29          
  30          static void PllInit(void);
  31          static void MP3Init(void);
  32          static void AudioInit();
  33          
  34          
  35          
  36          void MP3FsInit(unsigned char NDIV, unsigned int RDIV, unsigned char MPCD, unsigned char AUCD)
  37          {
  38   1              PLLNDIV = 0;
  39   1              PLLRDIV = 0;
  40   1              MP3CLK = 0;
  41   1              AUDCLK = 0;
  42   1      //PLLclk=(OSCclk*(RDIV+1))/(int)(NDIV+1)
  43   1              PLLNDIV = 0x7f&NDIV;           //set NDIV                  
  44   1              PLLCON  |= (0x3&RDIV) << 6;    //set RDIV                  
  45   1              PLLRDIV = (0x3ff&RDIV) >> 2;   
  46   1      
  47   1      //MP3CLK=PLLCLK/(int)(MPCD+1)
  48   1              MP3CLK |= MPCD;
  49   1      
  50   1      //AUDCLK=PLLCLK/(int)(AUCD+1)
  51   1              AUDCLK  |= AUCD;             
  52   1      
  53   1      }
  54          
  55          void PllInit(void)
C51 COMPILER V7.50   MP3_PLAYER                                                            11/18/2005 21:31:23 PAGE 2   

  56          {
  57   1              CKCON |= X2;
  58   1              PLLCON &= (~PLLRES);                             //Enable PLL
  59   1              PLLCON |= PLLEN;
  60   1      }
  61          
  62          void MP3Init(void)
  63          {
  64   1              MP3VOR = 0x0a;
  65   1              MP3VOL = 0x0a;
  66   1              MP3BAS = 0x10;
  67   1              MP3MED = 0x10;
  68   1              MP3TRE = 0x10;
  69   1      
  70   1              MP3CON &= (~MSKREQ);                              //Clear to allow the 
  71   1                                                                //MPREQ flag to generate a MP3 interrupt.
  72   1              MP3CON |= MPEN;                                   //enable the MP3 decoder.
  73   1      }
  74          
  75          void AudioInit()
  76          {       
  77   1          unsigned char i = 10;
  78   1              AUDCON0 = 0x85;                                    //0111 0110
  79   1              AUDCON1 &= (~0xB0);                                //SRC=0,MSREQ=0,MUDRN=0
  80   1              AUDCON1 |= 0x01;
  81   1              while (i)i--;
  82   1              AUDCON1 |= 0x40;
  83   1      }
  84          
  85          
  86          //For PCM1770============================
  87          
  88          void SendBytePCM(unsigned char byte)
  89          {
  90   1              char i=8;
  91   1              while(i--)
  92   1              {       
  93   2                      (byte&0x80)?(PCM_MD=1):(PCM_MD=0);
  94   2                      byte <<= 1;
  95   2                      PCM_MC = 1;
  96   2                      PCM_MC = 0; 
  97   2              }
  98   1      }
  99          void PCM1770_Init()
 100          {
 101   1              unsigned char data i,j=8;
 102   1              PCM_MC = 0;
 103   1              PCM_MS = 1;
 104   1              PCM_MD = 0;
 105   1              
 106   1              while(j--)       //delay more than 1ms
 107   1                      { i=250;
 108   2                        while(i--); 
 109   2                       }
 110   1              PCM_PD = 1;
 111   1              i=100;
 112   1              while(i--);      //delay 60us
 113   1      
 114   1              PCM_MS = 0;
 115   1              SendBytePCM(0x01);
 116   1              SendBytePCM(0x3f);        //Max volume
 117   1              SendBytePCM(0x02);      
C51 COMPILER V7.50   MP3_PLAYER                                                            11/18/2005 21:31:23 PAGE 3   

 118   1              SendBytePCM(0x3f);        //Max volume
 119   1              SendBytePCM(0x03);
 120   1              SendBytePCM(0x84);        //384Fs,LSB-16bit
 121   1              SendBytePCM(0x04);
 122   1              SendBytePCM(0x00);
 123   1              PCM_MS = 1;
 124   1      }
 125          
 126          
 127          //For PCM1770=========================================
 128          
 129          
 130          void MP3_Init(void)
 131          {
 132   1              PllInit();
 133   1              MP3Init();
 134   1              AudioInit();
 135   1              PCM1770_Init();
 136   1      }
 137          
 138          char PlayInit(unsigned char *SongName)
 139          {
 140   1                      int i = 0, j = 0, f = 0;
 141   1                      int k = 0;
 142   1                      unsigned int total_size;
 143   1                      DataRead = 0;
 144   1                      RDCOUNT = ReadSector(SongName, Page_Buf);      //Read 512 Bytes at first
 145   1              if(RDCOUNT==0) 
 146   1                         return 0;
 147   1      /*              when the first 3 bytes are 49 44 33 the next can be 03,this means ID3 V2.3  */
 148   1                              if (Page_Buf[0] == 0x49)
 149   1                                      if ((Page_Buf[1] == 0x44) && (Page_Buf[2] == 0x33))
 150   1                                      {
 151   2      /**********              search the 7th-10th bytes,use the formular to calculate ***********/
 152   2                                              total_size = (Page_Buf[6] & 0x7F) * 0x200000 + (Page_Buf[7] & 0x7F) * 0x4000 + (Page_Buf[8] & 0x7F) *
             - 0x80 + (Page_Buf[9] & 0x7F);
 153   2      
 154   2                                              while (total_size > 512)
 155   2                                              {
 156   3                                                      ReadSector(SongName, Page_Buf);
 157   3                                                      total_size -=512;
 158   3                                              }
 159   2      
 160   2                                              i = total_size;
 161   2                                      }
 162   1      
 163   1      
 164   1                              if (Page_Buf[i] != 0xFF)         //if not 0xFF,there is not the Frame head, but extend label 
 165   1                                      i += 10;                                 //then add 10 Bytes
 166   1      
 167   1                                                                                               
 168   1                              if ((Page_Buf[i] == 0xFF) && (Page_Buf[i + 1] & 0xF0 == 0xF0))//get MP3 information from FF FX XX XX 4b
             -ytes,
 169   1                              {
 170   2                                      MP3_Framehead[0] = Page_Buf[i];
 171   2                                      MP3_Framehead[1] = Page_Buf[i + 1];
 172   2                                      MP3_Framehead[2] = Page_Buf[i + 2];
 173   2                                      MP3_Framehead[3] = Page_Buf[i + 3];
 174   2                              }
 175   1      
 176   1                              if (MP3_Framehead[1] & 0x08) 
 177   1                              {
C51 COMPILER V7.50   MP3_PLAYER                                                            11/18/2005 21:31:23 PAGE 4   

 178   2                                      switch ((MP3_Framehead[2] & 0x0C) >> 2) 
 179   2                                      {
 180   3                                              case 0x00 : MP3FsInit(24, 126, 3, 5); break;          //Fs=44.1kHz
 181   3                                              case 0x01 : MP3FsInit(124, 575, 3, 4); break;         //Fs=48kHz
 182   3                                              case 0x02 : MP3FsInit(124, 511, 3, 9); AUDCON0 = 0x76; break;//Fs=32kHz
 183   3                                              default : break;
 184   3                                      }
 185   2                              } 
 186   1                              else 
 187   1                              {
 188   2                                      switch ((MP3_Framehead[2] & 0x0C) >> 2)
 189   2                                      {
 190   3                                              case 0x00 : MP3FsInit(24, 126, 3, 11); break;         //Fs=22.05kHz
 191   3                                              case 0x01 : MP3FsInit(124, 575, 3, 9); break;         //Fs=24kHz
 192   3                                              case 0x02 : MP3FsInit(124, 511, 3, 19); AUDCON0 = 0x76; break;  //Fs=16kHz
 193   3                                              default : break;
 194   3                                      }
 195   2                              }
 196   1                                                              
 197   1                              
 198   1                              return 1; 
 199   1      }
 200          
 201          void PlayMP3(unsigned char *SongName)
 202          {
 203   1              int i =0,m =0;
 204   1      
 205   1              while (1)

⌨️ 快捷键说明

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