lg252d.c
来自「DVB软件,基于CT216软件的开发源程序.」· C语言 代码 · 共 180 行
C
180 行
#include <string.h>
#include "ct_sys.h"
#include "ct_iic.h"
#include "ct_nim.h"
#include "LG252D.h"
//#define IIC_UART
#define TUNER_ADD 0xC0
//static u8 szBuffer[8];
#if 0
#ifdef IIC_UART
/*******************************************************************************************/
bool8 Tuner_Write(u8 *pu8Buffer , u8 u8Length)
{
if ((pu8Buffer == NULL)||
(u8Length > MAX_IIC_BURST_LENGTH)||
(u8Length==0))
{
return FALSE;
}
if ( IIC2UART_Write(TUNER_ADD, *pu8Buffer, (pu8Buffer+1), (u8Length-1)) == FALSE )
{
return FALSE;
}
return TRUE;
}
/*******************************************************************************************/
bool8 Tuner_Read(u8 *pu8Buffer, u8 u8Length)
{
if ((pu8Buffer == NULL)||(u8Length > MAX_IIC_BURST_LENGTH))
{
return FALSE;
}
if ( IIC2UART_Read(TUNER_ADD, 0, pu8Buffer, u8Length, FALSE) == FALSE )
{
return FALSE;
}
return TRUE;
}
#else
/*******************************************************************************************/
bool8 Tuner_Write(u8 *pu8Buffer , u8 u8Length)
{
u32 u32Handle;
if (CT_NIM_GetBus() == EN_CT_NIM_BUS_0)
{
if( CT_IIC_Open(EN_CT_IIC_BUS_0, TUNER_ADD, &u32Handle)!= DRV_OK)
{
printf("\nCT_IIC_Open 0 Error");
return FALSE;
}
}
else
{
if( CT_IIC_Open(EN_CT_IIC_BUS_1, TUNER_ADD, &u32Handle)!= DRV_OK)
{
printf("\nCT_IIC_Open 1 Error");
return FALSE;
}
}
#ifdef NIM_SW_IIC
if(CT_SW_IIC_WriteData(u32Handle, pu8Buffer, u8Length) != DRV_OK )
#else
if(CT_IIC_WriteData(u32Handle, pu8Buffer, u8Length) != DRV_OK )
#endif
{
printf("\nCT_IIC_WriteData Error");
CT_IIC_Close(u32Handle);
return(FALSE);
}
CT_IIC_Close(u32Handle);
return (TRUE);
}
/*******************************************************************************************/
bool8 Tuner_Read(u8 *pu8Buffer, u8 u8Length)
{
u32 u32Handle;
if (CT_NIM_GetBus() == EN_CT_NIM_BUS_0)
{
if( CT_IIC_Open(EN_CT_IIC_BUS_0, TUNER_ADD, &u32Handle)!= DRV_OK)
{
printf("\nR CT_IIC_Open 0 Error");
return FALSE;
}
}
else
{
if( CT_IIC_Open(EN_CT_IIC_BUS_1, TUNER_ADD, &u32Handle)!= DRV_OK)
{
printf("\nR CT_IIC_Open 1 Error");
return FALSE;
}
}
#ifdef NIM_SW_IIC
if(CT_SW_IIC_ReadData(u32Handle, pu8Buffer, u8Length) != DRV_OK )
#else
if(CT_IIC_ReadData(u32Handle, pu8Buffer, u8Length) != DRV_OK )
#endif
{
printf("\nR CT_IIC_ReadData Error");
CT_IIC_Close(u32Handle);
return FALSE;
}
CT_IIC_Close(u32Handle);
return (TRUE) ;
}
#endif
#endif
/*******************************************************************************
* Program LG252D tuner
*******************************************************************************/
bool8 CT221_ProgramTuner_LG252D(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 >= 738)
{
WriteBytes[2] = 0xfc;
WriteBytes[3] = 0x0c;
}
else if(TunerFreq >= 474)
{
WriteBytes[2] = 0xbc;
WriteBytes[3] = 0x04|0x08;
}
else
{
WriteBytes[2] = 0xb4;
WriteBytes[3] = 0x02;
}
// Set auxiliary byte.
// - Note: Auxiliary byte is WriteBytes[4].
WriteBytes[4] = 0x20;
// 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;
}*/
status = Tuner_Write(&WriteBytes[0], 5);
return TRUE;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?