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

📄 ar1000fsamplev085.c

📁 FM收音ICAR1010的DEMO程序
💻 C
📖 第 1 页 / 共 2 页
字号:
  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 
  }
  //TUNE Ends 
  
  //AR1000_MUTE_OFF      <---   we dont mute off now, bcz this function may be called by other functions 
  //AR1000_I2C_Write_Data(1);
  
  return;
}

void AR1000_I2C_SEEK(unsigned char updown, unsigned int band, unsigned char space)
{
  unsigned int status;
  unsigned int flag;
  unsigned int FreqKHz;
  
  AR1000_MUTE_ON   // Set Muto ON before SEEK
  AR1000_I2C_Write_Data(1);
  
  AR1000_TUNE_OFF  //clear TUNE
  AR1000_I2C_Write_Data(2);

  AR1000_SEEK_OFF;	//clear SEEK 
  AR1000_I2C_Write_Data(3);

  // Setting before seek
  Reg_Data[17].i = (Reg_Data[17].i & SEEK_MASK)|SEEK_SETTING;
  AR1000_I2C_Write_Data(17);
  //
  AR1000_SEEK_ON	 
  Reg_Data[3].BIT.B13=space;  // set SPACE 
  Reg_Data[3].BIT.B15=updown; // Seek up or down
  Reg_Data[3].i = (Reg_Data[3].i & 0xE7FF) | band;  // Set BAND
  AR1000_I2C_Write_Data(3); // set  and seek
  
  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 
  }
  // Seek Ends 
  // check SF if seek fail ?
  flag = status & MASK_SF;
  if ( flag )
  {
	//seek fail 
	return;
  }
  
  // seek success, get READCHAN  and fine-tune now !
  FreqKHz = 690 + ((status & MASK_READCHAN )>> SHIFT_READCHAN );

  // Restore setting after seek
  Reg_Data[17].i = AR1000reg[17];
  AR1000_I2C_Write_Data(17);
  //

  //fine-tune with auto hilo rejection
  AR1000_I2C_TUNE_HiLo(FreqKHz);// band, space);	
  
  AR1000_MUTE_OFF      
  AR1000_I2C_Write_Data(1);
  
  return;
}

unsigned int AR1000_I2C_SCAN(unsigned char updown, unsigned int band, unsigned char space)
{	// use the native seek capibility of AR1000 to accomplish  scan function 
  unsigned int status;
  unsigned int flag;
  unsigned int FreqKHz;
  unsigned int found;

  unsigned int start; // starting freuqncy (KHz) for scan
  unsigned int end;	// ending frequency (KHz) for scan
  
  AR1000_MUTE_ON   // Set Muto ON before SCAN
  AR1000_I2C_Write_Data(1);
  
  AR1000_TUNE_OFF  //clear TUNE
  AR1000_I2C_Write_Data(2);
  
  // Setting before seek
  Reg_Data[17].i = (Reg_Data[17].i & SEEK_MASK)|SEEK_SETTING;
  AR1000_I2C_Write_Data(17);
  // 
 
  start = 875; //87.5MHz is just an example 
  end = 1080;  //108.0MHz is just an example 
  
  AR1000_TUNE_OFF  //clear TUNE, just make sure tune if OFF
  Reg_Data[2].i &=0xfe00;
  Reg_Data[2].i|=(start-690); // set 87.5 MHz as starting point for this scan  
  AR1000_I2C_Write_Data(2);
 
  flag = 0;
  found = 0;
  
  while( flag == 0 )
  { //scan begin
	AR1000_SEEK_OFF;	//clear SEEK 
	AR1000_I2C_Write_Data(3);      
 

	AR1000_SEEK_ON	 
	Reg_Data[3].BIT.B13=space;  // set SPACE 
	Reg_Data[3].BIT.B15=updown; // Seek up or down
	Reg_Data[3].i = (Reg_Data[3].i & 0xE7FF) | band;  // Set BAND
	AR1000_I2C_Write_Data(3); // set  and seek
  
	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 
	}
	// Seek Ends 
	// check SF if seek fail ?   0 means successful seek
	flag = status & MASK_SF;
	if( flag ==0 )
	{
		// seek success, get READCHAN , you may record this FreqKHz into your station list !
		FreqKHz = 690 + ((status & MASK_READCHAN )>> SHIFT_READCHAN );

		// update seek result to CHAN for next seek
		AR1000_TUNE_OFF // just make sure tune bit is off
		Reg_Data[2].i &=0xfe00;
		Reg_Data[2].i|=((status & MASK_READCHAN )>> SHIFT_READCHAN );
		AR1000_I2C_Write_Data(2);
		found++;
		if( FreqKHz == end )
		{ // scan to the end !!
			flag = 1; // for quit the while loop
		}

	}
}	

  // Restore setting after seek
  Reg_Data[17].i = AR1000reg[17];
  AR1000_I2C_Write_Data(17);
  //
  
  AR1000_MUTE_OFF      
  AR1000_I2C_Write_Data(1);
  
  return found;
}

//void SetAR1000_Freq2ChanID
// calculate AR1000 CHAN id  :  Freq (MHz) = 69 + 0.1*CHAN
void SetAR1000_Freq2CHAN(unsigned int FreqKHz)    
{       
  unsigned int CHAN =0x0000; //actually it's 9-bit

  AR1000_TUNE_OFF  //clear TUNE
  AR1000_I2C_Write_Data(2);
  
  CHAN = FreqKHz-690;
  Reg_Data[2].i &=0xfe00;
  Reg_Data[2].i|=CHAN;
  AR1000_TUNE_ON
  AR1000_I2C_Write_Data(2);

}  

// Volume Control
// there are two different fields about volume control in AR1000F
//  Volume   :  D7  ~D10 in register R3
//  Volume2 :  D12~D15 in register R14
//  22 combinations of ( volume2 + volume)  are  recommended.
//  
//  
//code unsigned char AR1000vol[22]={ // volume control  (increasing)
// set volume
// void SetAR1000_volume (char vol)
// {
	// Reg_Data[3].i &= 0xF87F;
	// Reg_Data[3].i |= (unsigned int)((AR1000vol[vol]&0x0F)<<7);
	
	// Reg_Data[14].i &= 0x0FFF;
	// Reg_Data[14].i |= (unsigned int)((AR1000vol[vol]&0xF0)<<8);
// }
// Bus Transfer
void AR1000_I2C_Write_Data(char Reg)
{
	char ack;
	
	
again:	
	I2C_START
	ack=Write_I2C_Byte(AR1000_I2C_WRITE_ADDR);
	ack|=Write_I2C_Byte(Reg);
	ack|=Write_I2C_Byte(Reg_Data[Reg].c[0]);
	ack|=Write_I2C_Byte(Reg_Data[Reg].c[1]);
	
	I2C_STOP
	if(ack)
		goto again;
}

unsigned int AR1000_I2C_Read_Data(char Reg)
{
	char ack;
	DATA_TYPE_S value;
	
again:	
	I2C_START 
	// set address of the register which we want to read 
	ack=Write_I2C_Byte(AR1000_I2C_WRITE_ADDR);
	ack|=Write_I2C_Byte(Reg);
	if(ack)
		goto again;
		
again2:		
	I2C_START
	// start to read
	ack=Write_I2C_Byte(AR1000_I2C_READ_ADDR);
	if(ack)
		goto again2;
		
	value.c[0]= Read_I2C_Byte(); // read 8-bit data
	value.c[1]= Read_I2C_Byte(); // read another 8-bit data
	I2C_STOP
	
	return value.i;

}

unsigned char Write_I2C_Byte( unsigned char bits )
{
	unsigned char ack;
	// write a byte of data to I2C bus
	
	return ack;
}

unsigned char Read_I2C_Byte( )
{
	unsigned char bits;
	// read a byte of data from I2C bus
	
	return bits;
}

void AR1000_I2C_STANDBY( )
{
	Reg_Data[0].BIT.B0 = 0;
	AR1000_I2C_Write_Data(0);
}


void AR1000_I2C_WAKEUP(unsigned int FreqKHz)
{
	unsigned int status;
	
	Reg_Data[0].BIT.B0 = 1;
	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	
	
	//fine-tune with auto hilo rejection
	AR1000_I2C_TUNE_HiLo(FreqKHz);	
	
}


⌨️ 快捷键说明

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