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

📄 si47xxfmtx.c

📁 this is Si47xx Example Code
💻 C
📖 第 1 页 / 共 2 页
字号:
	// Disable the bit used for the interrupt of STC.
	SeekTuneInProc = 0;
}

//-----------------------------------------------------------------------------
// Tunes to the specified station in receive power scan mode for measuring
// the level of the station.
//
// Inputs:
//      frequency:  frequency in 10kHz steps
//-----------------------------------------------------------------------------
void si47xxFMTX_tuneMeasure(u16 frequency)
{
	// Enable the bit used for the interrupt of STC.
	SeekTuneInProc = 1;

	// Call the tune command to start the tune.
 	WaitSTCInterrupt = 1;
    txTuneMeasure(frequency);

    // wait for the interrupt before continuing
    // If you do not wish to use interrupts but wish to poll the part
    // then comment out this line.
    while (WaitSTCInterrupt); // Wait for interrupt to clear the bit

    // Wait for stc bit to be set
    while (!(getIntStatus() & STCINT));

	// Clear the STC bit and get the results of the tune.
    txTuneStatus(1);

	// Disable the bit used for the interrupt of STC.
	SeekTuneInProc = 0;
}

//-----------------------------------------------------------------------------
// Returns the current received noise level of the part if measured with
// txTuneMeasure.
//
// Returns:
//      frequency in 10kHz steps
//-----------------------------------------------------------------------------
u8 si47xxFMTX_get_rnl()
{
	// Get the tune status which contains the current frequency
	txTuneStatus(0);

    // Return the RSSI level
    return RNL;
}

