收音機(jī)模塊TEA5767的C51控制程序
TEA5767采用I2C或者三線接口控制,我是用的I2C,單片機(jī)用STC89C52,帶1K EEPROM,可以掉電存臺,1602LCD顯示.
本文引用地址:http://butianyuan.cn/article/151570.htmTEA5767讀寫數(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; //默認(rèn)存臺的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;i5;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;i5;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
}
評論