Embedded system Fun Blog
























































Find out all the best information, libraries and circuit about the latest Embedded systems.

Saturday 7 January 2012

VS1011 MP3 Decoder Module: VS1011 Code for AT91SAM7S64 CPU

.from: http://read.pudn.com/downloads102/sourcecode/embed/416830/FAT%E6%88%90%E5%8A%9F/vs1011.c__.htm

   
  1. /************************************************************/
  2. /*       VS1011 Code for   AT91SAM7S64                      */   
  3. /*              By   pasyong                                */   
  4. /*                  2006-5                                  */   
  5. /*              Base IAR 4.30A                      */   
  6. /************************************************************/   
  7. /*-----------------------------------------------------------------------  
  8. Ó²¼þÁ¬½Ó      VS1011_CMD_CS ---------------PA8  
  9.               VS1011_DATA_CS --------------PA9  
  10.               VS1011_DATA_REQ  -----------PA10  
  11.               VS1011_DATA_REST -----------PA24  
  12. -----------------------------------------------------------------------*/   
  13. #include "ioat91sam7s64.h"   
  14. #define uchar unsigned char   
  15. #define uint unsigned int   
  16. #define VS1011_CMD_CS     ((unsigned int) 1 << 8)   
  17. #define VS1011_DATA_CS    ((unsigned int) 1 << 9)   
  18. #define VS1011_DATA_REQ   ((unsigned int) 1 << 10)   
  19. #define VS1011_DATA_REST  ((unsigned int) 1 << 24)   
  20.    
  21. void SPI_init(void)   
  22. {   
  23. *AT91C_PMC_PCER=1<<AT91C_ID_SPI ;   
  24.   //PIOÍâÉ蹦ÄÜʱÖÓʼÄÜ   
  25.    
  26. *AT91C_PIOA_PDR|=(AT91C_PA12_MISO|AT91C_PA13_MOSI|AT91C_PA14_SPCK);   
  27. //PIOʹÄÜÒý½ÅµÄÍâÉ蹦ÄÜ   
  28.    
  29. *AT91C_PIOA_ASR|=(AT91C_PA12_MISO|AT91C_PA13_MOSI|AT91C_PA14_SPCK);   
  30. //ÍâÉèA·ÖÅä¸øSPIÍâÉèA¹¦ÄÜ;   
  31.    
  32. *AT91C_SPI_CR|=AT91C_SPI_SPIEN ;   
  33. //ÔÊÐíSPI¿Ú   
  34. *AT91C_SPI_MR|=(AT91C_SPI_MSTR|AT91C_SPI_PS_FIXED|AT91C_SPI_MODFDIS|AT91C_SPI_DLYBCS);   
  35. //Ö÷»úģʽ,²»·ÖƵ,¹Ì¶¨Æ¬Ñ¡0,½ûÖ¹´íÎó¼ì²â   
  36. *AT91C_SPI_CSR=AT91C_SPI_NCPHA|AT91C_SPI_BITS_8|((unsigned int) 0xFF <<  8);   
  37.    
  38. //8λÊý¾Ý£¬´«ÊäÍê³ÉºóƬѡ±£³Ö£¬48M/255·ÖƵ£¬Îª³õʼ»¯SD¿¨   
  39. }   
  40. /*-----------------------------------------------------------------------  
  41. PORT_INITº¯Êý  
  42. -----------------------------------------------------------------------*/   
  43. void vs1011_port_init(void)   
  44. {   
  45. SPI_init();   
  46. *AT91C_PMC_PCER=1<<AT91C_ID_PIOA;   
  47.   //PIOA¹¦ÄÜʱÖÓʹÄÜ   
  48. *AT91C_PIOA_PER|=VS1011_DATA_CS |VS1011_CMD_CS|VS1011_DATA_REST|VS1011_DATA_REQ;   
  49.    //×÷ΪI/OʹÓà  
  50. *AT91C_PIOA_ODR|=VS1011_DATA_REQ;   
  51.   //ÊäÈë   
  52. *AT91C_PIOA_SODR|=VS1011_DATA_REQ;   
  53. *AT91C_PIOA_OER|=VS1011_DATA_CS |VS1011_CMD_CS|VS1011_DATA_REST;   
  54.   //Êä³ö   
  55. *AT91C_PIOA_SODR|=VS1011_DATA_CS |VS1011_CMD_CS|VS1011_DATA_REST;   
  56.   //Êä³öΪ¸ßµçƽ   
  57. }   
  58.    
  59. void Write_Byte_SPI(unsigned char data)  //SPI·¢ËÍÒ»¸ö×Ö½ÚµÄÊý¾Ý   
  60. {   
  61.    
  62.   *AT91C_SPI_TDR = data;            // ´«ËÍÊý¾Ýµ½SPI¼Ä´æÆ÷   
  63.    
  64.     while((*AT91C_SPI_SR&AT91C_SPI_TXEMPTY)==0);  // µÈ´ýÊý¾Ý´«ËÍÍê±Ï   
  65. }   
  66.    
  67. unsigned char Read_Byte_SPI(void)             //SPI¶ÁÒ»¸ö×Ö½ÚµÄÊý¾Ý   
  68. {   
  69.  *AT91C_SPI_TDR = 0xffffffff;      
  70.  while((*AT91C_SPI_SR&AT91C_SPI_TXEMPTY)==0) ;  //µÈ´ýÊý¾Ý½ÓÊÕÍê³É   
  71.  return (*AT91C_SPI_RDR&0xff);   
  72.    
  73. }   
  74.    
  75. void vs1011_cmd_write(uchar address,uint data)   
  76. {   
  77. *AT91C_PIOA_CODR|=VS1011_DATA_CS;       //MP3_DATA_CS=1;   
  78. *AT91C_PIOA_CODR|=VS1011_CMD_CS;        //MP3_CMD_CS=0;   
  79. Write_Byte_SPI(0x02);                   //VS1011µÄдÃüÁî   
  80.    
  81. Write_Byte_SPI(address);                 //µØÖ·   
  82. Write_Byte_SPI(data>>8);   
  83. Write_Byte_SPI(data);   
  84.    
  85. *AT91C_PIOA_SODR|=VS1011_CMD_CS;       //MP3_CMD_CS=1;   
  86. }   
  87.    
  88. void vs1011_data_write(uchar data)   
  89. {   
  90. *AT91C_PIOA_CODR|=VS1011_DATA_CS;         //MP3_DATA_CS=0;   
  91. Write_Byte_SPI(data);   
  92. *AT91C_PIOA_SODR|=VS1011_DATA_CS;         //MP3_DATA_CS=1;   
  93. *AT91C_PIOA_SODR|=VS1011_CMD_CS;         //MP3_CMD_CS=1;   
  94. }   
  95.    
  96. uint vs1011_read(uchar address)   
  97. {   
  98. uchar temp1=0;   
  99. uint temp=0;   
  100. *AT91C_PIOA_SODR|=VS1011_DATA_CS;        //MP3_DATA_CS=1;   
  101. *AT91C_PIOA_CODR|=VS1011_CMD_CS;        //MP3_CMD_CS=0;   
  102. Write_Byte_SPI(0x03);                   //VS1011µÄ¶ÁÃüÁî   
  103.    
  104. Write_Byte_SPI(address);                //µØÖ·   
  105. temp=Read_Byte_SPI();   
  106. temp=temp<<8;   
  107. temp1=Read_Byte_SPI();   
  108. temp=temp|temp1;   
  109. *AT91C_PIOA_SODR|=VS1011_CMD_CS;        //MP3_CMD_CS=1;   
  110. return temp;   
  111. }   
  112.    
  113. void vs1011_init(void)   
  114. {   
  115. vs1011_cmd_write(0x00,0x0800);           //NEW MODE   
  116. vs1011_cmd_write(0x02,0X75);              //BASS   
  117. vs1011_cmd_write(0x03,0X9800);            //CLOCK F   
  118. vs1011_cmd_write(0x0b,0X0000);             //VOLUME   
  119. }  





No comments:

Post a Comment