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

📄 radio.c

📁 这是一个TDA7540的模版程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	        if(SMeterDelay>0)
		 break;
		if (P_SD==1)
	       {
		     RadioStatus = RADIO_IFCHECK;
		     l_cRadio_SDCnt = 0;
		     l_cRadio_SDVal = 0;		
		    break;
		 }
		else
		{
		     RadioStatus = RADIO_IFCHECKEND;
		     Radio_PLL_DisableIFCnt();
		 }
		 break;
	case RADIO_IFCHECK:
	      while (l_cRadio_SDCnt < MAX_SD_CNT)
	       {
		   if (P_SD==1)
		   {
			l_cRadio_SDVal++;						
		    }
		    l_cRadio_SDCnt++;
		}
		if (l_cRadio_SDVal > RADIO_SD_LIMIT)
		{						
		     F_TunerSearchOK =1;					
		}
     	      Radio_PLL_DisableIFCnt();
	      RadioStatus= RADIO_IFCHECKEND;
             break;
	case RADIO_IFCHECKEND:
		F_TunerDispReq=1;
		RadioStatus = RADIO_IDLE;
	      break;
   }
}

/*--------------------------------------------------------------------------
Routine : Radio_PresetLoad
Input   : 
Output  :
Description 
        - load the radio preset
--------------------------------------------------------------------------*/ 
void Radio_PresetLoad(unsigned char channel)
{
	radio_pll_freq = radio_pll_memfreq[radio_band][channel-1];
	radio_pll_offset =radio_pll_memoffset[radio_band][channel-1];
	PllRegisterRefresh();
}

/*--------------------------------------------------------------------------
Routine : RadioFreqBackUp
Input   : 
Output  :
Description 
        - back up the radio freq
--------------------------------------------------------------------------*/ 
void RadioFreqBackUp()
{
	radio_pll_lastfreq[radio_band] = radio_pll_freq;
	radio_pll_lastoffset[radio_band] = radio_pll_offset;
}

/*--------------------------------------------------------------------------
Routine : Radio_RecallFreq
Input   : 
Output  :
Description 
        - recall the frequency
--------------------------------------------------------------------------*/ 
void Radio_RecallFreq()
{
	radio_pll_freq = radio_pll_lastfreq[radio_band];
	radio_pll_offset = radio_pll_lastoffset[radio_band];
}

/*--------------------------------------------------------------------------
Routine : RadioBandChange
Input   : 
Output  :
Description 
        - radio band change 
--------------------------------------------------------------------------*/ 
void RadioBandChange(unsigned char band)
{
	switch(band)
	{
		case FM1:
			radio_band = FM1;
			AudioSource = AUDIO_SOURCE_FM;
			break;
		case MW1:
			radio_band = MW1;
			AudioSource = AUDIO_SOURCE_AM;
			break;
		case LW:
			radio_band = LW;
			AudioSource = AUDIO_SOURCE_AM;
			break;
	}

	AudioDataConvertSend(AUDIO_SOURCE);
	radio_pll_freq = radio_pll_lastfreq[radio_band];
	radio_pll_offset = radio_pll_lastoffset[radio_band];
	
	TunerRegisterRefresh();
	PllRegisterAllRefresh();
}

/*--------------------------------------------------------------------------
Routine : Start_Radio
Input   : 
Output  :
Description 
        - Start the radio routine
--------------------------------------------------------------------------*/ 
void Start_Radio()
{
	RadioMode = RM_IDLE;
	RadioStatus =RADIO_IDLE;
	F_RadioOK = 1;
	RadioFreqBackUp();
	
}

/*--------------------------------------------------------------------------
Routine : Radio_PowerOn
Input   : 
Output  :
Description 
        - Stop the radio routine
--------------------------------------------------------------------------*/ 
void Stop_Radio()
{
}

/*--------------------------------------------------------------------------
Routine : Radio_ATune
Input   : 
Output  :
Description 
        - auto seek
--------------------------------------------------------------------------*/ 
void Radio_ATune()
{
	if(F_TunerInSearch==0)
	{
		Radio_ClrSearch();
		RadioMode = RM_SCANING;
		radio_pll_lastmem[radio_band] = 0;
		F_TunerInSearch =1;
		radio_pll_prefreq = radio_pll_freq;
		Radio_NextFreq_Scan();
	}
	else
	{
		Radio_ClrSearch();
		PllRegisterRefresh();
		l_cSM_Val = Radio_EvalGetSMeter();
	       F_TunerDispReq=1;
	       radio_pll_lastmem[radio_band] = 0;
	       Start_Radio();
	}
}

