×
嵌入式 > 嵌入式开发 > 详情

AT89S52+12MHZ+TEA5767的数码管显示调频收音机

发布时间:2020-08-19 发布时间:
|
/**************************************************************************************************************
AT89S52+12MHZ+TEA5767的数码管显示调频收音机
本程序使用数码管显示频率晶振是用12M 已通过测试,收音机的频率调节是用计算的方法 将显示的频率算好后写到TEA5767
芯片里面实现调节的 两个按键实现自加或自减频率 加了连续加减功能!
使用的是在淘宝上买的4.5元/片的简化版的TEA5767模块.
2012-05-08
/**************************************************************************************************************/
#include < reg51.h >
#define uchar unsigned char
#define uint unsigned int
/**************************************************************************************************************/
sbit SDA = P3^0; //接在TEA5767的数据端口
sbit SCL = P3^1; //接在TEA5767的时钟端口
sbit KEY1 = P3^4; //频率增加按键端口
sbit KEY2 = P3^5; //频率减小按键端口
sbit KEY3 = P3^6; //频率增加按键端口
sbit KEY4 = P3^7; //频率减小按键端口
#define duan P0 //频率显示的数码管段选P0端口
//#define gy //使用共阴极时屏蔽这行
sbit dula=P2^6;
sbit wela=P2^7;
uchar IF,ADC,CH;
//bit RF,STEREO;
#ifdef gy
unsigned char code dispbit[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//显示位码
unsigned char code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};//数码管显示编码
#else
/**************************************************************************************************************/
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00}; //数码管显示编码
unsigned char code dispbit[]={0x7e,0x7d,0x7b,0x77,0x6f,0x5f};/*定义点亮的数码管与数组的关系*/
#endif
/**************************************************************************************************************
unsigned char radio_write_data[5] = {0x2c,0xe1,0x70,0x16,0x80}; //频率为93.9MHz 广东音乐电台
unsigned char radio_write_data[5] = {0x30,0x5c,0x70,0x16,0x80}; //频率为101.2MHz 广东电台音乐之声
unsigned char radio_write_data[5] = {0x31,0x38,0x70,0x16,0x80}; //频率为103.0MHz 广东珠江经济电台
unsigned char radio_write_data[5] = {0x31,0xd7,0x70,0x16,0x80}; //频率为104.3MHz 宝安广播电台
unsigned char radio_write_data[5] = {0x32,0x20,0x70,0x16,0x80}; //频率为104.9MHz 中央人民广播电台华夏之声
unsigned char radio_write_data[5] = {0x33,0x2d,0x70,0x16,0x80}; //频率为107.1MHz 中国国际广播电台环球资讯
/**************************************************************************************************************/
unsigned char radio_read_data[5];
unsigned char radio_write_data[5];
unsignedlongfrequency = 104900; //开机初始化的电台频率为104.9MHz中央民广播电台华夏之声
unsigned int PLL; //计算频率合成时用的变量
/**************************************************************************************************************/
void Delayus(unsigned char x)
{
for(;x > 0;x--);
}
/**************************************************************************************************************/
void iic_start() //启动总线传输
{
SDA = 1;
Delayus(4);
SCL = 1;
Delayus(4);
SDA = 0;
Delayus(4);
SCL = 0;
Delayus(4);
}
/**************************************************************************************************************/
void iic_stop() //结束总线传输
{
SCL = 0;
Delayus(4);
SDA = 0;
Delayus(4);
SCL = 1;
Delayus(4);
SDA = 1;
Delayus(4);
}
/**************************************************************************************************************/
void iic_ack() //发送应答位
{
SDA = 0;
Delayus(4);
SCL = 1;
Delayus(4);
SCL = 0;
Delayus(4);
SDA = 1;
Delayus(4);
}
/**************************************************************************************************************/
bit iic_testack()
{
bit ErrorBit;
SDA = 1;
Delayus(4);
SCL = 1;
Delayus(4);
ErrorBit = SDA;
Delayus(4);
SCL = 0;
return ErrorBit;
}
/**************************************************************************************************************/
void iic_write8bit(unsigned char input) //写一个字节的数据到总线上
{
unsigned char temp;
for(temp = 8;temp > 0;temp--)
{
SDA = (bit)(input & 0x80);
Delayus(4);
SCL = 1;
Delayus(4);
SCL = 0;
Delayus(4);
input = input << 1;
}
}
/**************************************************************************************************************/
uchar iic_rdbyt() //从总线上读取一个字节的数据
{
uchar a = 0,i = 0;
for(i = 0;i < 8;i++)
{
SDA = 1;
SCL = 1;
if(SDA == 1)
{
a = (a << 1) + 1;
SCL = 0;
}
else if(SDA == 0)
{
a = a << 1;
SCL = 0;
}
}
return(a);
}
/**************************************************************************************************************/
void delays (unsigned char b) //按键消抖用的延时程序
{
unsigned char i;
for(b;b > 0;b--)
for(i = 0;i < 250;i++);
}
/**************************************************************************************************************/
void radio_write(void) //写入TEA5767
{
unsigned char i;
iic_start(); //启动总线传输
iic_write8bit(0xc0); //TEA5767写地址
if(!iic_testack())
{
for(i = 0;i < 5;i++)
{
iic_write8bit(radio_write_data); //写一个字节的数据到总线上
iic_ack(); //发送应答位
}
}
iic_stop(); //结束总线传输
}
/**************************************************************************************************************/
//将显示的频率算好后写到TEA5767芯片里面实现调节,不用考虑TEA5767用于搜台的相关位:SM,SUD
//写模式
//数据字节1 数据字节2 数据字节3 数据字节4 数据字节5
void search()
{
PLL = (unsigned int)((float)((frequency + 225)) / (float)8.192); //计算合成频率数据 频率单位:k
/**************************************************************************************************************/
//数据字节1的格式 radio_write_data[0]
//位7(高位) 位6 位5 位4 位3 位2 位1 位0(低位)
// MUTE SM PLL13 PLL12 PLL11 PLL10 PLL9 PLL8
//7 MUTE 如果MUTE=1 则左右声道被静音;MUTE=0 左右声道正常工作。
//6 SM 如果SM=1 则处于搜索模式 SM=0 不处于搜索模式。
//5到0 PLL[13:8] 设定用于搜索和预设的可编程频率合成器。
radio_write_data[0] = PLL / 256; //将算好的频率高位数据存入将要TEA5767的数组里
/**************************************************************************************************************/
//数据字节2的格式 radio_write_data[1]
//位7(高位) 位6 位5 位4 位3 位2 位1 位0(低位)
// PLL7 PLL6 PLL5 PLL4 PLL3 PLL2 PLL1 PLL0
//PLL[7:0] 设定用于搜索和预设的可编程频率合成器。
radio_write_data[1] = PLL % 256; //将算好的频率低位数据存入将要TEA5767的数组里


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
瑞萨I3C总线扩展和SPD集线器产品通过基板管理控制器认证