1

Тема: TDA7313

Данный контент доступен только зарегистрированным пользователям.

TDA7313.h

// liman324@yandex.ru rcl-radio.ru


#ifndef TDA7313_H
#define TDA7313_H

#define TDA7313_address 0x44 // адрес 0b10001000 7 - bit


#include <Arduino.h>
class TDA7313
{
  public:
    TDA7313();
        void setVolume(int vol); //   0...63     
	void setAttLR(int att_lr); // 0..31       
	void setAttRR(int att_rr); // 0..31     
        void setAttLF(int att_lf); // 0..31         
        void setAttRF(int att_rf); // 0..31 
        void setSwitch(int input, int loud, int usil); // 0..2 , 1-on 0-off , 0...3 (0...11.25dB)
        void setBass(int bass); // -7...+7
        void setTreble(int treb); //  -7...+7
	
  private:
	void writeWire(char a);
};
	
#endif //TDA7313_H

TDA7313.cpp

#include <Arduino.h>
#include <Wire.h>
#include "TDA7313.h"

TDA7313::TDA7313(){
	Wire.begin();
}

void TDA7313::setVolume(int vol){
  vol = 63 - vol;
  writeWire(vol);
}

void TDA7313::setAttLF(int att_lf){
  att_lf = 0b10000000 + att_lf;
  writeWire(att_lf);
}

void TDA7313::setAttRF(int att_rf){
  att_rf = 0b10100000 + att_rf;
  writeWire(att_rf);
}

void TDA7313::setAttLR(int att_lr){
  att_lr = 0b11000000 + att_lr;
  writeWire(att_lr);
}

void TDA7313::setAttRR(int att_rr){
  att_rr = 0b11100000 + att_rr;
  writeWire(att_rr);
}

void TDA7313::setSwitch(int input, int loud, int usil){
  switch (input){
    case 0:input = 0b00000000;break;
    case 1:input = 0b00000001;break;
    case 2:input = 0b00000010;break;
  }
  switch (loud){
    case 1:loud = 0b00000000;break;
    case 0:loud = 0b00000100;break;
  }
  switch (usil){
    case 0:usil = 0b00011000;break;
    case 1:usil = 0b00010000;break;
    case 2:usil = 0b00001000;break;
    case 3:usil = 0b00000000;break; 
  }
  int sw = 0b01000000 + input + loud + usil;
  writeWire(sw);
}

void TDA7313::setBass(int bass){
  switch (bass){
    case -7: bass = 0b01100000;break;
    case -6: bass = 0b01100001;break;
    case -5: bass = 0b01100010;break;
    case -4: bass = 0b01100011;break; 
    case -3: bass = 0b01100100;break;
    case -2: bass = 0b01100101;break;
    case -1: bass = 0b01100110;break;
    case 0:  bass = 0b01100111;break;
    case 1:  bass = 0b01101110;break;
    case 2:  bass = 0b01101101;break;
    case 3:  bass = 0b01101100;break;
    case 4:  bass = 0b01101011;break;
    case 5:  bass = 0b01101010;break;
    case 6:  bass = 0b01101001;break;
    case 7:  bass = 0b01101000;break;
  }
  writeWire(bass);
}

void TDA7313::setTreble(int treb){
  switch (treb){
    case -7: treb = 0b01110000;break;
    case -6: treb = 0b01110001;break;
    case -5: treb = 0b01110010;break;
    case -4: treb = 0b01110011;break; 
    case -3: treb = 0b01110100;break;
    case -2: treb = 0b01110101;break;
    case -1: treb = 0b01110110;break;
    case 0:  treb = 0b01111111;break;
    case 1:  treb = 0b01111110;break;
    case 2:  treb = 0b01111101;break;
    case 3:  treb = 0b01111100;break;
    case 4:  treb = 0b01111011;break;
    case 5:  treb = 0b01111010;break;
    case 6:  treb = 0b01111001;break;
    case 7:  treb = 0b01111000;break;
  }
  writeWire(treb);
}

void TDA7313::writeWire(char a){
  Wire.beginTransmission(TDA7313_address);
  Wire.write (a);
  Wire.endTransmission();
}

TDA7313_test.ino

#include <Wire.h>
#include <TDA7313.h>
  TDA7313 tda;
  
void setup(){ 
  Serial.begin(9600);Wire.begin();
  audio();
}

void loop(){}

void audio(){
  tda.setVolume(55); // громкость 0...63
  tda.setAttLR(0);   // аттенюатор LR 0...31
  tda.setAttRR(0);   // аттенюатор RR 0...31
  tda.setAttLF(0);   // аттенюатор LF 0...31
  tda.setAttRF(0);   // аттенюатор RF 0...31
  tda.setSwitch(0,0,0); // вход 0...2, тонкомпенсация 1 вкл 0 выкл, усиление 0...3
  tda.setBass(0);    // тембр НЧ -7...+7
  tda.setTreble(0);  // тембр ВЧ -7...+7
}