1

Тема: LC75412

// LC75412
#define CE 3 // pin 24
#define DI 2 // pin 25
#define CL 4 // pin 26
#define MUTE 5

void setup(){
  Serial.begin(9600);
  pinMode(CE,OUTPUT);pinMode(DI,OUTPUT);pinMode(CL,OUTPUT);pinMode(MUTE,OUTPUT);
  digitalWrite(CL,LOW);digitalWrite(CE,LOW);digitalWrite(DI,LOW);
  delay(500);digitalWrite(MUTE,1);
  //      in  gain vol bass treb fader ch  r/f loud zero zero_s
    audio(0,  0,    0,  0,   0,   0,   3,  0,  0,   0,   3);
  }

void loop(){
    
  delay(1000);
  }


void audio(int in, int gain, int vol, int bass, int treb, int fader, int ch, int rf, int loud, int zero, int zero_s){
  digitalWrite(CL,LOW);
  digitalWrite(CE,LOW);
    byte addr = 0x81;                                         
 for(int i = 7; i >= 0; i--){
   digitalWrite(CL,LOW);
   digitalWrite(DI, (addr >> i) & 0x01);Serial.print((addr >> i) & 0x01);
   digitalWrite(CL,HIGH);
   }
   Serial.print(" "); 
   digitalWrite(CL,LOW);
   digitalWrite(CE,HIGH);
   digitalWrite(CL,LOW);

/// input control //////////////////////////////////////
// ch1...ch6 = byte 0...5 --- 0...2 bit
for(int i = 0; i <= 2; i++){
        digitalWrite(CL,LOW);
        switch(i){
         case 0: digitalWrite(DI, (in & 0b001)>>0);Serial.print((in & 0b001)>>0);break;
         case 1: digitalWrite(DI, (in & 0b010)>>1);Serial.print((in & 0b010)>>1);break;
         case 2: digitalWrite(DI, (in & 0b100)>>2);Serial.print((in & 0b100)>>2);break;
        } 
        digitalWrite(CL,HIGH);
        }     
        Serial.print(" ");

/// 3 bit to 0 normal   
        digitalWrite(CL,LOW);
        digitalWrite(DI, 0);Serial.print(0);Serial.print(" ");
        digitalWrite(CL,HIGH); 

/// input gain conrtol /////////////////////////////////
// 0...+18.75 dB = byte 0...15 --- 4...7 bit
    for(int i = 0; i <= 3; i++){
       digitalWrite(CL,LOW);
    switch(i){
       case 0: digitalWrite(DI, (gain & 0b0001)>>0);Serial.print((gain & 0b001)>>0);break;
       case 1: digitalWrite(DI, (gain & 0b0010)>>1);Serial.print((gain & 0b010)>>1);break;
       case 2: digitalWrite(DI, (gain & 0b0100)>>2);Serial.print((gain & 0b100)>>2);break;
       case 3: digitalWrite(DI, (gain & 0b1000)>>3);Serial.print((gain & 0b100)>>3);break;
       } 
       digitalWrite(CL,HIGH);
       }
       Serial.print(" ");
       
/// volume conrtol /////////////////////////////////
// 0...-78 dB = byte 0...78 --- 8...15 bit
    for(int i = 0; i <= 7; i++){
       digitalWrite(CL,LOW);
    switch(i){
       case 0: digitalWrite(DI, (vol & 0b00000001)>>0);Serial.print((vol & 0b00000001)>>0);break;
       case 1: digitalWrite(DI, (vol & 0b00000010)>>1);Serial.print((vol & 0b00000010)>>1);break;
       case 2: digitalWrite(DI, (vol & 0b00000100)>>2);Serial.print((vol & 0b00000100)>>2);break;
       case 3: digitalWrite(DI, (vol & 0b00001000)>>3);Serial.print((vol & 0b00001000)>>3);break;
       case 4: digitalWrite(DI, (vol & 0b00010000)>>4);Serial.print((vol & 0b00010000)>>4);break;
       case 5: digitalWrite(DI, (vol & 0b00100000)>>5);Serial.print((vol & 0b00100000)>>5);break;
       case 6: digitalWrite(DI, (vol & 0b01000000)>>6);Serial.print((vol & 0b01000000)>>6);break;
       case 7: digitalWrite(DI, (vol & 0b10000000)>>7);Serial.print((vol & 0b10000000)>>7);break;
       } 
       digitalWrite(CL,HIGH);
       } 
       Serial.print(" ");
       
/// bass conrtol /////////////////////////////////
// -18...+18 dB = int -18...0...+18 
// 16...19 bit
int bass_d;
switch(bass){
  case  18:bass_d = 0b1100;break;
  case  16:bass_d = 0b0100;break;
  case  14:bass_d = 0b1000;break;
  case  12:bass_d = 0b0110;break;
  case  10:bass_d = 0b1010;break;
  case  8 :bass_d = 0b0010;break;
  case  6 :bass_d = 0b1100;break;
  case  4 :bass_d = 0b0100;break;
  case  2 :bass_d = 0b1000;break;
  case  0 :bass_d = 0b0000;break;
  case  -2:bass_d = 0b1001;break;
  case  -4:bass_d = 0b0101;break;
  case  -6:bass_d = 0b1101;break;
  case  -8:bass_d = 0b0011;break;
  case -10:bass_d = 0b1011;break;
  case -12:bass_d = 0b0111;break;
  case -14:bass_d = 0b1001;break;
  case -16:bass_d = 0b0101;break;
  case -18:bass_d = 0b1101;break;
  }
 for(int i = 3; i >= 0; i--){
   digitalWrite(CL,LOW);
   digitalWrite(DI, (bass_d >> i) & 0x01);Serial.print((bass_d >> i) & 0x01);
   digitalWrite(CL,HIGH);
   } 
   Serial.print(" ");
       
////////////////////////////////////
// 20..23 bit
for(int i = 0; i <= 3; i++){
        digitalWrite(CL,LOW);
        digitalWrite(DI, 0);Serial.print(0);
        digitalWrite(CL,HIGH);
   } 
   Serial.print(" ");
/// treble conrtol /////////////////////////////////
// -18...+18 dB = int -18...0...+18 
// 24...27 bit
int treb_d;
switch(treb){
  case  18:treb_d = 0b1100;break;
  case  16:treb_d = 0b0100;break;
  case  14:treb_d = 0b1000;break;
  case  12:treb_d = 0b0110;break;
  case  10:treb_d = 0b1010;break;
  case  8 :treb_d = 0b0010;break;
  case  6 :treb_d = 0b1100;break;
  case  4 :treb_d = 0b0100;break;
  case  2 :treb_d = 0b1000;break;
  case  0 :treb_d = 0b0000;break;
  case  -2:treb_d = 0b1001;break;
  case  -4:treb_d = 0b0101;break;
  case  -6:treb_d = 0b1101;break;
  case  -8:treb_d = 0b0011;break;
  case -10:treb_d = 0b1011;break;
  case -12:treb_d = 0b0111;break;
  case -14:treb_d = 0b1001;break;
  case -16:treb_d = 0b0101;break;
  case -18:treb_d = 0b1101;break;
  }
 for(int i = 3; i >= 0; i--){
   digitalWrite(CL,LOW);
   digitalWrite(DI, (treb_d >> i) & 0x01);Serial.print((treb_d >> i) & 0x01);
   digitalWrite(CL,HIGH);
   }    
   Serial.print(" ");
       
/// fader volume conrtol /////////////////////////////////
// byte 0...15 --- 28...31 bit
  for(int i = 0; i <= 3; i++){
       digitalWrite(CL,LOW);
    switch(i){
       case 0: digitalWrite(DI, (fader & 0b0001)>>0);Serial.print((fader & 0b0001)>>0);break;
       case 1: digitalWrite(DI, (fader & 0b0010)>>1);Serial.print((fader & 0b0010)>>1);break;
       case 2: digitalWrite(DI, (fader & 0b0100)>>2);Serial.print((fader & 0b0100)>>2);break;
       case 3: digitalWrite(DI, (fader & 0b1000)>>3);Serial.print((fader & 0b1000)>>3);break;
       } 
       digitalWrite(CL,HIGH);
       }  
       Serial.print(" ");
          
/// ch selection conrtol /////////////////////////////////
// byte 0...3
// 32...33 bit
  for(int i = 0; i <= 1; i++){
       digitalWrite(CL,LOW);
    switch(i){
       case 0: digitalWrite(DI, (ch & 0b01)>>0);Serial.print((ch & 0b0001)>>0);break;
       case 1: digitalWrite(DI, (ch & 0b10)>>1);Serial.print((ch & 0b0010)>>1);break;
       } 
       digitalWrite(CL,HIGH);
       }   
       Serial.print(" ");
/// read/front conrtol /////////////////////////////////
// byte 0...1
// 34 bit
        digitalWrite(CL,LOW);
        digitalWrite(DI,rf);Serial.print(rf);
        digitalWrite(CL,HIGH);
        Serial.print(" ");
/// loudness conrtol /////////////////////////////////
// byte 0...1
// 35 bit
        digitalWrite(CL,LOW);
        digitalWrite(DI,loud);Serial.print(loud);
        digitalWrite(CL,HIGH); 
        Serial.print(" ");            
/// zero-cross conrtol /////////////////////////////////
// byte 0...2
// 36...37 bit
  for(int i = 0; i <= 1; i++){
       digitalWrite(CL,LOW);
    switch(i){
       case 0: digitalWrite(DI, (zero & 0b01)>>0);Serial.print((zero & 0b01)>>0);break;
       case 1: digitalWrite(DI, (zero & 0b10)>>1);Serial.print((zero & 0b10)>>1);break;
} 
       digitalWrite(CL,HIGH);
       } 
       Serial.print(" "); 
       
/// zero-cross signal conrtol /////////////////////////////////
// byte 0...2
// 38...39 bit
  for(int i = 0; i <= 1; i++){
       digitalWrite(CL,LOW);
    switch(i){
       case 0: digitalWrite(DI, (zero_s & 0b01)>>0);Serial.print((zero_s & 0b01)>>0);break;
       case 1: digitalWrite(DI, (zero_s & 0b10)>>1);Serial.print((zero_s & 0b10)>>1);break;
       } 
       digitalWrite(CL,HIGH);
       } 
       Serial.print(" ");
       
/// bass conrtol d40 /////////////////////////////////
// 40 bit
switch(bass){
  case  18:bass_d = 1;break;
  case  16:bass_d = 1;break;
  case  14:bass_d = 1;break;
  case  12:bass_d = 0;break;
  case  10:bass_d = 0;break;
  case  8 :bass_d = 0;break;
  case  6 :bass_d = 0;break;
  case  4 :bass_d = 0;break;
  case  2 :bass_d = 0;break;
  case  0 :bass_d = 0;break;
  case  -2:bass_d = 0;break;
  case  -4:bass_d = 0;break;
  case  -6:bass_d = 0;break;
  case  -8:bass_d = 0;break;
  case -10:bass_d = 0;break;
  case -12:bass_d = 0;break;
  case -14:bass_d = 1;break;
  case -16:bass_d = 1;break;
  case -18:bass_d = 1;break;
  }
        digitalWrite(CL,LOW);
        digitalWrite(DI, bass_d);Serial.print(bass_d);
        digitalWrite(CL,HIGH);
        Serial.print(" ");
/// treb conrtol d41 /////////////////////////////////
// 41 bit
switch(treb){
  case  18:treb_d = 1;break;
  case  16:treb_d = 1;break;
  case  14:treb_d = 1;break;
  case  12:treb_d = 0;break;
  case  10:treb_d = 0;break;
  case  8 :treb_d = 0;break;
  case  6 :treb_d = 0;break;
  case  4 :treb_d = 0;break;
  case  2 :treb_d = 0;break;
  case  0 :treb_d = 0;break;
  case  -2:treb_d = 0;break;
  case  -4:treb_d = 0;break;
  case  -6:treb_d = 0;break;
  case  -8:treb_d = 0;break;
  case -10:treb_d = 0;break;
  case -12:treb_d = 0;break;
  case -14:treb_d = 1;break;
  case -16:treb_d = 1;break;
  case -18:treb_d = 1;break;
  }
        digitalWrite(CL,LOW);
        digitalWrite(DI, treb_d);Serial.print(treb_d);
        digitalWrite(CL,HIGH); 
        Serial.print(" ");
/// test mode conrtol /////////////////////////////////
// byte 0...3
// 42...43 bit
int test = 0;
for(int i = 0; i <= 1; i++){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (test >> i) & 0x01);Serial.print(0);
        digitalWrite(CL,HIGH);
   }
//// end byte    
        digitalWrite(CL,LOW);
        delayMicroseconds(1);
        digitalWrite(CE,LOW);   
        delay(1);   
        Serial.println();    
  }