找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 10542|回復(fù): 14
打印 上一主題 下一主題
收起左側(cè)

基于51單片機的數(shù)控收音機(RDA5807程序)

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:103593 發(fā)表于 2016-3-11 22:53 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
基于51的數(shù)控收音機(帶時鐘顯示溫度顯示)程序經(jīng)過測試可以用。


下面是主程序:
  1. #include "iic.h"
  2. #include "reg51.h"
  3. #include "delay.h"
  4. #include "radio.h"
  5. #include "24c02.h"

  6. #define uchar unsigned char
  7. #define uint  unsigned int
  8. extern uchar data Display_FM[8];
  9. extern uchar data Display_Vol[6];

  10. sbit  K1 = P3^2;
  11. sbit  K2 = P3^3;
  12. sbit  K3 = P3^4;
  13. sbit  K4 = P3^5;

  14. unsigned long frequency;

  15. unsigned char  RDA_reg_data[8] =
  16. {
  17.    0xd0,0x00,  // 02H
  18.    0x00,0x00,  // 03H
  19.    0x00,0x40,  // 04H
  20.    0x90,0x80,  // 05H
  21. };

  22. char code reserve[3]_at_ 0x3b; // //保留0x3b開始的3個字節(jié)

  23. void RDA5807_write_reg(void)
  24. {
  25.    uchar i;

  26.    I2C_start(); //收音模塊寫入操作
  27.    I2C_write_byte(0x20);
  28.           for(i=0; i<8; i++)
  29.    {
  30.      I2C_write_byte(RDA_reg_data[i]);
  31.    }

  32.    I2C_stop();
  33. }


  34. void RDA5807_read_reg(uchar *reg_buf) //連續(xù)讀寄存器子函數(shù)
  35. {
  36.         I2C_start();
  37.         I2C_write_byte(0x21); //寄存器連續(xù)讀操作
  38.         reg_buf[0] = I2C_read_byte(0);
  39.         reg_buf[1] = I2C_read_byte(0);
  40.         reg_buf[2] = I2C_read_byte(0);
  41.         reg_buf[3] = I2C_read_byte(1);
  42.         I2C_stop();
  43. }


  44. void RDA5807_power(void) //模塊上電初始化子函數(shù)
  45. {
  46.         Delay_ms(50);
  47.         RDA_reg_data[0] = 0x00; //發(fā)送軟件復(fù)位指令
  48.         RDA_reg_data[1] = 0x02;
  49.         RDA5807_write_reg();
  50.         Delay_ms(10);
  51.         RDA_reg_data[0] = 0xd0; //收音模塊默認參數(shù)
  52.         RDA_reg_data[1] = 0x01;
  53.         a24c02_read();//讀取保存的頻率
  54.         RDA_reg_data[3] += 0x10; //調(diào)諧啟用
  55.         RDA5807_write_reg();
  56. }  


  57. void RDA5807_FM_seek(void) //功能描述:收音模塊自動尋臺模式
  58. {
  59.    uint chan;
  60.    uchar  reg_data[4] = {0x00, 0x00, 0x00, 0x00};

  61.         RDA_reg_data[3] &= ~(1 << 4); //調(diào)諧禁用 內(nèi)部自動尋臺使   
  62.         RDA_reg_data[0] |=  (1 << 0);      //SEEK位置        1
  63.         RDA5807_write_reg();
  64.         while(0 == (reg_data[0] & 0x40))  //等待 STC          標志置位
  65.     {
  66.                 Delay_ms(20);
  67.                
  68.                
  69.                
  70.                 RDA5807_read_reg(reg_data); //讀取內(nèi)部狀態(tài)
  71.         }
  72.         chan = reg_data[0] & 0x03; //獲取當前工作頻點
  73.         chan = reg_data[1] | (chan << 8);
  74.         chan = chan << 6;        
  75.         RDA_reg_data[2] = (chan >> 8) & 0xff; //保存當前工作頻點
  76.         RDA_reg_data[3] = (chan & 0xff);
  77.         a24c02_write();//保存當前頻率       
  78. }
  79.        
  80. void  show_frequency(void) //頻率顯示子函數(shù)
  81. {  
  82.         unsigned char i;
  83.         unsigned int  temp;

  84.         temp = (RDA_reg_data[2]*256)+(RDA_reg_data[3]&0xc0); //計算
  85.         temp = temp>>6;
  86.         frequency = (unsigned long)(100*temp+87000)/100;
  87.        
  88.         for(i=0; i<5; i++)  
  89.         Display_FM[i] = 0x00; //清顯存單元

  90.         Display_FM[0] = (frequency)/1000  ; //數(shù)據(jù)轉(zhuǎn)換
  91.         Display_FM[1] = (frequency%1000)/100;
  92.         Display_FM[2] = (frequency%100)/10;
  93.         Display_FM[3] = 0x2e;//小數(shù)點               
  94.         Display_FM[4] = (frequency%10);                        
  95.                
  96.          if( Display_FM[0] == 0)
  97.         {  
  98.           Display_FM[0] =  Display_FM[1]+0x30;
  99.           Display_FM[1] =  Display_FM[2]+0x30;
  100.           Display_FM[2] =  Display_FM[3];
  101.           Display_FM[3] =  Display_FM[4]+0x30;
  102.           Display_FM[4] = 0x20;
  103.         }
  104.         else
  105.         {  
  106.           Display_FM[0] += 0x30;
  107.           Display_FM[1] += 0x30;
  108.           Display_FM[2] += 0x30;
  109.           Display_FM[4] += 0x30;
  110.         }
  111. }                                                                           
  112.        
  113. void show_volume()//音量顯示子函數(shù)
  114. {
  115.         unsigned char temp;
  116.        
  117.         temp = RDA_reg_data[7] & 0x0f; //取音量值
  118.         Display_Vol[3] = temp/10;
  119.         Display_Vol[4] = temp%10;
  120.        
  121.         if(Display_Vol[3] == 0)// 如果高位為0         
  122.        
  123.         {  
  124.          Display_Vol[3] = Display_Vol[4];  //低位顯存內(nèi)容進入高位顯存  
  125.          Display_Vol[4] = 0x20;//低位不顯示
  126.         }
  127.          else  
  128.           Display_Vol[4] += 0x30;
  129.           Display_Vol[3] += 0x30;
  130. }

  131. void Set_Frq()        //按鍵設(shè)置
  132. {
  133. if(K1 == 0)
  134.      {
  135.        Delay_ms(20);
  136.        if(K1 == 0)
  137.        {
  138.          RDA_reg_data[0] |= (1 << 1); //SEEK UP  
  139.                  RDA5807_FM_seek();
  140.                    while(K1 == 0);
  141.          }
  142.      }   
  143. if(K2 == 0)
  144.      {
  145.        Delay_ms(20);
  146.        if(K2 == 0)
  147.        {
  148.          RDA_reg_data[0] &= ~(1 << 1);  //SEEK DOWN
  149.                   RDA5807_FM_seek();
  150.          while(K2 == 0);
  151.                 }
  152.      }
  153. if(K3 == 0)
  154.      {
  155.        Delay_ms(20);
  156.        if(K3 == 0)
  157.                 {
  158.          if((RDA_reg_data[7] & 0x0f) < 0x0f)
  159.          {
  160.            RDA_reg_data[0] = 0xd0;
  161.            RDA_reg_data[1] = 0x01;
  162.            RDA_reg_data[3] &= ~(1 << 4);

  163.            RDA_reg_data[7]++; //音量遞增
  164.                   RDA5807_write_reg();
  165.                      while(K3 == 0);
  166.                    }
  167.        }
  168.      }

  169. if(K4 == 0)
  170.      {
  171.        Delay_ms(20);
  172.        if(K4 == 0)
  173.        {
  174.          if((RDA_reg_data[7] & 0x0f) > 0x00)
  175.          {
  176.            RDA_reg_data[0] = 0xd0;
  177.            RDA_reg_data[1] = 0x01;
  178.            RDA_reg_data[3] &= ~(1 << 4);
  179.             
  180.            RDA_reg_data[7]--; //音量遞減
  181.                      RDA5807_write_reg();
  182.            while(K4 == 0);
  183.                    }
  184.         }
  185.      }
  186. }       



復(fù)制代碼


數(shù)控收音機.rar

105.53 KB, 下載次數(shù): 263, 下載積分: 黑幣 -5

程序

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏10 分享淘帖 頂2 踩

相關(guān)帖子

回復(fù)

使用道具 舉報

沙發(fā)
ID:130513 發(fā)表于 2016-7-15 00:12 | 只看該作者
正在學(xué)習(xí)單片機程序
回復(fù)

使用道具 舉報

板凳
ID:58110 發(fā)表于 2016-9-7 10:34 | 只看該作者
最好有圖片,看看效果
回復(fù)

使用道具 舉報

地板
ID:72088 發(fā)表于 2016-9-25 19:32 | 只看該作者
我想學(xué)習(xí)收音機,實現(xiàn)兒時的夢想
回復(fù)

使用道具 舉報

5#
ID:72088 發(fā)表于 2016-9-25 19:33 | 只看該作者
好喜歡收音機,曾經(jīng)刻板一臺
回復(fù)

使用道具 舉報

6#
ID:120085 發(fā)表于 2017-4-25 09:30 | 只看該作者
下載試試看看,是不是我的硬件壞了
回復(fù)

使用道具 舉報

7#
ID:120085 發(fā)表于 2017-4-25 09:37 | 只看該作者
怎么接線的?shuoming
回復(fù)

使用道具 舉報

8#
ID:120085 發(fā)表于 2017-4-25 09:37 | 只看該作者
怎么接線的,說明一下?
回復(fù)

使用道具 舉報

9#
ID:84238 發(fā)表于 2017-10-6 12:03 | 只看該作者
請問  QN8075能代用嗎
回復(fù)

使用道具 舉報

10#
ID:526841 發(fā)表于 2019-5-9 12:30 | 只看該作者
大哥有接線圖嗎?還有你這個RDA5807芯片是什么型號的?多少個腳位的?
回復(fù)

使用道具 舉報

11#
ID:299054 發(fā)表于 2020-4-24 11:46 | 只看該作者
謝謝樓主分享!
回復(fù)

使用道具 舉報

12#
ID:799862 發(fā)表于 2020-7-8 17:28 | 只看該作者
樓主,請問RDA5807_write_reg(void)函數(shù)的作用是啥?
回復(fù)

使用道具 舉報

13#
ID:543424 發(fā)表于 2023-10-18 18:20 | 只看該作者
不知道有電路圖嗎?
回復(fù)

使用道具 舉報

14#
ID:1096562 發(fā)表于 2023-10-19 13:04 | 只看該作者
感謝分享,保存研究
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表