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

📄 ar1000fsamplev085.c

📁 FM收音ICAR1010的DEMO程序
💻 C
📖 第 1 页 / 共 2 页
字号:
// ----- AR1000 VerF Sample Code ( v0.85, No-RDS ) by AIROHA Technology Corp. -------
// Version : 0.85   ( No-RDS)  for using internal XO or external 32.768 KHz reference clock
// Files : AR1000FSample.c , AR1000FSample.h
//
// This sample code presents following functions of AR1000/AR1010:
//
//       1. power-on sequence
//       2.frequency calculation and basic tune 
//	3. tune with Hi/Lo side rejection (** recommended procedure for tune )
//       4.seek with Hi/Lo side rejection ( and smute)
//       5.volume control
//	6. scan(** recommended procedure for scan )	
//	7. standby and wakeup procedure
//  
// This sample code could be compatiable with RDS function. However,the RDS related 
// opertions are beyond the scope of this sample code and are not presented here.
// ---------------------------------------------------------------------------------------------------------------
//
// Upgrade from 0.84 to 0.85
// - update register setting
//
// Upgrade from 0.82 to 0.83
// - Conditional compilation ( INTERNAL_XO)
// - DEMO: standby and wakeup
// Upgrade from 0.81 to0.82a
// - register update to ARF_V21_070813  ( disable xo_en & xo output  )
// - volume control update 
// - make sure hmute is always ON all over the seek and Hi/Lo-tune process
//   that is ,   AR1000_I2C_TUNE_HiLo (  )  and  AR1000_I2C_TUNE(  )  will MUTE ON
//   but not MUTE OFF. Caller must MUTE OFF explicitly.
// - completely scan procedure
// - errata:  
//                 "if (rssi < 0) ..... "    in AR1000_I2C_TUNE_HiLo (  )   
// 		
// Upgrade from 0.80 to 0.81
// - make sure RDS interrupt is OFF before seek and tune
// - max output of volume is recommended  (as default setting)

#include "AR1000FSample.h"

// the initial setting of AR1000 register ( base on ARF_V23_080121 )

#define INTERNAL_XO   // mark this line if you're using external reference clock
#ifdef INTERNAL_XO
code unsigned int AR1000reg[18]={ //using  AR1000 XO function
	0xFFFB,		// R0 -- the first writable register .
	0x5B15,		// R1.
	0xD0B9,		// R2.
	0xA010,		// R3, seekTHD = 16
	0x0780,		// R4
	0x28AB,		// R5
	0x6400,		// R6
	0x1EE7,		// R7
	0x7141,		// R8
	0x007D,		// R9
	0x82C6,		// R10  disable wrap
	0x4E55,		// R11. <--- 
	0x970C,		// R12.
	0xB845,		// R13
	0xFC2D,		// R14
	0x8097,		// R15
	0x04A1,		// R16
	0xDF6A		// R17
};    
#else
code unsigned int AR1000reg[18]={ // using External 32.768KHz Reference Clock
	0xFF7B,		// R0 -- the first writable register .  (disable xo_en)
	0x5B15,		// R1.
	0xD0B9,		// R2.
	0xA010,		// R3   seekTHD = 16
	0x0780,		// R4
	0x28AB,		// R5
	0x6400,		// R6
	0x1EE7,		// R7
	0x7141,		// R8
	0x007D,		// R9
	0x82C6,		// R10  disable wrap
	0x4F55,		// R11. <--- (disable xo_output)
	0x970C,		// R12.
	0xB845,		// R13
	0xFC2D,		// R14
	0x8097,		// R15
	0x04A1,		// R16
	0xDF6A		// R17
};    
#endif

// Volume Control
// there are two different fields about volume control in AR1000F
//  Volume   :  D7  ~D10 in register R3
//  Volume2 :  D12~D15 in register R14
//  17 combinations of ( volume2 + volume)  are  recommended.
//  
//  
// code unsigned char AR1000vol[19]={ // volume control  (increasing) 070822
	// 0x0F,	// step 0
	// 0xCF,	// step 1
	// 0xDF,	// step 2
	// 0xFF,	// 3
	// 0xCB,	// 4
	// 0xDB,	// 5
	// 0xFB,	// 6
	// 0xFA,	// 7
	// 0xF9,	// 8
	// 0xF8,	// 9
	// 0xF7,	//10
	// 0xD6,	//11
	// 0xE6,	//12
	// 0xF6,	//13
	// 0xE3,	//14
	// 0xF3,	//15
	// 0xF2,	//16 
	// 0xF1,	//17
	// 0xF0	//18 <------ default setting
// };
idata DATA_TYPE_S Reg_Data[18]; 

void main  ( void )
{
	unsigned int val;
	// Get IC version
	val = AR1000_I2C_Read_Data(ADDR_CHIPID);	
	if( val != CHIPNO_AR1000 ) {
		// this is not AR1000
		return;
	}
	
	val = AR1000_I2C_Read_Data(ADDR_DEVID);	

	// MUST-BE : AR1000 Power-On Sequence
	AR1000_init();

	// DEMO: Hi/Lo Tune  to the station - 98.1MHZ
	AR1000_RDSInt_OFF // Remeber to OFF RDS Interrupt before seek and tune , if you are using RDS Interrupt
	AR1000_I2C_TUNE_HiLo(981);//, UEBAND, SPACE100K); // to 98.1 MHz	
	AR1000_RDSInt_ON  // Turn on RDS interrupt  if you want
	AR1000_MUTE_OFF      
	AR1000_I2C_Write_Data(1);	
	
	// DEMO: the complete SEEK function 
	//
	// use default SEEKTH 
	//
	AR1000_RDSInt_OFF // Remeber to OFF RDS Interrupt before seek and tune , if you are using RDS Interrupt
	AR1000_I2C_SEEK(SEEKUP, UEBAND, SPACE100K); 
	AR1000_RDSInt_ON  // Turn on RDS interrupt  if you want
	
	// DEMO: the scan function 
	//
	// use the native seek capibility of AR1000 to accomplish  scan function 
	//	
	AR1000_RDSInt_OFF // Remeber to OFF RDS Interrupt before seek and tune , if you are using RDS Interrupt
	val = AR1000_I2C_SCAN(SEEKUP, UEBAND, SPACE100K);
	AR1000_RDSInt_ON  // Turn on RDS interrupt  if you want
	// totally  "val" stations are found  by scan !

	// DEMO: standby mode
	AR1000_I2C_STANDBY();
	
	//DEMO:wakeup 
	AR1000_I2C_WAKEUP(981); // wake up and tune to 98.1MHz

	return;
}


