wangine
Joined: 07 Jul 2009 Posts: 98 Location: Curtea de Arges, Romania
|
PT2257 audio controller I2C protocol |
Posted: Mon Aug 02, 2010 12:45 pm |
|
|
Greeting
Below we have a driver written by me for an IC (volume control)
the SDA / SCL volume control that lets the 79 decades
It is written for two channels simultaneously but can write and balance
Code: | ////////////////////////////////////////////////////////////////
// Driver sda/ Scl volum PT2257 //
// Version 0.1 //
// Writer Tanase Bogdan //
// Chip information //
// Pin 1 == Left In //
// Pin 2 == Left Out //
// Pin 3 == VSS //
// Pin 4 == SDA //
// Pin 5 == SCL //
// Pin 6 == VDD (3 to 9V) //
// Pin 7 == Right Out //
// Pin 8 == Right In //
////////////////////////////////////////////////////////////////
// Require pullup rezistor an SDA/SCL 10k
#define zeci_max 0b11100000
#define zeci_min 0b11100111
#define unit_max 0b11010000
#define unit_min 0b11011001
volatile unsigned int zeci, unit, ref, level;
void vol_send_data(void);
//////////////////////////////////////////////////////////////////
// functie ce desparte valoarea volumului in zeci si unitati
// value function that divides the volume into tens and units
void decode_niv (unsigned int vol)
{
if(vol >= 79)
{
vol = 79;
}
//**********************************
zeci = vol/10; // cifra zecilor
unit = vol%10; // cifra unitatilor
vol_send_data();
}
//
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
// function that allows data transmission chip
void vol_send_data()
{
i2c_start();
i2c_write(0x88); // Adress chip
i2c_write(0b11100000 + zeci); //Write tens value
i2c_write(0b11010000 + unit); //Write units value
i2c_stop();
}
//
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// The first function called in the program
void volume ()
{
if(0x14 == ref) // ref is reference value for comparation tast
{
if(level <= 79) // Maxim level is -79dB
level++;
}
//****************************
if(0x13 == ref)
{ if(level >= 1)
level--;
}
decode_niv(level);
}
//
/////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
// mute functions
void muting ()
{
if(0x15 == ref)
{
i2c_start();
i2c_write(0x88); // Adress chip
i2c_write(0b0111110001); //Write muting value
i2c_stop();
}
}
/////////////////////////////////////////////////////////////////// |
all the best |
|