微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机驱动收音机模块程序

单片机驱动收音机模块程序

时间:11-30 来源:互联网 点击:
这是从http://www.51hei.com/bbs/dpj-20623-1.html这个制作里面截取的一段子程序,调用函数请下载里面的附件.

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

uint8 radio_read[5];//定义2个五字节数组保存写入控制寄存器及读取数据的内存空间
uint8radio_write[5]={0x00,0x00,0xd0,0x17,0x00};
//uint16 pll;//14位PLL的值保存于一个字
static unsignedlongfrequency;//电台频率保存变量

/*-------------------------------------------------------------------------------------------------------------------
写寄存器1
msblsb
MUTESMPLL13PLL12PLL11PLL10PLL09PLL08
1:静音1:搜索模式PLL13->PLL8
0:正常0:非搜索预置或搜索电台的频率值高6位
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
写寄存器2
msblsb
PLL7PLL6PLL5PLL4PLL3PLL2PLL1PLL0
PLL7->PLL0
预置或搜索电台频率的低8位
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
写寄存器3
msblsb
SUDSSL1SSL0HLSIMSMLMRSWP1
1:向上搜台00:不搜索1:本振高出电台1:单声道1:左声道静音1:右声道静音可编程输出口设置
0:向下搜台01:ADC为5停止225KHz0:立体声0:右声道正常0:右声道正常1:SWPOR1高
10:ADC为7停止0:本振低于电台0:SWPOR1低
11:ADC为10停止225KHz
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
写寄存器4
msblsb
SWP2STBYBLXTALSMUTEHHCSNCSI
可编程输出口1:待机1:76~91MHz1:晶振32768Hz1:软件静音开1:高电平切割开1:立体声消噪开
1:SWPOR2高0:正常0:87.5~108MHz0:13MHz0:软件静音关0:高电平切割关0:立体声消噪关
0:SWPOR2低
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
写寄存器5
msblsb
PLLREFDTC------
1:去重时间75uS
0:去重时间50uS
--------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------
函数功能:电台频率到PLL的转换
调用形式:Convert_PLL();
参数:
返回值:
修改时间:
备注:HLSI为1,采用高本振状态、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;
}

/*---------------------------------------------------------
函数功能:初始化RADIO模块
调用形式:Radio_Init();
参数:
返回值:
修改时间:
备注:转换PLL值、写控制字
---------------------------------------------------------*/
void Radio_Init(void)
{
//frequency=93400000;//初始电台频率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:发现电台1:波段到头PLL13->PLL8
or搜索到头0:波段未到头搜索或预置电台频率高6位
0:未发现电台
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
读寄存器2
msblsb
PLL7PLL6PLL5PLL4PLL3PLL2PLL1PLL0
PLL7->PLL0
搜索或预置电台频率低8位
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
读寄存器3
msblsb
STERE0IF6IF5IF4IF3IF2IF1IF0
1:立体声IF6->IF0
0:单声道中频IF计数器结果
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
读寄存器4
msblsb
LEV3LEV2LEV1LEV0CI3CI2CI1CI0
LEV3->LEV0CI3->CI0
ADC输出电平芯片识别(均为0)
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
读寄存器5
均为保留位
--------------------------------------------------------------------------------------------------------------------*/
void Convert_Frequency()
{
frequency=radio_read[0]&0x3f;
frequency<=8;
frequency|=radio_read[1];
frequency=frequency*8192-225000;
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top