void spi_write(uint8 ch);
void VS1003init();
void wr_commad(unsigned char addr,unsigned char hdat,unsigned char ldat) ;
void sintest(unsigned char x) ;
void delayms(uint16 z);
void delayus(uint16 z);
void main()
{
int i;
VS1003init();
XDCS=0;
for(i=0;i<20000;i++)
{
DREQ=1;
while(!DREQ);
spi_write(music);
}
while(1);
}
void spi_write(uint8 ch)
{
uint8 i;
for(i=0;i<8;i++)
{
MOSI=0x80&ch; //高位先写
ch<<=1;
SCLK=0; //上升沿有效
SCLK=1;
}
}
void wr_commad(unsigned char addr,unsigned char hdat,unsigned char ldat)
{
DREQ=1;
while(!DREQ);
XCS=0;
spi_write(0x02);
spi_write(addr);
spi_write(hdat);
spi_write(ldat);
XCS=1;
}
void VS1003init()
{
XRST=0;
delayus(100);
XDCS=XCS=XRST=1;
wr_commad(0x00,0x80,0x04); //VS1003新模式 软件复位
delayus(10);
DREQ=1;
while(!DREQ);
wr_commad(0x03,0x98,0x00); //VS1003时钟:3倍频
delayus(10);
wr_commad(0x05,0xbb,0x81); //VS1003采样率:48Kps 立体声
delayus(10);
wr_commad(0x02,0x00,0x55); //设置重音
delayus(10);
wr_commad(0x0b,0x20,0x20); //设置音量
delayus(10);
spi_write(0x00); //写4个字节的无效数据以驱动
spi_write(0x00);
spi_write(0x00);
spi_write(0x00);
}
void sintest(unsigned char x) //正弦测试(循环)
{
wr_commad(0x00,0x08,0x20); //VS1003测试模式
DREQ=1;
while(!DREQ);
XDCS=0;
XCS=1;
spi_write(0x53);
spi_write(0xef);
spi_write(0x6e);
spi_write(x); //频率
spi_write(0);
spi_write(0);
spi_write(0);
spi_write(0);
delayus(5000);
spi_write(0x45);
spi_write(0x78);
spi_write(0x69);
spi_write(0x74);
spi_write(0);
spi_write(0);
spi_write(0);
spi_write(0);
delayus(5000);
XDCS=1;
}
void delayms(uint16 z)
{
uint16 i,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
void delayus(uint16 z)
{
while(z--);
}
这段代码可以播放原先附有的music[](音乐数据),然后我把这段音乐数据改为别的歌(前面32个字节有在的),为什么就播不了了?帮帮忙哈,太感谢您了 |