⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 si47xxamrx.c

📁 this is Si47xx Example Code
💻 C
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
//
// si47xxFAMRX.c
//
// Contains the AM radio functions with the exceptions of autoseek.
//
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051f320.h>
#include <stddef.h>
#include "typedefs.h"
#include "portdef.h"
#include "commanddefs.h"
#include "propertydefs.h"
#include "si47xxAMRX.h"

//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
#define POWERUP_TIME 110    // Powerup delay in milliseconds

//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
extern bit WaitSTCInterrupt;
extern bit PoweredUp;
extern bit SeekTuneInProc;
extern u8  idata cmd[8];
extern u8  idata rsp[13];
extern u8  chipFunction;

// This variables are used by the status commands.  Make sure to call those
// commands (amRsqStatus or amTuneStatus) prior to access.
extern u8  xdata Status;
extern u8  xdata RsqInts;
extern u8  xdata STC;
extern u8  xdata SMUTE;
extern u8  xdata BLTF;
extern u8  xdata AFCRL;
extern u8  xdata Valid;
extern u8  xdata Pilot;
extern u8  xdata Blend;
extern u16 xdata Freq;
extern u8  xdata RSSI;
extern u8  xdata ASNR;
extern u16 xdata AntCap;

//-----------------------------------------------------------------------------
// Function prototypes
//-----------------------------------------------------------------------------
void wait_ms(u16 ms);
void si47xx_command(u8 cmd_size, u8 idata *cmd, u8 reply_size, u8 idata *reply);
void si47xx_reset(void);
u8 getIntStatus(void);
void amTuneFreq(u16 frequency);
static void amSeekStart(u8 seekUp, u8 wrap);
static void amTuneStatus(u8 cancel, u8 intack);
static void amRsqStatus(u8 intack);

//-----------------------------------------------------------------------------
// Take the Si47xx out of powerdown mode.
//-----------------------------------------------------------------------------
void si47xxAMRX_powerup(void)
{

    // Check if the device is already powered up.
    if (PoweredUp) {
    } else {
        // Put the ID for the command in the first byte.
        cmd[0] = POWER_UP;

		// Enable the GPO2OEN on the part because it will be used to determine
        // RDS Sync timing.
        cmd[1] = POWER_UP_IN_GPO2OEN;

		// The device is being powered up in FM RX mode.
        cmd[1] |= POWER_UP_IN_FUNC_AMRX;

		// The opmode needs to be set to analog mode
        cmd[2] = POWER_UP_IN_OPMODE_RX_ANALOG;

        // Powerup the device
		si47xx_command(3, cmd, 8, rsp);
        wait_ms(POWERUP_TIME);               // wait for si47xx to powerup

        // Since we did not boot the part in query mode the result will not
        // contain the part information.

		PoweredUp = 1;
    }
}

//-----------------------------------------------------------------------------
// Place the Si47xx into powerdown mode.
//-----------------------------------------------------------------------------
void si47xxAMRX_powerdown(void)
{

	// Check to see if the device is powered up.  If not do not do anything.
    if(PoweredUp)
    {   
        // Set the powered up variable to 0
        PoweredUp = 0;

	    // Put the ID for the command in the first byte.
	    cmd[0] = POWER_DOWN;

	    // Invoke the command
		si47xx_command(1, cmd, 1, rsp);
    }
}

//-----------------------------------------------------------------------------
// This function will set up some general items on the hardware like
// initializing the STC interrupts.
//-----------------------------------------------------------------------------
static void si47xxAMRX_hardware_cfg(void)
{
	// Enable the RDS and STC interrupt here
    si47xx_set_property(GPO_IEN, GPO_IEN_STCIEN_MASK);
}

//-----------------------------------------------------------------------------
// Set up general configuration properties:
//      Soft Mute Rate, Soft Mute Max Attenuation, Soft Mute SNR Threshold,
//      Seek Tune SNR Threshold, Seek Tune RSSI Threshold
//
// Note:
//     * RDS is only available on certain parts.  Please refer to the data
//       sheet for your part to determine if your part supports RDS.
//-----------------------------------------------------------------------------
static void si47xxAMRX_general_cfg(void)
{
    // The softmute feature can be disabled, but it is normally left on.
    // The softmute feature is disabled by setting the attenuation property
    // to zero.
    //  si47xx_set_property(AM_SOFT_MUTE_RATE, 64);
    //  si47xx_set_property(AM_SOFT_MUTE_SLOPE, 2);
    //  si47xx_set_property(AM_SOFT_MUTE_MAX_ATTENUATION, 16);
    //  si47xx_set_property(AM_SOFT_MUTE_SNR_THRESHOLD, 10);

    // The channel filter usually is defaulted to 2kHz.  Change this and
    // uncomment if a different channel filter is desired.
    // si47xx_set_property(AM_CHANNEL_FILTER, 3);
 
    // The deemphasis is usually disabled.  Change if desired.
    // si47xx_set_property(AM_DEEMPHASIS, 0);

    // Typically the settings used for seek are determined by the designer
    // and not exposed to the end user. They should be adjusted here.
    si47xx_set_property(AM_SEEK_TUNE_SNR_THRESHOLD, 5);
    si47xx_set_property(AM_SEEK_TUNE_RSSI_THRESHOLD, 25);
}

