|
发表于 2008-7-12 11:30:22
|
显示全部楼层
这是我的VS1003底层驱动程序,给你参考下:
//---------------------------------------------------------
// VS1003b 底层驱动函数库
// 编译环境:Keil C
// 编写日期:2008-04-07
// 最后更新:2008-06-21
//---------------------------------------------------------
#include "main.h"
/*---------------------------------------------------
// 函数名:VS1003b_sine
// 功 能:VS1003B 正弦测试
// 参 数:
// 返回值:
//---------------------------------------------------
void VS1003b_sine()
{
xCS_En();
while(!DREQ);
SPI_SendByte(VS_Write);
SPI_SendByte(VS_Mode);
SPI_SendByte(0x08);
SPI_SendByte(0x20); // 设置VS1003b 进入音频测试状态
while(!DREQ);
xCS_Dis();
xDCS_En();
while(!DREQ);
SPI_SendByte(0x53); // 开始
SPI_SendByte(0xEF);
SPI_SendByte(0x6E);
SPI_SendByte(0x24); // 改变发送数值可改变声音频率
SPI_SendByte(0x00);
SPI_SendByte(0x00);
SPI_SendByte(0x00);
SPI_SendByte(0x00);
delayms(350);
while(!DREQ);
SPI_SendByte(0x45); // 退出
SPI_SendByte(0x78);
SPI_SendByte(0x69);
SPI_SendByte(0x74);
SPI_SendByte(0x00);
SPI_SendByte(0x00);
SPI_SendByte(0x00);
SPI_SendByte(0x00);
delayms(350);
xDCS_Dis();
}
*/
//---------------------------------------------------
// 函数名:VS1003b_Read
// 功 能:读VS1003b状态
// 参 数:
// 返回值:
//---------------------------------------------------
uint VS1003b_Read(uchar Regadd)
{
uint temp;
xCS_En();
while(!DREQ);
SPI_SendByte(VS_Read);
SPI_SendByte(Regadd);
temp =((uint16)SPI_SendByte(0xFF))<<8;
temp|= (uint16)SPI_SendByte(0xFF);
xCS_Dis();
return temp;
}
//---------------------------------------------------
// 函数名:VS_VOL_up
// 功 能:VS1003B 音量加
// 参 数:
// 返回值:
//---------------------------------------------------
void VS_VOL_up()
{
uint temp;
temp =VS1003b_Read(VS_Vol);
temp =(temp+8)<<8;
temp+=8;
xCS_En();
while(!DREQ);
SPI_SendByte(VS_Write);
SPI_SendByte(VS_Vol);
SPI_SendByte(temp>>8);
SPI_SendByte(temp);
xCS_Dis();
}
//---------------------------------------------------
// 函数名:VS_VOL_down
// 功 能:VS1003B 音量减
// 参 数:
// 返回值:
//---------------------------------------------------
void VS_VOL_down()
{
uint temp;
temp =VS1003b_Read(VS_Vol);
temp =(temp-8)<<8;
temp-=8;
xCS_Dis();
while(!DREQ);
SPI_SendByte(VS_Write);
SPI_SendByte(VS_Vol);
SPI_SendByte(temp>>8);
SPI_SendByte(temp);
xCS_Dis();
}
//---------------------------------------------------
// 函数名:VS1003b_Reset
// 功 能:VS1003B 软复位
// 参 数:
// 返回值:
//---------------------------------------------------
void VS1003b_Reset()
{
xDCS_Dis();
xCS_En();
while(!DREQ); // 等待VS1003 就绪
SPI_SendByte(VS_Write);
SPI_SendByte(VS_Mode);
SPI_SendByte(0x08);
SPI_SendByte(0x04);
xCS_Dis();
delayms(5); // 延时需大于1.35ms
}
//---------------------------------------------------
// 函数名:VS1003b_init
// 功 能:VS1003B 初始化
// 参 数:
// 返回值:
//---------------------------------------------------
void VS1003b_init()
{
xRST_En(); // 硬件复位
xCS_Dis();
xDCS_Dis();
delayms(5);
xRST_Dis();
delayms(20); //** 延时不可少于1ms **//
xCS_En();
while(!DREQ); //等待VS1003 就绪
SPI_SendByte(VS_Write);
SPI_SendByte(VS_Clk);
SPI_SendByte(0xE0); //0x9800
SPI_SendByte(0x00);
SPI_speed=0x05; // MCU VS1003b_SPI CLK
delayms(2);
while(!DREQ);
SPI_SendByte(VS_Write);
SPI_SendByte(VS_Audata);
SPI_SendByte(0xBB); //采样率48k,立体声
SPI_SendByte(0x81);
while(!DREQ);
SPI_SendByte(VS_Write);
SPI_SendByte(VS_Bass);
SPI_SendByte(0x00); //设置重低音
SPI_SendByte(0xF6);
while(!DREQ);
SPI_SendByte(VS_Write);
SPI_SendByte(VS_Vol); //设置音量
SPI_SendByte(0x80); // L-CH
SPI_SendByte(0x80); // R-CH
xCS_Dis();
// VS1003b_Reset();
/* while(!DREQ);
SPI_SendByte(0x00); // send 4 bytes , Enabled SPI Bus
SPI_SendByte(0x00);
SPI_SendByte(0x00);
SPI_SendByte(0x00);*/
}
//-----------------------------------------------------------
// End of File
//----------------------------------------------------------- |
|