?? autoadj.c
字號:
#include "8051.H"
#include "MATH.H"
#include "Scaler.H"
#include "AutoAdj.H"
#include "MyDef.H"
#include "IIC.H"
#include "RAM.H"
#include "stdio.h"
#include "F63XREG.H"
#include "F63XDEF.H"
#include "MCU.H"
#include "UserAdj.H"
#include "ModeHandle.H"
#include "ROM_MAP.H"
#include "OSD.H"
void TunePositionOnly()
{
Abort = 0;
WriteIIC563(0x001,FuncBuf[pRADC]);
WriteIIC563(0x004,FuncBuf[pGADC]);
WriteIIC563(0x007,FuncBuf[pBADC]);
AutoPosition();
if(Abort)
{ //fail
LoadModeDependentSettings();
SetHP();
SetVP();
#if PRINT_MESSAGE
printf("Auto Position fail\n");
#endif
}
else{ //ok
SaveModeDependentSettings();
#if PRINT_MESSAGE
printf("Auto Position OK\n");
#endif
}
SetContrast();
}
void AutoTune(void)
{
Word addr;
// Byte PixelRate;
Abort = 0;
NonFullScreen = 0;
WriteIIC563(0x001,FuncBuf[pRADC]);
WriteIIC563(0x004,FuncBuf[pGADC]);
WriteIIC563(0x007,FuncBuf[pBADC]);
// if(ModePoint < UserModeSt)
// Recall();
WriteIIC563(0x06a,0x00); //jacky 20050426 disable de-jitter
//WriteIIC563(0x069,0x00); //jacky 20050426 disable NR
//WriteIIC563(0x06b,0x00); //jacky 20050426 disable NR
AutoPosition();
if(!Abort)
AutoClock();
// PixelRate = ((unsigned long)FuncBuf[pCLOCK] * H_SYNC)/10000;
// if(PixelRate >= PanelMaxPClk/1000)
// Abort = 1;
if(NonFullScreen && !Abort) //non fullscreen recall
{
//addr = ep_Sync_Data + (ModePoint * 8);
//FuncBuf[pCLOCK] = Read24C16(addr+4) << 8;
//FuncBuf[pCLOCK] |= Read24C16(addr+5);
LoadPresetModeSettings(2);
SetADC_PLL();
}
CheckAnyKey();
#if 0
if(Abort){
if(NonFullScreen == 0){
//goto Error;
}
else{
Abort = 0;
AutoClockByPhase(1);
}
}
else{
AutoClockByPhase(0);
}
#else
if(!Abort)
AutoClockByPhase(0);
#endif
CheckAnyKey();
if(!Abort)
AutoPhaseFineTune(16);
CheckAnyKey();
if(!Abort)
AutoPosition();
CheckAnyKey();
WriteIIC563(0x06a,0xd2); //jacky 20050426 enable de-jitter
//WriteIIC563(0x069,0x43); //jacky 20050426 enable NR
//WriteIIC563(0x06b,0x03); //jacky 20050426 enable NR
if(Abort)
{ //fail
Osd_Off();
//if(ModePoint < UserModeSt)
// addr = ModePoint * 8;
//else
// addr = UserModeRefReso * 8;
LoadPresetModeSettings(0);
//LoadModeDependentSettings();
SetADC_PLL();
SetADC_Phase();
//-------------------------------------------------------
if(SyncMode != 3)
{
SetHP();
SetVP();
}
if(Interlance){
WriteWordIIC563(0x032,Vresolution); // Capture V_Active
}
else{
WriteWordIIC563(0x032,Vresolution); // Capture V_Active
}
WriteWordIIC563(0x036,Hresolution); // Capture H_Active
//WriteWordIIC563(0x036,Hresolution + H_ActErrTab[ResolutionPtr]); // Capture H_Active
//SetScaler();
//--------------------------------------------------
addr = ep_Reso_Offset + (ModePoint * 8);
Write24C16(addr,Read24C16(addr));
//Write24C16(addr,(Read24C16(addr) & 0x7f));
#if PRINT_MESSAGE
printf("AutoTune fail\n");
#endif
}
else{ //ok
Osd_Off();
SaveModeDependentSettings();
//Range.Hpos_Ref = FuncBuf[pHPOSITION];
//Range.Vpos_Ref = (Byte)FuncBuf[pVPOSITION];
//Range.Clock_Ref = FuncBuf[pCLOCK];
//SaveRangeRef();
Write24C16(ep_Reso_Offset + (ModePoint * 8), ResolutionPtr|0x80);
#if PRINT_MESSAGE
printf("AutoTune OK\n");
#endif
}
LoadADC_Gain();
}
#if 0
void AutoPosition(void)
{
Byte temp;
#if PRINT_MESSAGE
printf("AutoPosition\n");
#endif
WriteIIC563(0x02A,0); // AutoPosition Pixel mask -> H
WriteIIC563(0x02B,24); // AutoPosition Pixel mask -> H
WriteIIC563(0x02C,0x00); // AutoPosition Pixel mask -> H
WriteIIC563(0x02D,0x00); // AutoPosition Pixel mask -> H
WriteIIC563(0x107,0x30); // Red Noise Margin
WriteIIC563(0x106,0x00);
if(SyncMode == 3)
WriteIIC563(0x106,0x11);
else
WriteIIC563(0x106,0x01);
#if DVImode == HVmode
if(SyncMode == 3)
WaitSetup(5);
//Sleep(50);
#endif
LocalTimer = 10;
while((ReadIIC563(0x106) & BIT_0) && LocalTimer != 0)
{
CheckModeChange();
if(Abort)
return;
}
if(LocalTimer != 0)
{ // Auto-Position OK
FuncBuf[pVPOSITION] = ReadIIC563(0x109) & 0x07;
FuncBuf[pVPOSITION] <<= 8;
FuncBuf[pVPOSITION] |= ReadIIC563(0x108);
FuncBuf[pHPOSITION] = ReadIIC563(0x10F) & 0x07;
FuncBuf[pHPOSITION] <<= 8;
FuncBuf[pHPOSITION] |= ReadIIC563(0x10E);
#if PRINT_MESSAGE
printf("VP_Start = %d\n",FuncBuf[pVPOSITION]);
printf("HP_Start = %d\n",FuncBuf[pHPOSITION]);
#endif
if(((FuncBuf[pVPOSITION] > 0xff) || (FuncBuf[pHPOSITION] > (FuncBuf[pCLOCK]-H_Act)))&&(SyncMode != 3))
{
Abort = 1; // abort
#if PRINT_MESSAGE
printf("AutoPosition fail\n");
#endif
}
else{
if(ResolutionPtr < 4)
{
if(FuncBuf[pVPOSITION] > (VTotal - Vresolution-1))
FuncBuf[pVPOSITION] = VTotal - Vresolution-14;
}
SetHP();
SetVP();
}
}
else
{
Abort = 1; // abort
#if PRINT_MESSAGE
printf("AutoPosition fail\n");
#endif
}
// wait for next V pulse coming to latch data
WriteIIC563(0x1ab,BIT_1);
LocalTimer = 100;
while(LocalTimer != 0)
{
Sleep(1);
temp = ReadIIC563(0x1ab);
if(temp & BIT_1)
break;
}
}
#endif
void AutoPosition(void)
{
Word OldVp,NewVp,Vact,Hact;
#if PRINT_MESSAGE
printf("AutoPosition\n");
#endif
WriteIIC563(0x02A,0); // AutoPosition Pixel mask -> H
WriteIIC563(0x02B,24); // AutoPosition Pixel mask -> H
WriteIIC563(0x02C,0x00); // AutoPosition Pixel mask -> H
WriteIIC563(0x02D,0x00); // AutoPosition Pixel mask -> H
WriteIIC563(0x107,0x30); // Red Noise Margin
WriteIIC563(0x106,0x00);
if(SyncMode == 3)
WriteIIC563(0x106,0x11);
else
WriteIIC563(0x106,0x01);
#if DVImode == HVmode
if(SyncMode == 3)
WaitSetup(5);
#endif
OldVp = FuncBuf[pVPOSITION];
LocalTimer = 100;
while((ReadIIC563(0x106) & BIT_0) && LocalTimer != 0)
{
CheckModeChange();
if(Abort)
return;
}
if(LocalTimer != 0)
{ // Auto-Position OK
Hact = ReadWordIIC563(0x110) & 0x0fff;
//Hact = ReadIIC563(0x111) & 0x3f;
//Hact <<= 8;
//Hact |= ReadIIC563(0x110);
// if(Hact < 300)
if(Hact < Hresolution - 100)
{
Abort = 1;
return;
}
FuncBuf[pVPOSITION] = ReadWordIIC563(0x108) & 0x07ff;
//FuncBuf[pVPOSITION] = ReadIIC563(0x109) & 0x07;
//FuncBuf[pVPOSITION] <<= 8;
//FuncBuf[pVPOSITION] |= ReadIIC563(0x108);
GetFuncRange(pVPOSITION);
if(FuncBuf[pVPOSITION] > FuncMax)//over VPosition Max
{
FuncBuf[pVPOSITION] = FuncMax;
#if PRINT_MESSAGE
printf("VPositon over Max");
#endif
}
FuncBuf[pHPOSITION] = ReadWordIIC563(0x10e) & 0x07ff;
//FuncBuf[pHPOSITION] = ReadIIC563(0x10F) & 0x07;
//FuncBuf[pHPOSITION] <<= 8;
//FuncBuf[pHPOSITION] |= ReadIIC563(0x10E);
GetFuncRange(pHPOSITION);
if(FuncBuf[pHPOSITION] > FuncMax)//over VPosition Max
{
FuncBuf[pHPOSITION] = FuncMax;
#if PRINT_MESSAGE
printf("HPositon over Max");
#endif
}
Vact = ReadWordIIC563(0x10c) & 0x07ff;
//Vact = ReadIIC563(0x10d) & 0x07;
//Vact <<= 8;
//Vact |= ReadIIC563(0x10c);
NewVp = FuncBuf[pVPOSITION];
#if PRINT_MESSAGE
printf("VP_Start = %d\n",FuncBuf[pVPOSITION]);
printf("HP_Start = %d\n",FuncBuf[pHPOSITION]);
#endif
if(((FuncBuf[pVPOSITION] > 0x40) || ((FuncBuf[pHPOSITION]>>1) > (FuncBuf[pCLOCK]-Hresolution))||(Vact < 340))&&(SyncMode != 3))
//if((FuncBuf[pVPOSITION] > 0xff) || ((FuncBuf[pHPOSITION]>>1) > (FuncBuf[pCLOCK]-Hresolution)))
{
Abort = 1; // abort
#if PRINT_MESSAGE
printf("AutoPosition fail\n");
#endif
}
else
{
//if(ResolutionPtr < 4)
// {
// if(FuncBuf[pVPOSITION] > (VTotal - Vresolution-1))
// FuncBuf[pVPOSITION] = VTotal - Vresolution-14;
// }
SetHP();
if(ResolutionPtr < 5 && Vact > 300)
{
if(NewVp >= (Vresolution - Vact) / 2)
NewVp = NewVp - (Vresolution - Vact) / 2;
else
{
Abort = 1;
return;
}
}
if(OldVp > NewVp)
{
//for(;OldVp>=NewVp;OldVp--)
//{
// FuncBuf[pVPOSITION] = OldVp;
// SetVP();
//}
}
else if(OldVp < NewVp)
{
for(;OldVp<=NewVp;OldVp++)
{
FuncBuf[pVPOSITION] = OldVp;
SetVP();
}
}
else
{
FuncBuf[pVPOSITION] = OldVp;
SetVP();
}
}
}
else
{
Abort = 1; // abort
#if PRINT_MESSAGE
printf("AutoPosition fail\n");
#endif
}
// wait for next V pulse coming to latch data
WaitVblank();
}
void AutoClock()
{
//preset mode total
bit FirstDo;
Byte H_Difference,i,Compare;
Word H_Ref,H_Act,TempClock;
#if PRINT_MESSAGE
printf("AutoClock\n");
#endif
TempClock = FuncBuf[pCLOCK];
if(VTotal > (Vresolution + 190)) //not full screen
{
NonFullScreen = 1;
#if PRINT_MESSAGE
printf("Non Full Screen");
#endif
return;
}
H_Ref = Hresolution;
if(H_Ref >= FuncBuf[pCLOCK])
{
Abort = 1;
FuncBuf[pCLOCK] = H_Ref + FuncBuf[pHPOSITION];
SetADC_PLL();
// return;
}
WriteWordIIC563(0x117, H_Ref);
FirstDo = 0;
for(i=0;i<20;i++)
{
WriteIIC563(0x106,0x01);
LocalTimer = 10;
while((ReadIIC563(0x106) & BIT_0) && LocalTimer != 0)
{
CheckModeChange();
if(Abort)
return;
}
H_Act = ReadWordIIC563(0x110) & 0x0fff;
//H_Act = ReadIIC563(0x111) & 0x0f;
//H_Act <<= 8;
//H_Act |= ReadIIC563(0x110);
// 20040224 Jacky
if(H_Act < (H_Ref - 124)){
i = 0xff;
break;
}
//------------------------
H_Difference = ReadIIC563(0x119);
Compare = (H_Difference & 0xC0) >> 6;
//H_Difference = (H_Difference & 0x3F);
H_Difference = (H_Difference & 0x3F) > AutoClock_Step ? AutoClock_Step : (H_Difference & 0x3f);
if(Compare == 0){ //H_Act == H_Ref jacky20040326 for AutoPhasebyClock
if(!FirstDo){
FirstDo = 1;
AutoPhaseByClock();
if(Abort)
return;
}
else
break;
}
//if(Compare == 0){ //H_Act == H_Ref
// break;
//}
if(Compare == 1)
{
FuncBuf[pCLOCK] += H_Difference;
if(FuncBuf[pCLOCK] > 2248)
{
i = 0xff;
break;
}
}
if(Compare == 2 || Compare == 3)
{
FuncBuf[pCLOCK] -= H_Difference;
if(FuncBuf[pCLOCK] < H_Ref)
{
i = 0xff;
break;
}
}
SetADC_PLL();
}
//printf("Clock divider 0 = %d\n",FuncBuf[pCLOCK]);
if(i == 0xff)
{
#if PRINT_MESSAGE
printf("None full screen\n");
#endif
Abort = 1;
NonFullScreen = 1;
return;
}
else
{
#if PRINT_MESSAGE
if(i == 20)
printf("AutoClock fail.\n");
#endif
if(abs(FuncBuf[pCLOCK] - TempClock) > (TempClock / 11))
// FuncBuf[pCLOCK] = TempClock;
Abort = 1;
else
FuncBuf[pCLOCK] = (FuncBuf[pCLOCK] + 2) & 0xfffc;
GetFuncRange(pCLOCK);
if(FuncBuf[pCLOCK] > FuncMax)//over VPosition Max
{
FuncBuf[pCLOCK] = FuncMax;
#if PRINT_MESSAGE
printf("Clock over Max");
#endif
}
SetADC_PLL();
}
}
void AutoClockByPhase(bit h)
{
bit R_L,U_D;
Byte k,temp;
Word GoodClk;
xdata unsigned long MaxMin,Value;
#if PRINT_MESSAGE
printf("AutoClockByPhase\r\n");
#endif
// if((ModePoint < UserModeSt)&&(h == 1)){
// i = 0x104 + (ModePoint * 8);
// FuncBuf[pCLOCK] = EEP_SyncMap[i];
// i++;
// FuncBuf[pCLOCK] <<= 8;
// FuncBuf[pCLOCK] += EEP_SyncMap[i];
// }
if(h == 1)
LoadPresetModeSettings(2);
//printf("Phase ok = %d\n",(unsigned short)FuncBuf[pPHASE]);
GoodClk = FuncBuf[pCLOCK];
SetADC_PLL();
WaitSetup(4);
if(Abort)
return;
//Sleep(25);
MaxMin = CheckPhaseData();
//printf("Clock Value Original = %x %x\n",(unsigned short)(MaxMin >> 16),(unsigned short)MaxMin);
temp = TempPhase;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -