📄 lcd_auto.c
字号:
ulTemp0 = 0;
Set_Phase(ucPhase);
ucDetect = (select == 0) ? 0x77 : 0x7b;
while(1)
{
RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
Wait_Finish();
if (ERROR_SUCCEED != Data[0]) return Data[0];
Read_Auto_Info(1);
if (ulTemp0 < ((unsigned long *)Data)[1])
{
ulTemp0 = ((unsigned long *)Data)[1];
}
ucPhase += 0x20;
if(ucPhase > 0x60)
break;
Set_Phase(ucPhase);
}
return ulTemp0;
}
//------------------------------------------------------------------//
// Return Message => ERROR_SUCCESS : Success //
// ERROR_TOO_SMALL : Measure Result << ACT_WIDTH //
// ERROR_TOO_BIG : Measure Result >> ACT_WIDTH //
// ERROR_INPUT : 1. IVS or IHS changed //
// 2. underflow or overflow //
// ERROR_TIMEOUT : Measure Time_Out //
// Process Time_Out //
// ERROR_NOTACTIVE : No Avtive Image //
//------------------------------------------------------------------//
unsigned char Auto_Clock_Do(unsigned char NM)
{
#if(0)
unsigned char ucResult;
unsigned char count, delta, stop;
///////////////////////////////
// Measure (V) Start & End //
///////////////////////////////
ucResult = Measure_PositionV(NM);
if (ERROR_SUCCEED != (ucResult & 0x80))
{
if (ERROR_NOTACTIVE == ucResult)
{
if (0x80 < stMUD.CLOCK)
{
stMUD.CLOCK = 0x80;
Set_H_Position();
Set_Clock();
}
else
{
stMUD.CLOCK = 0x80;
Set_Clock();
Set_H_Position();
}
ucResult = Measure_PositionV(NM);
if (ERROR_SUCCEED != (ucResult & 0x80)) return ucResult;
}
else
return ucResult;
}
NM = NM + 0x10; // See Min_Noise_Margin(). Horizontal Measure Result is the same when applying (NM + 0x10)
count = 10;
do
{
///////////////////////////////
// Measure (H) Start & End //
///////////////////////////////
ucResult = Measure_PositionH(NM);
if (ERROR_SUCCEED != (ucResult & 0x80)) return ucResult;
usH_End = usH_End + 1 - usH_Start;
// H_Active Delta
if (usH_End < usIPH_ACT_WID)
delta = (usIPH_ACT_WID - usH_End > 0x00ff) ? 0xff : (unsigned char)(usIPH_ACT_WID - usH_End);
else
delta = (usH_End - usIPH_ACT_WID > 0x00ff) ? 0xff : (unsigned char)(usH_End - usIPH_ACT_WID);
if (0xc8 < delta) // The difference is too large to fine-tune.
{
if (10 == count)
{
if (0x80 < stMUD.CLOCK)
{
stMUD.CLOCK = 0x80;
Set_H_Position();
Set_Clock();
}
else
{
stMUD.CLOCK = 0x80;
Set_Clock();
Set_H_Position();
}
continue;
}
else
return (usH_End < usIPH_ACT_WID) ? ERROR_TOO_SMALL : ERROR_TOO_BIG;
}
if (2 >= delta) break; // 1023,1024,1025,1026,1027
delta = (delta + (delta >> 2) + 2) & 0xfc; // 4n number
// Adjust Clock
if (usH_End < usIPH_ACT_WID) // delta < 0, Measure < Active
{
if ((228 - stMUD.CLOCK) < delta) return ERROR_TOO_SMALL;
stMUD.CLOCK += delta;
Set_Clock();
Set_H_Position();
}
else // delta >= 0, Measure >= Active
{
if ((stMUD.CLOCK - 28) < delta) return ERROR_TOO_BIG;
stMUD.CLOCK -= delta;
Set_H_Position();
Set_Clock();
}
}
while (--count);
if (0 == count) return ERROR_TIMEOUT;
stop = 0;
while (1)
{
count = 0x10; // Phase 4 ~ 28 step 8 (4,12,20,28)
delta = 0x00;
while (1)
{
Set_Phase(count);
// Measure usH_Start & usH_End
ucResult = Measure_PositionH(NM);
if (ERROR_SUCCEED != (ucResult & 0x80))
{
if (ERROR_NOTACTIVE == ucResult)
{
// Input pattern is black/white vertical lines.
if (0x70 == count)
{
Set_Phase(stMUD.PHASE); // Restore phase
break;
}
else
{
count += 0x20;
continue;
}
}
Set_Phase(stMUD.PHASE); // Restore phase
return ucResult;
}
usH_End = usH_End + 1 - usH_Start;
ucResult = (usH_End < usIPH_ACT_WID)
? 0x80 - (unsigned char)(usIPH_ACT_WID - usH_End)
: 0x80 + (unsigned char)(usH_End - usIPH_ACT_WID);
if (ucResult > delta)
{
delta = ucResult; // Save the biggest width
}
if (0x70 == count)
{
Set_Phase(stMUD.PHASE); // Restore phase
break;
}
count += 0x20;
}
if (0x82 < delta)
{
stMUD.CLOCK -= 4;
Set_H_Position();
Set_Clock();
stop = 1;
}
else if (0x80 > delta)
{
if (stop && (0x7f == delta)) break;
stMUD.CLOCK += 4;
Set_Clock();
Set_H_Position();
delta += 3;
if (stop) break;
}
else
break;
}
#if (MORE_CLOCK)
if (0x84 > delta && 0x7c < delta)
{
unsigned long ulTemp0, ulMaxVal;
unsigned char ucPhase, ucDetect;
if (ERROR_SUCCEED != Measure_PositionN(NM)) return ERROR_ABORT;
// Set auto-tracking window
Data[0] = 6;
Data[1] = Y_INC;
Data[2] = H_BND_STA_L_75;
Data[3] = (unsigned char)(usH_Start + MEAS_H_STA_OFFSET - 2);
Data[4] = (unsigned char)(usH_End + MEAS_H_END_OFFSET + 1);
Data[5] = ((unsigned char)((usH_Start + MEAS_H_STA_OFFSET - 2) >> 4) & 0x70) | ((unsigned char)((usH_End + MEAS_H_END_OFFSET + 1) >> 8) & 0x0f);
Data[6] = 0;
RTDWrite(Data);
RTDSetByte(DIFF_THRED_7E, 0x50);
ulTemp0 = 0;
ucDetect = 0x7b;
ucResult = COLORS_GREEN;
ucPhase = COLORS_GREEN;
do
{
RTDSetByte(MARGIN_B_7D, ucPhase);
RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
Wait_Finish();
if (ERROR_SUCCEED != Data[0]) return Data[0];
/*
RTDRead(AUTO_PHASE0_88, 4, Y_INC);
Data[4] = Data[3];
Data[5] = Data[2];
Data[6] = Data[1];
Data[7] = Data[0];
*/
Read_Auto_Info(1);
if (ulTemp0 < ((unsigned long *)Data)[1])
{
ulTemp0 = ((unsigned long *)Data)[1];
ucResult = ucPhase;
if (0x10000 < ulTemp0) break;
}
if (COLORS_GREEN == ucPhase)
ucPhase = COLORS_BLUE;
else if (COLORS_BLUE == ucPhase)
ucPhase = COLORS_RED;
else
{
if (0x10000 <= ulTemp0 || 0x77 == ucDetect) break;
ulTemp0 = 0;
ucDetect = 0x77;
ucPhase = COLORS_GREEN;
ucResult = COLORS_GREEN;
RTDSetByte(DIFF_THRED_7E, 0x70);
}
}
while (1);
// Abort if no suitable color is found
if (0x8000 > ulTemp0)
{
return (28 > stMUD.CLOCK) ? ERROR_TOO_BIG : (228 < stMUD.CLOCK) ? ERROR_TOO_SMALL : ERROR_SUCCEED;
}
// Save 4N clock
stop = stMUD.CLOCK;
if (0x81 > delta)
{
stMUD.CLOCK = stMUD.CLOCK + 4;
Set_Clock();
Set_H_Position();
}
ulMaxVal = 0;
delta = 4;
do
{
if (ERROR_SUCCEED != Measure_PositionN(NM)) return ERROR_ABORT;
// Set auto-tracking window
Data[0] = 6;
Data[1] = Y_INC;
Data[2] = H_BND_STA_L_75;
Data[3] = (unsigned char)(usH_Start + MEAS_H_STA_OFFSET - 2);
Data[4] = (unsigned char)(usH_End + MEAS_H_END_OFFSET + 1);
Data[5] = ((unsigned char)((usH_Start + MEAS_H_STA_OFFSET - 2) >> 4) & 0x70) | ((unsigned char)((usH_End + MEAS_H_END_OFFSET + 1) >> 8) & 0x0f);
Data[6] = 0;
RTDWrite(Data);
// Select color for auto-phase tracking
RTDSetByte(MARGIN_B_7D, ucResult);
// Set threshold
RTDSetByte(DIFF_THRED_7E, (0x7b == ucDetect) ? 0x50 : 0x70);
ulTemp0 = 0;
ucPhase = 0x00;
do
{
Set_Phase(ucPhase);
RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
Wait_Finish();
if (ERROR_SUCCEED != Data[0]) return Data[0];
RTDRead(AUTO_PHASE0_88, 4, Y_INC);
Data[4] = Data[3];
Data[5] = Data[2];
Data[6] = Data[1];
Data[7] = Data[0];
if (ulTemp0 < ((unsigned long *)Data)[1]) ulTemp0 = ((unsigned long *)Data)[1];
ucPhase += 0x10;
}
while (0x80 > ucPhase);
if (ulMaxVal < ulTemp0)
{
ulMaxVal = ulTemp0;
count = stMUD.CLOCK;
}
if (0x00 == delta)
{
if (128 < stMUD.CLOCK)
{
// See if default clock is the best
delta = 0xff;
stMUD.CLOCK = 128;
Set_H_Position();
Set_Clock();
continue;
}
else
break;
}
else if (0xff == delta)
{
break;
}
delta -= 1;
stMUD.CLOCK -= 1;
Set_H_Position();
Set_Clock();
}
while (1);
if (0x7b == ucDetect)
stMUD.CLOCK = ((unsigned long)0x38000 < ulMaxVal) ? count : stop;
else
stMUD.CLOCK = ((unsigned long)0x48000 < ulMaxVal) ? count : stop;
Set_Clock();
Set_H_Position();
Set_Clock();
}
#endif
#else
unsigned char Result;
unsigned char count, delta, stop,start;
unsigned long ulSum,ulCompare;
ulCompare = 0;
ulSum = 0;
///////////////////////////////
// Measure (V) Start & End //
///////////////////////////////
Result = Measure_PositionV(NM);
if (ERROR_SUCCEED != (Result & 0x80)) return Result;
NM = NM + 0x10; // See Min_Noise_Margin(). Horizontal Measure Result is the same when applying (NM + 0x10)
count = 10;
do
{
///////////////////////////////
// Measure (H) Start & End //
///////////////////////////////
Result = Measure_PositionH(NM);
if (ERROR_SUCCEED != (Result & 0x80)) return Result;
usH_End = usH_End + 1 - usH_Start;
// H_Active Delta
if (usH_End < usIPH_ACT_WID)
delta = (usIPH_ACT_WID - usH_End > 0x00ff) ? 0xff : (unsigned char)(usIPH_ACT_WID - usH_End);
else
delta = (usH_End - usIPH_ACT_WID > 0x00ff) ? 0xff : (unsigned char)(usH_End - usIPH_ACT_WID);
//if (0xc0 < delta) // The difference is too large to fine-tune.
if((usIPH_ACT_WID/3) < delta) //modified 2003/02/25
{
return (usH_End < usIPH_ACT_WID) ? ERROR_TOO_SMALL : ERROR_TOO_BIG;
}
if (1 >= delta) break; // 1023,1024,1025,1026,1027
delta = delta + (delta >> 2);//& 0xfe; // 4n number
// Adjust Clock
if (usH_End < usIPH_ACT_WID) // delta < 0, Measure < Active
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -