lg352dn.c

来自「DVB软件,基于CT216软件的开发源程序.」· C语言 代码 · 共 78 行

C
78
字号
#include <stdio.h>
#include "ct_os.h"
#include "ct_sys.h"
#include "ct_iic.h"
#include "ct_nim.h"
#include "LG352DN.h"
#include "tunerAPI.h"

#define TUNER_ADD   	0xC0

/*******************************************************************************
 * Program LG252D tuner
 *******************************************************************************/
bool8 CT221_ProgramTuner_LG352DN(u32 RfFreq, u8 dwBWandFreqkHz)
{
	unsigned int N;
	u8 WriteBytes[5];
	float TunerFreq;
	u8    status;
//	u8    TUNER_ID      = 0xc0;
	u8 ByteMask = 0xff;
	unsigned int NMask = 0x7fff;
	unsigned int ByteShift = 8;
	 
	TunerFreq = RfFreq / 1000.0;
	
	// Calculate divider N with step size = 166.67 kHz.
	N = (unsigned int)(TunerFreq * 6 + 217 + 0.5);
	N &= NMask;

	//printf("\n\r LG252D freq %ld", (u32)(TunerFreq * 1000));		

	// Set divider byte 1 and 2.
	//   - Note: Divider byte 1 is WriteBytes[0].
	//           Divider byte 2 is WriteBytes[1].
	WriteBytes[0] = N >> ByteShift & ByteMask;
	WriteBytes[1] = N & ByteMask;

	// Set control byte and band switch byte.
	//   - Note: Control byte is WriteBytes[2].
	//           Band switch byte is WriteBytes[3].
	WriteBytes[2] = 0x98;
	
	if(TunerFreq >= 474)
	{
		WriteBytes[3] = 0x88;
	}
	else
	{	
		WriteBytes[3] = 0x82;
	}	
	
	if (dwBWandFreqkHz == 8)
	{
		WriteBytes[3] |= 0x10;
	}
	else
	{
		WriteBytes[3] &= ~0x10;
	}

	// Set auxiliary byte.
	//   - Note: Auxiliary byte is WriteBytes[4].
	WriteBytes[4] = 0xC0;

	// Enable demod I2C repeating and send 5 bytes to tuner.
	/*CT226_Repeat(DEMOD_ADDR);
      if (!RegisterWrite2wb(TUNER_Addr, WriteBytes[0], &WriteBytes[1], 4))	
      {
      printf("\n\r write tuner fail");
      return FALSE;
      }*/
	printf("\n[###]0x%02x-%02x-%02x-%02x-%02x",WriteBytes[0],WriteBytes[1],WriteBytes[2],WriteBytes[3],WriteBytes[4]);
	status = Tuner_Write(&WriteBytes[0], 5);

	return TRUE; 	       
}

⌨️ 快捷键说明

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