lg101d.c

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

C
70
字号
#include <string.h>
#include "ct_sys.h"
#include "ct_iic.h"
#include "ct_nim.h"
#include "LG101D.h"
#include "tunerAPI.h"

#define TUNER_ADD   	0xC2

/*******************************************************************************
 * Program LG252D tuner
 *******************************************************************************/
bool8 CT221_ProgramTuner_LG101D(u32 RfFreq, u8 dwBWandFreqkHz)
{
	printf("CT221_ProgramTuner_LG101D\n");
  	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] = 0x90;

	/* ------------- UHF -----------------*/
	if (TunerFreq > 430 )
		WriteBytes[3] = 0x88;
	   //  10 | 0|1 |1000
	/* ------------- VHF High -----------------*/
	else if(TunerFreq > 145 && TunerFreq <= 430)
		WriteBytes[3] = 0xc2;

	/* ------------- VHF Low -----------------*/
	else if(TunerFreq <= 145)
		WriteBytes[3] = 0xc1;
	else
		WriteBytes[3] = 0x81;

	if (dwBWandFreqkHz == 6)
		WriteBytes[3] |= 0x10;

	// Set auxiliary byte.
	//   - Note: Auxiliary byte is WriteBytes[4].
	WriteBytes[4] = 0xc1;  // 11 00 0010
	
	status = Tuner_Write(&WriteBytes[0],5);
	
	return TRUE; 	
	
}

⌨️ 快捷键说明

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