- 阅读权限
- 150
- UID
- 7
- 帖子
- 140
- 精华
- 0
- 注册时间
- 2013-2-26
- 在线时间
- 20 小时
- UID
- 7
- 帖子
- 140
- 精华
- 0
- 注册时间
- 2013-2-26
- 在线时间
- 20 小时
|
#include <iom64v.h>
#include <macros.h>
#include "vs1003B.h"
#define uchar unsigned char
#define uint unsigned int
#define MP3_DDR DDRB
#define MP3_PORT PORTB
#define MP3_PIN PINB
#define MP3_CMD_CS BIT(4)
#define MP3_DATA_REST BIT(5)
#define MP3_DATA_REQ BIT(6)
#define MP3_DATA_CS BIT(7)
//SPI initialize
void spi_init(void)
{
DDRB = 0xBF; //SI输入,SO,SCK,SS输出
SPCR = 0x50; //setup SPI
SPSR = 0x01; //setup SPI
}
void Write_Byte_SPI(unsigned char byte)
{
SPDR = byte;
while (!(SPSR & (1<<SPIF)));
}
unsigned char Read_Byte_SPI(void)
{
SPDR = 0xFF;
while (!(SPSR &(1<<SPIF)));
return SPDR;
}
void mp3_port_init()
{
spi_init();
MP3_DDR|=MP3_DATA_CS |MP3_CMD_CS|MP3_DATA_REST;
MP3_DDR&=~MP3_DATA_REQ;
MP3_PORT|=MP3_DATA_CS |MP3_CMD_CS|MP3_DATA_REST;
DDRC=0XFFORTC=0XFF;
}
void vs1003_cmd_write(uchar address,uint data)
{
MP3_PORT|=MP3_DATA_CS;
MP3_PORT&=~MP3_CMD_CS;
Write_Byte_SPI(0x02); //VS1003的写命令
Write_Byte_SPI(address); //地址
Write_Byte_SPI(data>>8);
Write_Byte_SPI(data);
MP3_PORT|=MP3_CMD_CS;
}
void vs1003_data_write(uchar data)
{
MP3_PORT&=~MP3_DATA_CS;
Write_Byte_SPI(data);
MP3_PORT|=MP3_DATA_CS;
MP3_PORT|=MP3_CMD_CS;
}
uint vs1003_read(uchar address)
{
uchar temp1=0;
uint temp=0;
MP3_PORT|=MP3_DATA_CS;
MP3_PORT&=~MP3_CMD_CS;
Write_Byte_SPI(0x03); //VS1003的读命令
Write_Byte_SPI(address); //地址
temp=Read_Byte_SPI();
temp=temp<<8;
temp1=Read_Byte_SPI();
temp=temp|temp1;
MP3_PORT|=MP3_CMD_CS;
return temp;
}
void vs1003_init(void)
{
vs1003_cmd_write(0x00,0x0800); //NEW MODE
vs1003_cmd_write(0x02,0X75); //BASS
vs1003_cmd_write(0x03,0X4000); //2倍频
vs1003_cmd_write(0x0b,0X2020); //VOLUME
}
void test_1003()
{
unsigned int data_pointer;unsigned char i;
while ( 1)
{
data_pointer=0;
while(data_pointer<4800)
{
if(MP3_PIN &MP3_DATA_REQ)
{
for(i=0;i<32;i++)
{
vs1003_data_write(vsBeepMP3[data_pointer]);
data_pointer++;
}
if(data_pointer==4799) break; //如果现在的数据不够了,则跳出来
}
}
}
}
void main()
{
mp3_port_init();
vs1003_init();vs1003_init();
while(1)
{
test_1003();
}
}
|
|