搜索
bottom↓
回复: 2

我的VS1011B Sine Test都正常,就是放不了MP3!请教要注意什么问题??????

[复制链接]

出0入0汤圆

发表于 2006-4-3 00:32:55 | 显示全部楼层 |阅读模式
晶体使用24.576;SDINEW模式.



VS1011.C



unsigned char WriteByteSPI(unsigned char byte)

{

SPDR = byte;

while(!(SPSR & (1<<7))); // Wait Queue off

return SPDR;

}



//*************************************

// void VS1001_Read(unsigned char Address,int Count,unsigned int *pData)

//*************************************

void VS1001_Read(unsigned char Address,int Count,unsigned int *pData)

{

PORT_MP3_OUT &= ~XCS;                     // XCS Low

WriteByteSPI(VS1001_READ);

WriteByteSPI(Address);

while(Count--)

                          {

                          *pData = WriteByteSPI(0) << 8;

                          *pData++ |= WriteByteSPI(0);

                          }

PORT_MP3_OUT |= XCS;                     // XCS High

delay_us(5);

}



//*************************************

// void VS1001_Write(unsigned char Address,int Count,unsigned int *pData)

//*************************************

void VS1001_Write(unsigned char Address,int Count,unsigned int *pData)

{

PORT_MP3_OUT &= ~XCS;                     // XCS Low

WriteByteSPI(VS1001_WRITE);

WriteByteSPI(Address);

while(Count--)

                          {

                          WriteByteSPI((unsigned char) ((*pData) >> 8));

                          WriteByteSPI((unsigned char) *pData);

                          }

PORT_MP3_OUT |= XCS;                     // XCS High

delay_us(5);

}



//*************************************

// void VS1001_Stream(unsigned char Data,unsigned char Qte)

//*************************************

void VS1001_Stream(unsigned char *Data,unsigned char Qte)

{

    PORT_MP3_OUT &= ~BSYNC;                     // BSYNC Low

    while((Qte --) > 0)

    WriteByteSPI(*Data++);

    PORT_MP3_OUT |= BSYNC;                     // BSYNC High

}



//*************************************

// void VS1001Init(void)

//*************************************

void VS1001Init(unsigned char HardReset)

{

unsigned int buf[2];



unsigned char bufc[4];

if (HardReset == TRUE)

   {

   PORT_MP3_DDR = XRES | BSYNC | XCS | MOSI | SCK | SS;

   SPCR = 0x50;                                                    // SPI ENABLE, MSB FIRST, MASTER,

                                                                             // CPOL=0, CPHA=0, CLK/16

                                               



   PORT_MP3_OUT = XRES + XCS + BSYNC;                                                  // XCS 1 - RESET 1 - BSYNC 1

   delay_ms(5);       



   PORT_MP3_OUT &= ~XRES;                                                        // Reset is 0

   delay_ms(5);

   PORT_MP3_OUT |= XRES;;                                                        // Reset is 1

   delay_ms(5);

   }



while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

buf[0] = 0x0804;

VS1001_Write(0,1,buf);

delay_ms(2);



while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

buf[0] = 0xac45;                       

VS1001_Write(5,1,buf);                                        // 44kHz



while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

VS1001_SetVolume(0,0);



bufc[0] = 0x00;

bufc[1] = 0x00;

bufc[2] = 0x00;

bufc[3] = 0x00;

while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

VS1001_Stream(&bufc[0],4);



}

//*************************************

// void Working_Test(void)

//*************************************

void Working_Test(void)

{

  unsigned int i;

  for(i=0;i<10;i++)

  {

    while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

    VS1001_SetVolume(0,0);

    delay_ms(500);

    while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

    VS1001_SetVolume(255,255);

    delay_ms(500);

  }

}

//*************************************

// void Reg_Test(void)

//*************************************

unsigned char Reg_Test()

