新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 收音機(jī)模塊TEA5767的C51控制程序

收音機(jī)模塊TEA5767的C51控制程序

作者: 時(shí)間:2010-09-11 來源:網(wǎng)絡(luò) 收藏

  采用I2C或者三線接口,我是用的I2C,單片機(jī)用STC89C52,帶1K EEPROM,可以掉電存臺(tái),1602LCD顯示.

本文引用地址:http://2s4d.com/article/151570.htm

  讀寫數(shù)據(jù)都是5個(gè)字節(jié),其中PLL參數(shù)14位,具體數(shù)據(jù)格式請(qǐng)看datasheet.以下中的函數(shù)可以直接在主中調(diào)用.

  #include iic.c

  #define max_freq 108000

  #define min_freq 87500

  unsigned char radio_write_data[5]={0x29,0xc2,0x20,0x11,0x00}; //要寫入的數(shù)據(jù)

  unsigned char radio_read_data[5]; //TEA5767讀出的狀態(tài)

  unsigned int default_pll=0x29c2;//0x29f9; //默認(rèn)存臺(tái)的pll,87.8MHz

  //unsigned int max_pll=0x339b; //108MHz時(shí)的pll,

  //unsigned int min_pll=9000; //70MHz時(shí)的pll

  void radio_write(void)

  {

  unsigned char i;

  iic_start();

  iic_write8bit(0xc0); //TEA5767寫地址

  if(!iic_testack())

  {

  for(i=0;i5;i++)

  {

  iic_write8bit(radio_write_data[i]);

  iic_ack();

  }

  }

  iic_stop();

  }

  //讀TEA5767狀態(tài),并轉(zhuǎn)換成頻率

  void radio_read(void)

  {

  unsigned char i;

  unsigned char temp_l,temp_h;

  pll=0;

  iic_start();

  iic_write8bit(0xc1); //TEA5767讀地址

  if(!iic_testack())

  {

  for(i=0;i5;i++)

  {

  radio_read_data[i]=iic_read8bit();

  iic_ack();

  }

  }

  iic_stop();

  temp_l=radio_read_data[1];

  temp_h=radio_read_data[0];

  temp_h=0x3f;

  pll=temp_h*256+temp_l;

  get_frequency();

  }

  //由頻率計(jì)算PLL

  void get_pll(void)

  {

  unsigned char hlsi;

  unsigned int twpll=0;

  hlsi=radio_write_data[2]0x10;

  if (hlsi)

  pll=(unsigned int)((float)((frequency+225)*4)/(float)32.768); //頻率單位:k

  else

  pll=(unsigned int)((float)((frequency-225)*4)/(float)32.768); //頻率單位:k

  }

  //由PLL計(jì)算頻率

  void get_frequency(void)

  {

  unsigned char hlsi;

  unsigned int npll=0;

  npll=pll;

  hlsi=radio_write_data[2]0x10;

  if (hlsi)

  frequency=(unsigned long)((float)(npll)*(float)8.192-225); //頻率單位:KHz

  else

  frequency=(unsigned long)((float)(npll)*(float)8.192+225); //頻率單位:KHz

  }


上一頁(yè) 1 2 下一頁(yè)

評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