//-----------------------------------------------------------------------------
// Helper function that sends the TX_TUNE_FREQ command to the part
//
// Inputs:
// 	frequency in 10kHz steps
//-----------------------------------------------------------------------------
static void txTuneFreq(u16 frequency)
{
    // Put the ID for the command in the first byte.
    cmd[0] = TX_TUNE_FREQ;

	// Initialize the reserved section to 0
    cmd[1] = 0;

	// Put the frequency in the second and third bytes.
    cmd[2] = (u8)(frequency >> 8);
	cmd[3] = (u8)(frequency & 0x00FF);

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

//-----------------------------------------------------------------------------
// Helper function that sends the TX_TUNE_POWER command to the part
//
// Inputs:
// 	Voltage in 1dBuV steps
//-----------------------------------------------------------------------------
static void txTunePower(u8 voltage)
{
    // Put the ID for the command in the first byte.
    cmd[0] = TX_TUNE_POWER;

	// Initialize the reserved section to 0
    cmd[1] = 0;
	cmd[2] = 0;

	// The voltage
	cmd[3] = voltage;

	// Set the chip to automatically calculate the antenna cap.
	cmd[4] = 0;

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

//-----------------------------------------------------------------------------
// Helper function that sends the TX_TUNE_MEASURE command to the part
//
// Inputs:
//      frequency in 10kHz steps
//-----------------------------------------------------------------------------
static void txTuneMeasure(u16 frequency)
{
    // Put the ID for the command in the first byte.
    cmd[0] = TX_TUNE_MEASURE;

	// Initialize the reserved section to 0
    cmd[1] = 0;

	// Put the frequency in the second and third bytes.
    cmd[2] = (u8)(frequency >> 8);
	cmd[3] = (u8)(frequency & 0x00FF);

	// Set the chip to automatically calculate the antenna cap.
	cmd[4] = 0;

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


//-----------------------------------------------------------------------------
// Helper function that sends the TX_TUNE_STATUS command to the part
//
// Inputs:
//  intack: If non-zero the interrupt for STCINT will be cleared.
//
// Outputs:  // These are global variables and are set by this method
//  STC:    The seek/tune is complete
//  Freq:   The current frequency
//  Voltage:The current tuned voltage level.
//  AntCap: The antenna capacitor value.
//  RNL:    The measured signal level if called after TX_TUNE_MEASURE
//-----------------------------------------------------------------------------
static void txTuneStatus(u8 intack)
{
    // Put the ID for the command in the first byte.
    cmd[0] = TX_TUNE_STATUS;

	// Put the flags if the bit was set for the input parameters.
	cmd[1] = 0;
	if(intack) cmd[1] |= TX_TUNE_STATUS_IN_INTACK;

    // Invoke the command
	si47xx_command(2, cmd, 8, rsp);

    // Parse the results
    STC    = !!(rsp[0] & STCINT);
    Freq   = ((u16)rsp[2] << 8) | (u16)rsp[3];
    Voltage= rsp[5];
    AntCap = rsp[6];   
	RNL    = rsp[7];

}

//-----------------------------------------------------------------------------
// Helper function that sends the TX_ASQ_STATUS command to the part
//
// Inputs:
//  intack: If non-zero the interrupt for ASQINT will be cleared.
//
// Outputs:  // These are global variables and are set by this method
//  OverMod: The audio signal is overmodulating the device.
//  IALH:    The audio signal was above the audio threshold for the duration
//           specified.
//  IALL:    The audio signal was below the audio threshold for the duration
//           specified.
//  InLevel: The current measured audio input level.
//-----------------------------------------------------------------------------
void txAsqStatus(u8 intack)
{
    // Put the ID for the command in the first byte.
    cmd[0] = TX_ASQ_STATUS;

	// Put the flags if the bit was set for the input parameters.
	cmd[1] = 0;
	if(intack) cmd[1] |= TX_ASQ_STATUS_IN_INTACK;

    // Invoke the command
	si47xx_command(2, cmd, 5, rsp);

    // Parse the results
	OverMod = !!(rsp[1] & TX_ASQ_STATUS_OUT_OVERMOD);
	IALH    = !!(rsp[1] & TX_ASQ_STATUS_OUT_IALH);
	IALL    = !!(rsp[1] & TX_ASQ_STATUS_OUT_IALL);
	InLevel = rsp[4];
}

//-----------------------------------------------------------------------------
// Helper function that sends the TX_RDS_PS command to the part
//
// Inputs:
//  id, char0-3: See the programming manual for more information.
//-----------------------------------------------------------------------------
void txRdsPs(u8 id, u8 char0, u8 char1, u8 char2, u8 char3)
{
    // Put the ID for the command in the first byte.
    cmd[0] = TX_RDS_PS;

	// Store the id and characters into the input parameters.
	cmd[1] = id;
	cmd[2] = char0;
	cmd[3] = char1;
	cmd[4] = char2;
	cmd[5] = char3;

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


//-----------------------------------------------------------------------------
// Helper function that sends the TX_RDS_BUFF command to the part
//
// Inputs:
//  intack: If non-zero the interrupt for RDSINT will be cleared.
//  mtbuff: Empties the specified buffer.
//  ldbuff: Loads the RDS data passed into the specified buffer.
//  fifo:   If 0-this command will interact with the circular buffer otherwise
//          the fifo.
//  rdsb:   RDS group b data placed into the buffer if ldbuff is 1.
//  rdsc:   RDS group c data placed into the buffer if ldbuff is 1.
//  rdsd:   RDS group d data placed into the buffer if ldbuff is 1.
//
// Outputs:  // These are global variables and are set by this method
//  RdsInt:    Contains any RDS interrupt information
//  CbAvail:   The amount of circular buffer currently available.
//  CbUsed:    The amount of circular buffer currently being used.
//  FifoAvail: The amount of the fifo currently available.
//  FifoUsed:  The amount of the fifo currently being used.
//-----------------------------------------------------------------------------
void txRdsBuff(bit intack, bit mtbuff, bit ldbuff, bit fifo,
			   u16 rdsb, u16 rdsc, u16 rdsd)
{
    // Put the ID for the command in the first byte.
    cmd[0] = TX_RDS_BUFF;

	// Put the flags if the bit was set for the input parameters.
	cmd[1] = 0;
	if(intack) cmd[1] |= TX_RDS_BUFF_IN_INTACK;
	if(mtbuff) cmd[1] |= TX_RDS_BUFF_IN_MTBUFF;
	if(ldbuff) cmd[1] |= TX_RDS_BUFF_IN_LDBUFF;
	if(fifo)   cmd[1] |= TX_RDS_BUFF_IN_FIFO;
    
	// Load the RDS values into the command array.
	cmd[2] = (u8)(rdsb >> 8);
	cmd[3] = (u8)(rdsb & 0x00FF);
	cmd[4] = (u8)(rdsc >> 8);
	cmd[5] = (u8)(rdsc & 0x00FF);
	cmd[6] = (u8)(rdsd >> 8);
	cmd[7] = (u8)(rdsd & 0x00FF);

    // Invoke the command
	si47xx_command(8, cmd, 6, rsp);

    // Parse the results
	RdsInt	  = rsp[1];
	CbAvail   = rsp[2];
	CbUsed    = rsp[3];
	FifoAvail = rsp[4];
	FifoUsed  = rsp[5];

}

⌨️ 快捷键说明

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