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

📄 nvram.c

📁 宏芯T102芯片驱动(51单片机作主控)
💻 C
字号:
#include <reg51.h>
#include "common.h"
#include "Struct.h"
#include "system.h"
#include "NVRam.h"
#include "TW101Reg.h"
#include "TwoWire.h"
//#include "OSDCtrl.h"
#include "KeyPad.h"
//#include "ModeCtrl.h"
//#include "ModeTbl.h"
#include "Video.h"

EEPVIDEO   idata EepVideo;	
#ifdef NVRAM
extern uWORD IDATA m_wBuff[3];
extern uCHAR IDATA m_cBuff[4];
extern bit m_bKyPowerOn;
#ifdef TV
extern bit m_bAir_Cable;
#endif
void EEPLoadPubData(void)
{

	if(!(ReadPort()&kyMENU))
	{
  		InitEEPRom();
		OSDResetVideoData();
		while(!(ReadPort()&kyMENU))	{};
	}
	else
	{
		if(I2CReadByte(0xA0, 0x00) != '1' || I2CReadByte(0xA0, 0x01)!= '0' || I2CReadByte(0xA0, 0x02)!= '1' )
		{
			InitEEPRom();
			OSDResetVideoData();
		}
		else
			I2CReadBytes(EEPVIDEOBLOCK, 0x04, (uCHAR *)&EepVideo, EEPVIDEOSIZE);
	}
#ifdef TV
	if(I2CReadByte(EEPVIDEOBLOCK, idVIDEO_FLAG_INDEX)&0x01)
	{
		m_bAir_Cable=1;
	}
	else
	{
		m_bAir_Cable=0;
	}
#endif
	if(I2CReadByte(EEPVIDEOBLOCK,idVIDEO_POWER_INDEX)&0x01)
	{
		m_bKyPowerOn=0;
	}
	else 
	{
		m_bKyPowerOn=1;
	}
	OSDSetVideoValues();
	EEPSaveVideoData();
}

void InitEEPRom(void)
{
 	I2CWriteByte(EEPBLOCK0, 0x00, '1');
  	twdDelay(NVRDELAY);
	I2CWriteByte(EEPBLOCK0, 0x01, '0');
	twdDelay(NVRDELAY);
	I2CWriteByte(EEPBLOCK0, 0x02, '1');

}

void OSDResetVideoData(void)
{
	EepVideo.cBright 	= V_BRIGHT_DEF;
	EepVideo.cContrast 	= V_CONTRAST_DEF ;
   	EepVideo.cSharp 	= V_SHARP_DEF;
   	EepVideo.cHue 		= V_HUE_DEF;
   	EepVideo.cSat 		= V_SAT_DEF;
  	EepVideo.cVolume	= V_VOL_DEF;
	EepVideo.cLanguage  = V_LAG_DEF;
}

void OSDSetVideoValues(void)
{
//	I2CWriteByte(VIDEO_ADDR,VSHARP,(I2CReadByte(VIDEO_ADDR,VSHARP)&0xF0)|EepVideo.cSharp);

    I2CWriteByte(TW101+4,0x80,V_SHARP_MSK|(EepVideo.cSharp<<1));

//	I2CWriteByte(VIDEO_ADDR,VBRIGHT,EepVideo.cBright);
//	I2CWriteByte(VIDEO_ADDR,VCONTRAST,EepVideo.cContrast);
	I2CWriteByte(TW101,VBRIGHT,EepVideo.cBright);
	I2CWriteByte(TW101,VCONTRAST,EepVideo.cContrast);
	I2CWriteByte(TW101,VSAT,EepVideo.cSat);
	I2CWriteByte(TW101,VOLUME,EepVideo.cVolume);
	I2CWriteByte(VIDEO_ADDR,VHUE,EepVideo.cHue-0x80);
#ifdef LG_7
	I2CWriteByte(TW101+4, 0x80, 0x25);
#endif
}

void EEPSaveVideoData(void)
{
	I2CWriteByte(EEPVIDEOBLOCK, idVIDEO_CONTRAST_INDEX,EepVideo.cContrast );
	twdDelay(NVRDELAY);
	I2CWriteByte(EEPVIDEOBLOCK, idVIDEO_BRIGHT_INDEX, EepVideo.cBright);
	twdDelay(NVRDELAY);
	I2CWriteByte(EEPVIDEOBLOCK, idVIDEO_SHARP_INDEX, EepVideo.cSharp);
	twdDelay(NVRDELAY);
	I2CWriteByte(EEPVIDEOBLOCK, idVIDEO_HUE_INDEX, EepVideo.cHue);
	twdDelay(NVRDELAY);
	I2CWriteByte(EEPVIDEOBLOCK, idVIDEO_SAT_INDEX, EepVideo.cSat);
	twdDelay(NVRDELAY);
	I2CWriteByte(EEPVIDEOBLOCK, idVIDEO_VOLUME_INDEX, EepVideo.cVolume);
}
#ifdef TV

void EEPSaveTVChannel(uCHAR cTVNum, uWORD wTVFreq)
{
	if(m_bAir_Cable)
	{
	I2CWriteByte(EEPVIDEOBLOCK+4, idTVCHANNEL_STAT+cTVNum*2, (uCHAR)(wTVFreq>>8));
	twdDelay(NVRDELAY);
	I2CWriteByte(EEPVIDEOBLOCK+4, idTVCHANNEL_STAT+cTVNum*2+1, (uCHAR)(wTVFreq&0x00FF));
	twdDelay(NVRDELAY);
	}
	else
	{
	I2CWriteByte(EEPVIDEOBLOCK+2, idTVCHANNEL_STAT+cTVNum*2, (uCHAR)(wTVFreq>>8));
	twdDelay(NVRDELAY);
	I2CWriteByte(EEPVIDEOBLOCK+2, idTVCHANNEL_STAT+cTVNum*2+1, (uCHAR)(wTVFreq&0x00FF));
	twdDelay(NVRDELAY);
	}
}



#endif
#endif

⌨️ 快捷键说明

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