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

📄 radio.c

📁 7541数字高频头源程序
💻 C
📖 第 1 页 / 共 4 页
字号:
#include "public.h"

#define M_RadioNewKey {	if(F_InTASwitch)break;\
						BreakAFCheck();\
						if(RDSDispTimer>1)RDSDispTimer=1;\
						if(AFTAShowTimer>1)AFTAShowTimer=1;}
						
typedef struct Band_conststuct {
	unsigned int BandFreq;
	unsigned int MemFreq[6];
	unsigned char CurrentMem;
} BandConstStuct;
typedef struct Area_stuct {
	BandConstStuct Band[5];
	unsigned char FMStep;
	unsigned char FMSeekStep;
	unsigned int FMMaxFreq;
	unsigned int FMMinFreq;
	unsigned char FMStepOirt;
	unsigned int FMMaxFreqOirt;
	unsigned int FMMinFreqOirt;
	unsigned char AMStepMW;
	unsigned int AMMaxFreqMW;
	unsigned int AMMinFreqMW;
	unsigned char AMStepLW;
	unsigned int AMMaxFreqLW;
	unsigned int AMMinFreqLW;
	unsigned char FMStepWB;
	unsigned int FMMaxFreqWB;
	unsigned int FMMinFreqWB;
} AreaStuct;

static const AreaStuct Area[]=
{
	// USA
	8750,8750,9010,9810,10610,10790,8750,0,
	8750,8750,9670,10490,10690,10790,8750,0,
	//162400, 162425, 162450, 162475, 162500, 162525
	2400, 2400, 2425, 2450, 2475, 2500, 2525, 0,//Weather band
	530,530,600,1000,1600,1720,530,0,
	530,530,600,1000,1600,1720,530,0,	
	20,20,10790,8750,
	0,0,0,
	10,1720,530,
	0,0,0,
	25,2550,2400,

	// LATIN
	8750,8750,9010,9810,10610,10800,8750,0,
	8750,8750,8750,8750,8750,8750,8750,0,
	//162400, 162425, 162450, 162475, 162500, 162525
	2400, 2400, 2425, 2450, 2475, 2500, 2525, 0,//Weather band
	520,520,600,1000,1400,1620,520,0,
	520,520,520,520,520,520,520,0,
	10,10,10800,8750,
	0,0,0,
	10,1620,520,
	0,0,0,
	25,2550,2400,

	// EUROPE
	8750,8750,9010,9810,10610,10800,9120,0,
	8780,8780,9180,9390,9710,10300,10430,0,
	8750,8750,8750,8750,8750,8750,8750,0,
	522,522,603,999,1404,1620,522,0,
	144,144,171,216,270,288,144,0,
	5,10,10800,8750,
	//5,5,10800,8750,
	0,0,0,
	9,1620,522,
 	9,288,144,
	0,0,0,

	// OIRT
	6500,6500,8750,9000,9800,10600,10800,0,
	6500,6500,8750,9000,9800,10600,10800,0,
	6500,6500,8750,9000,9800,10600,10800,0,
	531,531,603,999,1404,1620,531,0,
	144,144,171,216,270,288,144,0,
	5,10,10800,8750,
	3,7400,6500,
	9,1620,522,
 	9,288,144,
	0,0,0,
 	
 	// JAPAN
	7600,7600,7820,7900,8000,8500,9000,0,
	7600,7600,7900,8200,8500,8800,9000,0,
	7600,7600,7950,8250,8550,8850,9000,0,
	531,531,603,999,1404,1620,531,0,
	144,144,171,216,270,288,144,0,
	5,10,9000,7600,
	0,0,0,
	9,1620,522,
 	9,288,144,
	0,0,0,
};

#if TDA7540Tuner
static const unsigned char TunerDefaultSetting[]=
{
	0xd1,0x60,0x08,0x80,0x1a,0x98,0x8f,0x00,0x61,0xd0,
	0x20,0x4a,0x93,0x35,0x25,0x20,0x00,0xc0,0x36,0xc6,
	0x00,0x07,0x04,0x60,0x46,0x9e,0xe7,0x79,0x7c,0xdc,
	0x14,0x7d,0x79,0x00,0x00,0x00,0x00,0x00,0xfe,0xfe,
	0xaf,0x94,0x8d,0x48,0x48,0x48,0xa6,0x9d,0x92,0x90,
};
#endif

