使用VS1003,这个程序还在调试中,正弦测试通过,但是播放音频没有声音,自己也在找问题,现在公开代码,大家可以一起讨论讨论.
#include "VS1003.h"
unsigned char szBeepMP3[864] =
{
0x4d, 0x54, 0x68, 0x64, 0x0, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0x1, 0x0, 0x78, 0x4d, 0x54, 0x72,
0x6b, 0x0, 0x0, 0x11, 0x33, 0x0, 0xff, 0x1, 0x47, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74,
0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x47, 0x4e, 0x4d, 0x49, 0x44, 0x49, 0x20, 0x32, 0x2e, 0x30,
0x20, 0x64, 0x65, 0x6d, 0x6f, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x64, 0x75,
0x72, 0x69, 0x6e, 0x67, 0x20, 0x31, 0x34, 0x20, 0x64, 0x61, 0x79, 0x73, 0x20, 0x66, 0x72, 0x65,
0x65, 0x20, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x68, 0x61, 0x73, 0x65, 0xa,
0x0, 0xff, 0x1, 0x47, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79,
0x20, 0x47, 0x4e, 0x4d, 0x49, 0x44, 0x49, 0x20, 0x32, 0x2e, 0x30, 0x20, 0x64, 0x65, 0x6d, 0x6f,
0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x64, 0x75, 0x72, 0x69, 0x6e, 0x67, 0x20,
0x31, 0x34, 0x20, 0x64, 0x61, 0x79, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x74, 0x65, 0x73,
0x74, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x68, 0x61, 0x73, 0x65, 0xa, 0x0, 0xff, 0x3, 0x14, 0xce,
0xa7, 0xcd, 0xfe, 0xec, 0xbf, 0xd6, 0xc6, 0xd7, 0xf7, 0x71, 0x71, 0x33, 0x31, 0x36, 0x33, 0x38,
0x32, 0x35, 0x36, 0x0, 0xff, 0x1, 0x9, 0x2e, 0x75, 0x2e, 0x2e, 0x66, 0x2e, 0x2e, 0x72, 0xa,
0x0, 0xff, 0x58, 0x4, 0x4, 0x2, 0x18, 0x8, 0x0, 0xff, 0x59, 0x2, 0x0, 0x0, 0x0, 0xff,
0x51, 0x3, 0xb, 0xbc, 0xcf, 0x0, 0xff, 0x1, 0x47, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74,
0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x47, 0x4e, 0x4d, 0x49, 0x44, 0x49, 0x20, 0x32, 0x2e, 0x30,
0x20, 0x64, 0x65, 0x6d, 0x6f, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x64, 0x75,
0x72, 0x69, 0x6e, 0x67, 0x20, 0x31, 0x34, 0x20, 0x64, 0x61, 0x79, 0x73, 0x20, 0x66, 0x72, 0x65,
0x65, 0x20, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x68, 0x61, 0x73, 0x65, 0xa,
0x0, 0xc0, 0x50, 0x0, 0xb0, 0x7, 0x7f, 0x0, 0xa, 0x40, 0x0, 0xff, 0x1, 0x47, 0x47, 0x65,
0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x47, 0x4e, 0x4d, 0x49, 0x44,
0x49, 0x20, 0x32, 0x2e, 0x30, 0x20, 0x64, 0x65, 0x6d, 0x6f, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69,
0x6f, 0x6e, 0x20, 0x64, 0x75, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x31, 0x34, 0x20, 0x64, 0x61, 0x79,
0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x70,
0x68, 0x61, 0x73, 0x65, 0xa, 0x0, 0xc1, 0x19, 0x0, 0xb1, 0x7, 0x46, 0x0, 0xa, 0x40, 0x0,
0xff, 0x1, 0x47, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20,
0x47, 0x4e, 0x4d, 0x49, 0x44, 0x49, 0x20, 0x32, 0x2e, 0x30, 0x20, 0x64, 0x65, 0x6d, 0x6f, 0x20,
0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x64, 0x75, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x31,
0x34, 0x20, 0x64, 0x61, 0x79, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x74, 0x65, 0x73, 0x74,
0x69, 0x6e, 0x67, 0x20, 0x70, 0x68, 0x61, 0x73, 0x65, 0xa, 0x0, 0xc2, 0x21, 0x0, 0xb2, 0x7,
0x64, 0x0, 0xa, 0x40, 0x0, 0xff, 0x1, 0x47, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65,
0x64, 0x20, 0x62, 0x79, 0x20, 0x47, 0x4e, 0x4d, 0x49, 0x44, 0x49, 0x20, 0x32, 0x2e, 0x30, 0x20,
0x64, 0x65, 0x6d, 0x6f, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x64, 0x75, 0x72,
0x69, 0x6e, 0x67, 0x20, 0x31, 0x34, 0x20, 0x64, 0x61, 0x79, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65,
0x20, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x68, 0x61, 0x73, 0x65, 0xa, 0x0,
0xc3, 0x3, 0x0, 0xb3, 0x7, 0x78, 0x0, 0xa, 0x40, 0x0, 0xff, 0x1, 0x47, 0x47, 0x65, 0x6e,
0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x47, 0x4e, 0x4d, 0x49, 0x44, 0x49,
0x20, 0x32, 0x2e, 0x30, 0x20, 0x64, 0x65, 0x6d, 0x6f, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
0x6e, 0x20, 0x64, 0x75, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x31, 0x34, 0x20, 0x64, 0x61, 0x79, 0x73,
0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x68,
0x61, 0x73, 0x65, 0xa, 0x0, 0xc4, 0x50, 0x0, 0xb4, 0x7, 0x3c, 0x0, 0xff, 0x1, 0x47, 0x47,
0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x47, 0x4e, 0x4d, 0x49,
0x44, 0x49, 0x20, 0x32, 0x2e, 0x30, 0x20, 0x64, 0x65, 0x6d, 0x6f, 0x20, 0x76, 0x65, 0x72, 0x73,
0x69, 0x6f, 0x6e, 0x20, 0x64, 0x75, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x31, 0x34, 0x20, 0x64, 0x61,
0x79, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20,
0x70, 0x68, 0x61, 0x73, 0x65, 0xa, 0x0, 0xc5, 0x47, 0x0, 0xb5, 0x7, 0x46, 0x0, 0xa, 0x40,
0x0, 0xff, 0x1, 0x47, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79,
0x20, 0x47, 0x4e, 0x4d, 0x49, 0x44, 0x49, 0x20, 0x32, 0x2e, 0x30, 0x20, 0x64, 0x65, 0x6d, 0x6f,
};
void Waitms(unsigned int i)
{
unsigned int ct;
while(i--)
{
for(ct=0; ct <100 ;ct++);
}
/*
#define COUNTER 8000
unsigned int ct=i;
while(ct--)
{
CCR0 = COUNTER;
TACTL = TASSEL1+TACLR; // ACLK, upmode
TACTL |= MC0;
while(TAIFG == 0 ) ;
TACTL = MC0 | MC1;
}
*/
}
void SerialWrite(unsigned char Data)
{
unsigned char i;
for(i=0; i<8 ;i++)
{
P1DIR |= REQ;
P1OUT |= REQ;
P1DIR &= ~REQ;
while(! ( P1IN & REQ ) ) ;
CLR(SCLK);
if(Data & 0x80)
SET(SI);
else
CLR(SI);
Data <<= 1;
SET(SCLK);
}
}
unsigned char SerialRead()
{
unsigned char i;
unsigned char res=0x00;
for(i=0; i<8 ;i++)
{
SET(SCLK);
_NOP();
CLR(SCLK);
res <<=1;
if( P1IN & SO )
res |= 0x01;
}
return res;
}
void SCIWrite(unsigned char addr, unsigned int Data)
{
SET(DCS);
CLR(CS);
SerialWrite(SI_WRITE);
SerialWrite(addr);
SerialWrite(Data >> 8);
SerialWrite(Data);
SET(CS);
CLR(DCS);
}
unsigned int SCIRead(unsigned char addr)
{
unsigned char i;
unsigned int r;
SET(DCS);
CLR(CS);
SerialWrite(SI_READ);
SerialWrite(addr);
r = SerialRead() << 8;
r += SerialRead();
SET(CS);
CLR(DCS);
for( i=20 ; i>0; i--);
return r;
}
void SetVolume(unsigned char l, unsigned char r)
{
SCIWrite(SCI_VOL, ((l << 8) + r));
}
void SetBass(unsigned char amp, unsigned char freq)
{
SCIWrite(SCI_BASS, ((amp & 0x0f) << 4) | (freq & 0x0f));
}
unsigned char Version()
{
return (SCIRead(SCI_STATUS) >> 4) & 0x7;
}
void PlayBeep()
{
unsigned int i;
SET(CS);
CLR(DCS);
for( i=0; i< 864 ;i++)
SerialWrite(szBeepMP3);
CLR(CS);
SET(DCS);
for(i=0; i<30;i++)
SerialWrite(0x00);
}
void InitVS1003()
{
SET(SI|SCLK|DCS|CS);
CLR(REQ|SO);
CLR(RST);
_NOP();
_NOP();
SET(RST);
while(! ( P1IN & REQ ) ) ; // Wait untill the REQ is high
SCIWrite(SCI_MODE, SM_SDINEW | SM_RESET);
SetBass(0, 10); // 0db, 100Hz
SCIWrite(SCI_CLOCKF, 0x9800);
SetVolume(0, 0);
}
void InitPort()
{
P1DIR |= (RST|SI|SCLK|CS|DCS);
P1DIR &=~(REQ|SO);
}
void SineTest(void)
{
//
//向vs1003发送正弦测试命令:0x53 0xef 0x6e n 0x00 0x00 0x00 0x00
//其中n = 0x24, 设定vs1003所产生的正弦波的频率值,具体计算方法见vs1003的datasheet
//
SET(CS);
CLR(DCS);
SCIWrite(0x00,0x0820);
SerialWrite(0x53);
SerialWrite(0xef);
SerialWrite(0x6e);
SerialWrite(0x24);
SerialWrite(0x00);
SerialWrite(0x00);
SerialWrite(0x00);
SerialWrite(0x00);
while(!(P1IN & REQ ));
CLR(CS);
SET(DCS);
Waitms(500);
//
//退出正弦测试
//
SET(CS);
CLR(DCS);
SerialWrite(0x45);
SerialWrite(0x78);
SerialWrite(0x69);
SerialWrite(0x74);
SerialWrite(0x00);
SerialWrite(0x00);
SerialWrite(0x00);
SerialWrite(0x00);
while(!(P1IN & REQ ));
CLR(CS);
SET(DCS);
//
//再次进入正弦测试并设置n值为0x44,即将正弦波的频率设置为另外的值
//
SET(CS);
CLR(DCS);
SerialWrite(0x53);
SerialWrite(0xef);
SerialWrite(0x6e);
SerialWrite(0x44);
SerialWrite(0x00);
SerialWrite(0x00);
SerialWrite(0x00);
SerialWrite(0x00);
while(!(P1IN & REQ ));
CLR(CS);
SET(DCS);
Waitms(500);
//
//退出正弦测试
//
SET(CS);
CLR(DCS);
SerialWrite(0x45);
SerialWrite(0x78);
SerialWrite(0x69);
SerialWrite(0x74);
SerialWrite(0x00);
SerialWrite(0x00);
SerialWrite(0x00);
SerialWrite(0x00);
while(!(P1IN & REQ ));
CLR(CS);
SET(DCS);
}
void play (unsigned char dat){
while(!(P1IN & REQ ));
SerialWrite(dat);
}
|