1

Тема: R2S15900SP

Description
The R2S15900SP is an optimum audio signal processor IC for TV. It has a 5ch input selector, surround/pseudo stereo tone control(2band), output gain control and 2ch master volume. It can control all of these functions with I2 C bus.

Features
• Volume 0 to –84dB, –∞/ 1dB step | Each channel is independence control.
• 5 input selector + MUTE
• 2 Rec output
• Tone control Bass: –15dB to +15dB/ 1dB step | Treble: –15dB to +15dB/ 1dB step
• Surround <Low/ High> / Pseudo Stereo
• Mode selector Bypass/ Tone / Tone & Pseudo Stereo or Surround
• Output gain control 0dB/ +4.5dB
• I2C-BUS control
• Package 28pin SOP

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

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

R2S15900SP.h

// Алксандр Лиман
// liman324@yandex.ru

#ifndef R2S15900SP_H
#define R2S15900SP_H
#define R2S15900SP_address 0b1000001 

#define R2S15900SP_VOL_L   0x00
#define R2S15900SP_VOL_R   0x01
#define R2S15900SP_INPUT   0x02
#define R2S15900SP_BASS    0x03
#define R2S15900SP_TREB    0x04

#include <Arduino.h>
class R2S15900SP
{
  public:
    R2S15900SP();
              
        void setVol_l(int vol_l);  // volume left >> int 84...0 === -84...0 dB
        void setVol_r(int vol_r);  // volume_right >> int 84...0 === -84...0 dB
        void setIn(int in, int gain, int mute);     
             // input >> int 0 === all off | int 1...5 === input 1...5 
             // gain >> int 0...1 === 0 dB...+4.5 dB
             // mute >> int 0...1 === mute on...mute off
        void set_Bass(int surr, int mode, int bass);
             // surround mode >> int 0...1 === low level...high level
             // mode selector >> int 0...3 === bypass tone tone&Pseudo_stereo tone&Surround
             // tone control bass >> int -15...15 === -15dB...+15dB
        void set_Treb(int treb);   // tone control treble >> int -15...15 === -15dB...+15dB

  private:
	void writeWire(char a, char b);
};
	
#endif //R2S15900SP_H

R2S15900SP.cpp

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

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

void R2S15900SP::setVol_l(int vol_l){
      byte vol_l10 = vol_l/10;
      byte vol_l1 = vol_l%10;
  writeWire(R2S15900SP_VOL_L, (vol_l10 << 4) + vol_l1);
}

void R2S15900SP::setVol_r(int vol_r){
      byte vol_r10 = vol_r/10;
      byte vol_r1 = vol_r%10;
  writeWire(R2S15900SP_VOL_R, (vol_r10 << 4) + vol_r1);
}

void R2S15900SP::setIn(int in, int gain, int mute){
      switch(in){
       case 0: in = 0b00011;break;
       case 1: in = 0b00111;break;
       case 2: in = 0b01011;break;
       case 3: in = 0b01111;break;
       case 4: in = 0b10011;break;
       case 5: in = 0b10111;break;
}
  writeWire(R2S15900SP_INPUT, (in << 3) + (gain << 2) + (mute << 1) + mute);
}

void R2S15900SP::set_Bass(int surr, int mode, int bass){
       if(bass >= 0){bass = bass + 0b10000;}
       if(bass <  0){bass = abs(bass);}
  writeWire(R2S15900SP_BASS, (bass << 3) + (surr << 2) + mode);
}

void R2S15900SP::set_Treb(int treb){
       if(treb >= 0){treb = treb + 0b10000;}
       if(treb <  0){treb = abs(treb);}
  writeWire(R2S15900SP_TREB, (treb << 3));
}

void R2S15900SP::writeWire(char a, char b){
  Wire.beginTransmission(R2S15900SP_address);
  Wire.write(a);
  Wire.write(b);
  Wire.endTransmission();
}

test.ino

#include <Wire.h>
#include <R2S15900SP.h>
  R2S15900SP r2s;

void setup() {
  audio();
}

void loop() {
  
}

void audio(){             
  r2s.setVol_l(0);  // volume left >> int 84...0 === -84...0 dB
  r2s.setVol_r(0);  // volume_right >> int 84...0 === -84...0 dB
  r2s.setInput(1, 0, 0);     
             // input >> int 0 === all off | int 1...5 === input 1...5 
             // gain >> int 0...1 === 0 dB...+4.5 dB
             // mute >> int 0...1 === mute off...mute on
  r2s.set_Bass(0, 0, 0);
             // surround mode >> int 0...1 === low level...high level
             // mode selector >> int 0...3 === bypass tone tone&Pseudo_stereo tone&Surround
             // tone control bass >> int -15...15 === -15dB...+15dB
  r2s.set_Treb(0);   // tone control treble >> int -15...15 === -15dB...+15dB
}

Скетч использует 2054 байт (6%) памяти устройства. Всего доступно 32256 байт.
Глобальные переменные используют 219 байт (10%) динамической памяти, оставляя 1829 байт для локальных переменных. Максимум: 2048 байт.

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

2

Re: R2S15900SP

#define CLK     9   //  ENCODER 
#define DT      8   //  ENCODER 
#define SW     10   //  ENCODER 

