51單片機驅(qū)動TEA5767調(diào)頻收音機芯片C程序
/********************** 由PLL獲取頻率**************************/
void TEA5767_Get_Frequency(void)
{
uchar HLSI;
uint NPLL=0;
NPLL=PLL;
HLSI=TEA5767_Write_Data[2]&0x10;
if (HLSI)
Frequency=(unsigned long)((float)(NPLL)*(float)8.192-225); //頻率單位:KHz
else
Frequency=(unsignedlong)((float)(NPLL)*(float)8.192+225); //頻率單位:KHz
}
/**********************顯示當前頻率**************************/
void TEA5767_Display_Frequency()
{
TEA5767_Get_Frequency(); //由PLL得到頻率
Display_FM[0]=(Frequency/100000);
if(Display_FM[0]==0)
Display_FM[0]=0x20; //第一位為0的話,不顯示
else
Display_FM[0]|=0x30;
Frequency=Frequency%100000;
Display_FM[1]=0x30|(Frequency/10000);
Frequency=Frequency%10000;
Display_FM[2]=0x30|(Frequency/1000);
Frequency=Frequency%1000;
Display_FM[4]=0x30|(Frequency/100);
}
/**********************初始化TEA5767**************************/
void TEA5767_Init()
{
TEA5767_Write(); //寫入初始化參數(shù)
//EEPROM_Save_PLL(1,0x29de); //預(yù)置第1頻道
//EEPROM_Save_PLL(2,0x2bb0); //預(yù)置第2頻道
//EEPROM_Save_PLL(3,0x2cc9); //預(yù)置第3頻道
//EEPROM_Save_PLL(4,0x2fa5); //預(yù)置第4頻道
//EEPROM_Save_PLL(5,0x3050); //預(yù)置第5頻道
//EEPROM_Save_PLL(6,0x309a); //預(yù)置第6頻道
//EEPROM_Save_PLL(7,0x328e); //預(yù)置第7頻道
//EEPROM_Save_PLL(8,0x2fa5); //預(yù)置第8頻道
//EEPROM_Save_PLL(9,0x2fa5); //預(yù)置第9頻道
//EEPROM_Save_PLL(10,0x2fa5); //預(yù)置第10頻道
//EEPROM_Save_PLL(11,0x2fa5); //預(yù)置第11頻道
//EEPROM_Save_PLL(12,0x2fa5); //預(yù)置第12頻道
//EEPROM_Save_PLL(13,0x2fa5); //預(yù)置第13頻道
//EEPROM_Save_PLL(14,0x2fa5); //預(yù)置第14頻道
//EEPROM_Save_PLL(15,0x2fa5); //預(yù)置第15頻道 注:第一次編譯使用預(yù)置頻道
}
/**********************手動搜索**************************/
void TEA5767_User_Search(uchar Mode)
{
switch(Mode) //向上搜索
{
case 1:
PLL+=1;
if(PLL>0x3370) //108MHz時的PLL,
PLL=0x298d; //87.5MHz時的PLL,
break;
case 0: //向下搜索
PLL-=1; //改變該值可提高精度,但步進變得緩慢
if(PLL<0x298d)
PLL=0x3270;
break;
}
TEA5767_Write_Data[0]=(PLL/256)&0x7f;
TEA5767_Write_Data[1]=PLL%256;
TEA5767_Write(); //重新寫入?yún)?shù)
}
/**********************更新PLL**************************/
void TEA5767_Update_PLL(void)
{
TEA5767_Write_Data[0]=(PLL/256)&0x7f;
TEA5767_Write_Data[1]=PLL%256;
TEA5767_Write(); //重新寫入?yún)?shù)
}本文引用地址:http://butianyuan.cn/article/201611/323741.htm
評論