?? autoseek.c
字號:
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051f320.h>
#include <stddef.h>
#include "typedefs.h"
#include "example.h"
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
u16 seek_preset[NUM_SEEK_PRESETS];
//-----------------------------------------------------------------------------
// Function prototypes
//-----------------------------------------------------------------------------
void si470x_tune (u16 frequency);
u8 si470x_seek (u8 seekup);
u16 si470x_get_frequency(void);
u8 si470x_get_rssi(void);
void _nop_(void);
//-----------------------------------------------------------------------------
// Inserts a channel in the preset array. First it finds the channel with the
// lowest rssi. If the current channel has a higher rssi, the channel with the
// lowest rssi is replaced. Channels are kept in order of increasing frequency.
//
// Inputs:
// frequency: Frequency of station found
// rssi: Rssi of station found
// seek_prset_rssi: Array of rsssi values for each preset
//
//-----------------------------------------------------------------------------
static void insert_preset(u16 frequency, u8 rssi, u8 *seek_preset_rssi)
{
u8 i;
u8 min_rssi = 0xff;
u8 min_rssi_preset=0;
// first find the minimum rssi and its location
// this will always stop at the first location with a zero rssi
for (i=0; i<NUM_SEEK_PRESETS; i++) {
if (seek_preset_rssi[i] < min_rssi) {
min_rssi = seek_preset_rssi[i];
min_rssi_preset = i;
}
}
// return if current preset rssi is less than minimum preset in array
if (rssi < min_rssi)
return;
// delete the preset with the minimum rssi, and clear the last preset
// since it would only be a copy of the second to last preset after
// the deletion
for (i=min_rssi_preset; i<NUM_SEEK_PRESETS-1; i++) {
seek_preset[i] = seek_preset[i+1];
seek_preset_rssi[i] = seek_preset_rssi[i+1];
}
seek_preset[i] = 0;
seek_preset_rssi[i] = 0;
// fill the first preset with a zero for the frequency. This will
// always overwrite the last preset once all presets have been filled.
for (i=min_rssi_preset; i<NUM_SEEK_PRESETS; i++) {
if(seek_preset[i] == 0) {
seek_preset[i] = frequency;
seek_preset_rssi[i] = rssi;
break;
}
}
}
//-----------------------------------------------------------------------------
// This routine scans the band and populates the seek_presets array with the
// strongest signals in the band. If the band is searched without filling all
// presets, the lowest preset numbers are left set to zero. Do not tune to
// presets set to zero.
//
// Note that during autoseek, the seek threshold can be lowered to increase
// the chances of filling all of the presets. A lower seek threshold will
// only increase the seek time and fill empty preset slots with weak stations
// instead of leaving them set to zero. It should not change the outcome in
// the preset array.
//
//-----------------------------------------------------------------------------
void si470x_autoseek(void)
{
u8 seek_preset_rssi [NUM_SEEK_PRESETS]; // local array storing rssi of each preset.
u8 i;
u8 seek_fail;
u16 current_frequency, last_frequency;
// initialize preset array and rssi array
for (i=0; i<NUM_SEEK_PRESETS; i++) {
seek_preset_rssi[i] = 0;
seek_preset[i] = 0;
}
// tune to the bottom of the band, then seek up once
si470x_tune(0);
last_frequency = si470x_get_frequency();
seek_fail = si470x_seek(1);
current_frequency = si470x_get_frequency();
while ((seek_fail == 0) && (last_frequency < current_frequency)) {
insert_preset(current_frequency, si470x_get_rssi(), seek_preset_rssi);
last_frequency = current_frequency;
seek_fail = si470x_seek(1); // seek up to the next station
current_frequency = si470x_get_frequency();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -