⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vs1003.c

📁 msp430 和VS1003 的例子,联系qqliuyong007@163.com
💻 C
字号:
#include "VS1003.h"


unsigned char szBeepMP3[432] = 
{
	0xff, 0xe2, 0x19, 0xc0, 0xd4, 0x80, 0x00, 0x0a, 0x61, 0x76, 0x72, 0xe9, 0x41, 0x30, 0x01, 0x0d,
	0xbe, 0x90, 0xcc, 0x13, 0x0f, 0xc6, 0xe3, 0xf8, 0xdf, 0xfe, 0x05, 0xfc, 0x0b, 0xc0, 0xab, 0xc8,
	0x0b, 0xff, 0xff, 0xf6, 0x8b, 0xbf, 0xe2, 0x23, 0x2c, 0x10, 0x82, 0x18, 0xf7, 0x7a, 0xd7, 0x77,
	0xad, 0x11, 0x8e, 0x61, 0x04, 0x00, 0x3a, 0xf0, 0xff, 0xb0, 0x04, 0xb1, 0x00, 0x00, 0x06, 0x59,
	0xc3, 0x99, 0x00, 0x00, 0x70, 0x0b, 0x80, 0x00, 0xff, 0xe2, 0x19, 0xc0, 0xc6, 0xe8, 0x07, 0x0b,
	0x11, 0x9e, 0xee, 0xf9, 0x81, 0x68, 0x02, 0x01, 0xb8, 0x00, 0x00, 0x39, 0x42, 0x12, 0xff, 0xff,
	0x70, 0x0f, 0xff, 0xae, 0xbf, 0xab, 0xfe, 0xa4, 0x1b, 0xf0, 0xe5, 0x37, 0xd6, 0x1d, 0x7e, 0xa6,
	0x7f, 0xe3, 0x30, 0xdf, 0xfe, 0x33, 0x0e, 0xbc, 0xb1, 0x97, 0xf5, 0x07, 0x7b, 0x27, 0xff, 0xff,
	0xff, 0x25, 0x5d, 0xb8, 0xce, 0x9b, 0x0a, 0x7a, 0x9b, 0x96, 0x81, 0xaf, 0x92, 0x02, 0x83, 0x97,
	0xff, 0xe2, 0x19, 0xc0, 0x06, 0x63, 0x13, 0x0b, 0x79, 0x7e, 0x90, 0x21, 0xc0, 0xd8, 0x00, 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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xe2, 0x19, 0xc0, 0xbc, 0xd1, 0x25, 0x00,
	0x00, 0x02, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
};

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++)
	{
		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< 432 ;i++)
		SerialWrite(szBeepMP3[i]);
                
	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_TESTS);	   
	SetBass(0, 10);						// 0db, 100Hz
	SCIWrite(SCI_CLOCKF, 0x9770);		
	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);
	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);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -