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

📄 5767.txt

📁 keil c 编写的tea5767HL 的程序代码
💻 TXT
📖 第 1 页 / 共 2 页
字号:
返回大虾电子网首页 返回历史帖子
[+6]这是TEA5767控制的C语言程序,小弟刚学习C语言,看得不明白,那位可以帮帮我吗 ?我打算用汇编写程序14位的PLL不知道怎么算。
 

帖子编号: 32026/797356, 发表用户:调频爱好者    发表时间:2006-1-16 12:45:08     访问次数:115 发贴IP:222.212.70.39 

文章内容: 

    COMPANY CONFIDENTIAL

***************************************************************************
        Filename : Tuner.c
Rev     Date        Author
____________________________________________________________________________
1.0        2002/01/13    Tenon Mao

        TEA5767 basic control 
*/
#define XTAL32K

#define LowestFM         87500              //87.5MHz    for EUR only for USA 87.9M
#define HighestFM       108000              //108.Mhz
#define InitVCO         98000             // 98.00 MHz  for reset Freq  
                              
#define STEP               100                  //setp size =100KHz.
#define AST_STEP        200       //200

#define MAX_STATION        20
#define TUNER_DELAY     250000            //250MS
            
#ifdef XTAL32K
#define REFERENCE_FREQ    32.768
#else
#define REFERENCE_FREQ    50.000
#endif


/**********************
* INCLUDE FILES       *
**********************/
/* Standard include files */

/* Project  include files */
#include "global.h"
#include "tuner.h"
#include "util.h"
#include "lcd.h"
#include "key.h"

/**********************
* LOCAL TYPEDEFS      *
**********************/


/**********************
* EXPORTED DATA       *
**********************/
BYTE  data SearchLevel=3;

BYTE idata WriteDataWord[5];                    // write tea5767H dataword 
BYTE idata ReadDataWord[5];                        // read tea5767H dataword
unsigned long idata TunerStation[20];            //save radio station FM Value HEX format

///For assembly data 
BIT data FlagMute = False;                     // flag to Mute R&L

BIT data FlagSearch = False;                     // flag to search or preset mode
BIT data FlagSearchtUp =True;                 // flag for search direction  
BYTE data FlagLevel =2;                      // flag for current search level
BIT data FlagHighInjection=False;
BIT data FlagMono = False;                   // flag to force mono 
//Mute L
//Mute R
//SWPORT1 for GPIO out 

BIT data FlagSWPORT2=Low;                      // flag for level of pin15
//standy_by
//Japan or ther area 
//XTAL selecton 1 for 32k
BIT data FlagSoftMute = True;//False;                   // flag to force mono 
//HCC 
//SNC
BIT data FlagSWPORT1=True;                      // 1= confige as indication of found!!

//PLL selection 0
//Deem 1.


BYTE data NowStation=0;
BYTE data Max_Station=0;

unsigned long gdwSearchedVCO;               // vco frequency after search command
unsigned long gdwPresetVCO=89800;                 // target vco frequency for Preset
unsigned long gdwWorkingVCO;                // displayed vco frequency 

BIT data NotFound = True;
BIT data BandLimit = False;                  // Indicate the end of band

//unsigned char TunerSearchTimer;            //Timeout for serach
                     

/**********************
* STATIC DATA         *
**********************/


/**********************
* LOCAL MACROS        *
**********************/


/**********************
* FUNCTION PROTOTYPES *
**********************/


/****************************************************************************/
/*    Command Delay                                                         */
/****************************************************************************/
void CMD_Delay(BYTE i)
{
    for (; i!=0; i--) ;
}  

void CMD_CheckHighSCL()
{
    I2cSCL = 1;
}

void CMD_SendStart()
{
    I2cSCL = 1;
    CMD_Delay(CMD_DELAY);
    I2cSDA = 0;
    CMD_Delay(CMD_DELAY);
    I2cSCL = 0;
    CMD_Delay(CMD_DELAY);
}

void CMD_SendStop()
{
    I2cSDA = 0;
    CMD_CheckHighSCL();
    CMD_Delay(CMD_DELAY);
    I2cSDA = 1;
    CMD_Delay(CMD_DELAY);
}

BYTE  CMD_SendByte(BYTE bByte)
{
    BYTE i;
    BIT  Acknowledge=1;
    for(i=0;i<8;i++)
       {
         if(bByte&0x80)
            I2cSDA=1;
         else
            I2cSDA=0;
         bByte<<=1;
         CMD_Delay(CMD_DELAY);
         CMD_CheckHighSCL();
         I2cSCL  =0;
       }
    I2cSDA=1;
    I2cSCL=1;
    CMD_Delay(CMD_DELAY);
    if (I2cSDA) Acknowledge=0;
    I2cSCL=0;
    CMD_Delay(CMD_DELAY);
    return Acknowledge;
}

