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

📄 mp3_player.lst

📁 基于atmel单片机的MP3设计。音质很好
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.08   MP3_PLAYER                                                            05/19/2008 19:51:05 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE MP3_PLAYER
OBJECT MODULE PLACED IN MP3_PLAYER.OBJ
COMPILER INVOKED BY: C:\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 V8.08   MP3_PLAYER                                                            05/19/2008 19:51:05 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 = 0x77;                                    //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          void MP3_Init(void)
  86          {
  87   1              PllInit();
  88   1              MP3Init();
  89   1              AudioInit();
  90   1      }
  91          
  92          char PlayInit(unsigned char *SongName)
  93          {
  94   1                      int i = 0, j = 0, f = 0;
  95   1                      int k = 0;
  96   1                      unsigned int total_size;
  97   1                      DataRead = 0;
  98   1                      RDCOUNT = ReadSector(SongName, Page_Buf);      //Read 512 Bytes at first
  99   1              if(RDCOUNT==0) 
 100   1                         return 0;
 101   1      /*              when the first 3 bytes are 49 44 33 the next can be 03,this means ID3 V2.3  */
 102   1                              if (Page_Buf[0] == 0x49)
 103   1                                      if ((Page_Buf[1] == 0x44) && (Page_Buf[2] == 0x33))
 104   1                                      {
 105   2      /**********              search the 7th-10th bytes,use the formular to calculate ***********/
 106   2                                              total_size = (Page_Buf[6] & 0x7F) * 0x200000 + (Page_Buf[7] & 0x7F) * 0x4000 + (Page_Buf[8] & 0x7F) *
             - 0x80 + (Page_Buf[9] & 0x7F);
 107   2      
 108   2                                              while (total_size > 512)
 109   2                                              {
 110   3                                                      ReadSector(SongName, Page_Buf);
 111   3                                                      total_size -=512;
 112   3                                              }
 113   2      
 114   2                                              i = total_size;
 115   2                                      }
 116   1      
C51 COMPILER V8.08   MP3_PLAYER                                                            05/19/2008 19:51:05 PAGE 3   

 117   1      
 118   1                              if (Page_Buf[i] != 0xFF)         //if not 0xFF,there is not the Frame head, but extend label 
 119   1                                      i += 10;                                 //then add 10 Bytes
 120   1      
 121   1                                                                                               
 122   1                              if ((Page_Buf[i] == 0xFF) && (Page_Buf[i + 1] & 0xF0 == 0xF0))//get MP3 information from FF FX XX XX 4b
             -ytes,
 123   1                              {
 124   2                                      MP3_Framehead[0] = Page_Buf[i];
 125   2                                      MP3_Framehead[1] = Page_Buf[i + 1];
 126   2                                      MP3_Framehead[2] = Page_Buf[i + 2];
 127   2                                      MP3_Framehead[3] = Page_Buf[i + 3];
 128   2                              }
 129   1      
 130   1                              if (MP3_Framehead[1] & 0x08) 
 131   1                              {
 132   2                                      switch ((MP3_Framehead[2] & 0x0C) >> 2) 
 133   2                                      {
 134   3                                              case 0x00 : MP3FsInit(24, 126, 3, 5); break;          //Fs=44.1kHz
 135   3                                              case 0x01 : MP3FsInit(124, 575, 3, 4); break;         //Fs=48kHz
 136   3                                              case 0x02 : MP3FsInit(124, 511, 3, 9); AUDCON0 = 0x76; break;//Fs=32kHz
 137   3                                              default : break;
 138   3                                      }
 139   2                              } 
 140   1                              else 
 141   1                              {
 142   2                                      switch ((MP3_Framehead[2] & 0x0C) >> 2)
 143   2                                      {
 144   3                                              case 0x00 : MP3FsInit(24, 126, 3, 11); break;         //Fs=22.05kHz
 145   3                                              case 0x01 : MP3FsInit(124, 575, 3, 9); break;         //Fs=24kHz
 146   3                                              case 0x02 : MP3FsInit(124, 511, 3, 19); AUDCON0 = 0x76; break;  //Fs=16kHz
 147   3                                              default : break;
 148   3                                      }
 149   2                              }
 150   1                                                              
 151   1                              
 152   1                              return 1; 
 153   1      }
 154          
 155          void PlayMP3(unsigned char *SongName)
 156          {
 157   1              int i =0,m =0;
 158   1      
 159   1              while (1)
 160   1                      {   
 161   2                              RDCOUNT = ReadSector(SongName, Page_Buf); 
 162   2                              for (i=0; i<RDCOUNT; i++) 
 163   2                              {
 164   3                                      while (!(MP3STA1 & MPBREQ)); 
 165   3                                      MP3DAT = Page_Buf[i]; 
 166   3                              }
 167   2                              
 168   2      
 169   2                      
 170   2      //////////////////////////////////////////for LCD display                                       
 171   2                              KeyState1=KeyState;             
 172   2                          do{
 173   3                                  switch(KeyState)
 174   3                                       {  case 0: break;
 175   4                                          case 1: LCD_printen(72,2,"VOLUME");break;
 176   4                                          case 2: LCD_printen(72,2,"TONE  ");break;
 177   4                                              case 3: LCD_printen(72,2,LCD_chstr);
C51 COMPILER V8.08   MP3_PLAYER                                                            05/19/2008 19:51:05 PAGE 4   

 178   4                                                              if(PlayState)
 179   4                                                                 LCD_printen(72,3,"PLAY..");
 180   4                                                                else
 181   4                                                                 LCD_printen(72,3,"STOP..");
 182   4                                                              break;

⌨️ 快捷键说明

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