|
基于51的数控收音机(带时钟显示温度显示)程序经过测试可以用。
下面是主程序:
- #include "iic.h"
- #include "reg51.h"
- #include "delay.h"
- #include "radio.h"
- #include "24c02.h"
- #define uchar unsigned char
- #define uint unsigned int
- extern uchar data Display_FM[8];
- extern uchar data Display_Vol[6];
- sbit K1 = P3^2;
- sbit K2 = P3^3;
- sbit K3 = P3^4;
- sbit K4 = P3^5;
-
- unsigned long frequency;
- unsigned char RDA_reg_data[8] =
- {
- 0xd0,0x00, // 02H
- 0x00,0x00, // 03H
- 0x00,0x40, // 04H
- 0x90,0x80, // 05H
- };
-
- char code reserve[3]_at_ 0x3b; // //保留0x3b开始的3个字节
- void RDA5807_write_reg(void)
- {
- uchar i;
-
- I2C_start(); //收音模块写入操作
- I2C_write_byte(0x20);
- for(i=0; i<8; i++)
- {
- I2C_write_byte(RDA_reg_data[i]);
- }
-
- I2C_stop();
- }
-
- void RDA5807_read_reg(uchar *reg_buf) //连续读寄存器子函数
- {
- I2C_start();
- I2C_write_byte(0x21); //寄存器连续读操作
- reg_buf[0] = I2C_read_byte(0);
- reg_buf[1] = I2C_read_byte(0);
- reg_buf[2] = I2C_read_byte(0);
- reg_buf[3] = I2C_read_byte(1);
- I2C_stop();
- }
-
- void RDA5807_power(void) //模块上电初始化子函数
- {
- Delay_ms(50);
- RDA_reg_data[0] = 0x00; //发送软件复位指令
- RDA_reg_data[1] = 0x02;
- RDA5807_write_reg();
- Delay_ms(10);
- RDA_reg_data[0] = 0xd0; //收音模块默认参数
- RDA_reg_data[1] = 0x01;
- a24c02_read();//读取保存的频率
- RDA_reg_data[3] += 0x10; //调谐启用
- RDA5807_write_reg();
- }
- void RDA5807_FM_seek(void) //功能描述:收音模块自动寻台模式
- {
- uint chan;
- uchar reg_data[4] = {0x00, 0x00, 0x00, 0x00};
-
- RDA_reg_data[3] &= ~(1 << 4); //调谐禁用 内部自动寻台使
- RDA_reg_data[0] |= (1 << 0); //SEEK位置 1
- RDA5807_write_reg();
- while(0 == (reg_data[0] & 0x40)) //等待 STC 标志置位
- {
- Delay_ms(20);
-
-
-
- RDA5807_read_reg(reg_data); //读取内部状态
- }
- chan = reg_data[0] & 0x03; //获取当前工作频点
- chan = reg_data[1] | (chan << 8);
- chan = chan << 6;
- RDA_reg_data[2] = (chan >> 8) & 0xff; //保存当前工作频点
- RDA_reg_data[3] = (chan & 0xff);
- a24c02_write();//保存当前频率
- }
-
- void show_frequency(void) //频率显示子函数
- {
- unsigned char i;
- unsigned int temp;
-
- temp = (RDA_reg_data[2]*256)+(RDA_reg_data[3]&0xc0); //计算
- temp = temp>>6;
- frequency = (unsigned long)(100*temp+87000)/100;
-
- for(i=0; i<5; i++)
- Display_FM[i] = 0x00; //清显存单元
- Display_FM[0] = (frequency)/1000 ; //数据转换
- Display_FM[1] = (frequency%1000)/100;
- Display_FM[2] = (frequency%100)/10;
- Display_FM[3] = 0x2e;//小数点
- Display_FM[4] = (frequency%10);
-
- if( Display_FM[0] == 0)
- {
- Display_FM[0] = Display_FM[1]+0x30;
- Display_FM[1] = Display_FM[2]+0x30;
- Display_FM[2] = Display_FM[3];
- Display_FM[3] = Display_FM[4]+0x30;
- Display_FM[4] = 0x20;
- }
- else
- {
- Display_FM[0] += 0x30;
- Display_FM[1] += 0x30;
- Display_FM[2] += 0x30;
- Display_FM[4] += 0x30;
- }
- }
-
- void show_volume()//音量显示子函数
- {
- unsigned char temp;
-
- temp = RDA_reg_data[7] & 0x0f; //取音量值
- Display_Vol[3] = temp/10;
- Display_Vol[4] = temp%10;
-
- if(Display_Vol[3] == 0)// 如果高位为0
-
- {
- Display_Vol[3] = Display_Vol[4]; //低位显存内容进入高位显存
- Display_Vol[4] = 0x20;//低位不显示
- }
- else
- Display_Vol[4] += 0x30;
- Display_Vol[3] += 0x30;
- }
- void Set_Frq() //按键设置
- {
- if(K1 == 0)
- {
- Delay_ms(20);
- if(K1 == 0)
- {
- RDA_reg_data[0] |= (1 << 1); //SEEK UP
- RDA5807_FM_seek();
- while(K1 == 0);
- }
- }
- if(K2 == 0)
- {
- Delay_ms(20);
- if(K2 == 0)
- {
- RDA_reg_data[0] &= ~(1 << 1); //SEEK DOWN
- RDA5807_FM_seek();
- while(K2 == 0);
- }
- }
- if(K3 == 0)
- {
- Delay_ms(20);
- if(K3 == 0)
- {
- if((RDA_reg_data[7] & 0x0f) < 0x0f)
- {
- RDA_reg_data[0] = 0xd0;
- RDA_reg_data[1] = 0x01;
- RDA_reg_data[3] &= ~(1 << 4);
-
- RDA_reg_data[7]++; //音量递增
- RDA5807_write_reg();
- while(K3 == 0);
- }
- }
- }
-
- if(K4 == 0)
- {
- Delay_ms(20);
- if(K4 == 0)
- {
- if((RDA_reg_data[7] & 0x0f) > 0x00)
- {
- RDA_reg_data[0] = 0xd0;
- RDA_reg_data[1] = 0x01;
- RDA_reg_data[3] &= ~(1 << 4);
-
- RDA_reg_data[7]--; //音量递减
- RDA5807_write_reg();
- while(K4 == 0);
- }
- }
- }
- }
-
复制代码
|
-
-
数控收音机.rar
105.53 KB, 下载次数: 263, 下载积分: 黑币 -5
程序
评分
-
查看全部评分
|