#if TDA7541Tuner
static const unsigned char TunerDefaultSetting[]=
{
 	0x0b,0x60,0x08,0x00,0xdc,0x3d,0x06,0x50,0x7a,0x49,
	0x0e,0x49,0xa9,0x40,0xd8,0xe7,0x1d,0x77,0x0d,0x2f,
	0x97,0xfa,0x05,0xe2,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,
 };
#endif
 

unsigned char CheckSD(unsigned int times,unsigned int all)
{
	unsigned int i,j;
	for(i=0,j=0;i<all;i++)
	{
		if(!Pin_SSTOP)
		{
			j++;
			if(j>=times)return(0);
		}
	}
	return(1);
}

unsigned char CheckIFC(unsigned int times,unsigned int all)
{
	unsigned int i,j;
	for(i=0,j=0;i<all;i++)
	{
		if(!Pin_SSTOP)
		{
			j++;
			if(j>=times)return(0);
		}
	}
	return(1);
}


unsigned char GetSMeter (void)
{
	unsigned int inttemp;
	unsigned char temp;
  	unsigned char i,max,min;

	//F_ADDisable=1;
	inttemp=0;
  	for (i=0,max=0,min=255;i<5;i++)
  	{
		temp=(GetADCValue(AD_FSU)>>1);
		inttemp+=(int)temp;
		if(temp<min)min=temp;
		if(temp>max)max=temp;
  	}  	
  	//F_ADDisable=0;
	temp = (inttemp-min-max)/3;
  	return(temp);	
}

void LoadArea(void)
{
	unsigned char i,j;
	for(i=0;i<5;i++)
	{
		for(j=0;j<6;j++)
			Radio.Band[i].MemFreq[j]=Area[Radio.Area].Band[i].MemFreq[j];
		Radio.Band[i].BandFreq=Area[Radio.Area].Band[i].BandFreq;
		Radio.Band[i].CurrentMem=Area[Radio.Area].Band[i].CurrentMem;		
	}

	Radio.MaxFreq=Area[Radio.Area].FMMaxFreq;
	Radio.MinFreq=Area[Radio.Area].FMMinFreq;
	Radio.Step=Area[Radio.Area].FMStep;
	Radio.SeekStep=Area[Radio.Area].FMSeekStep;

	Radio.CurrentBand=0;
}

signed char ChangeTV2(unsigned char inputbuff)
{
	if(inputbuff&0x80)
		return (inputbuff&0x7F);
	else
		return (0-(inputbuff&0x7F));
}

unsigned char ChangeToTV2(signed char inputbuff)
{
	if(inputbuff&0x80)
		return (0x80-(inputbuff&0x7F));
	else
		return ((inputbuff&0x7F)+0x80);
}

/*unsigned char GetTV2(unsigned int inputfreq,unsigned int maxfreq,unsigned int minfreq,unsigned char maxval,unsigned char minval)
{
	signed char temp;
	temp=(signed char)((signed long int)(ChangeTV2(minval)-ChangeTV2(maxval))*(maxfreq-inputfreq)/(maxfreq-minfreq)+ChangeTV2(maxval));
	return(ChangeToTV2(temp));
}*/

unsigned char GetTV2(unsigned int inputfreq)
{
	signed char temp;
	signed int tempslope;
	if(FreqInAM(inputfreq))
		return(0x90);

	if(FreqInOirtFM(inputfreq))
	{
		if(inputfreq<6650)
			return(TunerEepromBuff[53]);
		else if(inputfreq<7050)
			return(TunerEepromBuff[54]);
		else
			return(TunerEepromBuff[55]);
	}
	if(FreqInJapanFM(inputfreq))
	{
		if(inputfreq<8100)
			return(TunerEepromBuff[60]);//need to consistent with the module EEPROM table
		else if(inputfreq<8600)
			return(TunerEepromBuff[61]);
		else
			return(TunerEepromBuff[62]);
	}	
	if(FreqInWBFM(inputfreq))
	//	//return(EepromBuff[49]);//need to consistent with the module FE design and EEPROM table
		return(0xff);//tempory
		
	if(inputfreq<Radio.TestPointFreq)
		tempslope=Radio.Slope;
	else
		tempslope=Radio.Slope2;
	temp=(signed char)((signed int)(Radio.TestPointFreq-inputfreq)/tempslope+Radio.TestPointVal);
	return(ChangeToTV2(temp));
}

