.from: http://read.pudn.com/downloads102/sourcecode/embed/416830/FAT%E6%88%90%E5%8A%9F/vs1011.c__.htm
- /************************************************************/
- /* VS1011 Code for AT91SAM7S64 */
- /* By pasyong */
- /* 2006-5 */
- /* Base IAR 4.30A */
- /************************************************************/
- /*-----------------------------------------------------------------------
- Ó²¼þÁ¬½Ó VS1011_CMD_CS ---------------PA8
- VS1011_DATA_CS --------------PA9
- VS1011_DATA_REQ -----------PA10
- VS1011_DATA_REST -----------PA24
- -----------------------------------------------------------------------*/
- #include "ioat91sam7s64.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define VS1011_CMD_CS ((unsigned int) 1 << 8)
- #define VS1011_DATA_CS ((unsigned int) 1 << 9)
- #define VS1011_DATA_REQ ((unsigned int) 1 << 10)
- #define VS1011_DATA_REST ((unsigned int) 1 << 24)
- void SPI_init(void)
- {
- *AT91C_PMC_PCER=1<<AT91C_ID_SPI ;
- //PIOÍâÉ蹦ÄÜʱÖÓʼÄÜ
- *AT91C_PIOA_PDR|=(AT91C_PA12_MISO|AT91C_PA13_MOSI|AT91C_PA14_SPCK);
- //PIOʹÄÜÒý½ÅµÄÍâÉ蹦ÄÜ
- *AT91C_PIOA_ASR|=(AT91C_PA12_MISO|AT91C_PA13_MOSI|AT91C_PA14_SPCK);
- //ÍâÉèA·ÖÅä¸øSPIÍâÉèA¹¦ÄÜ;
- *AT91C_SPI_CR|=AT91C_SPI_SPIEN ;
- //ÔÊÐíSPI¿Ú
- *AT91C_SPI_MR|=(AT91C_SPI_MSTR|AT91C_SPI_PS_FIXED|AT91C_SPI_MODFDIS|AT91C_SPI_DLYBCS);
- //Ö÷»úģʽ,²»·ÖƵ,¹Ì¶¨Æ¬Ñ¡0,½ûÖ¹´íÎó¼ì²â
- *AT91C_SPI_CSR=AT91C_SPI_NCPHA|AT91C_SPI_BITS_8|((unsigned int) 0xFF << 8);
- //8λÊý¾Ý£¬´«ÊäÍê³ÉºóƬѡ±£³Ö£¬48M/255·ÖƵ£¬Îª³õʼ»¯SD¿¨
- }
- /*-----------------------------------------------------------------------
- PORT_INITº¯Êý
- -----------------------------------------------------------------------*/
- void vs1011_port_init(void)
- {
- SPI_init();
- *AT91C_PMC_PCER=1<<AT91C_ID_PIOA;
- //PIOA¹¦ÄÜʱÖÓʹÄÜ
- *AT91C_PIOA_PER|=VS1011_DATA_CS |VS1011_CMD_CS|VS1011_DATA_REST|VS1011_DATA_REQ;
- //×÷ΪI/OʹÓÃ
- *AT91C_PIOA_ODR|=VS1011_DATA_REQ;
- //ÊäÈë
- *AT91C_PIOA_SODR|=VS1011_DATA_REQ;
- *AT91C_PIOA_OER|=VS1011_DATA_CS |VS1011_CMD_CS|VS1011_DATA_REST;
- //Êä³ö
- *AT91C_PIOA_SODR|=VS1011_DATA_CS |VS1011_CMD_CS|VS1011_DATA_REST;
- //Êä³öΪ¸ßµçƽ
- }
- void Write_Byte_SPI(unsigned char data) //SPI·¢ËÍÒ»¸ö×Ö½ÚµÄÊý¾Ý
- {
- *AT91C_SPI_TDR = data; // ´«ËÍÊý¾Ýµ½SPI¼Ä´æÆ÷
- while((*AT91C_SPI_SR&AT91C_SPI_TXEMPTY)==0); // µÈ´ýÊý¾Ý´«ËÍÍê±Ï
- }
- unsigned char Read_Byte_SPI(void) //SPI¶ÁÒ»¸ö×Ö½ÚµÄÊý¾Ý
- {
- *AT91C_SPI_TDR = 0xffffffff;
- while((*AT91C_SPI_SR&AT91C_SPI_TXEMPTY)==0) ; //µÈ´ýÊý¾Ý½ÓÊÕÍê³É
- return (*AT91C_SPI_RDR&0xff);
- }
- void vs1011_cmd_write(uchar address,uint data)
- {
- *AT91C_PIOA_CODR|=VS1011_DATA_CS; //MP3_DATA_CS=1;
- *AT91C_PIOA_CODR|=VS1011_CMD_CS; //MP3_CMD_CS=0;
- Write_Byte_SPI(0x02); //VS1011µÄдÃüÁî
- Write_Byte_SPI(address); //µØÖ·
- Write_Byte_SPI(data>>8);
- Write_Byte_SPI(data);
- *AT91C_PIOA_SODR|=VS1011_CMD_CS; //MP3_CMD_CS=1;
- }
- void vs1011_data_write(uchar data)
- {
- *AT91C_PIOA_CODR|=VS1011_DATA_CS; //MP3_DATA_CS=0;
- Write_Byte_SPI(data);
- *AT91C_PIOA_SODR|=VS1011_DATA_CS; //MP3_DATA_CS=1;
- *AT91C_PIOA_SODR|=VS1011_CMD_CS; //MP3_CMD_CS=1;
- }
- uint vs1011_read(uchar address)
- {
- uchar temp1=0;
- uint temp=0;
- *AT91C_PIOA_SODR|=VS1011_DATA_CS; //MP3_DATA_CS=1;
- *AT91C_PIOA_CODR|=VS1011_CMD_CS; //MP3_CMD_CS=0;
- Write_Byte_SPI(0x03); //VS1011µÄ¶ÁÃüÁî
- Write_Byte_SPI(address); //µØÖ·
- temp=Read_Byte_SPI();
- temp=temp<<8;
- temp1=Read_Byte_SPI();
- temp=temp|temp1;
- *AT91C_PIOA_SODR|=VS1011_CMD_CS; //MP3_CMD_CS=1;
- return temp;
- }
- void vs1011_init(void)
- {
- vs1011_cmd_write(0x00,0x0800); //NEW MODE
- vs1011_cmd_write(0x02,0X75); //BASS
- vs1011_cmd_write(0x03,0X9800); //CLOCK F
- vs1011_cmd_write(0x0b,0X0000); //VOLUME
- }
No comments:
Post a Comment