{

unsigned int buf;

unsigned int j;



for (j=0;j<20;j++)

        {

        buf = j*256+j;

        while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

        VS1001_Write(3,1,&buf);

        buf = 0xffff;

        VS1001_Read(3,1,&buf);

        if (buf != j*256+j) return 0;

        }

return 1;

}



//*************************************

// void Sine_On(unsigned char Freq)

//*************************************

void Sine_On(unsigned int freq)

{

unsigned char buf[4];



buf[0] = 0x53;

buf[1] = 0xef;

buf[2] = 0x6e;

buf[3] = ((freq * 128) / 44100) & 0x1f;

while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

VS1001_Stream(&buf[0],4);



buf[0] = 0x00;

buf[1] = 0x00;

buf[2] = 0x00;

buf[3] = 0x00;

while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

VS1001_Stream(&buf[0],4);

}



//*************************************

// void Sine_Off(void)

//*************************************

void Sine_Off(void)

{

unsigned char buf[4];



buf[0] = 0x45;

buf[1] = 0x78;

buf[2] = 0x69;

buf[3] = 0x74;

while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

VS1001_Stream(&buf[0],4);



//buf[0] = 0x00;

//buf[1] = 0x00;

//buf[2] = 0x00;

//buf[3] = 0x00;

//while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

//VS1001_Stream(&buf[0],4);

}



//*************************************

// void Sine_Sweep(void)

//*************************************

void Sine_Sweep(void)

{

   unsigned int buf[2];

   unsigned int i;

while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

buf[0] = 0x0820;

VS1001_Write(0,1,buf);

delay_ms(2);



while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

VS1001_SetVolume(0,0);



for (i=0;i<20000;i+=1000)

        {

        Sine_Off();

        Sine_On(i);

        delay_ms(300);

        }

Sine_Off();

VS1001Init(1);

}



//*************************************

// void VS1001_SetVolume(unsigned char Left,unsigned char Right)

//*************************************

void VS1001_SetVolume(unsigned char Left,unsigned char Right)

{

unsigned int buf[2];



buf[0] = (((unsigned int)Left) << 8) | ((unsigned int)Right);

VS1001_Write(11,1,buf);

}









主程序节选,MP3文件放在FLASH中.

void PlayMP3(void)

{

unsigned char i,temp[32];

unsigned long j=0;

while(j < 0x2e1f)

  {

         for(i=0;i<32;i++)

         {

            temp = __load_program_memory(&mp3[j++]);

            //USART_Putchar(temp);

         }

        while(!(PORT_DREQ_IN & DREQ));                                // wait for DREQ

        VS1001_Stream(temp,32);

  }

}





//*************************************

// void main(void)

//*************************************

void main(void)

{

int i;

MCUCR = 0x80;

DDRF = 0x03;

PORTF = 0xff;

USART_Init();

while(1)

{

USART_Putstr("VS1011 initing....");

VS1001Init(HARD);

USART_Putstr("ok
");

PORTF &= ~0x02;

USART_Putstr("VS1011 working testing....");

Working_Test();

PORTF |= 0x02;

USART_Putstr("ok
");

USART_Putstr("VS1011 reg testing....");

if(Reg_Test())

USART_Putstr("ok
");

else

USART_Putstr("fail
");

VS1001_SetVolume(100,100);

USART_Putstr("VS1011 sine sweeping....");

for(i=0;i<2;i++)

Sine_Sweep();

USART_Putstr("ok
");

USART_Putstr("VS1011 mp3 playing....");

//VS1001Init(0);

PlayMP3();

USART_Putstr("ok
");

}

}

阿莫论坛20周年了!感谢大家的支持与爱护!!

月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!

出0入0汤圆

发表于 2006-5-17 09:24:02 | 显示全部楼层
点击此处下载armok01117688.rar

出0入0汤圆

发表于 2006-5-29 18:18:43 | 显示全部楼层
楼上的做广告的请版主删除.
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-28 20:22

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表