void AR1000_init(void)
{
 
	char Cnt1; // init R1, R2, ....R17 then R0
    unsigned int status;

	Reg_Data[0].i=AR1000reg[0]&0xFFFE;
	AR1000_I2C_Write_Data(0);
	
  	for(Cnt1=1;Cnt1<18;Cnt1++)
  	{
  		Reg_Data[Cnt1].i=AR1000reg[Cnt1]; 
  		AR1000_I2C_Write_Data(Cnt1);

	}
	
	Reg_Data[0].i=AR1000reg[0];
	AR1000_I2C_Write_Data(0);
	
	//Power-On Calibration begins
	// then wait for STC flag
	// maybe you need to delay for a while
	// delay ( 100 ms )
	status = AR1000_I2C_Read_Data(ADDR_STATUS);
	status &=MASK_STC; // check STC flag 
	while( status == 0)
	{
		// maybe you can delay for a while
		// delay ( 100 ms )
		status = AR1000_I2C_Read_Data(ADDR_STATUS);
		status &=MASK_STC; // check STC flag 
	}
	//Power-On Calibration Ends

	//SetAR1000_volume(19);	// max. output is recommended !! it is already set in the default register setting
						// you dont need to set it again
	
  	return;
}

void AR1000_I2C_TUNE_HiLo(unsigned int FreqKHz)// unsigned int band, unsigned char space)
{
  unsigned int status;
  unsigned int flag;
  unsigned int rssi;
  
  AR1000_MUTE_ON   // Set Muto ON before TUNE
  AR1000_I2C_Write_Data(1);
  
  AR1000_SEEK_OFF;	//clear SEEK 
  //Reg_Data[3].BIT.B13=space;  // set SPACE 
  //Reg_Data[3].i = (Reg_Data[3].i & 0xE7FF) | band;  // Set BAND
  AR1000_I2C_Write_Data(3);

  //Read Low-Side LO Injection
  //R11 --> clear  D15,  clear D0/D2,  D3 is the same as default
  Reg_Data[11].i = Reg_Data[11].i&0x7FFA; 
  AR1000_I2C_Write_Data(11);
  
  //TUNE to FreqKHz with current setting
  SetAR1000_Freq2CHAN(FreqKHz); // this function will turn on TUNE 
 
  // TUNE  begins
  // then wait for STC flag
  
  // maybe you need to delay for a while
  // delay ( 100 ms )
  status = AR1000_I2C_Read_Data(ADDR_STATUS);
  flag = status & MASK_STC; // check STC flag 
  while( flag == 0)
  {
		// maybe you can delay for a while
		// delay ( 100 ms )
		status = AR1000_I2C_Read_Data(ADDR_STATUS);
		flag = status & MASK_STC; // check STC flag 
  }
  //Low-side TUNE Ends 
  
  status = AR1000_I2C_Read_Data(ADDR_RSSI);
  rssi = (status & MASK_RSSI);

  //Read Hi-Side LO Injection
  // R11-->set D15, set D0/D2,  D3 is the same as default
  Reg_Data[11].i = Reg_Data[11].i|0x8005;
  AR1000_I2C_Write_Data(11);
  //TUNE to FreqKHz with current setting
  SetAR1000_Freq2CHAN(FreqKHz); // this function will turn on TUNE 
 
  // TUNE  begins
  // then wait for STC flag
  
  // maybe you need to delay for a while
  // delay ( 100 ms )
  status = AR1000_I2C_Read_Data(ADDR_STATUS);
  flag = status & MASK_STC; // check STC flag 
  while( flag == 0)
  {
		// maybe you can delay for a while
		// delay ( 100 ms )
		status = AR1000_I2C_Read_Data(ADDR_STATUS);
		flag = status & MASK_STC; // check STC flag 
  }
  //High-side TUNE Ends 
  
  status = AR1000_I2C_Read_Data(ADDR_RSSI);
  rssi = rssi- (status & MASK_RSSI);	
  if (rssi < 0) //errata in 0.82
  { 	
	// LO
	// R11--> clear D15, set D0/D2, D3 is the same as default
	Reg_Data[11].i = (Reg_Data[11].i&0x7FFF)|0x0005; 
	AR1000_I2C_Write_Data(11);
  }else{ 
	//HI
	//R11-->  set D15, clear D0/D2, D3 is the same as default
	Reg_Data[11].i = (Reg_Data[11].i|0x8000)&0xFFFA; 
	AR1000_I2C_Write_Data(11);
  }
  
  
  //fine-tune !!
  //TUNE to FreqKHz with current setting
  SetAR1000_Freq2CHAN(FreqKHz); // this function will turn on TUNE 
 
  // TUNE  begins
  // then wait for STC flag
  
  // maybe you need to delay for a while
  // delay ( 100 ms )

⌨️ 快捷键说明

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