📄 nvram.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"
extern uCHAR cPAL_Dot,cNTSC_Dot,cSTV1_ON;
extern void InitFactry(void);
extern uCHAR cPAL_Dot,cNTSC_Dot;
extern uCHAR cSTV1_ON;
extern uCHAR cSTV_OFFSET;
extern uCHAR cPAL_OFFSET,cNTSC_OFFSET,cGATE_PREDRIVE;
#define PAGE0_NUM 0x70
#define PAGE1_NUM 0x22
#define PAGE2_NUM 0x26
#define PAGE0_S 0x00
#define PAGE1_S PAGE0_NUM
#define PAGE2_S (PAGE1_S+PAGE1_NUM)
#define PAGE2_E (PAGE2_S+PAGE2_NUM)
#define REG_ADDR_S 0x20
uCHAR code RegisterMap[]={
0x00,0x01,0x02,0x04,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0f,//12
0x10,0x11,0x18,0x19,0x1a,0x1c,0x1d,0x1e,0x1f,//9
0x30,0x31,0x32,0x33,0x35,0x36,0x37,0x38,0x3a,0x3b,0x3f,//11
0x40,//1
0x61,0x62,0x63,0x64,0x65,0x66,0x6a,0x6b,0x6c,//0x68,0x69,11-2=9
0x70,0x72,0x73,0x74,0x75,0x76,0x77,0x7f,//8
0x80,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,//13
0x90,0x91,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,//13
0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,
0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,//16
0xc0,0xc1,0xc2,0xc3,0xc4,0xc7,0xc8,0xc9,0xca,//9
0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,//8
0xe1,0xe8,0xe9,//0xe0,0xe3,//5-2=3------------------------112
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2d,//13
0x30,0x31,0x32,0x33,0x34,0x35,//6
0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
0xd8,0xd9,0xda,0xdb,0xdc,0xde,0xdf,//15-------34
0x00,0x01,0x02,0x03,0x04,0x05,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0f,//14
0x10,0x11,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,//12
0x20,0x2c,0x2d,0x2e,0x2f,//5
0x30,0x31,0x39,0x3f,//4
0x80,0x82,0x83//3-------------38-------------------------184
};
EEPVIDEO idata EepVideo;
#ifdef NVRAM
extern uWORD IDATA m_wBuff[3];
extern uCHAR IDATA m_cBuff[4];
extern void InitFactry(void);
void EEPLoadPubData(void)
{
if(!(ReadPort()&kyMENU))
{
InitEEPRom();
OSDResetVideoData();
while(!(ReadPort()&kyMENU)) {};
}
else
{
if(I2CReadByte(0xA0, 0x00) != '1' || I2CReadByte(0xA0, 0x01)!= '0' || I2CReadByte(0xA0, 0x02)!= '0' )
{
InitEEPRom();
OSDResetVideoData();
}
else
I2CReadBytes(EEPVIDEOBLOCK, 0x04, (uCHAR *)&EepVideo, EEPVIDEOSIZE);
}
InitFactry();
OSDSetVideoValues();
I2CWriteByte(TW101, 0xE9, EepVideo.cVolume);
EEPSaveVideoData();
}
//extern uCHAR cPAL_OFFSET,cNTSC_OFFSET;
void InitEEPRom(void)
{
uCHAR i;
I2CWriteByte(EEPBLOCK0, 0x00, '1');
twdDelay(NVRDELAY);
I2CWriteByte(EEPBLOCK0, 0x01, '0');
twdDelay(NVRDELAY);
I2CWriteByte(EEPBLOCK0, 0x02, '0');
for(i=0x04;i<0xd8;i++)
{
twdDelay(NVRDELAY);
I2CWriteByte(EEPBLOCK0, i, 0xff);
}
for(i=0xd8;i<0xff;i++)
{
twdDelay(NVRDELAY);
I2CWriteByte(EEPBLOCK0, i, 0x00);
}
twdDelay(NVRDELAY);//*/
}
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 = 0x80;
}
void OSDSetVideoValues(void)
{
// I2CWriteByte(VIDEO_ADDR,VSHARP,(I2CReadByte(VIDEO_ADDR,VSHARP)&0xF0)|EepVideo.cSharp);
// I2CWriteByte(VIDEO_ADDR,VBRIGHT,EepVideo.cBright);
// I2CWriteByte(VIDEO_ADDR,VCONTRAST,EepVideo.cContrast);
I2CWriteByte(TW101,VBRIGHT,EepVideo.cBright);
I2CWriteByte(TW101,VCONTRAST,EepVideo.cContrast);
I2CWriteByte(VIDEO_ADDR,VSAT,EepVideo.cSat);
I2CWriteByte(VIDEO_ADDR,VHUE,EepVideo.cHue-0x80);
}
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);
twdDelay(NVRDELAY);
I2CWriteByte(EEPVIDEOBLOCK, idVIDEO_FLAG_INDEX, EepVideo.cFlag);
twdDelay(NVRDELAY);
I2CWriteByte(0xa0, 0x10, cPAL_Dot);//PAL
twdDelay(NVRDELAY);
I2CWriteByte(0xa0, 0x11, cNTSC_Dot);//NTSC
}
void ReadFactryData(void)
{
twdDelay(NVRDELAY);
cPAL_Dot =I2CReadByte(0xa0, 0x10);//PAL
twdDelay(NVRDELAY);
cNTSC_Dot =I2CReadByte(0xa0, 0x11);//NTSC
twdDelay(NVRDELAY);
cSTV1_ON =I2CReadByte(0xa0, 0x12);
twdDelay(NVRDELAY);
cSTV_OFFSET =I2CReadByte(0xa0, 0x13);
twdDelay(NVRDELAY);
cPAL_OFFSET =I2CReadByte(0xa0, 0x14);
twdDelay(NVRDELAY);
cNTSC_OFFSET=I2CReadByte(0xa0, 0x15);
twdDelay(NVRDELAY);
cGATE_PREDRIVE =I2CReadByte(0xa0, 0x16);
twdDelay(NVRDELAY);
}
#ifdef TV
extern bit m_bAir_Cable;
void EEPSaveTVChannel(uCHAR cTVNum, uWORD wTVFreq)
{
if(m_bAir_Cable)
{
I2CWriteByte(EEPVIDEOBLOCK, idTVCHANNEL_STAT+cTVNum*2, (uCHAR)(wTVFreq>>8));
twdDelay(NVRDELAY);
I2CWriteByte(EEPVIDEOBLOCK, 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
void RegisterSetting(void)
{
uCHAR cTemp,cTemp1,cTemp2,cTemp3,cAddr;
long int dwAddr;
dwAddr=I2CReadByte(EEPBLOCK0, 0xda);
dwAddr<<=8;
dwAddr|=I2CReadByte(EEPBLOCK0, 0xd9);
dwAddr<<=8;
dwAddr|=I2CReadByte(EEPBLOCK0, 0xd8);
if(!dwAddr)return;
for(cTemp=0;cTemp<23;cTemp++)
{
if(dwAddr&(1<<cTemp))
{
cTemp1=0xe0+cTemp;
cTemp2=I2CReadByte(EEPBLOCK0, cTemp1);
if(cTemp2)
{
for(cTemp3=0;cTemp3<8;cTemp3++)
{
if(cTemp2&(1<<cTemp3))
{
cTemp1=cTemp*8+cTemp3;
if(cTemp1<PAGE1_S)cAddr=0x50;
else if(cTemp1<PAGE2_S)cAddr=0x52;
else cAddr=0x54;
I2CWriteByte(cAddr,RegisterMap[cTemp1],I2CReadByte(EEPBLOCK0, cTemp1+0x20));
}
}
}
}
}
/* for(cTemp1=0xd8;cTemp1<=0xda;cTemp1++)
{
cTemp=I2CReadByte(EEPBLOCK0, cTemp1);
cTemp3=0;
while(cTemp)
{
if(cTemp&(1<<cTemp3))
{
cTemp2=I2CReadByte(EEPBLOCK0, ((cTemp1-0xd8)*8));
cTemp2=(cTemp1-0xd8)*0x40+cTemp3*8+cTemp2;
if(cTemp2<PAGE1_S)cAddr=0x50;
else if(cTemp2<PAGE2_S)cAddr=0x52;
else cAddr=0x54;
I2CWriteByte(cAddr,RegisterMap[cTemp2],I2CReadByte(EEPBLOCK0, cTemp2));
}
}
}//*/
}
uCHAR RegisterMapData(uCHAR cTemp)
{
return RegisterMap[cTemp];
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -