硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2990|回复: 1
收起左侧

Si4704收音机实现自动搜索方法,附上代码

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107101
QQ
发表于 2016-3-8 15:10:48 | 显示全部楼层 |阅读模式
具体可以查看手册,我这里将代码贴出来,添加到V4,V5或者V6板子的驱动末尾即可:
  1. /*
  2. *********************************************************************************************************
  3. *    函 数 名: Si47XX_FMSeekStart
  4. *    功能说明: 搜索有效的FM频率
  5. *    形    参: _SeekMode  搜索模式;
  6. *    返 回 值: 0 失败, 1 成功
  7. *********************************************************************************************************
  8. */
  9. static uint8_t Si47XX_FMSeekStart(SEEK_MODE_E _SeekMode)
  10. {
  11.     uint32_t uiTimeOut;
  12.     uint8_t ucCmdBuf[2];
  13.    
  14.     /*
  15.         FM_SEEK_START
  16.         Begins searching for a valid frequency.
  17.         CMD      0x21       FM_SEEK_START
  18.         ARG1     bit7:4     Reserved Always write to 0.
  19.                  bit3       SEEKUP Seek Up/Down.
  20.                             Determines the direction of the search, either UP = 1, or DOWN = 0.
  21.                  bit2       WRAP Wrap/Halt.
  22.                             Determines whether the seek should Wrap = 1, or Halt = 0 when it hits the
  23.                             band limit.
  24.                  bit1:0     Reserved Always write to 0.
  25.         STATUS   ?0x80      Reply Status. Clear-to-send high.
  26.     */
  27.    
  28.     ucCmdBuf[0] = 0x21;
  29.     switch(_SeekMode)
  30.     {
  31.         case SEEKDOWN_HALT:
  32.         {
  33.             ucCmdBuf[1] = 0x00;
  34.             break;
  35.         }
  36.         
  37.         case SEEKDOWN_WRAP:
  38.         {
  39.             ucCmdBuf[1] = 0x04;
  40.             break;
  41.         }
  42.         
  43.         case SEEKUP_HALT:
  44.         {
  45.             ucCmdBuf[1] = 0x08;
  46.             break;
  47.         }
  48.         
  49.         case SEEKUP_WRAP:
  50.         {
  51.             ucCmdBuf[1] = 0x0C;
  52.             break;
  53.         }
  54.     }
  55.     /* AN332  page = 277
  56.         Powerup in Analog Mode
  57.         CMD      0x01     POWER_UP
  58.         ARG1     0xC0     Set to FM Receive. Enable interrupts.
  59.         ARG2     0x05     Set to Analog Audio Output
  60.         STATUS   →0x80   Reply Status. Clear-to-send high.
  61.     */
  62.     SI4730_SendCmd(ucCmdBuf, 2);
  63.     /*
  64.         第1个形参表示最大轮询次数; 如果成功,返回值uiTimeOut > 0 表示实际轮询次数
  65.         第2个形参1表示结束后发送STOP
  66.     */
  67.     uiTimeOut = SI4730_WaitStatus80(1000, 1);
  68.     if (uiTimeOut == 0)
  69.     {
  70.         return 0;
  71.     }
  72.     return 1;
  73. }
  74. /*
  75. *********************************************************************************************************
  76. *    函 数 名: Si47XX_FMSeek
  77. *    功能说明: 搜索所有可用的FM频道
  78. *    形    参: _SeekMode  搜索模式
  79. *             _pFre      数组地址,用于记录搜索到的频道
  80. *             _FMLength  搜索到频道数。
  81. *    返 回 值: 无
  82. *********************************************************************************************************
  83. */
  84. void Si47XX_FMSeek(SEEK_MODE_E _SeekMode, uint16_t *_pFre, uint16_t *_FMLength)
  85. {
  86.     uint32_t uiTimeOut;
  87.     uint8_t ucCmdBuf[7];
  88.     uint16_t i = 0;
  89.    
  90.     while(1)
  91.     {
  92.         uiTimeOut = 0;
  93.         do
  94.         {
  95.             Si47XX_FMSeekStart(_SeekMode);
  96.             SI4730_GetFMTuneStatus(ucCmdBuf);
  97.             
  98.             uiTimeOut++;
  99.         }
  100.         while(((ucCmdBuf[0]&0x01) == 0) && (uiTimeOut < 5000) && ((ucCmdBuf[0]&0x80) == 0));
  101.         
  102.         /* 搜索完成一次后,一定要加100ms的延迟才能开启下次搜索 */
  103.         bsp_DelayMS(100);
  104.         
  105.         if((ucCmdBuf[0]&0x01) == 0x01)
  106.         {
  107.             /* 记录搜索到的频道 */
  108.             _pFre[i++] = (uint16_t)(ucCmdBuf[1] << 8) + ucCmdBuf[2];            
  109.         }
  110.         
  111.     #if 0
  112.         printf("---- = %d, %d\r\n", (ucCmdBuf[1] << 8) + ucCmdBuf[2], i);
  113.     #endif
  114.         
  115.         /* 搜索到FM频段末尾, 记录搜索到的总的频道数 */
  116.         if((ucCmdBuf[0]&0x80) != 0)
  117.         {
  118.             *_FMLength = i;
  119.             break;
  120.         }
  121.     }
  122. }
复制代码



回复

使用道具 举报

610

主题

3063

回帖

4913

积分

至尊会员

积分
4913
发表于 2016-3-18 13:15:04 | 显示全部楼层
不错不错啊,等会试试看
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-18 11:10 , Processed in 0.250856 second(s), 26 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表