📄 tuner.c
字号:
}
/*********************************************************
* NAME : TuneOver
* CHK if the PreeSet or search Finished according
* the read byte1.7
*
*
* Returns : none
*
* Parameter Description
* --------------------------------------------------------
* none
*
* Externals Usage
* --------------------------------------------------------
*
*
* Additional information:
* Local subfunction
*********************************************************/
BYTE tbRead1; //for test only
BYTE tbRead2;
BYTE tbRead3;
BYTE tbRead4;
BIT Stereo=False;
BIT Ready=False;
/*********************************************************
* NAME : AssembleFrequencyWord
* given a VCO frequency calculate and load the
* frequency databitsr and save the PLL Freq to
* DataWord[37-24] =14 bits
*
* Returns : none
*
* Parameter Description
* --------------------------------------------------------
* none
*
* Externals Usage
* --------------------------------------------------------
* WriteDataWord[37-24] the bits will be Set according cal result(out)
* gdwPresetVCO in
*
* Additional information:
* Local subfunction
* All the Frequency unit is KHz.!
* Test it is ok 02/26
*********************************************************/
static void AssembleFrequencyWord(void)
{
UINT16 twPLL =0; //Dec
UINT32 tdwPresetVCO =gdwPresetVCO; //Khz
BYTE tbTmp1;
BYTE tbTmp2;
// calcu1ate frequency dataword bits from given station frequency BCD:
if(FlagHighInjection)
twPLL =(unsigned int)((float)((tdwPresetVCO +225)*4)/(float)REFERENCE_FREQ);
else
twPLL =(unsigned int)((float)((tdwPresetVCO -225)*4)/(float)REFERENCE_FREQ);
//convert BCD to Hex.
tbTmp1 =(unsigned char)(twPLL%256); //6789=Hex1A85 -->133=Hex85
tbTmp2 =(unsigned char)(twPLL/256); // -->26=Hex1A
WriteDataWord[0]=tbTmp2; //high block
WriteDataWord[1]=tbTmp1;
}
/*********************************************************
* NAME : DisAssembleFrequencyWord
* given a frequency dataword and waveband,
* calculate the VCO frequency
* Get the PLL Freq BITs from DataWord[37-24] =14 bits
* 5757 have 15 bits and the bits location is different!
* Returns : none
*
* Parameter Description
* --------------------------------------------------------
* none
*
* Externals Usage
* --------------------------------------------------------
* ReadDataWord[37-24] the bits will be taken(in)
* gdwSearchedVCO the Freq (out)
*
* Additional information:
* Local subfunction
* Tested, It is Ok. 02/26
********************************************************
void DisAssembleFrequencyWord(void)
{
UINT16 twPLL =0; //Dec
UINT32 tdwPresetVCO =gdwPresetVCO; //Khz
BYTE tbTmp1=ReadDataWord[1];
BYTE tbTmp2=ReadDataWord[0];
tbTmp2&=0x3f;
twPLL=tbTmp2*256+tbTmp1;
// calculate searched station frequency from dataword bits
if(FlagHighInjection)
gdwSearchedVCO =(unsigned long)((float)twPLL*(float)REFERENCE_FREQ*(float)0.25-225);
else
gdwSearchedVCO =(unsigned long)((float)twPLL*(float)REFERENCE_FREQ*(float)0.25+225);
}
*/
/*********************************************************
* NAME : AssembleData
* assemble a full data word based on global variables
*
* Returns : none
*
* Parameter Description
* --------------------------------------------------------
* none
*
* Externals Usage
* --------------------------------------------------------
* DataWord[39-0] the bits will be Set(out)
* The global Variable in as below list!!
*
* FlagSearch in, if search or preSet mode? StartSearch [38]
* FlagLevel in search stop level [21,22]
* FalgMono in.
* FlagSWPORT2 in
* FlagSearchtUp in
* gdwPresetVCO in
*
* WriteDataWord[] out.
*
* Additional information:
* Local subfunction
* Tested, It is Ok. 4/16
*********************************************************/
BYTE Write1;
static void AssembleData(void)
{
WriteDataWord[3] = 0x11; //32k /p1 found.
WriteDataWord[4] = 0x40;
if(FlagMute) WriteDataWord[0] |= 0x80;
else WriteDataWord[0] &= 0x7f ; //0111 1111
if (FlagSearch ) // search mode
{
WriteDataWord[0] |= 0x40; // Set to 1 for search start; other =0.
// Set the bits of BYTE3 of search
if(FlagSearchtUp) WriteDataWord[2] |= 0x80;
else WriteDataWord[2] &= 0x7f; //0111 1111
if ((FlagLevel & 0x02) == 0x02) WriteDataWord[2] |=0x40 ;
else WriteDataWord[2] &=0x0bf; //1011 1111
if ((FlagLevel & 0x01) == 0x01) WriteDataWord[2] |=0x20;
else WriteDataWord[2] &=0x0df; //1101 1111
Write1= WriteDataWord[0] ;
}
/////PreSet mode
else
{
AssembleFrequencyWord();
WriteDataWord[0] &= 0x0bf; // Set to 0 for Preset mode. 1011,1111
}
//set the public data bit of BYTE3
if(FlagHighInjection) WriteDataWord[2] |= 0x10 ;
else WriteDataWord[2] &= 0x0ef; //1110 1111
if(FlagMono) WriteDataWord[2] |= 0x08 ;
else WriteDataWord[2] &= 0x0f7 ; //1111 0111
//set the public data bit of BYTE4
if(FlagSWPORT2) WriteDataWord[3] |= 0x80;
else WriteDataWord[3] &= 0x7f ; //0111 1111
if(FlagSoftMute) WriteDataWord[3] |= 0x08;
else WriteDataWord[3] &= 0xf7 ; //1111 0111
if(FlagSWPORT1) WriteDataWord[3] |= 0x01;
else WriteDataWord[3] &= 0xfe ; //1111 1110
}
//////////////////////////////////////////////////////////////////////////////////
/* Above are local sub routine and called in this file */
/*********************************************************
* NAME : Tuner_Preset
* PreSet the 5767 to a Staion_FREQ
*
* Returns : none
*
* Parameter Description
* --------------------------------------------------------
* none
*
* Externals Usage
* --------------------------------------------------------
* Target VCO in
*
* Additional information:
* Local subfunction
* Tested, It is Ok. 4/16
*********************************************************/
void Tuner_Preset (BIT Mute, BIT SetMono,BIT Pin15,unsigned long VCO)
{
FlagSearch = False; // Set global parameters
FlagMono = SetMono;
FlagSWPORT2 = Pin15;
gdwPresetVCO = VCO;
FlagMute=Mute; //0301 mao
AssembleData();
Tuner_I2cSendData();
Delay10us(50000); //200ms
Tuner_I2cReadData(); //read data to ReadDataWord[] .
Delay10us(2);
#if 0
while (SWPORT1);
while(!SearchOver() ) // waiting for station detected
{
Delay10us(2000);
Tuner_I2cSendData();
}
#endif
}
/*********************************************************
* NAME : main()
* Main routine.
*
* Returns : none
*
* Parameter Flow Description
* --------------------------------------------------------
* none
*
*********************************************************/
void main(void)
{
WriteDataWord[0] = 0x2a; // init FM89.8MHz ok.
WriteDataWord[1] = 0x0b6;
WriteDataWord[2] = 0x41; //p1 high
WriteDataWord[3] = 0x11;
WriteDataWord[4] = 0x40;
Tuner_I2cSendData();
Tuner_Preset( False, False,High,97100 ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -