📄 sta013.c
字号:
//初始化端口
void STA013_Ini(void)
{
DDRA|=(1<<RST); //RST为输出
DDRA|=(1<<STA013_Chip_Select); //STA013_Chip_Select为输出
STA013_Disable();
}
//STA013初始化
uint8 sta_Init(void)
{
//复位
sta_Reset();
//识别STA013
if(sta_ReadDevice(STA_REG_IDENT,device1) != STA_IDENT)
{
return 1;
}
//配置STA013
sta_DownloadUpdate();
sta_StartDecoder();
return 0;
}
//=======================================================================
//STA013复位
void sta_Reset(void)
{
PORTA|=1<<RST; //RST低为复位
PORTA&=~(1<<RST);
Delay_us(1200);
PORTA|=1<<RST;
}
//=======================================================================
//写配置文件
void sta_DownloadUpdate(void)
{
unsigned int i;
i = 0;
do
{
i2c_Write(STA013_UpdateData[i],device1, STA013_UpdateData[i+1]);
i+=2;
}
while(STA013_UpdateData[i] != 0xff);
}
/*
//=======================================================================
//设置音调
void sta_SetTone(uint8 bassEnh,uint16 bassFreq, uint8 trebleEnh, uint16 trebleFreq)
{
//设置低音增益
i2c_Write(STA_REG_BASS_FREQUENCY_LOW,device1, (bassFreq ) & 0xFF );
i2c_Write(STA_REG_BASS_FREQUENCY_HIGH,device1, (bassFreq>>8) & 0xFF );
//注意界限
bassEnh = MIN(bassEnh,MAX_BASS_ENHANCE);
bassEnh = MAX(bassEnh,MIN_BASS_ENHANCE);
i2c_Write(STA_REG_BASS_ENHANCE,device1, bassEnh);
//设置高音增益
i2c_Write(STA_REG_TREBLE_FREQUENCY_LOW,device1, (trebleFreq ) & 0xFF );
i2c_Write(STA_REG_TREBLE_FREQUENCY_HIGH,device1, (trebleFreq>>8) & 0xFF );
//注意界限
trebleEnh = MIN(trebleEnh,MAX_TREBLE_ENHANCE);
trebleEnh = MAX(trebleEnh,MIN_TREBLE_ENHANCE);
i2c_Write(STA_REG_TREBLE_ENHANCE,device1, trebleEnh);
//
i2c_Write( STA_REG_TONE_ATTEN,device1, MAX(bassEnh,trebleEnh) );
}
*/
//=======================================================================
//配置STA013并开始解压
void sta_StartDecoder(void)
{
//静音
i2c_Write(STA_REG_MUTE,device1, 0x01);
//软件复位
i2c_Write(STA_REG_SOFT_RESET,device1, 0x01);
// 配置DAC输出--Configure PLL for MP3 rates
i2c_Write(STA_REG_PCMDIVIDER,device1, 0x02); // 32-bit mode, O_FAC = 384
i2c_Write(STA_REG_PCMCONF,device1, 0x33); // 24-bit mode
//配置PLL
i2c_Write(STA_REG_PLLFRAC_441_H,device1, 124);
i2c_Write(STA_REG_PLLFRAC_441_L,device1, 0);
i2c_Write(STA_REG_PLLFRAC_H,device1, 64);
i2c_Write(STA_REG_PLLFRAC_L,device1, 0);
i2c_Write(STA_REG_MFSDF_441,device1, 9);
i2c_Write(STA_REG_MFSDF,device1, 8);
//配置界面等
i2c_Write(STA_REG_PLLCTL_2,device1, 0x0C);
i2c_Write(STA_REG_PLLCTL_3,device1, 0x00);
//i2c_Write(STA_REG_PLLCTL_1,device1, 0x01);
i2c_Write(STA_REG_SCLK_POL,device1, 0x00); // data sampled on rising edge
i2c_Write(STA_REG_REQ_POL,device1, 0x01); // REQ line active high
i2c_Write(STA_REG_DATA_REQ_ENABLE,device1, 0x04);
i2c_Write(STA_REG_PLLCTL_1,device1, 0xA1);
//STA013开始运行
i2c_Write(STA_REG_RUN,device1, 0x01);
i2c_Write(STA_REG_PLAY,device1, 0x01);
i2c_Write(STA_REG_MUTE,device1, 0x00);
}
/*
//=======================================================================
//停止解压
void sta_StopDecoder(void)
{
//静音
i2c_Write(STA_REG_MUTE,device1, 0x01);
//软件复位
i2c_Write(STA_REG_SOFT_RESET,device1, 0x01);
i2c_Write(STA_REG_SOFT_RESET,device1, 0x00);
}
*/
//=======================================================================
//暂停解压
void sta_PauseDecoder(void)
{
//静音
//i2c_Write(STA_REG_MUTE,device1, 0x01);
//停止
i2c_Write(STA_REG_PLAY,device1, 0x00);
}
//=======================================================================
//恢复解压
void sta_ResumeDecoder(void)
{
//开始解压
i2c_Write(STA_REG_PLAY,device1, 0x01);
//放音
//i2c_Write(STA_REG_MUTE,device1, 0x00);
}
//=======================================================================
//设置音量
void sta_SetVolume(uint8 volume, uint8 balance)
{
char attenL, attenR;
/*
// volume is expected as 0-100 value
// Note:
// #define MIN_VOLUME_ATTENUATION 0
// #define MAX_VOLUME_ATTENUATION 96
if( balance > 0)
{ // balance to the left, attenuate right
attenL = (100 - volume);
attenR = (100 - volume) - (balance);
}
else
{ // balance to the right, attenuate left
attenL = (100 - volume) + (balance);
attenR = (100 - volume);
}
*/
attenL = (100 - volume);
attenR = (100 - volume);
// respect limits
attenL = MIN(attenL,MAX_VOLUME_ATTENUATION);
attenL = MAX(attenL,MIN_VOLUME_ATTENUATION);
attenR = MIN(attenR,MAX_VOLUME_ATTENUATION);
attenR = MAX(attenR,MIN_VOLUME_ATTENUATION);
// set volume
i2c_Write(STA_REG_DLA,device1, attenL);
i2c_Write(STA_REG_DLB,device1, MAX_VOLUME_ATTENUATION);
i2c_Write(STA_REG_DRA,device1, attenR);
i2c_Write(STA_REG_DRB,device1, MAX_VOLUME_ATTENUATION);
}
/*
//=======================================================================
//设置音调
void sta_SetTone(uint8 N)
{ // TRLow TRHigh BSLow BSHigh TEhnc BSEnhc
//设置高音增益
i2c_Write(STA_REG_TREBLE_FREQUENCY_LOW,device1,BassTrebleTable[N][0]);
i2c_Write(STA_REG_TREBLE_FREQUENCY_HIGH,device1,BassTrebleTable[N][1]);
//设置低音增益
i2c_Write(STA_REG_BASS_FREQUENCY_LOW,device1,BassTrebleTable[N][2]);
i2c_Write(STA_REG_BASS_FREQUENCY_HIGH,device1,BassTrebleTable[N][3]);
i2c_Write(STA_REG_TREBLE_ENHANCE,device1,BassTrebleTable[N][4]);
i2c_Write(STA_REG_BASS_ENHANCE,device1,BassTrebleTable[N][5]);
//
i2c_Write( STA_REG_TONE_ATTEN,device1, MAX(BassTrebleTable[N][4],BassTrebleTable[N][5]) );
}
*/
//=======================================================================
//检测STA013的REQ
uint8 sta_Demand(void)
{
return (PINA & (1<<REQ));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -