📄 pt2322s.c
字号:
#include "config.h"
#define IN_PT2322S
#define PT2322_I2CADDRESS 0x88 // PT2322的I2C的地址
// --------------------------------------------------------------------------------
// ------------ 主音量的控制 -----------------------------------------------------
unsigned char idata master_volume=0x00; //主音量的值
unsigned char idata pt2322_buffer[5]; //I2C发送的buffer,不包含子地址,一般为2个字节而已
/* ------------------------------------------------------------------
FUNCTION DEFINITION
MSB LSB
B7 B6 B5 B4 B3 B2 B1 B0 Function
0 0 0 0 x x x x No function
0 0 0 1 E3 E2 E1 E0 Front left channel volume TRIM control
0 0 1 0 E3 E2 E1 E0 Front right channel volume TRIM control
0 0 1 1 E3 E2 E1 E0 Center channel volume TRIM control
0 1 0 0 E3 E2 E1 E0 Rear left channel volume TRIM control
0 1 0 1 E3 E2 E1 E0 Rear right channel volume TRIM control
0 1 1 0 E3 E2 E1 E0 Subwoofer volume TRIM control
0 1 1 1 I1 I0 J1 J0 Function select
1 0 0 0 x x x x No function
1 0 0 1 G3 G2 G1 G0 Bass tone control
1 0 1 0 K3 K2 K1 K0 Middle tone control
1 0 1 1 H3 H2 H1 H0 Treble tone control
1 1 0 0 0 C2 C1 C0 Input SW
1 1 0 1 A3 A2 A1 A0 Master volume control (-1dB Step)
1 1 1 0 0 B2 B1 B0 Master volume control (-10dB Step)
FUNCTION SELECT BITS
I1=0 Mute Off I1=1 Mute On
I0=0 3D On I0=1 3D Off
J1=0 Tone Control ON J1=1 TONE Defeat
J0=0 No Function J0=1 No Function
MASTER VOLUME CONTROL BITS // 主音量的调节
A3 A2(B2) A1(B1) A0(B0) Attenuation (dB)
0 0 0 0 0 (0)
0 0 0 1 -1 (-10)
0 0 1 0 -2 (-20)
0 0 1 1 -3 (-30)
0 1 0 0 -4 (-40)
0 1 0 1 -5 (-50)
0 1 1 0 -6 (-60)
0 1 1 1 -7 (-70)
1 0 0 0 -8 (x)
1 0 0 1 -9 (x)
Note: A=-1dB/Step, B=-10dB/Step
TONE CONTROL BITS //音调的调节
G3/K3/H3 G2/K2/H2 G1/K1/H1 G0/K0/H0 Attenuation (dB)
0 0 0 0 -14
0 0 0 1 -12
0 0 1 0 -10
0 0 1 1 -8
0 1 0 0 -6
0 1 0 1 -4
0 1 1 0 -2
0 1 1 1 0
1 0 0 0 +14
1 0 0 1 +12
1 0 1 0 +10
1 0 1 1 +8
1 1 0 0 +6
1 1 0 1 +4
1 1 1 0 +2
1 1 1 1 0
Note: G=Bass, K=Middle, H=Treble
CHANNEL TRIM VOLUME CONTROL BITS
E3 E2 E1 E0 Attenuation (dB)
0 0 0 0 0
0 0 0 1 -1
0 0 1 0 -2
0 0 1 1 -3
0 1 0 0 -4
0 1 0 1 -5
0 1 1 0 -6
0 1 1 1 -7
1 0 0 0 -8
1 0 0 1 -9
1 0 1 0 -10
1 0 1 1 -11
1 1 0 0 -12
1 1 0 1 -13
1 1 1 0 -14
1 1 1 1 -15
------------------------------------------------------------------*/
// PT2322S的初始化程序
void pt2322s_initialize(void)
{
#if EEPROM_USING
eeprom_operatemode=0x01; //将要记忆的内容写入EEPROM
eeprom_process(); //取得音量值和音乐模式
#endif
pt2322_buffer[0]=0xff; //Clear Register
PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x01); // 关于mute功能的控制
pt2322_buffer[0]=0xc7; //开放6个通道
PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x01); // 开放6通道
mastervolume_control();
musicmode_control();
pt2322_mutecontrol(0x00);
}
// ---音量0为最大, -79DB为最小
void mastervolume_control(void)
{unsigned char idata i=0x00;
if(master_volume>79)
master_volume=79; //不容许超过音量限制
pt2322_buffer[0]=0xe0+(master_volume/10);
pt2322_buffer[1]=0xd0+(master_volume%10);
//PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x02); //发送音量的控制
if(PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x02)==0x00) //; // 发送音量的控制
{//rs232_senddata(0x86);
//rs232_senddata(0x01);
}
else
{//rs232_senddata(0x86);
//rs232_senddata(0x02);
}
}
// --------------------------------------------------------------------------------
// ----模式的选择,通过TRIM的控制,以及3D效果的控制来实现
unsigned char idata music_mode=0x00; //PT2322的音响效果模式
unsigned char idata function_mode=0x00; //PT2322的模式选择
#define MAX_MUSIC_MODE 0x04
unsigned char code pt2322_trim_code[MAX_MUSIC_MODE][7]=
{// Front left, Front right,Center,Rear left,Rear right,Subwoofer,3D ON/OFF
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, // mode 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // mode 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, // mode 2
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // mode 3
};
void musicmode_control(void)
{
pt2322_mutecontrol(0x00);
if(music_mode >= MAX_MUSIC_MODE)
music_mode = 0x00;
if(music_mode==0x00)
{LED1=0x00;LED2=0x01;LED3=0x01;LED4=0x01;}
else if(music_mode==0x01)
{LED1=0x01;LED2=0x00;LED3=0x01;LED4=0x01;}
else if(music_mode==0x02)
{LED1=0x01;LED2=0x01;LED3=0x00;LED4=0x01;}
else if(music_mode==0x03)
{LED1=0x01;LED2=0x01;LED3=0x01;LED4=0x00;}
pt2322_buffer[0]=0x10+pt2322_trim_code[music_mode][0]&0x0f;
PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x01); // Front left channel volume TRIM control
pt2322_buffer[0]=0x20+pt2322_trim_code[music_mode][1]&0x0f;
PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x01); // Front right channel volume TRIM control
pt2322_buffer[0]=0x30+pt2322_trim_code[music_mode][2]&0x0f;
PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x01); // Center channel volume TRIM control
pt2322_buffer[0]=0x40+pt2322_trim_code[music_mode][3]&0x0f;
PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x01); // Rear left channel volume TRIM control
pt2322_buffer[0]=0x50+pt2322_trim_code[music_mode][4]&0x0f;
PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x01); // Rear right channel volume TRIM control
pt2322_buffer[0]=0x60+pt2322_trim_code[music_mode][5]&0x0f;
PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x01); // Subwoofer volume TRIM control
// ------- 3D开放的问题 -------
if(pt2322_trim_code[music_mode][5]!=0x00)
{function_mode|=0x04; //开放3D功能
}
else
{function_mode=function_mode&0x0b; //屏蔽3D功能
}
pt2322_buffer[0]=0x70+function_mode&0x0f;
if(PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x01)==0x00) //; // 关于3D功能的控制
{//rs232_senddata(0x85);
//rs232_senddata(0x01);
}
else
{//rs232_senddata(0x85);
//rs232_senddata(0x02);
}
}
void pt2322_mutecontrol(unsigned char mute_onoff)
{if(mute_onoff!=0x00)
{function_mode|=0x08; //mute on
MUTE_CTL=0x01; //静音 高为截至
}
else
{function_mode=function_mode&0x07; //mute off
MUTE_CTL=0x00; // 低开放音频
}
pt2322_buffer[0]=0x70+(function_mode&0x0f);
PSendStr(PT2322_I2CADDRESS,pt2322_buffer,0x01); // 关于mute功能的控制
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -