⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fq1236.c

📁 7寸TFT电视的源程序
💻 C
字号:
#include "target.h"
#include "fq1236.h"


#define TUNER_ADDR						0xc6
#define IF_ADDR							0x87

#define AFCWIN_mask	0x80
#define AFCVAL_mask	0x1e
#define	PONR_mask	0x01
#define	RSA			62
#define NTSC_IF		1	// 45.75mhz
#define TVDELAY					200

unsigned char idata tunerbuf[6] = {0x0f,0xf2,0x8e,0x22};
unsigned char idata CurTvChannel = 2;

#ifdef __TV_US__


int code TVChannelData[MAX_CHANNEL+1]=
{
	0,
	0,
	0x650,	/*2 */
	0x6B0,	/*3 */
	0x710,	/*4 */
	0x7B0,	/*5 */
	0x810,	/*6 */
	0xdd0,	/*7 */
	0xe30,	/*8 */
	0xe90,	/*9 */
	0xef0,	/*10 */
	0xf50,	/*11 */
	0xfb0,	/*12 */
	0x1010,	/*13 */
	0x2050,	/*14 */
	0x20b0,	/*15 */
	0x2110,	/*16 */
	0x2170,	/*17 */
	0x21d0,	/*18 */
	0x2230,	/*19 */
	0x2290,	/*20 */
	0x22f0,	/*21 */
	0x2350,	/*22 */
	0x23b0,	/*23 */
	0x2410,	/*24 */
	0x2470,	/*25 */
	0x24d0,	/*26 */
	0x2530,	/*27 */
	0x2590,	/*28 */
	0x25f0,	/*29 */
	0x2650,	/*30 */
	0x26b0,	/*31 */
	0x2710,	/*32 */
	0x2770,	/*33 */
	0x27d0,	/*34 */
	0x2830,	/*35 */
	0x2890,	/*36 */
	0x28f0,	/*37 */
	0x2950,	/*38 */
	0x29b0,	/*39 */
	0x2a10,	/*40 */
	0x2a70,	/*41 */
	0x2ad0,	/*42 */
	0x2b30,	/*43 */
	0x2b90,	/*44 */
	0x2bf0,	/*45 */
	0x2c50,	/*46 */
	0x2cb0,	/*47 */
	0x2d10,	/*48 */
	0x2d70,	/*49 */
	0x2dd0,	/*50 */
	0x2e30,	/*51 */
	0x2e90,	/*52 */
	0x2ef0,	/*53 */
	0x2f50,	/*54 */
	0x2fb0,	/*55 */
	0x3010,	/*56 */
	0x3070,	/*57 */
	0x30d0,	/*58 */
	0x3130,	/*59 */
	0x3190,	/*60 */
	0x31f0,	/*61 */
	0x3250,	/*62 */
	0x32b0,	/*63 */
	0x3310,	/*64 */
	0x3370,	/*65 */
	0x33d0,	/*66 */
	0x3430,	/*67 */
	0x3490,	/*68 */
	0x34f0	/*69 */
};

#else

int code TVChannelData[MAX_CHANNEL+1]=
{
//  38.9
//  VHF Low
	0,
	0x058a,// DS-1 	01
	0x060a,// DS-2
	0x068a,// DS-3
	0x0742,// DS-4
	0x07c2,// DS-5

	0x0972,// Z-1		06
	0x09f2,// Z-2

	0x0a72,// Z-3
	0x0af2,// Z-4
	0x0b72,// Z-5

	0x0bf2,// Z-6		11
	0x0c72,// Z-7
	0x0cf2,// DS-6          3314.4

// VHF High

	0x0d72,// DS-7     14   3442.4
	0x0df2,// DS-8
	0x0e72,// DS-9
	0x0ef2,// DS-10
	0x0f72,// DS-11

	0x0ff2,// DS-12	19
	0x1072,// Z-8
	0x10f2,// Z-9
	0x1172,// Z-10
	0x11f2,// Z-11

	0x1272,// Z-12	24
	0x12f2,// Z-13
	0x1372,// Z-14
	0x13f2,// Z-15
	0x1472,// Z-16

	0x14f2,// Z-17	29
	0x1572,// Z-18
	0x15f2,// Z-19
	0x1672,// Z-20
	0x16f2,// Z-21

	0x1772,// Z-22	34
	0x17f2,// Z-23
	0x1872,// Z-24
	0x18f2,// Z-25
	0x1972,// Z-26	

	0x19f2,// Z-27	39
	0x1a72,// Z-28

	0x1af2,// Z-29
	0x1b72,// Z-30
	0x1bf2,// Z-31

	0x1c72,// Z-32	44
	0x1cf2,// Z-33
	0x1d72,// Z-34
	0x1df2,// Z-35
	0x1e72,// Z-36    7794.4

//  UHF
	0x1ef2,// Z-37     49	7922.4
	0x1f62,// S-41
	0x1fe2,// DS-13
	0x2062,// DS-14
	0x20e2,// DS-15

	0x2162,// DS-16	54
	0x21e2,// DS-17
	0x2262,// DS-18
	0x22e2,// DS-19
	0x2362,// DS-20

	0x23e2,// DS-21	59
	0x2462,// DS-22
	0x24e2,// DS-23
	0x2562,// DS-24
	0x2862,// DS-25

	0x28e2,// DS-26	64
	0x2962,// DS-27
	0x29e2,// DS-28
	0x2a62,// DS-29
	0x2ae2,// DS-30

	0x2b62,// DS-31	69
	0x2be2,// DS-32
	0x2c62,// DS-33
	0x2ce2,// DS-34
	0x2d62,// DS-35

	0x2de2,// DS-36	74
	0x2e62,// DS-37
	0x2ee2,// DS-38
	0x2f62,// DS-39
	0x2fe2,// DS-40

	0x3062,// DS-41	79
	0x30e2,// DS-42
	0x3162,// DS-43
	0x31e2,// DS-44
	0x3262,// DS-45

	0x32e2,// DS-46	84
	0x3362,// DS-47
	0x33e2,// DS-48
	0x3462,// DS-49
	0x34e2,// DS-50

	0x3562,// DS-51	89   
	0x35e2,// DS-52
	0x3662,// DS-53
	0x36e2,// DS-54
	0x3762,// DS-55

	0x37e2,// DS-56	94
	0x3862,// DS-57
};

#endif

void TvDelay()
{
	unsigned int i;
	for(i=0;i<TVDELAY;i++);
}

void SetTvTunerFreqBuf(unsigned int freq)
{
	tunerbuf[0]=(freq>>8)&0x0ff;
	tunerbuf[1]=freq&0x0ff;
	if (freq<TVChannelData[LVHF_INDEX]+10)
	{
		tunerbuf[3]=0x01;
	}

	else if (freq<TVChannelData[HVHF_INDEX]+10)
	{
		tunerbuf[3]=0x02;
	}

	else if (freq<TVChannelData[UHF_INDEX]+10)
	{
		tunerbuf[3]=0x04;
	}
}

void SetTvTunerFreq(unsigned int freq)
{
	SetTvTunerFreqBuf(freq);
	iic_WriteBytes(TUNER_ADDR,tunerbuf[0],tunerbuf+1,3);
}

void SetTvChannel(unsigned char channel)
{
	if(channel<2)
		channel = 2;
	else if(channel>UHF_INDEX)
		channel = UHF_INDEX;
	SetTvTunerFreq(TVChannelData[channel]);
}

unsigned char SearchPLLlock(unsigned char *tunerData)
{
#if 1
	unsigned char	IFstatus = 0;
 
	TvDelay();

	iic_ReadByte(IF_ADDR,&IFstatus);
	if( IFstatus == 0xae || IFstatus == 0x0e || IFstatus == 0xce ||
		IFstatus == 0x8e || IFstatus == 0x90 || IFstatus == 0xd0 ||
		IFstatus == 0x4e){
		IFstatus = 1;
	}
	else{
		IFstatus = 0;
	}
	return IFstatus;
#else
	short	status = 0,	afcData,	freqStep;
	unsigned char	IFstatus;
	short	temp;
	short   loop_cnt;
	unsigned char isInAFCWindow;

	TvDelay();

	status = iic_ReadByte(IF_ADDR,&IFstatus);
	if(!status){
		return 1;
	}
	if (IFstatus & PONR_mask)
	{
		ShowLcdString(0x40,"invalid PONR\n");
		return 1;
	}

	afcData = (short)((IFstatus & AFCVAL_mask) >> 1);

	isInAFCWindow = (IFstatus & 0x80) ? 1 : 0;
	if (!isInAFCWindow && ((afcData == 0x7)||(afcData == 0x08)))
	{
		ShowLcdString(0x40,"No signal detected\n");
		return 2;
	}

	loop_cnt =0;
	while ((afcData != 0x1) && (afcData != 0x0) && (afcData != 0xf))	// while not zero'ed in	
	{
		if ((afcData == 0x7) || (afcData == 0x8)) loop_cnt++;	// within AFC window but far out

		if (loop_cnt == 3)	return 4;	// can't get there

		if (afcData & 0x08)
		{
			afcData |= 0xfff0;	// sign extend
		}
	
		if (IFstatus & AFCWIN_mask)	// if within AFC window
		{
			freqStep = (short)((afcData * 25) + 12);	// in khz (signed number

			temp = (*tunerData << 8) | *(tunerData+1);
			temp += (short)(freqStep/RSA);

			*tunerData = (temp & 0xff00) >> 8;
			*(tunerData+1) = temp & 0x00ff;
			ShowLcdHex(0x50,*tunerData);
			ShowLcdHex(0x52,*(tunerData+1));
			iic_WriteBytes(TUNER_ADDR,tunerData[0],tunerData+1,3);
		}
		else return 3;	// out of window, will not attempt to zero in.

		TvDelay();

		iic_ReadByte(IF_ADDR,&IFstatus);

		if (IFstatus & PONR_mask)
		{
			ShowLcdString(0x40,"invalid PONR\n");
			return 1;
		}

		TvDelay();

	}	// end while

	return 0;
#endif
}


⌨️ 快捷键说明

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