//AM (Medium Wave), SW (Short Wave), and LW (Long Wave) use the same AM_SW_LW 
//components, thus the commands and properties for these functions are the same.
//For simplicity reasons, the commands and properties only have a prefix AM 
//instead of AM_SW_LW. The main difference among AM, SW, and LW is only the
//frequency range.

//-----------------------------------------------------------------------------
// Set up regional configuration properties including:
//      Seek Band Bottom, Seek Band Top, Seek Freq Spacing
//-----------------------------------------------------------------------------
static void si47xxAMRX_regional_cfg(void)
{
	// Change the following properties if desired for the AM settings appropriate
    // for your region.
    si47xx_set_property(AM_SEEK_FREQ_SPACING, 10); // Set spacing to 10kHz
    si47xx_set_property(AM_SEEK_BAND_BOTTOM, 520); // Set the band bottom to 520kHz
    si47xx_set_property(AM_SEEK_BAND_TOP, 1710);   // Set the band top to 1710kHz
}
//-----------------------------------------------------------------------------
// Set up regional configuration properties including:
//      Seek Band Bottom, Seek Band Top, Seek Freq Spacing
//-----------------------------------------------------------------------------
static void si47xxAMSWLWRX_regional_cfg(void)
{
	// Change the following properties if desired for the AM/SW/LW settings
	// appropriate for your region.

	//AM band
 //   si47xx_set_property(AM_SEEK_FREQ_SPACING, 10); // Set spacing to 10kHz
 //   si47xx_set_property(AM_SEEK_BAND_BOTTOM, 520); // Set the band bottom to 520kHz
 //   si47xx_set_property(AM_SEEK_BAND_TOP, 1710);   // Set the band top to 1710kHz

	//LW band
 //   si47xx_set_property(AM_SEEK_FREQ_SPACING, 9); // Set spacing to 9kHz
 //   si47xx_set_property(AM_SEEK_BAND_BOTTOM, 153); // Set the band bottom to 153kHz
 //   si47xx_set_property(AM_SEEK_BAND_TOP, 279);   // Set the band top to 279kHz

	//SW band (entire band)
 //   si47xx_set_property(AM_SEEK_FREQ_SPACING, 5); // Set spacing to 5kHz
 //   si47xx_set_property(AM_SEEK_BAND_BOTTOM, 2300); // Set the band bottom to 2300kHz
 //   si47xx_set_property(AM_SEEK_BAND_TOP, 23000);   // Set the band top to 23000kHz

	//SW band (120m band)
 //   si47xx_set_property(AM_SEEK_FREQ_SPACING, 5); // Set spacing to 5kHz
 //   si47xx_set_property(AM_SEEK_BAND_BOTTOM, 2300); // Set the band bottom to 2300kHz
 //   si47xx_set_property(AM_SEEK_BAND_TOP, 2495);   // Set the band top to 2495kHz

	//SW band (60m band)
    si47xx_set_property(AM_SEEK_FREQ_SPACING, 5); // Set spacing to 5kHz
    si47xx_set_property(AM_SEEK_BAND_BOTTOM, 4750); // Set the band bottom to 4750kHz
    si47xx_set_property(AM_SEEK_BAND_TOP, 5060);   // Set the band top to 5060kHz
}



//-----------------------------------------------------------------------------
// Configures the device for normal operation
//-----------------------------------------------------------------------------
void si47xxAMRX_configure(void)
{
    // Configure all other registers
    si47xxAMRX_hardware_cfg();
    si47xxAMRX_general_cfg();
    si47xxAMRX_regional_cfg();

	// Turn on the Headphone Amp and analog out.
	M_INPUT_AD = 1;
	M_OUTPUT_AD = 0;
	GP1 = 1;
}

//-----------------------------------------------------------------------------
// Configures the device for normal operation
//-----------------------------------------------------------------------------
void si47xxAMSWLWRX_configure(void)
{
    // Configure all other registers
    si47xxAMRX_hardware_cfg();
    si47xxAMRX_general_cfg();
    si47xxAMSWLWRX_regional_cfg();

	// Turn on the Headphone Amp and analog out.
	M_INPUT_AD = 1;
	M_OUTPUT_AD = 0;
	GP1 = 1;
}

//-----------------------------------------------------------------------------
// Resets the part and initializes registers to the point of being ready for
// the first tune or seek.
//-----------------------------------------------------------------------------
void si47xxAMRX_initialize(void)
{
    // Zero status registers.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -