Lcd_auto.lst
上传用户:xmyjxjd
上传日期:2013-05-04
资源大小:1517k
文件大小:350k
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 1
- C51 COMPILER V7.06, COMPILATION OF MODULE LCD_AUTO
- OBJECT MODULE PLACED IN .OutputLcd_auto.obj
- COMPILER INVOKED BY: C:KeilC51BINC51.EXE CodeLcd_auto.c OPTIMIZE(9,SPEED) BROWSE DEBUG OBJECTEXTEND CODE SYMBOLS PR
- -INT(.OutputLcd_auto.lst) PREPRINT(.OutputLcd_auto.i) OBJECT(.OutputLcd_auto.obj)
- stmt level source
- 1 #define __AUTO__
- 2
- 3 #include "reg52.h"
- 4
- 5 #include "HeaderMAIN_DEF.h"
- 6 #include "HeaderACCESS.H"
- 7 #include "HeaderLCD_MAIN.H"
- 8 #include "HeaderCONFIG.H"
- 9 #include "HeaderLCD_FUNC.H"
- 10 #include "HeaderLCD_AUTO.H"
- 11 #include "HeaderLCD_OSD.H"
- 12
- 13
- 14 void Wait_Finish(void)
- 15 {
- 16 1 unsigned char Wait_Time_Cnt, IVS_Event;
- 17 1
- 18 1 RTDSetByte(STATUS0_01, 0x00); // Clear status
- 19 1 RTDSetByte(STATUS1_1F, 0x00); // Clear status
- 20 1
- 21 1
- 22 1 Wait_Time_Cnt = 60; // Auto-Phase timeout 60ms
- 23 1 IVS_Event = 25; // IVS timeout 25ms
- 24 1 do
- 25 1 {
- 26 2 Delay_Xms(1);
- 27 2
- 28 2 /*
- 29 2 #if(AS_NON_FRAMESYNC == 0)
- 30 2
- 31 2 RTDRead(STATUS0_01, 1, N_INC); // Get status
- 32 2
- 33 2 if (Data[0] & 0x63)
- 34 2 {
- 35 2
- 36 2 #if(MCU_TYPE == MCU_WINBOND)
- 37 2 bLIGHT_PWR = LIGHT_OFF;
- 38 2 #else
- 39 2 MCU_WriteBacklightPower(LIGHT_OFF);
- 40 2 #endif
- 41 2
- 42 2 RTDCodeW(FreeV);
- 43 2
- 44 2 Data[0] = ERROR_INPUT;
- 45 2 RTDSetByte(STATUS0_01, 0x00); // Clear status
- 46 2
- 47 2 return;
- 48 2
- 49 2 }
- 50 2 #endif
- 51 2 //Delay_Xms(2);
- 52 2 #if(MCU_TYPE == MCU_MTV512)
- 53 2 RTDSetByte(STATUS1_1F, 0x00); // Clear status
- 54 2 #endif
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 2
- 55 2
- 56 2 #if(AS_NON_FRAMESYNC == 0 || AS_DV_TOTAL == 0)
- 57 2 RTDRead(STATUS1_1F, 1, N_INC); // Get status
- 58 2
- 59 2
- 60 2 if ((Data[0] & (EVENT_UNDERFLOW | EVENT_OVERFLOW)) || (0 == --IVS_Event))
- 61 2 {
- 62 2
- 63 2 #if(MCU_TYPE == MCU_WINBOND)
- 64 2 bLIGHT_PWR = LIGHT_OFF;
- 65 2 #else
- 66 2 MCU_WriteBacklightPower(LIGHT_OFF);
- 67 2 #endif
- 68 2 RTDCodeW(FreeV);
- 69 2
- 70 2 Data[0] = ERROR_INPUT;
- 71 2 RTDSetByte(STATUS1_1F,0x00); //Event happened, write once to clear the status
- 72 2
- 73 2 return;
- 74 2 }
- 75 2 else if (Data[0] & (EVENT_IVS | EVENT_IEN_START))
- 76 2 {
- 77 2 IVS_Event = 25; // IVS timeout 25ms
- 78 2 RTDSetByte(STATUS1_1F,0x00); //Event happened, write once to clear the status
- 79 2 }
- 80 2
- 81 2 #endif
- 82 2 */
- 83 2 RTDRead(AUTO_ADJ_CTRL_7F, 1, N_INC);
- 84 2 }
- 85 1 while ((Data[0] & 0x01) && (--Wait_Time_Cnt));
- 86 1
- 87 1 RTDRead(STATUS0_01, 1, N_INC); // Get status
- 88 1
- 89 1
- 90 1 if(Data[0])
- 91 1 RTDSetByte(STATUS0_01,0x00); //Event happened, write once to clear the status
- 92 1
- 93 1
- 94 1 // Return non-zero value in Data[0] if :
- 95 1 // 1. IVS or IHS changed
- 96 1 // 2. Buffer underflow or overflow
- 97 1 // 3. Auto-Phase Tracking timeout
- 98 1
- 99 1 Data[0] = (Data[0] & 0x63) ? ERROR_INPUT : (0 == Wait_Time_Cnt) ? ERROR_TIMEOUT : ERROR_SUCCEED;
- 100 1 }
- 101
- 102 #if(HARDWARE_AUTO)
- 103 void Wait_For_IVS(void)
- 104 {
- 105 1 unsigned char t;
- 106 1
- 107 1 t = 50;
- 108 1
- 109 1 RTDSetByte(0x1f,0x00);
- 110 1 do
- 111 1 {
- 112 2 RTDRead(0x1f, 1, Y_INC);
- 113 2 Data[0] = Data[0] & EVENT_IVS;
- 114 2 //t--;
- 115 2 Delay_Xms(1);
- 116 2 }while((Data[0] == 0) && (t--));
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 3
- 117 1 }
- 118 #endif
- 119
- 120 //--------------------Measure Vertical Position---------------------//
- 121 // Return Message => ERROR_SUCCESS : Success //
- 122 // ERROR_INPUT : 1. IVS or IHS changed //
- 123 // 2. underflow or overflow //
- 124 // ERROR_TIMEOUT : Measure Time_Out //
- 125 // ERROR_NOTACTIVE : No Avtive Image //
- 126 //------------------------------------------------------------------//
- 127 unsigned char Measure_PositionV(unsigned char NM_V)
- 128 {
- 129 1 unsigned int usLBound, usRBound;
- 130 1
- 131 1 RTDRead(MEAS_HI_51, 0x02, Y_INC);
- 132 1 Data[2] = Data[1] & 0x0f;
- 133 1 Data[3] = Data[0];
- 134 1
- 135 1 usRBound = usADC_Clock + (unsigned int)stMUD.CLOCK - 128;
- 136 1 usLBound = (unsigned long)usRBound * ((unsigned int *)Data)[1] / usStdHS;
- 137 1
- 138 1 // Original formula :
- 139 1 // usRBound = usRBound - 2 - (PROGRAM_HDELAY - MEASURE_HDEALY) - (stMUD.H_POSITION - ucH_Min_Margin
- -);
- 140 1 // usLBound = usLBound + 20 - (PROGRAM_HDELAY - MEASURE_HDEALY) - (stMUD.H_POSITION - ucH_Min_Margi
- -n);
- 141 1
- 142 1 usRBound = usRBound - 2 + MEASURE_HDEALY - PROGRAM_HDELAY + ucH_Min_Margin - stMUD.H_POSITION;
- 143 1 usLBound = usLBound + 20 + ucH_Min_Margin + MEASURE_HDEALY;
- 144 1 usLBound = usLBound > ((unsigned int)stMUD.H_POSITION + PROGRAM_HDELAY) ? (usLBound - PROGRAM_HDELA
- -Y - stMUD.H_POSITION) : 1;
- 145 1
- 146 1 NM_V = NM_V & 0xfc;
- 147 1
- 148 1 Data[0] = 6;
- 149 1 Data[1] = Y_INC;
- 150 1 Data[2] = H_BND_STA_L_75;
- 151 1 Data[3] = (unsigned char)usLBound;
- 152 1 Data[4] = (unsigned char)usRBound;
- 153 1 Data[5] = ((unsigned char)(usLBound >> 4) & 0x70) | ((unsigned char)(usRBound >> 8) & 0x0f);
- 154 1 Data[6] = 8;
- 155 1 Data[7] = Y_INC;
- 156 1 Data[8] = MARGIN_R_7B;
- 157 1 Data[9] = NM_V;
- 158 1 Data[10] = NM_V | PIXEL_1;
- 159 1 Data[11] = NM_V;
- 160 1 Data[12] = 0x00;
- 161 1 Data[13] = 0x01;
- 162 1 Data[14] = 0;
- 163 1 RTDWrite(Data);
- 164 1
- 165 1 Wait_Finish();
- 166 1
- 167 1
- 168 1 if (ERROR_SUCCEED != Data[0]) return Data[0];
- 169 1
- 170 1 RTDRead(VER_START_80, 4, Y_INC);
- 171 1
- 172 1 // Translate byte order : RTD little indian -> 8051 big indian
- 173 1 Data[6] = Data[1] & 0x0f;
- 174 1 Data[7] = Data[0];
- 175 1 Data[8] = Data[3] & 0x0f;
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 4
- 176 1 Data[9] = Data[2];
- 177 1
- 178 1 // V Start/End should subtract 1
- 179 1 usVer_Start = ((unsigned int *)Data)[3] ? ((unsigned int *)Data)[3] - 1 : 0;
- 180 1 usVer_End = ((unsigned int *)Data)[4] ? ((unsigned int *)Data)[4] - 1 : 0;
- 181 1
- 182 1 // Check all black
- 183 1 if (0x0000 == usVer_End) return ERROR_NOTACTIVE;
- 184 1
- 185 1 /*
- 186 1 // Issac 2002/10/15
- 187 1 // To prevent from noise induced by VSYNC
- 188 1 if (usVer_End > (usVer_Start + usIPV_ACT_LEN - 1))
- 189 1 {
- 190 1 usVer_End = usVer_Start + usIPV_ACT_LEN - 1;
- 191 1
- 192 1 ((unsigned int *)Data)[4] = usVer_End;
- 193 1 }
- 194 1 */
- 195 1 if ((9 - PROGRAM_VDELAY) > usVer_Start)
- 196 1 {
- 197 2 ((unsigned int *)Data)[3] = 9 - PROGRAM_VDELAY;
- 198 2 }
- 199 1 else
- 200 1 {
- 201 2 // To prevent from noise induced by VSYNC
- 202 2 if (usVer_End > (usVer_Start + usIPV_ACT_LEN - 1))
- 203 2 {
- 204 3 usVer_End = usVer_Start + usIPV_ACT_LEN - 1;
- 205 3
- 206 3 ((unsigned int *)Data)[4] = usVer_End;
- 207 3 }
- 208 2 }
- 209 1
- 210 1 // Update auto-tracking window vertical range
- 211 1 Data[0] = 6;
- 212 1 Data[1] = Y_INC;
- 213 1 Data[2] = V_BND_STA_L_78;
- 214 1 Data[3] = Data[7];
- 215 1 Data[4] = Data[9];
- 216 1 Data[5] = (Data[6] << 4) + Data[8];
- 217 1 Data[6] = 0;
- 218 1 RTDWrite(Data);
- 219 1
- 220 1 return ERROR_SUCCEED;
- 221 1 }
- 222
- 223 //--------------------Measure Horizontal Position-------------------//
- 224 // Return Message => ERROR_SUCCESS : Success //
- 225 // ERROR_INPUT : 1. IVS or IHS changed //
- 226 // 2. underflow or overflow //
- 227 // ERROR_TIMEOUT : Measure Time_Out //
- 228 // ERROR_NOTACTIVE : No Avtive Image //
- 229 //------------------------------------------------------------------//
- 230 unsigned char Measure_PositionH(unsigned char NM_H)
- 231 {
- 232 1 unsigned int usLBound, usRBound;
- 233 1
- 234 1 RTDRead(MEAS_HI_51, 0x02, Y_INC);
- 235 1 Data[2] = Data[1] & 0x0f;
- 236 1 Data[3] = Data[0];
- 237 1
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 5
- 238 1 usRBound = usADC_Clock + (unsigned int)stMUD.CLOCK - 128;
- 239 1 usLBound = (unsigned long)usRBound * ((unsigned int *)Data)[1] / usStdHS;
- 240 1
- 241 1 usRBound = usRBound - 2 + MEASURE_HDEALY - PROGRAM_HDELAY + ucH_Min_Margin - stMUD.H_POSITION;
- 242 1
- 243 1 usLBound = usLBound + 20 + ucH_Min_Margin + MEASURE_HDEALY;
- 244 1 usLBound = usLBound > ((unsigned int)stMUD.H_POSITION + PROGRAM_HDELAY) ? (usLBound - PROGRAM_HDELA
- -Y - stMUD.H_POSITION) : 1;
- 245 1
- 246 1 NM_H = NM_H & 0xfc;
- 247 1
- 248 1 Data[0] = 6;
- 249 1 Data[1] = Y_INC;
- 250 1 Data[2] = H_BND_STA_L_75;
- 251 1 Data[3] = (unsigned char)usLBound;
- 252 1 Data[4] = (unsigned char)usRBound;
- 253 1 Data[5] = ((unsigned char)(usLBound >> 4) & 0x70) | ((unsigned char)(usRBound >> 8) & 0x0f);
- 254 1 Data[6] = 8;
- 255 1 Data[7] = Y_INC;
- 256 1 Data[8] = MARGIN_R_7B;
- 257 1 Data[9] = NM_H;
- 258 1 Data[10] = NM_H;
- 259 1 Data[11] = NM_H;
- 260 1 Data[12] = 0x00;
- 261 1 Data[13] = 0x01;
- 262 1 Data[14] = 0;
- 263 1 RTDWrite(Data);
- 264 1
- 265 1 Wait_Finish();
- 266 1
- 267 1 if (ERROR_SUCCEED != Data[0]) return Data[0];
- 268 1
- 269 1 RTDRead(HOR_START_84, 4, Y_INC);
- 270 1
- 271 1 // Translate byte order : RTD little indian -> 8051 big indian
- 272 1 Data[4] = Data[3] & 0x0f;
- 273 1 Data[5] = Data[2];
- 274 1 Data[2] = Data[1] & 0x0f;
- 275 1 Data[3] = Data[0];
- 276 1
- 277 1 if (0x07FF <= ((unsigned int *)Data)[1]) return ERROR_NOTACTIVE;
- 278 1
- 279 1
- 280 1 RTDRead(VGIP_CTRL_04, 1, N_INC);
- 281 1
- 282 1 //if (0x14 == (Data[0] & 0x1c))
- 283 1 if (0x08 == (Data[0] & 0x0c))
- 284 1 {
- 285 2 ((unsigned int *)Data)[1] += 0x03;
- 286 2 ((unsigned int *)Data)[2] += 0x03;
- 287 2 }
- 288 1
- 289 1 /*
- 290 1 usH_Start = MEAS_H_STA_OFFSET < ((unsigned int *)Data)[1] ? ((unsigned int *)Data)[1] - MEAS_H_STA_O
- -FFSET : 0x0000;
- 291 1 usH_End = MEAS_H_END_OFFSET < ((unsigned int *)Data)[2] ? ((unsigned int *)Data)[2] - MEAS_H_END_O
- -FFSET : 0x0fff;
- 292 1
- 293 1 if (0x0000 != usH_Start) usH_Start = usH_Start + stMUD.H_POSITION - 128;
- 294 1 if (0x0fff != usH_End) usH_End = usH_End + stMUD.H_POSITION - 128;
- 295 1 */
- 296 1
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 6
- 297 1 usH_Start = (((unsigned int *)Data)[1] + stMUD.H_POSITION) >= (128 + MEAS_H_STA_OFFSET)
- 298 1 ? (((unsigned int *)Data)[1] + stMUD.H_POSITION) - (128 + MEAS_H_STA_OFFSET) : 0x0000;
- 299 1 usH_End = (((unsigned int *)Data)[2] + stMUD.H_POSITION) >= (128 + MEAS_H_END_OFFSET)
- 300 1 ? (((unsigned int *)Data)[2] + stMUD.H_POSITION) - (128 + MEAS_H_END_OFFSET) : 0x0fff;
- 301 1
- 302 1 return ERROR_SUCCEED;
- 303 1 }
- 304
- 305 //---------------Measure Vertical & Horizontal Position-------------//
- 306 // Return Message => ERROR_SUCCESS : Success //
- 307 // ERROR_INPUT : 1. IVS or IHS changed //
- 308 // 2. underflow or overflow //
- 309 // ERROR_TIMEOUT : Measure Time_Out //
- 310 // ERROR_NOTACTIVE : No Avtive Image //
- 311 //------------------------------------------------------------------//
- 312 unsigned char Measure_PositionN(unsigned char NM)
- 313 {
- 314 1 unsigned char Result;
- 315 1
- 316 1 Result = Measure_PositionV(NM);
- 317 1
- 318 1 if (ERROR_SUCCEED == Result)
- 319 1 {
- 320 2 Result = Measure_PositionH(NM);
- 321 2 }
- 322 1
- 323 1 return Result;
- 324 1 }
- 325
- 326 /*
- 327 //------------------------------------------------------------------//
- 328 // Auto Clock //
- 329 //------------------------------------------------------------------//
- 330 unsigned char Auto_Clock(void)
- 331 {
- 332 unsigned char Result, Curr_PosH, Curr_PosV, Curr_Clock, Curr_Phase;
- 333
- 334 bAutoInProgress = 1;
- 335
- 336 Curr_PosH = stMUD.H_POSITION; // Save current stMUD.H_POSITION
- 337 Curr_PosV = stMUD.V_POSITION; // Save current stMUD.V_POSITION
- 338 Curr_Clock = stMUD.CLOCK; // Save current stMUD.CLOCK
- 339 Curr_Phase = stMUD.PHASE; // Save current stMUD.PHASE
- 340
- 341 if (ucV_Max_Margin < stMUD.V_POSITION)
- 342 {
- 343 stMUD.V_POSITION = ucV_Max_Margin;
- 344 Set_V_Position();
- 345 }
- 346
- 347 RTDCodeW(ADC_DEFAULT);
- 348
- 349 ///////////////////////////////
- 350 // Measure NOISE_MARGIN //
- 351 ///////////////////////////////
- 352 Result = Min_Noise_Margin(); // Data[0] : Noise Margin
- 353
- 354 if (ERROR_SUCCEED == (Result & 0x80))
- 355 {
- 356 Result = Data[0];
- 357
- 358 stMUD.CLOCK &= 0xfc; // stMUD.CLOCK must be times of 4
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 7
- 359
- 360 if (stMUD.CLOCK != Curr_Clock || 28 > stMUD.CLOCK || 228 < stMUD.CLOCK)
- 361 {
- 362 Set_Clock();
- 363 }
- 364
- 365 ///////////////////////////////
- 366 // Adjust Clock //
- 367 ///////////////////////////////
- 368 Result = Auto_Clock_Do(Result);
- 369
- 370 if (ERROR_SUCCEED != (Result & 0x80))
- 371 {
- 372 if (stMUD.CLOCK != Curr_Clock)
- 373 {
- 374 // Fail to find out suitable clock. Restore original clock and H position.
- 375 stMUD.CLOCK = Curr_Clock;
- 376 stMUD.H_POSITION = Curr_PosH;
- 377
- 378 Set_Clock();
- 379 Set_H_Position();
- 380 }
- 381 }
- 382 else
- 383 {
- 384 if (stMUD.CLOCK != Curr_Clock)
- 385 {
- 386 stMUD.H_POSITION = usH_Start + 128 + 64 - usIPH_ACT_STA - (stMUD.CLOCK >> 1);
- 387
- 388 if (ucH_Max_Margin < stMUD.H_POSITION)
- 389 stMUD.H_POSITION = ucH_Max_Margin;
- 390 else if (ucH_Min_Margin > stMUD.H_POSITION)
- 391 stMUD.H_POSITION = ucH_Min_Margin;
- 392
- 393 Set_H_Position();
- 394
- 395 Save_MUD(ucMode_Curr);
- 396 }
- 397 }
- 398 }
- 399
- 400 // Restore ADC Gain/Offset
- 401 SetADC_GainOffset();
- 402
- 403 // Restore ADC phase
- 404 stMUD.PHASE = Curr_Phase;
- 405 Set_Phase(stMUD.PHASE);
- 406
- 407 // Restore vertical position
- 408 if (Curr_PosV != stMUD.V_POSITION)
- 409 {
- 410 stMUD.V_POSITION = Curr_PosV;
- 411 Set_V_Position();
- 412 }
- 413
- 414 bAutoInProgress = 0;
- 415
- 416 return Result;
- 417 }
- 418 */
- 419 void Read_Auto_Info(unsigned char index)
- 420 {
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 8
- 421 1 if(index == 0) return;
- 422 1
- 423 1 RTDRead(AUTO_PHASE0_88, 4, Y_INC);
- 424 1
- 425 1 Data[index << 2] = Data[3];
- 426 1 Data[(index << 2) + 1] = Data[2];
- 427 1 Data[(index << 2) + 2] = Data[1];
- 428 1 Data[(index << 2) + 3] = Data[0];
- 429 1
- 430 1 }
- 431
- 432 unsigned char FindColor()
- 433 {
- 434 1 unsigned long ulTemp0;
- 435 1 unsigned char ucDetect,ucResult,ucPhase;
- 436 1
- 437 1 RTDSetByte(DIFF_THRED_7E, 0x28);
- 438 1
- 439 1 ulTemp0 = 0;
- 440 1 ucDetect = 0x77;
- 441 1 do
- 442 1 {
- 443 2 ucResult = COLORS_BLUE;
- 444 2 ucPhase = COLORS_BLUE;
- 445 2 do
- 446 2 {
- 447 3 RTDSetByte(MARGIN_B_7D, ucPhase);
- 448 3 RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
- 449 3
- 450 3 Wait_Finish();
- 451 3 if (ERROR_SUCCEED != Data[0]) return Data[0];
- 452 3
- 453 3 Read_Auto_Info(1);
- 454 3
- 455 3 if (ulTemp0 < ((unsigned long *)Data)[1])
- 456 3 {
- 457 4 ulTemp0 = ((unsigned long *)Data)[1];
- 458 4 ucResult = ucPhase;
- 459 4
- 460 4 if (0x8000 < ulTemp0) break;
- 461 4 }
- 462 3
- 463 3 if (COLORS_BLUE == ucPhase)
- 464 3 ucPhase = COLORS_GREEN;
- 465 3 else if (COLORS_GREEN == ucPhase)
- 466 3 ucPhase = COLORS_RED;
- 467 3 else
- 468 3 break;
- 469 3 }
- 470 2 while (1);
- 471 2
- 472 2 if (0 != ulTemp0 || 0x7b != ucDetect) break;
- 473 2
- 474 2 ucDetect = 0x77;
- 475 2 }
- 476 1 while (1);
- 477 1
- 478 1 return ERROR_SUCCEED;
- 479 1 }
- 480 unsigned long GetMaxSum(unsigned char select)
- 481 {
- 482 1 unsigned char ucPhase,ucDetect;
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 9
- 483 1 unsigned long ulTemp0;
- 484 1 ucPhase = 0; //0,8,16,24
- 485 1 ulTemp0 = 0;
- 486 1 Set_Phase(ucPhase);
- 487 1 ucDetect = (select == 0) ? 0x77 : 0x7b;
- 488 1
- 489 1 #if(HARDWARE_AUTO)
- 490 1
- 491 1 RTDSetByte(HW_AUTO_PHASE_9E,0x07); //Step 8 auto phase
- 492 1 Wait_For_IVS();
- 493 1 //Wait_For_Event(EVENT_IVS);
- 494 1 RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect); //Auto start
- 495 1 //Wait_For_Event(EVENT_IVS);
- 496 1 Wait_For_IVS();
- 497 1 for(ucPhase = 0;ucPhase < 4; ucPhase++)
- 498 1 {
- 499 2 //Wait_For_Event(EVENT_IVS);
- 500 2 Wait_For_IVS();
- 501 2 Read_Auto_Info(1);
- 502 2
- 503 2 if(ulTemp0 < ((unsigned long *)Data)[1])
- 504 2 {
- 505 3 ulTemp0 = ((unsigned long *)Data)[1] & 0xffffff00;
- 506 3 }
- 507 2 }
- 508 1 RTDSetByte(HW_AUTO_PHASE_9E,0x00); //Switch back to software auto phase
- 509 1 Wait_Finish();
- 510 1 if(ERROR_SUCCEED != Data[0]) return (Data[0] & 0x000000ff);
- 511 1
- 512 1 #else
- 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);
- }
- #endif
- 532 1 return ulTemp0;
- 533 1 }
- 534 //------------------------------------------------------------------//
- 535 // Return Message => ERROR_SUCCESS : Success //
- 536 // ERROR_TOO_SMALL : Measure Result << ACT_WIDTH //
- 537 // ERROR_TOO_BIG : Measure Result >> ACT_WIDTH //
- 538 // ERROR_INPUT : 1. IVS or IHS changed //
- 539 // 2. underflow or overflow //
- 540 // ERROR_TIMEOUT : Measure Time_Out //
- 541 // Process Time_Out //
- 542 // ERROR_NOTACTIVE : No Avtive Image //
- 543 //------------------------------------------------------------------//
- 544 unsigned char Auto_Clock_Do(unsigned char NM)
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 10
- 545 {
- 546 1 #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)
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 11
- {
- 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
- #if(ALIGN_LEFT == CLOCK_ALIGN)
- // Adjust Clock
- if (usH_End < usIPH_ACT_WID) // delta < 0, Measure < Active
- {
- if ((178 - stMUD.CLOCK) < delta) return ERROR_TOO_SMALL;
-
- stMUD.CLOCK += delta;
-
- Set_Clock();
- Set_H_Position();
- }
- else // delta >= 0, Measure >= Active
- {
- if ((stMUD.CLOCK - 78) < delta) return ERROR_TOO_BIG;
-
- stMUD.CLOCK -= delta;
-
- Set_H_Position();
- Set_Clock();
- }
-
- #else
- // 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();
- }
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 12
- #endif
- }
- 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;
- }
-
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 13
- 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];
-
- Read_Auto_Info(1);
-
- if (ulTemp0 < ((unsigned long *)Data)[1])
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 14
- {
- 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_SUCC
- -EED;
- }
-
- // 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);
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 15
-
- // 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];
-
- Read_Auto_Info(1);
- 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();
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 16
- Set_Clock();
- }
- #endif
-
- #else
- 918 1 unsigned char Result;
- 919 1 unsigned char count, delta, stop,start;
- 920 1 unsigned long ulSum,ulCompare;
- 921 1 ulCompare = 0;
- 922 1 ulSum = 0;
- 923 1
- 924 1 ///////////////////////////////
- 925 1 // Measure (V) Start & End //
- 926 1 ///////////////////////////////
- 927 1 Result = Measure_PositionV(NM);
- 928 1
- 929 1 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
- 930 1
- 931 1 NM = NM + 0x10; // See Min_Noise_Margin(). Horizontal Measure Result is the same when applying
- - (NM + 0x10)
- 932 1
- 933 1 count = 10;
- 934 1 do
- 935 1 {
- 936 2
- 937 2 ///////////////////////////////
- 938 2 // Measure (H) Start & End //
- 939 2 ///////////////////////////////
- 940 2 Result = Measure_PositionH(NM);
- 941 2
- 942 2 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
- 943 2
- 944 2 usH_End = usH_End + 1 - usH_Start;
- 945 2
- 946 2 // H_Active Delta
- 947 2 if (usH_End < usIPH_ACT_WID)
- 948 2 delta = (usIPH_ACT_WID - usH_End > 0x00ff) ? 0xff : (unsigned char)(usIPH_ACT_WID - usH_End);
- 949 2 else
- 950 2 delta = (usH_End - usIPH_ACT_WID > 0x00ff) ? 0xff : (unsigned char)(usH_End - usIPH_ACT_WID);
- 951 2
- 952 2 //if (0xc0 < delta) // The difference is too large to fine-tune.
- 953 2 if((usIPH_ACT_WID/3) < delta) //modified 2003/02/25
- 954 2 {
- 955 3 return (usH_End < usIPH_ACT_WID) ? ERROR_TOO_SMALL : ERROR_TOO_BIG;
- 956 3 }
- 957 2
- 958 2 if (1 >= delta) break; // 1023,1024,1025,1026,1027
- 959 2
- 960 2 delta = delta + (delta >> 2);//& 0xfe; // 4n number
- 961 2
- 962 2 #if(ALIGN_LEFT == CLOCK_ALIGN)
- 963 2 // Adjust Clock
- 964 2 if (usH_End < usIPH_ACT_WID) // delta < 0, Measure < Active
- 965 2 {
- 966 3 if ((178 - stMUD.CLOCK) < delta) return ERROR_TOO_SMALL;
- 967 3
- 968 3 stMUD.CLOCK += delta;
- 969 3
- 970 3 Set_Clock();
- 971 3 Set_H_Position();
- 972 3 }
- 973 2 else // delta >= 0, Measure >= Active
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 17
- 974 2 {
- 975 3 if ((stMUD.CLOCK - 78) < delta) return ERROR_TOO_BIG;
- 976 3
- 977 3 stMUD.CLOCK -= delta;
- 978 3
- 979 3 Set_H_Position();
- 980 3 Set_Clock();
- 981 3 }
- 982 2
- 983 2 #else
- // 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();
- }
-
- #endif
- 1005 2 }
- 1006 1 while (--count);
- 1007 1
- 1008 1
- 1009 1
- 1010 1 if (0 == count) return ERROR_TIMEOUT;
- 1011 1
- 1012 1 stop = 0;
- 1013 1
- 1014 1 while (1)
- 1015 1 {
- 1016 2 count = 0x10; // Phase 4 ~ 28 step 4 (4,8,12,16,20,24,28)
- 1017 2 delta = 0xff;
- 1018 2
- 1019 2 while (1)
- 1020 2 {
- 1021 3
- 1022 3
- 1023 3 Set_Phase(count);
- 1024 3
- 1025 3 // Measure usH_Start & usH_End
- 1026 3 Result = Measure_PositionH(NM);
- 1027 3
- 1028 3 if (ERROR_SUCCEED != (Result & 0x80))
- 1029 3 {
- 1030 4 if (ERROR_NOTACTIVE == Result)
- 1031 4 {
- 1032 5 // Input pattern is black/white vertical lines.
- 1033 5 if (0x70 == count)
- 1034 5 {
- 1035 6 Set_Phase(stMUD.PHASE); // Restore phase
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 18
- 1036 6 break;
- 1037 6 }
- 1038 5 else
- 1039 5 {
- 1040 6 count += 0x20;
- 1041 6 continue;
- 1042 6 }
- 1043 5 }
- 1044 4
- 1045 4 Set_Phase(stMUD.PHASE); // Restore phase
- 1046 4
- 1047 4 return Result;
- 1048 4 }
- 1049 3
- 1050 3 usH_End = usH_End + 1 - usH_Start;
- 1051 3
- 1052 3 Result = (usH_End < usIPH_ACT_WID)
- 1053 3 ? 0x80 - (unsigned char)(usIPH_ACT_WID - usH_End)
- 1054 3 : 0x80 + (unsigned char)(usH_End - usIPH_ACT_WID);
- 1055 3
- 1056 3 if (Result < delta)
- 1057 3 {
- 1058 4 delta = Result; // Save the smallest width
- 1059 4 }
- 1060 3
- 1061 3 if (0x70 == count)
- 1062 3 {
- 1063 4 Set_Phase(stMUD.PHASE); // Restore phase
- 1064 4 break;
- 1065 4 }
- 1066 3
- 1067 3 count += 0x10;
- 1068 3 }
- 1069 2
- 1070 2 if (0x81 < delta)
- 1071 2 {
- 1072 3 stMUD.CLOCK -= 1;
- 1073 3
- 1074 3 Set_H_Position();
- 1075 3 Set_Clock();
- 1076 3
- 1077 3 stop = 1;
- 1078 3 }
- 1079 2 else if (0x80 > delta)
- 1080 2 {
- 1081 3 if (stop && (0x7f == delta)) break;
- 1082 3
- 1083 3 stMUD.CLOCK += 1;
- 1084 3
- 1085 3 Set_Clock();
- 1086 3 Set_H_Position();
- 1087 3
- 1088 3 if (stop) break;
- 1089 3 }
- 1090 2 else
- 1091 2 break;
- 1092 2 }
- 1093 1
- 1094 1 count = stMUD.PHASE; // Record Current Phase
- 1095 1 start = stMUD.CLOCK ;
- 1096 1
- 1097 1
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 19
- 1098 1 if(FindColor() != ERROR_SUCCEED) return ERROR_ABORT;
- 1099 1 // Set threshold
- 1100 1 RTDSetByte(DIFF_THRED_7E, 0x30);
- 1101 1
- 1102 1 ulSum = GetMaxSum(1); //judge if pulse information large enough
- 1103 1 ulCompare = GetMaxSum(0);
- 1104 1
- 1105 1
- 1106 1
- 1107 1 if((ulSum > 460000) || ((ulSum < 460000) && (ulCompare > 2000000)) )
- 1108 1 {
- 1109 2
- 1110 2 ulCompare = 0;
- 1111 2 // ulSum = 0;//GetMaxSum(0);
- 1112 2 //////////////////////////////////////////////
- 1113 2 if(0x80 < (start - 2) || 0x80 > start)
- 1114 2 {
- 1115 3 stMUD.CLOCK = 0x80;
- 1116 3 Set_H_Position();
- 1117 3 Set_Clock();
- 1118 3 ulSum = GetMaxSum(0);
- 1119 3
- 1120 3 if(ulCompare < ulSum)
- 1121 3 {
- 1122 4 ulCompare = ulSum;
- 1123 4 Result = stMUD.CLOCK;
- 1124 4 }
- 1125 3
- 1126 3 stMUD.CLOCK = start + 1;
- 1127 3 }
- 1128 2 else
- 1129 2 {
- 1130 3 stMUD.CLOCK = start;
- 1131 3 Set_H_Position();
- 1132 3 Set_Clock();
- 1133 3 ulSum = GetMaxSum(0);
- 1134 3 }
- 1135 2 ////////////////////////////////////////////////
- 1136 2
- 1137 2
- 1138 2 while(1)
- 1139 2 {
- 1140 3 if(ulCompare < ulSum)
- 1141 3 {
- 1142 4 ulCompare = ulSum;
- 1143 4 Result = stMUD.CLOCK;
- 1144 4 }
- 1145 3 if(stMUD.CLOCK == start - 2)
- 1146 3 break;
- 1147 3
- 1148 3 stMUD.CLOCK -= 1;
- 1149 3 Set_Clock();
- 1150 3 Set_H_Position();
- 1151 3 ulSum = GetMaxSum(0);
- 1152 3 }
- 1153 2
- 1154 2 stMUD.CLOCK = Result;
- 1155 2 stMUD.PHASE = count;
- 1156 2 Set_Clock();
- 1157 2 Set_H_Position();
- 1158 2 Set_Phase(stMUD.PHASE);
- 1159 2 }
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 20
- 1160 1
- 1161 1
- 1162 1
- 1163 1 #endif
- 1164 1 return (28 > stMUD.CLOCK) ? ERROR_TOO_BIG : (228 < stMUD.CLOCK) ? ERROR_TOO_SMALL : ERROR_SUCCEED;
- 1165 1 }
- 1166
- 1167 //------------------------------------------------------------------//
- 1168 // Auto Position //
- 1169 //------------------------------------------------------------------//
- 1170 unsigned char Auto_Position(void)
- 1171 {
- 1172 1 unsigned char Result, Curr_PosH, Curr_PosV;
- 1173 1
- 1174 1 bAutoInProgress = 1;
- 1175 1
- 1176 1 Curr_PosH = stMUD.H_POSITION; // Save current stMUD.H_POSITION
- 1177 1 Curr_PosV = stMUD.V_POSITION; // Save current stMUD.V_POSITION
- 1178 1
- 1179 1 if (ucV_Max_Margin < stMUD.V_POSITION)
- 1180 1 {
- 1181 2 stMUD.V_POSITION = ucV_Max_Margin;
- 1182 2 Set_V_Position();
- 1183 2 }
- 1184 1
- 1185 1 RTDCodeW(ADC_DEFAULT);
- 1186 1
- 1187 1 ///////////////////////////////
- 1188 1 // Measure NOISE_MARGIN //
- 1189 1 ///////////////////////////////
- 1190 1 Result = Min_Noise_Margin();
- 1191 1
- 1192 1 if (ERROR_SUCCEED == (Result & 0x80))
- 1193 1 {
- 1194 2 ///////////////////////////////
- 1195 2 // Adjust (H/V)Position //
- 1196 2 ///////////////////////////////
- 1197 2 Result = Auto_Position_Do(Data[0]); // Noise margin returned by Min_Noise_Margin() is saved in
- - Data[0];
- 1198 2 }
- 1199 1
- 1200 1 if (ERROR_SUCCEED == (Result & 0x80))
- 1201 1 {
- 1202 2 Save_MUD(ucMode_Curr);
- 1203 2 }
- 1204 1 else
- 1205 1 {
- 1206 2 stMUD.H_POSITION = Curr_PosH;
- 1207 2 stMUD.V_POSITION = Curr_PosV;
- 1208 2
- 1209 2 Set_H_Position();
- 1210 2 Set_V_Position();
- 1211 2 }
- 1212 1
- 1213 1 // Restore ADC Gain/Offset
- 1214 1 SetADC_GainOffset();
- 1215 1
- 1216 1 bAutoInProgress = 0;
- 1217 1
- 1218 1 return Result;
- 1219 1 }
- 1220
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 21
- 1221 //------------------------------------------------------------------//
- 1222 // Return Message => ERROR_SUCCESS : Success //
- 1223 // ERROR_SUCCESS_1 : Vertical Start > Max //
- 1224 // ERROR_SUCCESS_2 : Vertical Start < Min //
- 1225 // ERROR_SUCCESS_4 : Vertical Start/End Fail //
- 1226 // ERROR_SUCCESS_8 : Horizontal Start > Max //
- 1227 // ERROR_SUCCESS_16: Horizontal Start < Min //
- 1228 // ERROR_SUCCESS_32: Horizontal Start/End Fail //
- 1229 // ERROR_INPUT : 1. IVS or IHS changed //
- 1230 // 2. underflow or overflow //
- 1231 // ERROR_TIMEOUT : Measure Time_Out //
- 1232 // ERROR_NOTACTIVE : No Avtive Image //
- 1233 //------------------------------------------------------------------//
- 1234 unsigned char Auto_Position_Do(unsigned char NM)
- 1235 {
- 1236 1 unsigned char Result;//,ucTemp,ucTemp1;
- 1237 1 // unsigned int usTemp;
- 1238 1
- 1239 1 /*
- 1240 1
- 1241 1 ///////////////////////////////////////////////////////////
- 1242 1 stMUD.H_POSITION = 128;
- 1243 1
- 1244 1 if(128 >= stMUD.H_POSITION)
- 1245 1 {
- 1246 1 ucTemp = 128 - stMUD.H_POSITION;
- 1247 1
- 1248 1 if(stMUD.CLOCK > 128)
- 1249 1 ucTemp1 = 128;
- 1250 1 else
- 1251 1 ucTemp1 = stMUD.CLOCK;
- 1252 1
- 1253 1 ucH_Min_Margin = 128 - ucTemp - (64 - (ucTemp1 >> 1));
- 1254 1 usIPH_ACT_STA = usIPH_ACT_STA + 50 - ucTemp - (64 - (ucTemp1 >> 1));
- 1255 1 usTemp = usIPH_ACT_STA;
- 1256 1
- 1257 1 Set_H_Position();
- 1258 1 }
- 1259 1 ///////////////////////////////////////////////////////////////////
- 1260 1 */
- 1261 1 Result = Measure_PositionN(NM);
- 1262 1
- 1263 1 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
- 1264 1 Result = ERROR_SUCCEED;
- 1265 1
- 1266 1 /////////////////////////////////
- 1267 1 // Calculate Vertical Position //
- 1268 1 /////////////////////////////////
- 1269 1 NM = 1;
- 1270 1 while (1)
- 1271 1 {
- 1272 2 if ((usIPV_ACT_STA + ucV_Max_Margin - 128) >= usVer_Start)
- 1273 2 {
- 1274 3 if ((usIPV_ACT_STA + ucV_Min_Margin - 128) <= usVer_Start)
- 1275 3 {
- 1276 4 stMUD.V_POSITION = (usVer_Start + 128) - usIPV_ACT_STA;
- 1277 4 Set_V_Position();
- 1278 4
- 1279 4 break; // Success
- 1280 4 }
- 1281 3 else
- 1282 3 Result |= ERROR_SUCCESS_2;
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 22
- 1283 3 }
- 1284 2 else
- 1285 2 Result |= ERROR_SUCCESS_1;
- 1286 2
- 1287 2 // If we can't align upper bound, we try to align lower bound.
- 1288 2 if (NM && usVer_End > usIPV_ACT_LEN)
- 1289 2 {
- 1290 3 usVer_Start = usVer_End - usIPV_ACT_LEN + 1;
- 1291 3 NM = 0;
- 1292 3 }
- 1293 2 else
- 1294 2 {
- 1295 3 Result |= ERROR_SUCCESS_4;
- 1296 3 break;
- 1297 3 }
- 1298 2 }
- 1299 1
- 1300 1 ///////////////////////////////////
- 1301 1 // Calculate Horizontal Position //
- 1302 1 ///////////////////////////////////
- 1303 1 NM = 1;
- 1304 1 while (1)
- 1305 1 {
- 1306 2 #if(ALIGN_LEFT == CLOCK_ALIGN)
- 1307 2
- 1308 2 if ((usIPH_ACT_STA + (stMUD.CLOCK >> 2) + ucH_Max_Margin - 32 - 128) >= usH_Start)
- 1309 2 {
- 1310 3
- 1311 3 //if(ucH_Min_Margin == (128 - 10))
- 1312 3 if(ucH_Min_Margin <= 128 )
- 1313 3 ((unsigned int*)Data)[0] = usH_Start + 128 - stMUD.H_POSITION + 50;//((unsigned int*)Data)[0] = usH_S
- -tart + ucTemp + 100;//((unsigned int*)Data)[0] = usH_Start + 10;
- 1314 3 else
- 1315 3 ((unsigned int*)Data)[0] = usH_Start;// + (stMUD.H_POSITION - 128) + 10;
- 1316 3
- 1317 3 //if ((usIPH_ACT_STA + (stMUD.CLOCK >> 1) + ucH_Min_Margin - 64 - 128) <= (usH_Start + 50))
- 1318 3 if ((usIPH_ACT_STA + (stMUD.CLOCK >> 2) + ucH_Min_Margin - 32 - 128) <= ((unsigned int*)Data)[0])
- 1319 3 {
- 1320 4 //usH_Start is the actual distance from Hsync to active image
- 1321 4 stMUD.H_POSITION = usH_Start + 128 + 32 - usIPH_ACT_STA - (stMUD.CLOCK >> 2);
- 1322 4 Set_H_Position();
- 1323 4
- 1324 4 break; // Success
- 1325 4 }
- 1326 3 else
- 1327 3 Result |= ERROR_SUCCESS_16;
- 1328 3 }
- 1329 2 else
- 1330 2 Result |= ERROR_SUCCESS_8;
- 1331 2
- 1332 2
- 1333 2 #else
- if ((usIPH_ACT_STA + (stMUD.CLOCK >> 1) + ucH_Max_Margin - 64 - 128) >= usH_Start)
- {
-
- //if(ucH_Min_Margin == (128 - 10))
- if(ucH_Min_Margin <= 128 )
- ((unsigned int*)Data)[0] = usH_Start + 128 - stMUD.H_POSITION + 100;//((unsigned int*)Data)[0] = usH_
- -Start + ucTemp + 100;//((unsigned int*)Data)[0] = usH_Start + 10;
- else
- ((unsigned int*)Data)[0] = usH_Start;// + (stMUD.H_POSITION - 128) + 10;
-
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 23
- //if ((usIPH_ACT_STA + (stMUD.CLOCK >> 1) + ucH_Min_Margin - 64 - 128) <= (usH_Start + 50))
- if ((usIPH_ACT_STA + (stMUD.CLOCK >> 1) + ucH_Min_Margin - 64 - 128) <= ((unsigned int*)Data)[0])
- {
- //usH_Start is the actual distance from Hsync to active image
- stMUD.H_POSITION = usH_Start + 128 + 64 - usIPH_ACT_STA - (stMUD.CLOCK >> 1);
- Set_H_Position();
-
- break; // Success
- }
- else
- Result |= ERROR_SUCCESS_16;
- }
- else
- Result |= ERROR_SUCCESS_8;
-
- #endif
- 1359 2 // If we can't align upper bound, we try to align lower bound.
- 1360 2 if (NM && usH_End > usIPH_ACT_WID)
- 1361 2 {
- 1362 3 usH_Start = usH_End - usIPH_ACT_WID + 1;
- 1363 3 NM = 0;
- 1364 3 }
- 1365 2 else
- 1366 2 {
- 1367 3 Result |= ERROR_SUCCESS_32;
- 1368 3 break;
- 1369 3 }
- 1370 2 }
- 1371 1 /*
- 1372 1 //////////////////////////////////////////////////////////////////////////////
- 1373 1 if(ucH_Min_Margin == (128 - ucTemp))
- 1374 1 {
- 1375 1 if(usTemp != usIPH_ACT_STA)
- 1376 1 {
- 1377 1 stMUD.H_POSITION = stMUD.H_POSITION - (usTemp - usIPH_ACT_STA);
- 1378 1 usIPH_ACT_STA = usTemp - 50 + ucTemp + (64 - (ucTemp1 >> 1));
- 1379 1 }
- 1380 1 else
- 1381 1 usIPH_ACT_STA = usIPH_ACT_STA - 50 + ucTemp + (64 - (ucTemp1 >> 1));
- 1382 1
- 1383 1 ucH_Min_Margin = 128 - 50;
- 1384 1 Set_H_Position();
- 1385 1 }
- 1386 1 ////////////////////////////////////////////////////////////////////////////////
- 1387 1 */
- 1388 1 return Result;
- 1389 1 }
- 1390
- 1391 unsigned char Min_Noise_Margin(void)
- 1392 {
- 1393 1 unsigned char Result, Noise;
- 1394 1 unsigned int Curr_StartH, Curr_EndH;
- 1395 1
- 1396 1 Result = Measure_PositionV(VERTICAL_MARGIN);
- 1397 1
- 1398 1 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
- 1399 1
- 1400 1 if (0 == usVer_Start)
- 1401 1 {
- 1402 2 Result = Measure_PositionV(VERTICAL_MARGIN + 0x20);
- 1403 2 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
- 1404 2 }
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 24
- 1405 1
- 1406 1 Noise = 0x00;
- 1407 1 Result = Measure_PositionH(Noise);
- 1408 1 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
- 1409 1
- 1410 1 Curr_StartH = usH_Start; // Save H start position at noise margin = 0
- 1411 1 Curr_EndH = usH_End; // Save H end position at noise margin = 0
- 1412 1
- 1413 1 do
- 1414 1 {
- 1415 2 Noise = Noise + 0x10;
- 1416 2 Result = Measure_PositionH(Noise);
- 1417 2
- 1418 2 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
- 1419 2
- 1420 2 if (Curr_StartH >= usH_Start)
- 1421 2 {
- 1422 3 Curr_StartH = usH_Start;
- 1423 3 }
- 1424 2 else if (0x08 < (usH_Start - Curr_StartH))
- 1425 2 {
- 1426 3 break; // A large gap of H start position is found.
- 1427 3 }
- 1428 2 }
- 1429 1 while (0x90 > Noise);
- 1430 1
- 1431 1 if (0x80 < Noise) return ERROR_NOISE_TOO_BIG;
- 1432 1
- 1433 1 while (1)
- 1434 1 {
- 1435 2 Curr_StartH = usH_Start;
- 1436 2 Curr_EndH = usH_End;
- 1437 2
- 1438 2 Result = Measure_PositionH(Noise + 0x28);
- 1439 2
- 1440 2 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
- 1441 2
- 1442 2 if ((Curr_EndH - Curr_StartH) == (usH_End - usH_Start) || (Curr_EndH - Curr_StartH) >= (usH_End -
- -usH_Start + 3))
- 1443 2 {
- 1444 3 break; // We got noise margin with stable horizontal start/end position.
- 1445 3 }
- 1446 2
- 1447 2 if (0xa0 <= Noise)
- 1448 2 {
- 1449 3 break; // No stable horizontal start/end position are found.
- 1450 3 }
- 1451 2
- 1452 2 Noise = Noise + 0x10;
- 1453 2 Result = Measure_PositionH(Noise);
- 1454 2
- 1455 2 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
- 1456 2 };
- 1457 1
- 1458 1 Data[0] = Noise + 0x10;
- 1459 1
- 1460 1 return ERROR_SUCCEED;
- 1461 1 }
- 1462
- 1463 unsigned char Auto_Phase(void)
- 1464 {
- 1465 1 unsigned char Result, Curr_PosV;
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 25
- 1466 1
- 1467 1 bAutoInProgress = 1;
- 1468 1
- 1469 1 Curr_PosV = stMUD.V_POSITION; // Save current stMUD.V_POSITION
- 1470 1
- 1471 1 if (ucV_Max_Margin < stMUD.V_POSITION)
- 1472 1 {
- 1473 2 stMUD.V_POSITION = ucV_Max_Margin;
- 1474 2 Set_V_Position();
- 1475 2 }
- 1476 1
- 1477 1 // Set ADC to default
- 1478 1 RTDCodeW(ADC_DEFAULT);
- 1479 1
- 1480 1 ///////////////////////////////
- 1481 1 // Measure NOISE_MARGIN //
- 1482 1 ///////////////////////////////
- 1483 1 Result = Min_Noise_Margin();
- 1484 1
- 1485 1 if (ERROR_SUCCEED == (Result & 0x80))
- 1486 1 {
- 1487 2 Result = Auto_Phase_Do(Data[0]); // Noise margin returned by Min_Noise_Margin() is saved in
- - Data[0];
- 1488 2 }
- 1489 1
- 1490 1 if (ERROR_SUCCEED != (Result & 0x80))
- 1491 1 {
- 1492 2 // Restore Phase
- 1493 2 Set_Phase(stMUD.PHASE);
- 1494 2 }
- 1495 1 else
- 1496 1 {
- 1497 2 Save_MUD(ucMode_Curr);
- 1498 2 }
- 1499 1
- 1500 1 // Restore ADC Gain/Offset
- 1501 1 SetADC_GainOffset();
- 1502 1
- 1503 1 // Restore vertical position
- 1504 1 if (Curr_PosV != stMUD.V_POSITION)
- 1505 1 {
- 1506 2 stMUD.V_POSITION = Curr_PosV;
- 1507 2 Set_V_Position();
- 1508 2 }
- 1509 1
- 1510 1 bAutoInProgress = 0;
- 1511 1
- 1512 1 return Result;
- 1513 1 }
- 1514
- 1515
- 1516 unsigned char Auto_Phase_Do(unsigned char NM)
- 1517 {
- 1518 1 unsigned char idata ucDetect, ucPhase, ucResult;
- 1519 1 unsigned long idata ulTemp0, ulTemp1, ulTemp2;
- 1520 1
- 1521 1 /*
- 1522 1 //reduce the bandwidth of ADC to prevent overshoot
- 1523 1 if(ucMode_Curr <= MODE_1280x1024x75HZ)
- 1524 1 RTDSetByte(ADC_REG_TEST_E9, 0x08);
- 1525 1 else if(ucMode_Curr < MODE_1024x0768x70HZ)
- 1526 1 RTDSetByte(ADC_REG_TEST_E9, 0x00);
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 26
- 1527 1 else
- 1528 1 RTDSetByte(ADC_REG_TEST_E9, 0x10);
- 1529 1 */
- 1530 1
- 1531 1 if (ERROR_SUCCEED != Measure_PositionN(NM)) return ERROR_ABORT;
- 1532 1
- 1533 1 // Set auto-tracking window
- 1534 1 Data[0] = 6;
- 1535 1 Data[1] = Y_INC;
- 1536 1 Data[2] = H_BND_STA_L_75;
- 1537 1 Data[3] = (unsigned char)(usH_Start + MEAS_H_STA_OFFSET - 2);
- 1538 1 Data[4] = (unsigned char)(usH_End + MEAS_H_END_OFFSET + 1);
- 1539 1 Data[5] = ((unsigned char)((usH_Start + MEAS_H_STA_OFFSET - 2) >> 4) & 0x70) | ((unsigned char)((u
- -sH_End + MEAS_H_END_OFFSET + 1) >> 8) & 0x0f);
- 1540 1 Data[6] = 0;
- 1541 1 RTDWrite(Data);
- 1542 1
- 1543 1 RTDSetByte(DIFF_THRED_7E, 0x30);
- 1544 1
- 1545 1 ulTemp0 = 0;
- 1546 1 ucDetect = 0x7b;
- 1547 1 do
- 1548 1 {
- 1549 2 ucResult = COLORS_GREEN;
- 1550 2 ucPhase = COLORS_GREEN;
- 1551 2 do
- 1552 2 {
- 1553 3 RTDSetByte(MARGIN_B_7D, ucPhase);
- 1554 3 RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
- 1555 3
- 1556 3 Wait_Finish();
- 1557 3 if (ERROR_SUCCEED != Data[0]) return Data[0];
- 1558 3
- 1559 3 Read_Auto_Info(1);
- 1560 3 if (ulTemp0 < ((unsigned long *)Data)[1])
- 1561 3 {
- 1562 4 ulTemp0 = ((unsigned long *)Data)[1];
- 1563 4 ucResult = ucPhase;
- 1564 4
- 1565 4 if (0x8000 < ulTemp0) break;
- 1566 4 }
- 1567 3
- 1568 3 if (COLORS_GREEN == ucPhase)
- 1569 3 ucPhase = COLORS_BLUE;
- 1570 3 else if (COLORS_BLUE == ucPhase)
- 1571 3 ucPhase = COLORS_RED;
- 1572 3 else
- 1573 3 break;
- 1574 3 }
- 1575 2 while (1);
- 1576 2
- 1577 2 if (0 != ulTemp0 || 0x7b != ucDetect) break;
- 1578 2
- 1579 2 ucDetect = 0x77;
- 1580 2 }
- 1581 1 while (1);
- 1582 1
- 1583 1 // Abort if no suitable color is found
- 1584 1 if (0 == ulTemp0) return ERROR_NOTACTIVE;
- 1585 1 // NM = COLORS_GREEN;
- 1586 1 // Select color for auto-phase tracking
- 1587 1 RTDSetByte(MARGIN_B_7D, NM | ucResult);
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 27
- 1588 1
- 1589 1 #if(1)
- 1590 1 //NM = 136;
- 1591 1 NM = 100;
- 1592 1 #else
- // Find suitable threshold
- // We use phase 8 and 24 to find out it
-
- ucPhase = 0x20;
- Set_Phase(ucPhase);
-
- ucResult = 0x28;
- NM = 0x00;
- do
- {
- do
- {
- ucResult += 0x20;
-
- RTDSetByte(DIFF_THRED_7E, ucResult);
- RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
-
- Wait_Finish();
- if (ERROR_SUCCEED != Data[0]) return Data[0];
-
- Read_Auto_Info(1);
-
- if ((unsigned long)0x1000 > ((unsigned long *)Data)[1])
- {
- ucResult -= 0x20;
- break;
- }
- }
- while (0x88 > ucResult);
-
- if (0x88 == ucResult)
- {
- NM = ucResult;
- break;
- }
- else
- {
- if (0x20 == ucPhase)
- {
- NM = ucResult;
-
- ucPhase = 0x60;
- Set_Phase(ucPhase);
- }
- else
- {
- if (NM < ucResult) NM = ucResult;
-
- break;
- }
- }
- }
- while (1);
-
- // Set threshold
- if(NM < 136) NM = 136;
- #endif
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 28
- 1650 1
- 1651 1 RTDSetByte(DIFF_THRED_7E, NM);
- 1652 1
- 1653 1 #if(1) //FAST_AUTO method 1
- 1654 1 // Set phase 30
- 1655 1 Set_Phase(0x78);
- 1656 1 Delay_Xms(1);
- 1657 1
- 1658 1 RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
- 1659 1
- 1660 1 Wait_Finish();
- 1661 1 if (ERROR_SUCCEED != Data[0]) return Data[0];
- 1662 1
- 1663 1 Read_Auto_Info(1);
- 1664 1
- 1665 1 ulTemp1 = ((unsigned long *)Data)[1];
- 1666 1
- 1667 1
- 1668 1 #if(HARDWARE_AUTO)
- 1669 1 ulTemp2 = ulTemp1;
- 1670 1 ulTemp0 = 0;
- 1671 1 RTDSetByte(HW_AUTO_PHASE_9E,0x05); //Step 2 auto phase
- 1672 1 //Wait_For_Event(EVENT_IVS);
- 1673 1 Wait_For_IVS();
- 1674 1 RTDSetByte(AUTO_ADJ_CTRL_7F,0x77); // Auto start
- 1675 1 //Wait_For_Event(EVENT_IVS);
- 1676 1 Wait_For_IVS();
- 1677 1 for(ucDetect = 0;ucDetect < 16; ucDetect++)
- 1678 1 {
- 1679 2 //Wait_For_Event(EVENT_IVS);
- 1680 2 Wait_For_IVS();
- 1681 2 Read_Auto_Info(3);
- 1682 2 /*
- 1683 2 Data[0] = 7;
- 1684 2 Data[1] = ADDR_EROM1;
- 1685 2 Data[2] = 0x40 + (ucDetect << 2);
- 1686 2 Data[3] = (unsigned char)(((unsigned long *)Data)[3] >> 12);
- 1687 2 Data[4] = (unsigned char)(((unsigned long *)Data)[3] >> 8);
- 1688 2 Data[5] = (unsigned char)(((unsigned long *)Data)[3] >> 4);
- 1689 2 Data[6] = 0x00;
- 1690 2
- 1691 2 I2CWrite(Data);
- 1692 2 */
- 1693 2
- 1694 2 if(ulTemp0 < ((unsigned long *)Data)[3])
- 1695 2 {
- 1696 3 ulTemp0 = ((unsigned long *)Data)[3] & 0xffffff00; //Store the SOD of phase(n)
- 1697 3 ulTemp1 = ulTemp2; //Store the SOD of phase(n-2)
- 1698 3 ucResult = ucDetect << 3; //Save the phase
- 1699 3 }
- 1700 2 ulTemp2 = ((unsigned long*)Data)[3] & 0xffffff00;
- 1701 2
- 1702 2 }
- 1703 1 Wait_Finish();
- 1704 1 if (ERROR_SUCCEED != Data[0]) return Data[0];
- 1705 1
- 1706 1 RTDSetByte(HW_AUTO_PHASE_9E,0x00); //Switch back to software auto phase
- 1707 1
- 1708 1 #else
- // Set phase 0
- Set_Phase(0x00);
- Delay_Xms(1);
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 29
-
- RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
-
- Wait_Finish();
- if (ERROR_SUCCEED != Data[0]) return Data[0];
-
- Read_Auto_Info(1);
-
- ulTemp0 = ((unsigned long *)Data)[1];
- ulTemp2 = ulTemp0;
-
-
- ucResult = 0x00;
-
- ucPhase = 0x08;//2 step rought scan
- do
- {
- Set_Phase(ucPhase);
- Delay_Xms(1);
-
- RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
-
- Wait_Finish();
- if (ERROR_SUCCEED != Data[0]) return Data[0];
-
- Read_Auto_Info(3);
-
- // ((unsigned long *)Data)[0] = ulTemp1 + ulTemp2 + ((unsigned long *)Data)[1];
-
- if (ulTemp0 < ((unsigned long *)Data)[3])
- {
- ulTemp0 = ((unsigned long *)Data)[3]; //Save the SOD of phase(n)
- ulTemp1 = ulTemp2; //Save the SOD of phase(n-2)
- ucResult = ucPhase;
- }
-
-
- ulTemp2 = ((unsigned long *)Data)[3];
-
- ucPhase = ucPhase + 0x08;
- }
- while (0x78 != ucPhase);
-
-
- if((ucResult == 0x00) && (ulTemp1 > ulTemp2))//Compare the value of phase 28 & phase 30
- {
- ucResult = 0x78; //The maximum equal to phase 30
- ulTemp0 = ulTemp1; //Save the value of phase 30
- ulTemp1 = ulTemp2; //Save the value of phase 28
- }
- #endif
- 1763 1
- 1764 1 ucPhase = ucResult == 0x00 ? 0x7c : (ucResult - 0x04 );
- 1765 1 ulTemp2 = 0;
- 1766 1 ucDetect = 2;
- 1767 1
- 1768 1
- 1769 1 Set_Phase(ucPhase); //set Phase(n-1)
- 1770 1 Delay_Xms(1);
- 1771 1
- 1772 1 RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
- 1773 1
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 30
- 1774 1 Wait_Finish();
- 1775 1 if (ERROR_SUCCEED != Data[0]) return Data[0];
- 1776 1 Read_Auto_Info(1);
- 1777 1 ulTemp2 = ((unsigned long*)Data)[1]; //Save the SOD of phase(n-1)
- 1778 1
- 1779 1 ((unsigned long*)Data)[0]
- 1780 1 = ulTemp1 + ulTemp2 + ulTemp0
- 1781 1 -((ulTemp1 > ulTemp2 ? ulTemp1 - ulTemp2 : ulTemp2 - ulTemp1)/2)
- 1782 1 -((ulTemp2 > ulTemp0 ? ulTemp2 - ulTemp0 : ulTemp0 - ulTemp2)/2);
- 1783 1
- 1784 1 ulTemp1 = ((unsigned long*)Data)[0];
- 1785 1 ucPhase = ucResult;
- 1786 1 ucResult = ucResult == 0x00 ? 0x7c : ucResult - 0x04;
- 1787 1
- 1788 1 do //detail scan by one step from phase(n-2) ~ pnase (n+2)
- 1789 1 {
- 1790 2 ucPhase = (ucPhase == 0x7c) ? 0x00 : ucPhase + 0x04;
- 1791 2 Set_Phase(ucPhase);
- 1792 2 Delay_Xms(1);
- 1793 2
- 1794 2 RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
- 1795 2
- 1796 2 Wait_Finish();
- 1797 2 if (ERROR_SUCCEED != Data[0]) return Data[0];
- 1798 2
- 1799 2 Read_Auto_Info(3);
- 1800 2
- 1801 2 ((unsigned long *)Data)[0]
- 1802 2 = ulTemp2 + ulTemp0 + ((unsigned long *)Data)[3]
- 1803 2 - ((ulTemp0 > ulTemp2 ? ulTemp0 - ulTemp2 : ulTemp2 - ulTemp0) / 2)
- 1804 2 - ((ulTemp0 > ((unsigned long *)Data)[3] ? ulTemp0 - ((unsigned long *)Data)[3] : ((unsigned lo
- -ng *)Data)[3] - ulTemp0) / 2);
- 1805 2
- 1806 2 if(((unsigned long*)Data)[0] > ulTemp1)
- 1807 2 {
- 1808 3 ulTemp1 = ((unsigned long*)Data)[0];
- 1809 3 ucResult = (ucPhase == 0x00) ? 0x7c : ucPhase - 0x04;
- 1810 3 }
- 1811 2 ucDetect -= 1;
- 1812 2
- 1813 2 ulTemp2 = ulTemp0;
- 1814 2 ulTemp0 = ((unsigned long *)Data)[3];
- 1815 2
- 1816 2 }while(ucDetect);
- 1817 1
- 1818 1
- 1819 1 #else //FAST AUTO method 2
- // Set phase 30
- Set_Phase(0x78);
- Delay_Xms(1);
-
- RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
-
- Wait_Finish();
- if (ERROR_SUCCEED != Data[0]) return Data[0];
-
- Read_Auto_Info(1);
-
- ulTemp2 = ((unsigned long *)Data)[1];
-
- // Set phase 0
- //Set_Phase(0x00 | ucDetect);
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 31
- Set_Phase(0x00);
- Delay_Xms(1);
-
- RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
-
- Wait_Finish();
- if (ERROR_SUCCEED != Data[0]) return Data[0];
-
- Read_Auto_Info(2);
-
-
- ulTemp1 = ((unsigned long *)Data)[2];
-
- ulTemp0 = 0;
- ucResult = 0x08;
- ucPhase = 0x08;//2 step rought scan
- do
- {
- Set_Phase(ucPhase);
- Delay_Xms(1);
-
- RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
-
- Wait_Finish();
- if (ERROR_SUCCEED != Data[0]) return Data[0];
-
- Read_Auto_Info(3);
-
- // ((unsigned long *)Data)[0] = ulTemp1 + ulTemp2 + ((unsigned long *)Data)[1];
-
- ((unsigned long *)Data)[0]
- = ulTemp2 + ulTemp1 + ((unsigned long *)Data)[3]
- - ((ulTemp1 > ulTemp2 ? ulTemp1 - ulTemp2 : ulTemp2 - ulTemp1) / 2)
- - ((ulTemp1 > ((unsigned long *)Data)[3] ? ulTemp1 - ((unsigned long *)Data)[3] : ((unsigned l
- -ong *)Data)[3] - ulTemp1) / 2);
-
-
- if (ulTemp0 < ((unsigned long *)Data)[0])
- {
- ulTemp0 = ((unsigned long *)Data)[0];
- ucResult = ucPhase - 0x08;
- }
-
- ulTemp2 = ulTemp1;
- ulTemp1 = ((unsigned long *)Data)[3];
-
- ucPhase = ucPhase + 0x08;
- }
- while (0x78 != ucPhase);
-
-
- // ((unsigned long *)Data)[0] = ulTemp1 + ulTemp2 + ((unsigned long *)Data)[3];
- // ((unsigned long *)Data)[1] = ((unsigned long *)Data)[3] + ulTemp1 + ((unsigned long *)Data)[2];
-
-
- ((unsigned long *)Data)[0]//phase26+phase28+phase30
- = ulTemp2 + ulTemp1 + ((unsigned long *)Data)[1]
- - ((ulTemp1 > ulTemp2 ? ulTemp1 - ulTemp2 : ulTemp2 - ulTemp1) / 2)
- - ((ulTemp1 > ((unsigned long *)Data)[1] ? ulTemp1 - ((unsigned long *)Data)[1] : ((unsigned long
- -*)Data)[1] - ulTemp1) / 2);
-
-
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 32
-
- ((unsigned long *)Data)[3]//phase28+phase30+phase0
- = ulTemp1 + ((unsigned long *)Data)[1] + ((unsigned long *)Data)[2]
- - ((((unsigned long *)Data)[1] > ulTemp1 ? ((unsigned long *)Data)[1] - ulTemp1 : ulTemp1 - ((unsi
- -gned long *)Data)[1]) / 2)
- - ((((unsigned long *)Data)[1] > ((unsigned long *)Data)[2] ? ((unsigned long *)Data)[1] - ((unsig
- -ned long *)Data)[2] : ((unsigned long *)Data)[2] - ((unsigned long *)Data)[1]) / 2);
-
-
- if (ulTemp0 < ((unsigned long *)Data)[0])
- {
- ulTemp0 = ((unsigned long *)Data)[0];
- ucResult = 0x70; //ucResult = phase28
- }
-
- if (ulTemp0 < ((unsigned long *)Data)[3])
- {
- ulTemp0 = ((unsigned long *)Data)[3];
- ucResult = 0x78; //ucResult = phase30
- }
-
-
- ucPhase = ucResult >= 0x08 ? (ucResult - 0x08) : (ucResult + 0x80 - 0x08);
- ulTemp0 = 0;
- ulTemp1 = 0;
- ulTemp2 = 0;
- ucDetect = 3;
-
- Set_Phase(ucPhase); //set Phase(n-2)
- Delay_Xms(1);
-
- RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
-
- Wait_Finish();
- if (ERROR_SUCCEED != Data[0]) return Data[0];
- Read_Auto_Info(1);
- ulTemp1 = ((unsigned long*)Data)[1];
-
- ucPhase = (ucPhase == 0x7c) ? 0x00 : ucPhase + 0x04; //set Phase(n-1)
- Set_Phase(ucPhase);
- Delay_Xms(1);
-
- RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
-
- Wait_Finish();
- if (ERROR_SUCCEED != Data[0]) return Data[0];
- Read_Auto_Info(2);
- ulTemp2 = ((unsigned long*)Data)[2];
-
-
- do //detail scan by one step from phase(n-2) ~ pnase (n+2)
- {
- ucPhase = (ucPhase == 0x7c) ? 0x00 : ucPhase + 0x04;
- Set_Phase(ucPhase);
- Delay_Xms(1);
-
- RTDSetByte(AUTO_ADJ_CTRL_7F, 0x77);
-
- Wait_Finish();
- if (ERROR_SUCCEED != Data[0]) return Data[0];
-
- Read_Auto_Info(3);
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 33
-
- ((unsigned long *)Data)[0]
- = ulTemp1 + ulTemp2 + ((unsigned long *)Data)[3]
- - ((ulTemp1 > ulTemp2 ? ulTemp1 - ulTemp2 : ulTemp2 - ulTemp1) / 2)
- - ((ulTemp2 > ((unsigned long *)Data)[3] ? ulTemp2 - ((unsigned long *)Data)[3] : ((unsigned lo
- -ng *)Data)[3] - ulTemp2) / 2);
-
- if(((unsigned long*)Data)[0] > ulTemp0)
- {
- ulTemp0 = ((unsigned long*)Data)[0];
- ucResult = (ucPhase == 0x00) ? 0x7c : ucPhase - 0x04;
- }
- ucDetect -= 1;
-
- ulTemp1 = ulTemp2;
- ulTemp2 = ((unsigned long *)Data)[3];
-
- }while(ucDetect);
-
- // ucDebug_Value1 = ucResult;
- #endif
- 1975 1
- 1976 1 stMUD.PHASE = ucResult;
- 1977 1 Set_Phase(stMUD.PHASE);
- 1978 1
- 1979 1 /*
- 1980 1 //restore the bandwidth setup of ADC
- 1981 1 if(ucMode_Curr < MODE_1024x0768x70HZ)
- 1982 1 RTDSetByte(ADC_REG_TEST_E9, 0x08);
- 1983 1 else
- 1984 1 RTDSetByte(ADC_REG_TEST_E9, 0x10);
- 1985 1 */
- 1986 1
- 1987 1 return ERROR_SUCCEED;
- 1988 1 }
- 1989
- 1990 unsigned char Auto_Config(void)
- 1991 {
- 1992 1 unsigned char Result, Noise, Curr_PosH, Curr_PosV, Curr_Clock, Curr_Phase;
- 1993 1
- 1994 1 unsigned char ucTemp1;
- 1995 1 unsigned int usTemp;
- 1996 1
- 1997 1
- 1998 1 bAutoInProgress = 1;
- 1999 1
- 2000 1 Curr_PosH = stMUD.H_POSITION; // Save current stMUD.H_POSITION
- 2001 1 Curr_PosV = stMUD.V_POSITION; // Save current stMUD.V_POSITION
- 2002 1 Curr_Clock = stMUD.CLOCK; // Save current stMUD.CLOCK
- 2003 1 Curr_Phase = stMUD.PHASE; // Save current stMUD.PHASE
- 2004 1
- 2005 1 if (ucV_Max_Margin < stMUD.V_POSITION)
- 2006 1 {
- 2007 2 stMUD.V_POSITION = ucV_Max_Margin - 1;
- 2008 2 Set_V_Position();
- 2009 2 }
- 2010 1
- 2011 1 // RTDCodeW(ADC_DEFAULT);
- 2012 1
- 2013 1 /////////original formula////////////////////////////////////////////
- 2014 1 //Set the H Position center(without IHS_Delay)
- 2015 1 /*
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 34
- 2016 1 stMUD.H_POSITION = 128;
- 2017 1
- 2018 1 if(128 >= stMUD.H_POSITION)
- 2019 1 {
- 2020 1 ucTemp = 128 - stMUD.H_POSITION;
- 2021 1
- 2022 1 if(stMUD.CLOCK > 128)
- 2023 1 ucTemp1 = 128;
- 2024 1 else
- 2025 1 ucTemp1 = stMUD.CLOCK;
- 2026 1
- 2027 1 //According to the H_Position adjust the IHS pre-delay
- 2028 1 ucH_Min_Margin = 128 - ucTemp - (64 - (ucTemp1 >> 1));
- 2029 1 //Return the IPH_ACT_STA to the original one first,and compensate the IHS pre-delay
- 2030 1 //The h position must be equal after change the IHS delay and IPH_ACT_STA
- 2031 1 usIPH_ACT_STA = usIPH_ACT_STA + 50 - ucTemp - (64 - (ucTemp1 >> 1));
- 2032 1 usTemp = usIPH_ACT_STA;
- 2033 1
- 2034 1 Set_H_Position();
- 2035 1 }
- 2036 1 */
- 2037 1 ///////////////////////////////////////////////////////////////////
- 2038 1
- 2039 1 ////////////////////////////////////////////////////////////////////
- 2040 1 //Set the H Position center(without IHS_Delay)
- 2041 1
- 2042 1 stMUD.H_POSITION = 128;
- 2043 1
- 2044 1
- 2045 1 //ucTemp = 128 - stMUD.H_POSITION;
- 2046 1
- 2047 1 if(stMUD.CLOCK > 128)
- 2048 1 ucTemp1 = 128;
- 2049 1 else
- 2050 1 ucTemp1 = stMUD.CLOCK;
- 2051 1
- 2052 1 //According to the H_Position adjust the IHS pre-delay
- 2053 1 ucH_Min_Margin = 128 - (64 - (ucTemp1 >> 1));
- 2054 1 //Return the IPH_ACT_STA to the original one first,and compensate the IHS pre-delay
- 2055 1 //The h position must be equal after change the IHS delay and IPH_ACT_STA
- 2056 1 usIPH_ACT_STA = CAP_WIN[ucMode_Curr][1];
- 2057 1
- 2058 1 if(ucMode_Curr < MODE_0800x0600x75HZ)
- 2059 1 Data[0] = 2;
- 2060 1 else if(ucMode_Curr < MODE_1280x1024x75HZ)
- 2061 1 Data[0] = 5;
- 2062 1 else
- 2063 1 Data[0] = 3;
- 2064 1
- 2065 1 // usIPH_ACT_STA = usIPH_ACT_STA + Data[0] - PROGRAM_HDELAY;
- 2066 1
- 2067 1 //usIPH_ACT_STA = usIPH_ACT_STA + 50 - (64 - (ucTemp1 >> 1));
- 2068 1 usIPH_ACT_STA = CAP_WIN[ucMode_Curr][1] + Data[0] - PROGRAM_HDELAY - (64 - (ucTemp1 >> 1));
- 2069 1
- 2070 1 usTemp = usIPH_ACT_STA;
- 2071 1
- 2072 1 Set_H_Position();
- 2073 1
- 2074 1 RTDSetByte(STATUS0_01, 0x00); // Clear status
- 2075 1 RTDSetByte(STATUS1_1F, 0x00); // Clear status
- 2076 1
- 2077 1
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 35
- 2078 1 ///////////////////////////////////////////////////////////////////
- 2079 1
- 2080 1 ///////////////////////////////
- 2081 1 // Measure NOISE_MARGIN //
- 2082 1 ///////////////////////////////
- 2083 1
- 2084 1 Result = Min_Noise_Margin();
- 2085 1 Noise = Data[0];
- 2086 1
- 2087 1
- 2088 1
- 2089 1
- 2090 1 //--------Auto_Clock-----------
- 2091 1 if (ERROR_SUCCEED == (Result & 0x80))
- 2092 1 {
- 2093 2 stMUD.CLOCK = (stMUD.CLOCK) & 0xfc; // stMUD.CLOCK must be times of 4
- 2094 2
- 2095 2 if (stMUD.CLOCK != Curr_Clock) Set_Clock();
- 2096 2
- 2097 2 ///////////////////////////////
- 2098 2 // Adjust Clock //
- 2099 2 ///////////////////////////////
- 2100 2 Result = Auto_Clock_Do(Noise);
- 2101 2
- 2102 2
- 2103 2 if (ERROR_SUCCEED != (Result & 0x80))
- 2104 2 {
- 2105 3 if (stMUD.CLOCK != Curr_Clock)
- 2106 3 {
- 2107 4 // Fail to find out suitable clock. Restore original clock and H position.
- 2108 4 stMUD.H_POSITION = Curr_PosH;
- 2109 4 stMUD.CLOCK = Curr_Clock;
- 2110 4
- 2111 4 Set_Clock();
- 2112 4 Set_H_Position();
- 2113 4 }
- 2114 3 }
- 2115 2 else
- 2116 2 {
- 2117 3 stMUD.H_POSITION = usH_Start + 128 + 64 - usIPH_ACT_STA - (stMUD.CLOCK >> 1);
- 2118 3
- 2119 3 if (ucH_Max_Margin < stMUD.H_POSITION)
- 2120 3 stMUD.H_POSITION = ucH_Max_Margin;
- 2121 3 else if (ucH_Min_Margin > stMUD.H_POSITION)
- 2122 3 stMUD.H_POSITION = ucH_Min_Margin;
- 2123 3
- 2124 3 Set_H_Position();
- 2125 3 }
- 2126 2 }
- 2127 1
- 2128 1 //---------Auto_Phase-----------
- 2129 1 if (ERROR_SUCCEED == (Result & 0x80))
- 2130 1 {
- 2131 2 Result = Auto_Phase_Do(Noise);
- 2132 2
- 2133 2 if (ERROR_SUCCEED != (Result & 0x80))
- 2134 2 {
- 2135 3 // Restore Phase
- 2136 3 stMUD.PHASE = Curr_Phase;
- 2137 3 Set_Phase(stMUD.PHASE);
- 2138 3
- 2139 3 if (ERROR_NOTACTIVE == Result) Result = ERROR_SUCCEED;
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 36
- 2140 3 }
- 2141 2 }
- 2142 1
- 2143 1 //---------Auto_Position-----------
- 2144 1 if (ERROR_SUCCEED == (Result & 0x80))
- 2145 1 {
- 2146 2 ///////////////////////////////
- 2147 2 // Adjust (H/V)Position //
- 2148 2 ///////////////////////////////
- 2149 2 Result = Auto_Position_Do(Noise);
- 2150 2
- 2151 2 // Because Auto_Position_Do() never returns bit-7 error, we don't have to check here.
- 2152 2 }
- 2153 1 else
- 2154 1 {
- 2155 2 stMUD.V_POSITION = Curr_PosV;
- 2156 2 Set_V_Position();
- 2157 2 }
- 2158 1
- 2159 1 // if (ERROR_SUCCEED == (Result & 0x80)) Save_MUD(ucMode_Curr);
- 2160 1
- 2161 1 //////////////////////////////////////////////////////////////////////////////
- 2162 1 /*
- 2163 1 if(ucH_Min_Margin == (128 - ucTemp - (64 - (ucTemp1 >> 1))))
- 2164 1 {
- 2165 1 if(usTemp != usIPH_ACT_STA)
- 2166 1 { //if usIPH_ACT_STA has been modified, turn back to original set value
- 2167 1 //stMUD.H_POSIITON also have to follow up the change of usIPH_ACT_STA
- 2168 1 stMUD.H_POSITION = stMUD.H_POSITION - (usTemp - usIPH_ACT_STA);
- 2169 1 usIPH_ACT_STA = usTemp - 50 + ucTemp + (64 - (ucTemp1 >> 1));
- 2170 1 }
- 2171 1 else
- 2172 1 usIPH_ACT_STA = usIPH_ACT_STA - 50 + ucTemp + (64 - (ucTemp1 >> 1));
- 2173 1
- 2174 1 ucH_Min_Margin = 128 - 50;
- 2175 1 Set_H_Position();
- 2176 1 }
- 2177 1 Set_Phase(stMUD.PHASE);
- 2178 1 */
- 2179 1 ////////////////////////////////////////////////////////////////////////////////
- 2180 1
- 2181 1 /////////////////////////////////////////////////////////////////////////////////
- 2182 1
- 2183 1 if(ucH_Min_Margin == (128 - (64 - (ucTemp1 >> 1))))
- 2184 1 {
- 2185 2 if(usTemp != usIPH_ACT_STA)
- 2186 2 { //if usIPH_ACT_STA has been modified, turn back to original set value
- 2187 3 //stMUD.H_POSIITON also have to follow up the change of usIPH_ACT_STA
- 2188 3 //Data[3] = 78 - usIPH_ACT_STA; Save the usIPH_ACT_STA compensate value
- 2189 3 stMUD.H_POSITION = stMUD.H_POSITION - (usTemp - usIPH_ACT_STA);
- 2190 3 usIPH_ACT_STA = usTemp - 50 + (64 - (ucTemp1 >> 1));
- 2191 3 Data[3] = 0x80 | (78 - stMUD.H_POSITION);
- 2192 3
- 2193 3 }
- 2194 2 else
- 2195 2 {
- 2196 3 usIPH_ACT_STA = usIPH_ACT_STA - 50 + (64 - (ucTemp1 >> 1));
- 2197 3 Data[3] = 0;
- 2198 3 }
- 2199 2
- 2200 2 // Save Frame-Sync Settings
- 2201 2 Data[0] = 4;
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 37
- 2202 2 Data[1] = ADDR_EROM1;
- 2203 2 Data[2] = (ucMode_Curr - 1);
- 2204 2
- 2205 2
- 2206 2
- 2207 2 if(0x80 < stMUD.H_POSITION)
- 2208 2 {
- 2209 3 if(stMUD.H_POSITION - 0x80 < 10)
- 2210 3 {
- 2211 4 usIPH_ACT_STA += (stMUD.H_POSITION - 0x80);
- 2212 4 Data[3] += (stMUD.H_POSITION - 0x80);
- 2213 4 stMUD.H_POSITION = 0x80;
- 2214 4 }
- 2215 3
- 2216 3 }
- 2217 2 else if(0x80 > stMUD.H_POSITION)
- 2218 2 {
- 2219 3 if(0x80 - stMUD.H_POSITION < 10)
- 2220 3 {
- 2221 4 usIPH_ACT_STA -= (0x80 - stMUD.H_POSITION);
- 2222 4
- 2223 4 Data[3] = (0x80 - stMUD.H_POSITION ) | 0x80;
- 2224 4 stMUD.H_POSITION = 0x80;
- 2225 4
- 2226 4 }
- 2227 3 }
- 2228 2
- 2229 2 I2CWrite(Data);
- 2230 2 Delay_Xms(SET_2404_DELAY);
- 2231 2
- 2232 2 ucH_Min_Margin = 128 - 50;
- 2233 2 Set_H_Position();
- 2234 2
- 2235 2 }
- 2236 1 Set_Phase(stMUD.PHASE);
- 2237 1 if (ERROR_SUCCEED == (Result & 0x80)) Save_MUD(ucMode_Curr);
- 2238 1
- 2239 1 RTDSetByte(STATUS0_01, 0x00); // Clear status
- 2240 1 RTDSetByte(STATUS1_1F, 0x00); // Clear status
- 2241 1
- 2242 1 /////////////////////////////////////////////////////////////////////////////////
- 2243 1
- 2244 1 // Restore ADC Gain/Offset
- 2245 1 // SetADC_GainOffset();
- 2246 1
- 2247 1 bAutoInProgress = 0;
- 2248 1 Set_Phase(stMUD.PHASE);
- 2249 1
- 2250 1 return Result;
- 2251 1 }
- 2252
- 2253 unsigned char Auto_Balance(void)
- 2254 {
- 2255 1 unsigned char Result, Curr_PosV;
- 2256 1
- 2257 1 bAutoInProgress = 1;
- 2258 1
- 2259 1 Curr_PosV = stMUD.V_POSITION; // Save current stMUD.V_POSITION
- 2260 1
- 2261 1 if (ucV_Max_Margin < stMUD.V_POSITION)
- 2262 1 {
- 2263 2 stMUD.V_POSITION = ucV_Max_Margin;
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 38
- 2264 2 Set_V_Position();
- 2265 2 }
- 2266 1
- 2267 1 // Do ADC gain/offset adjust
- 2268 1 Result = Tune_Balance();
- 2269 1
- 2270 1 // Restore vertical position
- 2271 1 if (Curr_PosV != stMUD.V_POSITION)
- 2272 1 {
- 2273 2 stMUD.V_POSITION = Curr_PosV;
- 2274 2 Set_V_Position();
- 2275 2 }
- 2276 1
- 2277 1 if (ERROR_SUCCEED != Result)
- 2278 1 {
- 2279 2 // Restore ADC Gain/Offset
- 2280 2 Load_GUD2();
- 2281 2 SetADC_GainOffset();
- 2282 2 }
- 2283 1 else
- 2284 1 {
- 2285 2 stGUD0.CONTRAST = 50;
- 2286 2 stGUD0.RTD_R_CONTRAST = 50;
- 2287 2 stGUD0.RTD_G_CONTRAST = 50;
- 2288 2 stGUD0.RTD_B_CONTRAST = 50;
- 2289 2 stGUD0.RTD_R_BRIGHT = 50;
- 2290 2 stGUD0.RTD_G_BRIGHT = 50;
- 2291 2 stGUD0.RTD_B_BRIGHT = 50;
- 2292 2 Set_Bright_Contrast();
- 2293 2
- 2294 2 #if(ANALOG_CONTRAST)
- 2295 2 SetADC_Gain();
- 2296 2 #endif
- 2297 2
- 2298 2 Save_GUD0();
- 2299 2 /*
- 2300 2 if (0 != stGUD2.AD_G_GAIN && 255 != stGUD2.AD_G_GAIN && 0 != stGUD2.AD_G_OFFSET && 255 != stGUD2.A
- -D_G_OFFSET)
- 2301 2 {
- 2302 2 stGUD2.AD_G_GAIN += 1;
- 2303 2 stGUD2.AD_G_OFFSET += 1;
- 2304 2 }
- 2305 2 SetADC_GainOffset();
- 2306 2 */
- 2307 2 Save_GUD2();
- 2308 2 }
- 2309 1
- 2310 1 bAutoInProgress = 0;
- 2311 1
- 2312 1 return Result;
- 2313 1 }
- 2314
- 2315 unsigned char Tune_Balance(void)
- 2316 {
- 2317 1 unsigned char Color, Count, Result, Margin, FineTune, Offset_Stop,ucTemp = 0;
- 2318 1
- 2319 1 FineTune = 0;
- 2320 1
- 2321 1 #if(ANALOG_CONTRAST)
- 2322 1 ucTemp = stGUD0.CONTRAST;
- 2323 1 stGUD0.CONTRAST = 50;
- 2324 1 SetADC_Gain();
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 39
- 2325 1 #endif
- 2326 1
- 2327 1 RTDCodeW(ADC_DEFAULT);
- 2328 1
- 2329 1 // Get usVer_Start, usVer_End, usH_Start, usH_Start
- 2330 1 if (ERROR_SUCCEED != Measure_PositionN(0x40)) return ERROR_ABORT;
- 2331 1
- 2332 1 if (ERROR_SUCCEED != Measure_Color(SELECT_RED, COLOR_MAX)) return ERROR_ABORT;
- 2333 1 if (0x60 > Data[0]) return ERROR_ABORT;
- 2334 1
- 2335 1 Margin = Data[0];
- 2336 1
- 2337 1 if (ERROR_SUCCEED != Measure_Color(SELECT_GREEN, COLOR_MAX)) return ERROR_ABORT;
- 2338 1 if (0x60 > Data[0]) return ERROR_ABORT;
- 2339 1
- 2340 1 Margin = Margin > Data[0] ? Data[0] : Margin;
- 2341 1
- 2342 1 if (ERROR_SUCCEED != Measure_Color(SELECT_BLUE, COLOR_MAX)) return ERROR_ABORT;
- 2343 1 if (0x60 > Data[0]) return ERROR_ABORT;
- 2344 1
- 2345 1 Margin = Margin > Data[0] ? Data[0] : Margin;
- 2346 1
- 2347 1 Margin = (Margin - 0x20) & 0xfc;
- 2348 1
- 2349 1 // Get usVer_Start, usVer_End, usH_Start, usH_Start
- 2350 1 if (ERROR_SUCCEED != Measure_PositionN(Margin)) return ERROR_ABORT;
- 2351 1
- 2352 1
- 2353 1 #if(0)
- SetADC_Offset();
- #else
- 2356 1 SetADC_GainOffset();
- 2357 1 #endif
- 2358 1
- 2359 1 Offset_Stop = 0;
- 2360 1 Color = SELECT_BLUE;
- 2361 1 do
- 2362 1 {
- 2363 2 Count = 0x30;
- 2364 2
- 2365 2 do
- 2366 2 {
- 2367 3 #if (0)
-
- if(Offset_Stop == 0)
- {
- ///////////////////////////////
- // Minimum Adjustment (0x02) //
- ///////////////////////////////
- if (ERROR_SUCCEED != Measure_Color(Color, COLOR_MIN)) return ERROR_ABORT;
- Margin = Data[0];
-
- if (0x0a < Margin)
- {
- Change_ADC_Offset(Color, 0x08, 0); // Increase Offset; Decrease Brightness
- }
- else if (0x02 < Margin)
- {
- Change_ADC_Offset(Color, Margin - 0x02, 0); // Increase Offset; Decrease Brightness
- }
- else if (0x02 > Margin)
- {
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 40
- if (0x00 == Margin && 0 == FineTune)
- Change_ADC_Offset(Color, 0x06, 1); // Decrease Offset; Increase Brightness
- else
- {
- Change_ADC_Offset(Color, 0x02 - Margin, 1); // Decrease Offset; Increase Brightness
-
- if(Color == SELECT_RED)
- {
- Offset_Stop = 1;
- SetADC_Gain();
- Color = SELECT_BLUE << 1;
- }
- break;
- }
- }
- }
- else
- {
- ///////////////////////////////
- // Maximum Adjustment (0xf2) //
- ///////////////////////////////
- if (ERROR_SUCCEED != Measure_Color(Color, COLOR_MAX)) return ERROR_ABORT;
- Margin = Data[0];
-
- if (0xf2 < Margin)
- {
- Result = Margin - 0xf2;
-
- // Non-zero return value of Change_ADC_Gain() means ADC gain reaches maximum.
- if (Change_ADC_Gain(Color, Result, 0)) // Increase Gain; Decrease Contrast
- {
- if (Change_ADC_Offset(Color, 4, 0)) break; // Increase Offset; Decrease Brightness
- }
- }
- else if (0xf2 > Margin)
- {
- Result = 0xf2 - Margin;
-
- // Non-zero return value of Change_ADC_Gain() means ADC gain reaches minimum.
- if (Change_ADC_Gain(Color, Result, 1)) // Decrease Gain; Increase Contrast
- {
- if (Change_ADC_Offset(Color, 4, 1)) break; // Decrease Offset; Increase Brightness
- }
- }
- else
- break;
- }
-
- if (8 < Count && 0xf3 >= Result && 0xf1 <= Result && 0x03 >= Margin && 0x01 <= Margin)
- {
- FineTune = 1;
- Count = 8;
- }
- #endif
- 2441 3
- 2442 3
- 2443 3 #if(1)
- 2444 3 ///////////////////////////////
- 2445 3 // Maximum Adjustment (0xf2) //
- 2446 3 ///////////////////////////////
- 2447 3 if (ERROR_SUCCEED != Measure_Color(Color, COLOR_MAX)) return ERROR_ABORT;
- 2448 3 Margin = Data[0];
- C51 COMPILER V7.06 LCD_AUTO 11/21/2005 13:47:25 PAGE 41
- 2449 3
- 2450 3 if (0xf2 < Margin)
- 2451 3 {
- 2452 4 Result = Margin - 0xf2;
- 2453 4
- 2454 4 // Non-zero return value of Change_ADC_Gain() means ADC gain reaches maximum.
- 2455 4 if (Change_ADC_Gain(Color, Result, 0)) // Increase Gain; Decrease Contrast
- 2456 4 {
- 2457 5 if (Change_ADC_Offset(Color, 4, 0)) break; // Increase Offset; Decrease Brightnes
- -s
- 2458 5 }
- 2459 4 }
- 2460 3 else if (0xf2 > Margin)
- 2461 3 {
- 2462 4 Result = 0xf2 - Margin;
- 2463 4
- 2464 4 // Non-zero return value of Change_ADC_Gain() means ADC gain reaches minimum.
- 2465 4 if (Change_ADC_Gain(Color, Result, 1)) // Decrease Gain; Increase Contrast
- 2466 4 {
- 2467 5 if (Change_ADC_Offset(Color, 4, 1)) break; // Decrease Offset; Increase Brightnes
- -s
- 2468 5 }
- 2469 4 }
- 2470 3
- 2471 3 Result = Margin;
- 2472 3
- 2473 3 ///////////////////////////////
- 2474 3 // Minimum Adjustment (0x02) //
- 2475 3 ///////////////////////////////
- 2476 3