#include <Wire.h>
#include <EEPROM.h>
#include <MsTimer2.h>                    // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip
#include <R2S15900SP.h>
#include <Encoder.h>                     // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip
#include <LiquidCrystal_I2C.h>           // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=45&download=1 
 Encoder myEnc(CLK, DT);
 R2S15900SP r2s;
 LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей 
 

    byte v1[8] = {0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07};
    byte v2[8] = {0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00};      
    byte v3[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F};
    byte v4[8] = {0x1F,0x1F,0x00,0x00,0x00,0x00,0x1F,0x1F};
    byte v5[8] = {0x1C,0x1C,0x00,0x00,0x00,0x00,0x1C,0x1C};
    byte v6[8] = {0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C};
    byte v7[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07};
    byte v8[8] = {0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00};
    unsigned long times,times1,oldPosition  = -999,newPosition;
    int menu,w,w2,vol,mut,a[3],in,bas,treb;
    byte i,d1,d2,d3,d4,d5,d6,e1,e2,e3;
  

void setup() {
  Serial.begin(9600);MsTimer2::set(3, to_Timer);MsTimer2::start();
  pinMode(SW,INPUT);
  lcd.init();lcd.backlight();
  lcd.createChar(1, v1);lcd.createChar(2, v2);lcd.createChar(3, v3);lcd.createChar(4, v4);lcd.createChar(5, v5);lcd.createChar(6, v6);lcd.createChar(7, v7);lcd.createChar(8, v8);
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении 
  vol = EEPROM.read(0);in = EEPROM.read(1);bas = EEPROM.read(2)-15;treb = EEPROM.read(3)-15;
  lcd.setCursor(0,0);lcd.print("   R2S15900SP   ");
  delay(1000);
  audio();
  lcd.clear();
}

void loop() {
  if(digitalRead(SW)==LOW){menu++;if(menu>2){menu=0;};delay(200);lcd.clear();w=1;times=millis();w2=1;}
  
  /// VOLUME ///////////////////////////////////////////////////
 if(menu==0){
   if (newPosition != oldPosition){oldPosition = newPosition;
     vol=vol-newPosition;myEnc.write(0);newPosition=0;w=1;times=millis();w2=1;
     if(vol>84){vol=84;}if(vol<0){vol=0;}
     audio();}
 
     lcd.setCursor(0,0);
       if(mut==1){lcd.print("MUTE    ");}
       if(mut==0){lcd.print("VOLUME  ");}  
     lcd.setCursor(0,1);lcd.print("IN ");lcd.print(in);
     
 
if(w2==1){w2=0;
     
     a[0]=(84-vol)/10;a[1]=(84-vol)%10;
      for(i=0;i<2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=12,e2=13,e3=14;break;
        }
      switch(a[i]){
        case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;
        case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
        case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;
        case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
        case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;
        case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
        case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;
        case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
        case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;
        case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;
    }
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);
 }} 
 }

  /// bas ///////////////////////////////////////////////////
 if(menu==1){
   if (newPosition != oldPosition){oldPosition = newPosition;
     bas=bas+newPosition;myEnc.write(0);newPosition=0;w=1;times=millis();w2=1;
     if(bas>15){bas=15;}if(bas<-15){bas=-15;}
     audio();}
 
     lcd.setCursor(0,0);
     lcd.print("BASS  ");
     if(bas<0){lcd.setCursor(8,1);lcd.write((uint8_t)0);}else{lcd.setCursor(8,1);lcd.print(" ");}
 
if(w2==1){w2=0;
     
     a[0]=abs(bas)/10;a[1]=abs(bas)%10;
      for(i=0;i<2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=12,e2=13,e3=14;break;
        }
      switch(a[i]){
        case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;
        case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
        case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;
        case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
        case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;
        case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
        case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;
        case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
        case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;
        case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;
    }
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);
 }} 
 }

 /// TREB ///////////////////////////////////////////////////
 if(menu==2){
   if (newPosition != oldPosition){oldPosition = newPosition;
     treb=treb+newPosition;myEnc.write(0);newPosition=0;w=1;times=millis();w2=1;
     if(treb>15){treb=15;}if(treb<-15){treb=-15;}
     audio();}
 
     lcd.setCursor(0,0);
     lcd.print("TREBLE  ");
     if(treb<0){lcd.setCursor(8,1);lcd.write((uint8_t)0);}else{lcd.setCursor(8,1);lcd.print(" ");}
 
if(w2==1){w2=0;
     
     a[0]=abs(treb)/10;a[1]=abs(treb)%10;
      for(i=0;i<2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=12,e2=13,e3=14;break;
        }
      switch(a[i]){
        case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;
        case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
        case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;
        case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
        case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;
        case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
        case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;
        case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
        case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;
        case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;
    }
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);
 }} 
 }


 //// EEPROM ///////////////////////////////////////
 if(millis()-times>5000 && w==1){w=0;EEPROM.update(0,vol);EEPROM.update(1,in);EEPROM.update(2,bas+15);EEPROM.update(3,treb+15);menu=0;lcd.clear();w2=1;}
 delay(10);
  
}

void to_Timer(){newPosition = myEnc.read()/4;}
void audio(){             
  r2s.setVol_l(vol);  // volume left >> int 84...0 === -84...0 dB
  r2s.setVol_r(vol);  // volume_right >> int 84...0 === -84...0 dB
  r2s.setIn(1, 0, 1);     
             // input >> int 0 === all off | int 1...5 === input 1...5 
             // gain >> int 0...1 === 0 dB...+4.5 dB
             // mute >> int 0...1 === mute on...mute off
  r2s.set_Bass(1, 1, bas);
             // surround mode >> int 0...1 === low level...high level
             // mode selector >> int 0...3 === bypass tone tone&Pseudo_stereo tone&Surround
             // tone control bas >> int -15...15 === -15dB...+15dB
  r2s.set_Treb(treb);   // tone control treble >> int -15...15 === -15dB...+15dB
}