dtt2004.c

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

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

#define TUNER_ADD   	0xC0

/*******************************************************************************
 * Program DTT2004(heifei radio) tuner
 *******************************************************************************/
bool8 CT221_ProgramTuner_DTT2004(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].
	if (TunerFreq >= 750)
	{
		WriteBytes[2] = 0xfc; // cp=650
		WriteBytes[3] = 0x0c;
		//WriteBytes[3] = 0x04;
	}
	else if(TunerFreq >= 610) 
	{
		WriteBytes[2] = 0xf4; // cp=250
		WriteBytes[3] = 0x0c;
		//WriteBytes[3] = 0x03;
	}
	else if(TunerFreq >= 430) 
	{
		WriteBytes[2] = 0xbc; // cp=125
		WriteBytes[3] = 0x04;
		//WriteBytes[3] = 0x01;
	}	
	else if(TunerFreq >= 145) 
	{
		WriteBytes[2] = 0xac; // cp=50
		WriteBytes[3] = 0x02;
		//WriteBytes[3] = 0x01;
	}	
	else
	{
		WriteBytes[2] = 0xbc;
		WriteBytes[3] = 0x01;
		//WriteBytes[3] = 0x01;
	}	
	

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

	// Set auxiliary byte.
	//   - Note: Auxiliary byte is WriteBytes[4].
	WriteBytes[4] = 0x20; //Charge pump current

	status = Tuner_Write(&WriteBytes[0], 5);

	CT_OS_MS_Delay(10);
	return TRUE; 	       
}

⌨️ 快捷键说明

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