edt1022.c
来自「DVB软件,基于CT216软件的开发源程序.」· C语言 代码 · 共 312 行
C
312 行
#include <stdio.h>
#include "ct_os.h"
#include "ct_sys.h"
#include "ct_iic.h"
#include "ct_nim.h"
#include "EDT1022.h"
#define EARDA_EDT1022II2B
//#define EARDA_EDT3022II2A
//#define IIC_UART
#ifdef EARDA_EDT1022II2B
#define TUNER_ADD 0xC2
#endif
#ifdef EARDA_EDT3022II2A
#define TUNER_ADD 0xC0
#endif
//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 EDT1022(Earda) tuner
*******************************************************************************/
bool8 CT221_ProgramTuner_EDT1022(u32 RfFreq, u8 dwBWandFreqkHz)
{
#ifdef EARDA_EDT1022II2B
u8 WriteBytes[5];
u32 u32Tuner_Freq;
float fTunerFreq;
u8 status;
fTunerFreq = RfFreq / 1000.0;
/* calculate LO frequency*/
u32Tuner_Freq = RfFreq + 36125; /* kHz*/
if(fTunerFreq > 446)
{
/* convert frequency to divider ratio*/
u32Tuner_Freq = (u32Tuner_Freq * 1000) / 16667;
WriteBytes[2] = 0xCA;//Byte 1(1)
}
else
{
/* convert frequency to divider ratio*/
u32Tuner_Freq = (u32Tuner_Freq * 1000) / 6250;//16667;
WriteBytes[2] = 0xC8;//Byte 1(1)
}
u32Tuner_Freq += 5;
u32Tuner_Freq /= 10; /*round off the result*/
WriteBytes[0] = (u8) ((u32Tuner_Freq >> 8) & 0xff);
WriteBytes[1] = (u8) (u32Tuner_Freq & 0xff);
if (fTunerFreq > 760) //? >762
{
WriteBytes[3] = (0xe0 | 0x0c); //600uA , 0x0c: UHF&8M
}
else if(fTunerFreq > 472) //>=474 +-0.2
{
WriteBytes[3] = (0xc0 | 0x0c); //410uA , 0x0c: UHF&8M
}
else if(fTunerFreq > 446) //VHF L=49~159; VHF H=162~444; UHF=448~861
{
WriteBytes[3] = (0xc0 | 0x0c); //410uA , 0x0c: UHF&8M
}
else if(fTunerFreq > 416)
{
WriteBytes[3] = (0xe0 | 0x02); //600uA , 0x02: VHF high&7M
}
else if(fTunerFreq > 160)
{
WriteBytes[3] = (0xc0 | 0x02); //410uA , 0x02: VHF high&7M
}
else if(fTunerFreq > 140)
{
WriteBytes[3] = (0xc0 | 0x01); //410uA , 0x01: VHF low&7M
}
else //51~
{
WriteBytes[3] = (0xa0 | 0x01); //280uA , 0x01: VHF low&7M
}
if (dwBWandFreqkHz == 0x08)
WriteBytes[3] |= 0x08;
else
WriteBytes[3] &= ~0x08;
WriteBytes[4] = 0x80;//Byte 1(2)
status = Tuner_Write(&WriteBytes[0], 5);
CT_OS_MS_Delay(5);
return TRUE;
#endif
#ifdef EARDA_EDT3022II2A
u8 WriteBytes[5];
u32 u32Tuner_Freq;
float fTunerFreq;
u8 status;
#define F_VHF 470
fTunerFreq = RfFreq / 1000.0;
/* calculate LO frequency*/
u32Tuner_Freq = RfFreq + 36125; /* kHz*/
if(fTunerFreq > F_VHF)
{
/* convert frequency to divider ratio*/
u32Tuner_Freq = (u32Tuner_Freq * 1000) / 16667;
}
else
{
/* convert frequency to divider ratio*/
u32Tuner_Freq = (u32Tuner_Freq * 1000) / 6250;//16667;
}
u32Tuner_Freq += 5;
u32Tuner_Freq /= 10; /*round off the result*/
WriteBytes[0] = (u8) ((u32Tuner_Freq >> 8) & 0xff);
WriteBytes[1] = (u8) (u32Tuner_Freq & 0xff);
// Set control byte and band switch byte.
// - Note: Control byte is WriteBytes[2].
// Band switch byte is WriteBytes[3].
if (fTunerFreq > 833)
{
WriteBytes[2] = (0xF8 |0x04);//0xf8:CP=650
WriteBytes[3] = (0x08 | 0x04); //0x08:8M , 0x04: UHF
}
else if(fTunerFreq > 545)
{
WriteBytes[2] = (0xF0 |0x04);//0xf0:CP=250
WriteBytes[3] = (0x08 | 0x04); //0x08:8M , 0x04: UHF
}
else if(fTunerFreq > 470) //>=474 +-0.2
{
WriteBytes[2] = (0xB8 |0x04); //0xb8:CP=125
WriteBytes[3] = (0x08 | 0x04); //0x08:8M , 0x04: UHF
}
else if(fTunerFreq > 457)
{
WriteBytes[2] = (0xF8 |0x04);//0xf8:CP=650
WriteBytes[3] = (0x00 | 0x02); //0x00:7M , 0x02: VHF high
}
else if(fTunerFreq > 377)
{
WriteBytes[2] = (0xF0 |0x04);//0xf0:CP=250
WriteBytes[3] = (0x00 | 0x02); //0x00:7M , 0x02: VHF high
}
else if(fTunerFreq > 177)
{
WriteBytes[2] = (0xB8 |0x04); //0xb8:CP=125
WriteBytes[3] = (0x00 | 0x02); //0x00:7M , 0x02: VHF high
}
else if(fTunerFreq > 138)
{
WriteBytes[2] = (0xF0 |0x04);//0xf0:CP=250
WriteBytes[3] = (0x00 | 0x01); //0x00:7M , 0x01: VHF low
}
else //51~
{
WriteBytes[2] = (0xB8 |0x04); //0xb8:CP=125
WriteBytes[3] = (0x00 | 0x01); //0x00:7M , 0x01: VHF low
}
if(fTunerFreq <= F_VHF)
WriteBytes[2] |= 0x06;//select 62.5k
if (dwBWandFreqkHz == 0x08)
WriteBytes[3] |= 0x08;
else
WriteBytes[3] &= ~0x08;
// Set auxiliary byte. // - Note: Auxiliary byte is WriteBytes[4].
WriteBytes[4] = 0x20; //if need LOOP Though, set 0X21
status = Tuner_Write(&WriteBytes[0], 4);
CT_OS_MS_Delay(5);
WriteBytes[2]|=0x18;
WriteBytes[2]&=~0x20;
WriteBytes[3] = WriteBytes[4];
status = Tuner_Write(&WriteBytes[0], 4);
CT_OS_MS_Delay(5);
return TRUE;
#endif
}
#if 0//if need, open it
bool8 Check_tuner_lock(void)
{
u8 buffer[1];
Tuner_Read(buffer, 1);
if((buffer[0] !=255)&&(buffer[0] &0x40))
return TRUE;
else
return FALSE;
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?