/*--------------------------------------------------------------------------
Routine : Radio_MTune
Input   : 
Output  :
Description 
        - manual seek
--------------------------------------------------------------------------*/ 
void Radio_MTune()
{
	Radio_ClrSearch();
	if (F_SearchUpDN==0)
	{
		Radio_FreqDec();
	}
	else
	{
		Radio_FreqInc();
	}
	F_SearchInManual=1;
	PllRegisterRefresh();
	l_cSM_Val = Radio_EvalGetSMeter();
	F_TunerDispReq=1;
	radio_pll_lastmem[radio_band] = 0;
	Start_Radio();

}

/*--------------------------------------------------------------------------
Routine : Radio_ClrSearch
Input   : 
Output  :
Description 
        - stop the tuner search routine
--------------------------------------------------------------------------*/ 
void Radio_ClrSearch()
{
	Radio_Tun_SeekOff();
	Radio_ClrScan();
}
/*--------------------------------------------------------------------------
Routine : Radio_ClrScan
Input   : 
Output  :
Description 
        - Stop the radio scan routine
--------------------------------------------------------------------------*/ 
void Radio_ClrScan()
{
	if (F_TunerInSearch==1)
	{
		F_TunerInSearch=0;
		Radio_Tun_SeekOff();
		Radio_RecallFreq();			
		PllRegisterRefresh();
		Start_Radio();
	}
}
/*--------------------------------------------------------------------------
Routine : Radio_NextFreq_Scan
Input   : 
Output  :
Description 
        - scan the next frequency
--------------------------------------------------------------------------*/ 
void Radio_NextFreq_Scan()
{
	F_TunerSearchOK = 0;
	if (F_SearchUpDN==0)
	{
		Radio_FreqDec();
	}
	else
	{
		Radio_FreqInc();
	}
	Radio_SetScan();
}

/*************************************************************************************************
ROUTINE NAME :Radio_FreqInc
INPUT		 :                                                            
OUTPUT		 :
DESCRIPTION  :frequency increment (100Khz FM or 9KHz MW, 1kHz LW ).  
COMMENTS 
**************************************************************************************************/

void Radio_FreqInc()
{
	switch (radio_band)
	{
		case FM1:
				Radio_PLL_FreqInc(FM_MAX_FREQ,FM_MIN_FREQ);
				break;
		case MW1:
				Radio_PLL_FreqInc(AM_MAX_FREQ,AM_MIN_FREQ);						
				break;
		case LW:
        			Radio_PLL_FreqInc(LW_MAX_FREQ,LW_MIN_FREQ);
				break;
	}									
}
	
/*************************************************************************************************
ROUTINE NAME :Radio_FreqDec
INPUT		 :                                                            
OUTPUT		 :
DESCRIPTION  :frequency decrement (100Khz FM or 9KHz MW, 1kHz LW ).  
COMMENTS 
**************************************************************************************************/
	
void Radio_FreqDec()
{
	switch (radio_band)
	{
		case FM1:
				Radio_PLL_FreqDec(FM_MAX_FREQ,FM_MIN_FREQ);
				break;
		case MW1:
				Radio_PLL_FreqDec(AM_MAX_FREQ,AM_MIN_FREQ);						
				break;
		case LW:
				Radio_PLL_FreqDec(LW_MAX_FREQ,LW_MIN_FREQ);
				break;
	}	
}	

/*--------------------------------------------------------------------------
Routine : Radio_SetScan
Input   : 
Output  :
Description 
        - set the scan setting of the tuner
--------------------------------------------------------------------------*/ 
void Radio_SetScan()
{
	F_RadioOK=1;
	Radio_Set_ErrTime();
	PllRegisterAllRefresh();	
	Radio_Tun_SeekOn();
	Radio_PLL_EnableIFCnt();
	RadioFreqBackUp();
	RadioStatus= RADIO_SEEK;

       if (radio_band > FM1)
       {
	    RadioDelay = 9;
           SMeterDelay=9;         //delay to wait the smeter stable
       }
    else
    {
	    RadioDelay = 0;
	    SMeterDelay=2;
    }
}


/*--------------------------------------------------------------------------
Routine : Radio_Set_ErrTime
Input   : 
Output  :
Description 
        - Error delay time
--------------------------------------------------------------------------*/ 
void Radio_Set_ErrTime()
{
	switch (radio_band)
	{
		case FM1:
				ErrDelay = 5;
				break;
		case MW1:
				ErrDelay = 14;
				break;
		case LW:
				ErrDelay = 10;
				break;	
	}	
}

/*--------------------------------------------------------------------------
Routine : Radio_10msTimer
Input   : 
Output  :
Description 
        - timer for radio functions
--------------------------------------------------------------------------*/ 
void Radio_10msTimer()
{
	if(RadioDelay!=0)  RadioDelay--;
	if(SMeterDelay!=0) SMeterDelay--;
	if(ErrDelay!=0) ErrDelay--;
}
/*** (c) 2005  STMicroelectronics ****************** END OF FILE ***/

⌨️ 快捷键说明

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