Paso 3: código
El código de Arduino es como a continuación:Original del receptor de FM de Arduino con TEA5767 http://www.electronicsblog.net
Modificado por Jingfeng Liu
LinkSprite.com
//
#include < Wire.h >
#include < LiquidCrystal.h >
unsigned char search_mode = 0;
int b = 0;
int c = 0;
#define Button_next 6
#define Button_prev 7
unsigned char frequencyH = 0;
unsigned char frequencyL = 0;
unsigned int frequencyB;
doble frecuencia = 0;
doble freq_available = 0;
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
void setup() {}
Wire.Begin();
LCD.Begin (16, 2);
botones
pinMode (Button_next, entrada);
digitalWrite (Button_next, alto); Tire hacia arriba de la resistencia
pinMode (Button_prev, entrada);
digitalWrite (Button_prev, alto); Tire hacia arriba de la resistencia
frecuencia = 87.5; a partir de frecuencia
frequencyB = 4 *(frequency*1000000+225000)/32768; cálculo de palabra PLL
frequencyH = frequencyB >> 8;
frequencyL = frequencyB & 0XFF;
Delay(100);
Wire.beginTransmission(0x60); escritura TEA5767
Wire.Write(frequencyH);
Wire.Write(frequencyL);
Wire.Write(0xB0);
Wire.Write(0x10);
Wire.Write(0x00);
Wire.endTransmission();
Delay(100);
}
void loop()
{
buffer de unsigned char [5];
lcd.setCursor (0, 0);
Wire.requestFrom(0x60,5); lectura TEA5767
Si (Wire.available())
{
para (int i = 0; i < 5; i ++) {}
buffer [i] = Wire.read();
}
freq_available = (((almacenador intermediario [0] & 0x3F) << 8) + buffer [1]) * 4/32768-225000;
LCD.Print ("FM");
LCD.Print((freq_available/1000000));
frequencyH = ((almacenador intermediario [0] & 0x3F));
frequencyL = buffer [1];
Si (search_mode) {}
Si (almacenador intermediario [0] & 0 x 80) search_mode = 0;
}
Si (search_mode == 1) lcd.print ("SCAN");
Else {}
LCD.Print("");
}
lcd.setCursor (0, 1);
LCD.Print ("nivel:");
LCD.Print ((almacenador intermediario [3] >> 4));
LCD.Print ("/ 16");
Si (almacenador intermediario [2] & 0 x 80) lcd.print ("STEREO");
Else lcd.print ("MONO");
}
botones de leer
button_next / / /
Si (! digitalRead(Button_next) & &! b) {}
frecuencia =(freq_available/1000000) + 0. 05;
frequencyB = 4 * (frecuencia * 1000000 + 225000) / 32768 + 1;
frequencyH = frequencyB >> 8;
frequencyL = frequencyB & 0XFF;
Wire.beginTransmission(0x60);
Wire.Write(frequencyH);
Wire.Write(frequencyL);
Wire.Write(0xB0);
Wire.Write(0x1F);
Wire.Write(0x00);
Wire.endTransmission();
//////////////////////
b = 100;
};
Si (! digitalRead(Button_next) & & b == 1) {}
scannnn arriba
search_mode = 1;
Wire.beginTransmission(0x60);
Wire.Write(frequencyH+0x40);
Wire.Write(frequencyL);
Wire.Write(0xD0);
Wire.Write(0x1F);
Wire.Write(0x00);
Wire.endTransmission();
/////////////////
b = 100;
};
Si (! b == 0) b--;
button_prev / / /
Si (! digitalRead(Button_prev) & &! c) {}
frecuencia =(freq_available/1000000)-0.05;
frequencyB = 4 * (frecuencia * 1000000 + 225000) / 32768 + 1;
frequencyH = frequencyB >> 8;
frequencyL = frequencyB & 0XFF;
Wire.beginTransmission(0x60);
Wire.Write(frequencyH);
Wire.Write(frequencyL);
Wire.Write(0xB0);
Wire.Write(0x1F);
Wire.Write(0x00);
Wire.endTransmission();
c = 100;
};
Si (! digitalRead(Button_prev) & & c == 1) {}
scannnn abajo
search_mode = 1;
Wire.beginTransmission(0x60);
Wire.Write(frequencyH+0x40);
Wire.Write(frequencyL);
Wire.Write(0x50);
Wire.Write(0x1F);
Wire.Write(0x00);
Wire.endTransmission();
c = 100;
};
Si (! c == 0) c--;
////////////////////
}
Después de descargar el código de Arduino, podemos apretamos los dos botones para escanear para arriba y explorar hacia abajo los canales para buscar emisoras.