BYTE CMD_GetByte(BYTE Acknowledge)
{
    BYTE i,bByte=0, bMask=0x80;
    for(i=0;i<8;i++)
       {
          CMD_Delay(CMD_DELAY);
          I2cSCL=1;
        if(I2cSDA)bByte|=bMask;
                bMask >>= 1;
                I2cSCL  =0;
       }
    I2cSDA =(Acknowledge)?1:0; 
    CMD_CheckHighSCL();
    CMD_Delay(CMD_DELAY);
    I2cSCL  =0;                
    I2cSDA  =1;
    CMD_Delay(CMD_DELAY);
    return bByte;
}

//////////////////////////////////////////////

void WriteSTR()
{
    BYTE i;
    EA=0;
    CMD_SendStart();
    if (CMD_SendByte(0x0c0))            //chip addr of write data to driver
    {
        for (i=0; i<5; i++)
        {
           if (!CMD_SendByte(WriteDataWord[i]))    //0 err
            {
                break;
            }
        }
    }
    CMD_SendStop();         //???
    EA=1;
    CMD_Delay(CMD_DELAY);
    CMD_Delay(CMD_DELAY);    
    
}
           

  Byte SearchRead1=0;    //for test only!!!
  Byte SearchRead2=0;        
  Byte SearchRead3=0;
  Byte SearchRead4=0;
  Byte SearchRead5=0;

void ReadSTR() //get datd../
{

   BYTE i;      
   #if 1        //test only!!
   for (i=0; i<=4; i++)            
   {
    ReadDataWord[i]=0;                    //init the read buffer.
   }                           
     SearchRead1=ReadDataWord[0];        //byte 0 --4 .byte 0 first.
    SearchRead2=ReadDataWord[1];        //byte 0 --4 .byte 0 first.
    SearchRead3=ReadDataWord[2];        //byte 0 --4 .byte 0 first.
    SearchRead4=ReadDataWord[3];        //byte 0 --4 .byte 0 first.
    SearchRead5=ReadDataWord[4];        //byte 0 --4 .byte 0 first.

    Delay10us(2);
   #endif              

    
    CMD_SendStart();
    if (CMD_SendByte(0x0c1))             //chip addr of read data 
       {
        for (i=0;i<5;i++)
            ReadDataWord[i] =(i==4)? CMD_GetByte(1):CMD_GetByte(0);      //the last byte with ACK.
        CMD_SendStop();
       }
    else CMD_SendStop();

    #if 1        //test only!!
    SearchRead1=ReadDataWord[0];        //byte 0 --4 .byte 0 first.
    SearchRead2=ReadDataWord[1];        //byte 0 --4 .byte 0 first.
    SearchRead3=ReadDataWord[2];        //byte 0 --4 .byte 0 first.
    SearchRead4=ReadDataWord[3];        //byte 0 --4 .byte 0 first.
    SearchRead5=ReadDataWord[4];        //byte 0 --4 .byte 0 first.

    Delay10us(2);

    #endif


}







/////////////////////////






/*********************************************************
* NAME    : SearchOver
*           CHK if the  search Finished accoding the SWPORT1 
*
* Returns : none
*
* Parameter         Description
* --------------------------------------------------------
* none
* 
* Externals         Usage
* --------------------------------------------------------
*
*
* Additional information:
* Local subfunction
*********************************************************/
BYTE data  LowCount=0;            //for test only 
static BIT SearchOver(void)
{
  LowCount++;                
  return(SWPORT1) ;         //PIN from low to high. Then tuning over
                        
} 

   
/*********************************************************
* 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;
 BYTE tbRead2;
 BIT Stereo=False;
 BIT Ready=False;


static void TuneOver(void)
{
 BIT Ready=False;
 ReadSTR();                                    //how about continue read????   mao 
0227
 tbRead1=ReadDataWord[0];
 tbRead2=ReadDataWord[2];
 LowCount++;                               //for test only.

 if((tbRead1&0x40) != 0) BandLimit=True;       //limited
 else BandLimit=False;
 
 if((tbRead2&0x80) != 0) Stereo=True;
 else Stereo=False;

 tbRead1=ReadDataWord[0];
 if((tbRead1&0x80) != 0) Ready=True;        //Found
 else Ready=False;

  
} 




/*********************************************************
* NAME    : AssembleFrequencyWord
*          given a VCO frequency calculate and load the frequency databitsr 
*           and save the PLL Fre to DataWord[37-24] =14 bits 
*           5757 have 15 bits and the bits location is different!
* 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;

⌨️ 快捷键说明

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