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

📄 vs1001k.c

📁 使用MSP430做MP3播放器的专题源码
💻 C
字号:
/*
 * Copyright (c) 2002, Jan Szymanski.
 * All rights reserved. 
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met: 
 * 1. Redistributions of source code must retain the above copyright 
 *    notice, this list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright 
 *    notice, this list of conditions and the following disclaimer in the 
 *    documentation and/or other materials provided with the distribution. 
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Jan Szymanski.
 * 4. The name of the author may not be used to endorse or promote
 *    products derived from this software without specific prior
 *    written permission.  
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 */
/*********************************************************/
/*                                                       */
/*  Module              : VS1001K.C                      */
/*  Language used       : C                              */
/*  Microprocessor      : MSP430F149                     */
/*                                                       */
/*  Function            : All function related to VS1001K*/
/*                        MP3 decoder                    */
/*  Revision History :                                   */
/*  Author          Date            Reason               */
/*  J.Szymanski     April 2002      Initial Design       */
/*                                                       */
/*********************************************************/

/* definition of internal registers addresses */
#define vMODE 0x00
#define vSTATUS 0x01
//#define vINT_FCTLH 0x02 /* not to be used */
#define vCLOCKF 0x03
#define vDECODE_TIME 0x04
#define vAUDATA 0x05
#define vWRAM 0x06
#define vWRAMADDR 0x07
#define vHDAT0 0x08
#define vHDAT1 0x09
#define vA1ADDR 0x0a
#define vVOL 0x0b
//#define vRESERVED 0x0c /* not to be used */
#define vA1CTRL0 0x0d
#define vA1CTRL1 0x0e

/**********************************************************/
/*  Local Functions Prototypes                            */
/**********************************************************/
void SCI_write_byte(unsigned char byte);
unsigned char SCI_read_byte(void);

/**********************************************************/
/*********************************************************/
/*  Name        : v_init                                 */
/*  Parameters  : none                                   */
/*  Returns     : none                                   */
/*  Scope       :                                        */
/*  Function    : to initialize VS1001K                  */
/*********************************************************/
void v_init(void)
{
unsigned int del;
/* hardware reset P3.2 is RESET */
P3OUT &= 0xfb;  // RESET active low
for (del=0;del<20000;del++){} // delay
t10ms_1=0;
while(t10ms_1<5){}

P3OUT |= 0x04; // release RESET line 
for (del=0;del<20000;del++){} // delay
t10ms_1=0;
while(t10ms_1<5){}

/* end of hardware reset */
//P5OUT |= 0x10;  // 0001 0000 P54=BIT_EN (BSYNC)
putchar_uart1(0);
putchar_uart1(0);
putchar_uart1(0);
putchar_uart1(0);

v_reset(vol); /* software reset */
}
/* End of v_init *****************************************/