void RadioInit(void)
{
	unsigned char i,j,k;
	Pin_POWER=1;
	Wait1ms(200);
	EepromRead(TunerEepromAddress,0,1,&TunerEepromBuff[0]);
	
#if TDA7540Tuner
	if(TunerEepromBuff[0]!=0x0C)
	{
		TRAP;
		for(i=0;i<50;i++)
			TunerEepromBuff[i+10]=TunerDefaultSetting[i];
		Radio.F_Tuner_Empty=1;
	}
	else
	{
		TRAP;
		EepromRead(TunerEepromAddress,0,72,&TunerEepromBuff[0]);
		Radio.F_Tuner_Empty=0;

	}
	TRAP;
#endif
	
#if TDA7541Tuner
	if(TunerEepromBuff[0]!=0x0b)
	{
		TRAP;
		for(i=0;i<30;i++)
			TunerEepromBuff[i+10]=TunerDefaultSetting[i];
		Radio.F_Tuner_Empty=1;
			//Display Empty and load default setting
	}
	else
	{
		TRAP;
		EepromRead(TunerEepromAddress,0,100,&TunerEepromBuff[0]);
		Radio.F_Tuner_Empty=0;

	}
	TRAP;
#endif
	
	Radio.TestPointFreq=9810;
	Radio.TestPointVal=ChangeTV2(TunerEepromBuff[51]);
	if(TunerEepromBuff[50]!=TunerEepromBuff[51])
	{
		Radio.Slope=(signed int)(9810-8810)/(ChangeTV2(TunerEepromBuff[50])-ChangeTV2(TunerEepromBuff[51])); //for Xinfa
	}
	else
	{
		Radio.Slope=(signed int)(30000);
	}
		
	if(TunerEepromBuff[51]!=TunerEepromBuff[52])
	{
		Radio.Slope2=(signed int)(10750-9810)/(ChangeTV2(TunerEepromBuff[51])-ChangeTV2(TunerEepromBuff[52]));
	}
	else
	{
		Radio.Slope2=(signed int)(30000);
	}

	RadioSetFreq(8750);
	Pin_POWER=0;

	//Radio.Area=Menu.Band_set;
	//Radio.Area=AREA_OIRT;
	//Radio.Area=AREA_JAPAN;
	Radio.Area=AREA_EUROPE;
	//Radio.Area=AREA_USA; //LG test seek step 10K
	LoadArea();
	
	Radio.F_ForceSetBuff=1;
	RadioSetFreq(Radio.Band[0].BandFreq);

	Radio.CurrentBand=0;

	for(k=0;k<5;k++)
	{
		for(j=0;j<6;j++)
		{
			Radio.Band[k].MemAFNum[j]=0;
			for(i=0;i<8;i++)
				Radio.Band[k].MemAFList[j][i]=0xFF;
		}
	}

#if TDA7540Tuner
	DB4=8;//delta value---for RDA AF check 
	DB10=50;//for radio to speed up seek
	DB20=66;//---for RDA AF check 
	DB40=105;//---for RDA AF check 
#endif

#if TDA7541Tuner
	DB4=6;//delta value---for RDA AF check 
	DB10=15;//for radio to speed up seek
	DB20=25;//---for RDA AF check 
	DB40=51;//---for RDA AF check
#endif
	
}

void RadioOn(void)
{
#if TDA7541Tuner
	EepromRead(TunerEepromAddress,0,1,&TunerEepromBuff[0]);
	Wait1ms(10);
	if(TunerEepromBuff[0]!=0x0b)
	{
		Radio.F_Tuner_Empty=1;
		RadioTunerEepromTimer=10;
	}
	else
	{
		Radio.F_Tuner_Empty=0;
	}
#endif

	Radio.ReqFreq=Radio.Band[Radio.CurrentBand].BandFreq;
	Radio.F_ForceSetBuff=1;
	RadioSetFreq(Radio.ReqFreq);
	Radio.F_TunerDispReq=1;

	RadioMute(SOFTOFF);
}

void RadioOff(void)
{
	RDSDataInit();
}

void RadioMain(void)
{
	if(System.FWorkMode.Next==WORKMODE_RADIO)
		RadioOn();
	if(System.FWorkMode.Last==WORKMODE_RADIO)
		RadioOff();
	//if(System.FWorkMode.Current!=WORKMODE_RADIO)return;
	RadioSeek();
	RadioWork();
	RadioKey();
	RadioDisplay();
}

void RadioKey(void)
{
	if(System.FWorkMode.Current!=WORKMODE_RADIO)return;

	if(Radio.F_ManualSeek ||((SeekKeyTimer%2)==0 && SeekKeyTimer>50))
	{
		if(Radio.F_ManualSeek)
			SeekKeyTimer=50;
		else
			SeekKeyTimer=255;
			
		Radio.F_ManualSeek=0;
		
		RadioMute(SOFTON);
		Radio.ReqFreq=RadioFreqCal(Radio.Step);
		RadioSetFreq(Radio.ReqFreq);
		Wait1ms(1);
		RadioMute(SOFTOFF);
		Radio.F_TunerDispReq=1;
	}
	
	switch(KeyCode)
	{
		case S_AD_M1:
		case S_RM_M1:
			M_RadioNewKey;
			RadioLoad(0);
			break;
		case S_AD_M2:
		case S_RM_M2:
			M_RadioNewKey;
			RadioLoad(1);
			break;
		case S_AD_M3:
		case S_RM_M3:
			M_RadioNewKey;
			RadioLoad(2);
			break;
		case S_AD_M4:
		case S_RM_M4:
			M_RadioNewKey;
			RadioLoad(3);
			break;
		case S_AD_M5:
		case S_RM_M5:
			M_RadioNewKey;
			RadioLoad(4);
			break;
		case S_AD_M6:
		case S_RM_M6:
			M_RadioNewKey;
			RadioLoad(5);
			break;
		case L_AD_M1:
		case L_RM_M1:
			M_RadioNewKey;
			RadioSave(0);
			break;
		case L_AD_M2:
		case L_RM_M2:
			M_RadioNewKey;
			RadioSave(1);
			break;
		case L_AD_M3:
		case L_RM_M3:
			M_RadioNewKey;
			RadioSave(2);
			break;
		case L_AD_M4:
		case L_RM_M4:
			M_RadioNewKey;
			RadioSave(3);
			break;
		case L_AD_M5:
		case L_RM_M5:
			M_RadioNewKey;
			RadioSave(4);
			break;
		case L_AD_M6:
		case L_RM_M6:
			M_RadioNewKey;
			RadioSave(5);
			break;
			
		case L_AD_SEEKUP:
		case L_AD_SEEKDN:
			SeekKeyTimer=255;
			if(KeyCode==L_AD_SEEKUP)
				Radio.Direction=1;
			else
				Radio.Direction=-1;
			break;

		case R_AD_SEEKUP:
		case R_AD_SEEKDN:
			if(SeekKeyTimer>50)
			{
				Radio.F_ManualSeek=0;
				SeekKeyTimer=50;
			}
			
			break;

		case S_AD_SEEKUP:
		case S_AD_SEEKDN:
		
			if(SeekKeyTimer>0)
			{
				Radio.F_ManualSeek=1;
				if(KeyCode==S_AD_SEEKUP)
					Radio.Direction=1;
				else
					Radio.Direction=-1;
			}
			else
			{
				M_RadioNewKey;
				if(AFTAShowTimer>1)AFTAShowTimer=1;
				if(AudioWorkMode!=AUDIO_MODE_IDLE)break;
				
				if(KeyCode==S_AD_SEEKUP)
					Radio.Direction=1;

⌨️ 快捷键说明

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