TEA5767采用I2C或者三線接口控制,我是用的I2C,單片機用STC89C52,帶1K EEPROM,可以掉電存臺,1602LCD顯示.
TEA5767讀寫數(shù)據(jù)都是5個字節(jié),其中PLL參數(shù)14位,具體數(shù)據(jù)格式請看datasheet.以下程序中的函數(shù)可以直接在主程序中調(diào)用.
#include "iic.c"
#define max_freq 108000
#define min_freq 87500
unsigned char radio_write_data[5]={0x29,0xc2,0x20,0x11,0x00}; //要寫入TEA5767的數(shù)據(jù)
unsigned char radio_read_data[5]; //TEA5767讀出的狀態(tài)
unsigned int default_pll=0x29c2;//0x29f9; //默認存臺的pll,87.8MHz
//unsigned int max_pll=0x339b; //108MHz時的pll,
//unsigned int min_pll=9000; //70MHz時的pll
void radio_write(void)
{
unsigned char i;
iic_start();
iic_write8bit(0xc0); //TEA5767寫地址
if(!iic_testack())
{
for(i=0;i<5;i++)
{
iic_write8bit(radio_write_data[i]);
iic_ack();
}
}
iic_stop();
}
//讀TEA5767狀態(tài),并轉(zhuǎn)換成頻率
void radio_read(void)
{
unsigned char i;
unsigned char temp_l,temp_h;
pll=0;
iic_start();
iic_write8bit(0xc1); //TEA5767讀地址
if(!iic_testack())
{
for(i=0;i<5;i++)
{
radio_read_data[i]=iic_read8bit();
iic_ack();
}
}
iic_stop();
temp_l=radio_read_data[1];
temp_h=radio_read_data[0];
temp_h&=0x3f;
pll=temp_h*256+temp_l;
get_frequency();
}
//由頻率計算PLL
void get_pll(void)
{
unsigned char hlsi;
unsigned int twpll=0;
hlsi=radio_write_data[2]&0x10;
if (hlsi)
pll=(unsigned int)((float)((frequency+225)*4)/(float)32.768); //頻率單位:k
else
pll=(unsigned int)((float)((frequency-225)*4)/(float)32.768); //頻率單位:k
}
//由PLL計算頻率
void get_frequency(void)
{
unsigned char hlsi;
unsigned int npll=0;
npll=pll;
hlsi=radio_write_data[2]&0x10;
if (hlsi)
frequency=(unsigned long)((float)(npll)*(float)8.192-225); //頻率單位:KHz
else
frequency=(unsigned long)((float)(npll)*(float)8.192+225); //頻率單位:KHz
}[!--empirenews.page--]
//手動設(shè)置頻率,mode=1,+0.1MHz; mode=0:-0.1MHz ,不用考慮TEA5767用于搜臺的相關(guān)位:SM,SUD
void search(bit mode)
{
radio_read();
if(mode)
{
frequency+=100;
if(frequency>max_freq)
frequency=min_freq;
}
else
{
frequency-=100;
if(frequency
frequency=max_freq;
}
get_pll();
radio_write_data[0]=pll/256;
radio_write_data[1]=pll%256;
radio_write_data[2]=0x20;
radio_write_data[3]=0x11;
radio_write_data[4]=0x00;
radio_write();
}
//自動搜臺,mode=1,頻率增加搜臺; mode=0:頻率減小搜臺,不過這個好像不能循環(huán)搜臺
void auto_search(bit mode)
{
radio_read();
get_pll();
if(mode)
radio_write_data[2]=0xa0;
else
radio_write_data[2]=0x20;
radio_write_data[0]=pll/256+0x40;
radio_write_data[1]=pll%256;
radio_write_data[3]=0x11;
radio_write_data[4]=0x00;
radio_write();
radio_read();
while(!(radio_read_data[0]&0x80)) //搜臺成功標志
{
radio_read();
disp_freq(9,1);
}
}