/*********************************************************/
/*  Name        : SCI_wread                              */
/*  Parameters  : address                                */
/*  Returns     : data_out                               */
/*  Scope       :                                        */
/*  Function    : to read VS1001K registers              */
/*********************************************************/
unsigned int SCI_wread(unsigned char regaddress)
{
unsigned int value;
unsigned char c;
value=0;
/* set lines to start with */
P6OUT |= 0x02;  /* P6.1=xCS=1 inactive */
P3OUT &= 0xbf;
P3DIR |= 0x40;  /* P3.6=SCL=0 output with 0 out */
P3OUT &= 0x7f;
P3DIR |= 0x80;  /* P3.7=SDA=1 output with 0 out */
P3OUT &= 0xfd;
P3DIR &= 0xfd;  /* P31=SO input */
P6OUT &= 0xfd;  /* P6.1=xCS=0 active */
SCI_write_byte(0x03); /* read command sent */
SCI_write_byte(regaddress); /* register address sent */
c=SCI_read_byte();
value=c;
value <<= 8;
c=SCI_read_byte();
value += c;
/* set lines to stop with */
P6OUT |= 0x02;  /* P6.1=xCS=1 */
P3OUT &= 0xbf;
P3DIR |= 0x40;  /* P3.6=SCL=0 output with 0 out */
P3OUT &= 0x7f;
P3DIR |= 0x80;  /* P3.7=SDA=1 output with 0 out */
return (value);
}
/* End of SCI_wread **************************************/
/*********************************************************/
/*  Name        : SCI_wwrite                             */
/*  Parameters  : address, word of data                  */
/*  Returns     : none                                   */
/*  Scope       :                                        */
/*  Function    : to read VS1001K registers              */
/*********************************************************/
void SCI_wwrite(unsigned char regaddress, unsigned int param)
{
unsigned char a,b;
unsigned int value;
/* set lines to start with */
P6OUT |= 0x02;  /* P6.1=xCS=1 inactive */
P3OUT &= 0xbf;
P3DIR |= 0x40;  /* P3.6=SCL=0 make it output with 0 out */
P3OUT &= 0x7f;
P3DIR |= 0x80;  /* P3.7=SDA=1 make it output with 0 out */
P6OUT &= 0xfd;  /* P6.1=xCS=0 active */
SCI_write_byte(0x02); /* write command sent */
SCI_write_byte(regaddress); /* register address sent */
value=param;
b=value;
value >>= 8;
a=value;
SCI_write_byte(a);
SCI_write_byte(b);
/* set lines to stop with */
P6OUT |= 0x02;  /* P6.1=xCS=1 inactive */
P3OUT &= 0xbf;
P3DIR |= 0x40;  /* P3.6=SCL=0 output with 0 out */
P3OUT &= 0x7f;
P3DIR |= 0x80;  /* P3.7=SDA=1 output with 0 out */
}
/* End of SCI_wwrite *************************************/
/*-------------------------------------------------------*/
void SCI_write_byte(unsigned char byte)
{
unsigned char c,i,n;
c=byte;
P3OUT &= 0xbf;
P3DIR |= 0x40;  // SCL output=low
P3OUT &= 0x7f;
P3DIR |= 0x80;  // SDA output=low
for(i=0;i<8;i++)
  {
  if((c&0x80)==0x80)
    P3OUT |= 0x80;  // SDA high
      else P3OUT &= 0x7f; // SDA low
  c <<= 1;
  P3OUT |= 0x40;  // SCL high
//  for(n=0;n<255;n++){} // delay 
  for(n=0;n<5;n++){} // delay 
  P3OUT &= 0xbf;  // SCL low
  }
}
/*-------------------------------------------------------*/
unsigned char SCI_read_byte(void)
{
unsigned char c,i,n;
c=0;
P3OUT &= 0xbf;
P3DIR |= 0x40;  // SCL output=low
P3OUT &= 0xfd;
P3DIR &= 0xfd;  // P3.1=SO=input
for(i=0;i<8;i++)
  {
  c <<= 1;
  P3OUT |= 0x40;  // SCL high
  if((P3IN&0x02)==0x02) c+=1; // SO is P3.1
  for(n=0;n<128;n++){} // delay 
  P3OUT &= 0xbf;  // SCL low
  for(n=0;n<128;n++){} // delay 
  }
return(c);
}
/*-------------------------------------------------------*/
/*  level = 1, wait for DREQ to go up */
/*  level = 0, wait for DREQ to go down */
void vWaitDReq(unsigned char level)
{
unsigned int i;

if(level==1)
  {
  // waiting for DREQ to be 1
  for(i=0; i<40000; i++)
	  { 
	  if((P5IN &0x01)==0x01) break; /* P51 is DREQ input */
	  }	// waiting for ready 
  }else /* level==0, waiting for DREQ to be 0 */
    {
    for(i=0; i<40000; i++)
	    { 
	    if((P5IN &0x01)==0x00) break; /* P51 is DREQ input */
	    }	
    }
}
/*********************************************************/
/*  Name        : v_reset                                */
/*  Parameters  : volume                                 */
/*  Returns     : none                                   */
/*  Scope       :                                        */
/*  Function    : to software reset V1001k               */
/*********************************************************/
void v_reset(unsigned char vol)
{
unsigned int del;

t10ms_1=0;
while(t10ms_1<5){}

vWaitDReq(1);
SCI_wwrite(0x00,0x0004); /* vMODE.bit2=SM_RESET */
vWaitDReq(0);
vWaitDReq(1);

t10ms_1=0;
while(t10ms_1<5){}

/* init of internal registers */
//SCI_wwrite(0x03,40140); /* vCLOCKF */
//for (del=0;del<20000;del++){} // delay
//SCI_wwrite(0x03,40140); /* vCLOCKF */
//for (del=0;del<20000;del++){} // delay
SCI_wwrite(0x03,12288); /* vCLOCKF */
SCI_wwrite(0x03,12288); /* vCLOCKF */

/* 24576MHZ crystal, 24576000/2000=12288 */
/* 14.745MHz crystal 14745000/2000=7372  + 32768 =40140 (0x9ccc)*/
v_volume(vol);

putchar_uart1(0x00);
putchar_uart1(0x00);
putchar_uart1(0x00);
putchar_uart1(0x00);

//SCI_wwrite(0x03,40140); /* vCLOCKF */
//for (del=0;del<20000;del++){} // delay
//SCI_wwrite(0x03,40140); /* vCLOCKF */
//for (del=0;del<20000;del++){} // delay
SCI_wwrite(0x03,12288); /* vCLOCKF */
SCI_wwrite(0x03,12288); /* vCLOCKF */

//t10ms_1=0;
//while(t10ms_1<100){}
}
/* End of v_reset ****************************************/

/*********************************************************/
/*  Name        : v_volume                               */
/*  Parameters  : volume                                 */
/*  Returns     : none                                   */
/*  Scope       :                                        */
/*  Function    : to software reset V1001k               */
/*********************************************************/
void v_volume(unsigned char vol)
{
unsigned int temp,del;
temp=vol;
temp<<=8;
temp+=vol;
SCI_wwrite(0x0b,temp); /* vVOL */
for (del=0;del<20000;del++){} // delay
}
/* End of v_volume ***************************************/

/* END OF FILE "VS1001K.C" *******************************/

⌨️ 快捷键说明

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