新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)驅(qū)動(dòng)收音機(jī)模塊程序

單片機(jī)驅(qū)動(dòng)收音機(jī)模塊程序

作者: 時(shí)間:2016-11-30 來(lái)源:網(wǎng)絡(luò) 收藏
這是從http://www.51hei.com/bbs/dpj-20623-1.html這個(gè)制作里面截取的一段子程序,調(diào)用函數(shù)請(qǐng)下載里面的附件.


radio.h文件如下:
#ifndef _RADIO_H_
#define _RADIO_H_

本文引用地址:http://m.butianyuan.cn/article/201611/323811.htm


uint8 radio_read[5];//定義2個(gè)五字節(jié)數(shù)組保存寫(xiě)入控制寄存器及讀取數(shù)據(jù)的內(nèi)存空間
uint8radio_write[5]={0x00,0x00,0xd0,0x17,0x00};
//uint16 pll;//14位PLL的值保存于一個(gè)字
static unsignedlongfrequency;//電臺(tái)頻率保存變量

/*-------------------------------------------------------------------------------------------------------------------
寫(xiě)寄存器1
msblsb
MUTESMPLL13PLL12PLL11PLL10PLL09PLL08
1:靜音1:搜索模式PLL13->PLL8
0:正常0:非搜索預(yù)置或搜索電臺(tái)的頻率值高6位
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
寫(xiě)寄存器2
msblsb
PLL7PLL6PLL5PLL4PLL3PLL2PLL1PLL0
PLL7->PLL0
預(yù)置或搜索電臺(tái)頻率的低8位
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
寫(xiě)寄存器3
msblsb
SUDSSL1SSL0HLSIMSMLMRSWP1
1:向上搜臺(tái)00:不搜索1:本振高出電臺(tái)1:單聲道1:左聲道靜音1:右聲道靜音可編程輸出口設(shè)置
0:向下搜臺(tái)01:ADC為5停止225KHz0:立體聲0:右聲道正常0:右聲道正常1:SWPOR1高
10:ADC為7停止0:本振低于電臺(tái)0:SWPOR1低
11:ADC為10停止225KHz
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
寫(xiě)寄存器4
msblsb
SWP2STBYBLXTALSMUTEHHCSNCSI
可編程輸出口1:待機(jī)1:76~91MHz1:晶振32768Hz1:軟件靜音開(kāi)1:高電平切割開(kāi)1:立體聲消噪開(kāi)
1:SWPOR2高0:正常0:87.5~108MHz0:13MHz0:軟件靜音關(guān)0:高電平切割關(guān)0:立體聲消噪關(guān)
0:SWPOR2低
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
寫(xiě)寄存器5
msblsb
PLLREFDTC------
1:去重時(shí)間75uS
0:去重時(shí)間50uS
--------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------
函數(shù)功能:電臺(tái)頻率到PLL的轉(zhuǎn)換
調(diào)用形式:Convert_PLL();
參數(shù):
返回值:
修改時(shí)間:
備注:HLSI為1,采用高本振狀態(tài)、XTAL=1,32.768KHz、PLLREF=0
---------------------------------------------------------*/
void Convert_PLL(void)
{
uint16 pll;
uint8 pll1,pll2;//高低位pll值暫存變量
pll=((frequency+225000)*4)/32768;// 單位均為Hz
pll1=pll/256;
pll2=pll%256;
radio_write[0]=pll1;
radio_write[1]=pll2;
}

/*---------------------------------------------------------
函數(shù)功能:初始化RADIO模塊
調(diào)用形式:Radio_Init();
參數(shù):
返回值:
修改時(shí)間:
備注:轉(zhuǎn)換PLL值、寫(xiě)控制字
---------------------------------------------------------*/
void Radio_Init(void)
{
//frequency=93400000;//初始電臺(tái)頻率93.4MHz
//radio_write[0]=0x00;
//radio_write[1]=0x00;
//radio_write[2]=0xf0;
radio_write[3]=0x40;
//radio_write[4]=0x00;
//Convert_PLL();
frequency=93400000;
SendString(RADIO_ADDRESS,radio_write,5);
}

/*--------------------------------------------------------------------------------------------------------------------
讀寄存器1
msblsb
RFBLFPLL13PLL12PLL11PLL10PLL9PLL8
1:發(fā)現(xiàn)電臺(tái)1:波段到頭PLL13->PLL8
or搜索到頭0:波段未到頭搜索或預(yù)置電臺(tái)頻率高6位
0:未發(fā)現(xiàn)電臺(tái)
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
讀寄存器2
msblsb
PLL7PLL6PLL5PLL4PLL3PLL2PLL1PLL0
PLL7->PLL0
搜索或預(yù)置電臺(tái)頻率低8位
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
讀寄存器3
msblsb
STERE0IF6IF5IF4IF3IF2IF1IF0
1:立體聲IF6->IF0
0:單聲道中頻IF計(jì)數(shù)器結(jié)果
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
讀寄存器4
msblsb
LEV3LEV2LEV1LEV0CI3CI2CI1CI0
LEV3->LEV0CI3->CI0
ADC輸出電平芯片識(shí)別(均為0)
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
讀寄存器5
均為保留位
--------------------------------------------------------------------------------------------------------------------*/
void Convert_Frequency()
{
frequency=radio_read[0]&0x3f;
frequency<<=8;
frequency|=radio_read[1];
frequency=frequency*8192-225000;
}

void Radio_Ing(void)
{
static bit k=0;
biti=0;
uint8 n=0;
uint16 j;
if(!k)
{
k=1;
radio_write[3]=0x17;
}


上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: 單片機(jī)收音機(jī)模

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