📄 lcd_auto.lst
字号:
1123 // 2. underflow or overflow //
1124 // ERROR_TIMEOUT : Measure Time_Out //
1125 // ERROR_NOTACTIVE : No Avtive Image //
1126 //------------------------------------------------------------------//
1127 unsigned char Auto_Position_Do(unsigned char NM)
1128 {
1129 1 unsigned char Result;
1130 1
1131 1 Result = Measure_PositionN(NM);
1132 1
1133 1 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
1134 1
1135 1 Result = ERROR_SUCCEED;
1136 1
1137 1 /////////////////////////////////
1138 1 // Calculate Vertical Position //
1139 1 /////////////////////////////////
1140 1 NM = 1;
1141 1 while (1)
1142 1 {
1143 2 if ((usIPV_ACT_STA + ucV_Max_Margin - 128) >= usVer_Start)
1144 2 {
1145 3 if ((usIPV_ACT_STA + ucV_Min_Margin - 128) <= usVer_Start)
1146 3 {
1147 4 stMUD.V_POSITION = (usVer_Start + 128) - usIPV_ACT_STA;
1148 4 Set_V_Position();
1149 4
1150 4 break; // Success
1151 4 }
1152 3 else
1153 3 Result |= ERROR_SUCCESS_2;
1154 3 }
1155 2 else
1156 2 Result |= ERROR_SUCCESS_1;
1157 2
1158 2 // If we can't align upper bound, we try to align lower bound.
C51 COMPILER V7.50 LCD_AUTO 07/28/2008 16:10:51 PAGE 20
1159 2 if (NM && usVer_End > usIPV_ACT_LEN)
1160 2 {
1161 3 usVer_Start = usVer_End - usIPV_ACT_LEN + 1;
1162 3 NM = 0;
1163 3 }
1164 2 else
1165 2 {
1166 3 Result |= ERROR_SUCCESS_4;
1167 3 break;
1168 3 }
1169 2 }
1170 1
1171 1 ///////////////////////////////////
1172 1 // Calculate Horizontal Position //
1173 1 ///////////////////////////////////
1174 1 NM = 1;
1175 1 while (1)
1176 1 {
1177 2 if ((usIPH_ACT_STA + (stMUD.CLOCK >> 1) + ucH_Max_Margin - 64 - 128) >= usH_Start)
1178 2 {
1179 3 if ((usIPH_ACT_STA + (stMUD.CLOCK >> 1) + ucH_Min_Margin - 64 - 128) <= usH_Start)
1180 3 {
1181 4 stMUD.H_POSITION = usH_Start + 128 + 64 - usIPH_ACT_STA - (stMUD.CLOCK >> 1);
1182 4 Set_H_Position();
1183 4
1184 4 break; // Success
1185 4 }
1186 3 else
1187 3 Result |= ERROR_SUCCESS_16;
1188 3 }
1189 2 else
1190 2 Result |= ERROR_SUCCESS_8;
1191 2
1192 2 // If we can't align upper bound, we try to align lower bound.
1193 2 if (NM && usH_End > usIPH_ACT_WID)
1194 2 {
1195 3 usH_Start = usH_End - usIPH_ACT_WID + 1;
1196 3 NM = 0;
1197 3 }
1198 2 else
1199 2 {
1200 3 Result |= ERROR_SUCCESS_32;
1201 3 break;
1202 3 }
1203 2 }
1204 1
1205 1 return Result;
1206 1 }
1207
1208 unsigned char Min_Noise_Margin(void)
1209 {
1210 1 unsigned char Result, Noise;
1211 1 unsigned int Curr_StartH, Curr_EndH;
1212 1
1213 1 Result = Measure_PositionV(VERTICAL_MARGIN);
1214 1 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
1215 1
1216 1 if (0 == usVer_Start)
1217 1 {
1218 2 Result = Measure_PositionV(VERTICAL_MARGIN + 0x20);
1219 2 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
1220 2 }
C51 COMPILER V7.50 LCD_AUTO 07/28/2008 16:10:51 PAGE 21
1221 1
1222 1 Noise = 0x00;
1223 1 Result = Measure_PositionH(Noise);
1224 1 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
1225 1
1226 1 Curr_StartH = usH_Start; // Save H start position at noise margin = 0
1227 1 Curr_EndH = usH_End; // Save H end position at noise margin = 0
1228 1
1229 1 do
1230 1 {
1231 2 Noise = Noise + 0x10;
1232 2 Result = Measure_PositionH(Noise);
1233 2
1234 2 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
1235 2
1236 2 if (Curr_StartH >= usH_Start)
1237 2 {
1238 3 Curr_StartH = usH_Start;
1239 3 }
1240 2 else if (0x08 < (usH_Start - Curr_StartH))
1241 2 {
1242 3 break; // A large gap of H start position is found.
1243 3 }
1244 2 }
1245 1 while (0x90 > Noise);
1246 1
1247 1 if (0x80 < Noise) return ERROR_NOISE_TOO_BIG;
1248 1
1249 1 while (1)
1250 1 {
1251 2 Curr_StartH = usH_Start;
1252 2 Curr_EndH = usH_End;
1253 2
1254 2 Result = Measure_PositionH(Noise + 0x28);
1255 2
1256 2 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
1257 2
1258 2 if ((Curr_EndH - Curr_StartH) == (usH_End - usH_Start) || (Curr_EndH - Curr_StartH) >= (usH_End -
-usH_Start + 3))
1259 2 {
1260 3 break; // We got noise margin with stable horizontal start/end position.
1261 3 }
1262 2
1263 2 if (0xa0 <= Noise)
1264 2 {
1265 3 break; // No stable horizontal start/end position are found.
1266 3 }
1267 2
1268 2 Noise = Noise + 0x10;
1269 2 Result = Measure_PositionH(Noise);
1270 2
1271 2 if (ERROR_SUCCEED != (Result & 0x80)) return Result;
1272 2 };
1273 1
1274 1 Data[0] = Noise + 0x10;
1275 1
1276 1 return ERROR_SUCCEED;
1277 1 }
1278
1279 unsigned char Auto_Phase(void)
1280 {
1281 1 unsigned char Result, Curr_PosV;
C51 COMPILER V7.50 LCD_AUTO 07/28/2008 16:10:51 PAGE 22
1282 1
1283 1 bAutoInProgress = 1;
1284 1
1285 1 Curr_PosV = stMUD.V_POSITION; // Save current stMUD.V_POSITION
1286 1
1287 1 if (ucV_Max_Margin < stMUD.V_POSITION)
1288 1 {
1289 2 stMUD.V_POSITION = ucV_Max_Margin;
1290 2 Set_V_Position();
1291 2 }
1292 1
1293 1 // Set ADC to default
1294 1 // RTDCodeW(ADC_DEFAULT);
1295 1
1296 1 ///////////////////////////////
1297 1 // Measure NOISE_MARGIN //
1298 1 ///////////////////////////////
1299 1 Result = Min_Noise_Margin();
1300 1
1301 1 if (ERROR_SUCCEED == (Result & 0x80))
1302 1 {
1303 2 Result = Auto_Phase_Do(Data[0]); // Noise margin returned by Min_Noise_Margin() is saved in
- Data[0];
1304 2 }
1305 1
1306 1 if (ERROR_SUCCEED != (Result & 0x80))
1307 1 {
1308 2 // Restore Phase
1309 2 Set_Phase(stMUD.PHASE);
1310 2 }
1311 1 else
1312 1 {
1313 2 Save_MUD(ucMode_Curr);
1314 2 }
1315 1
1316 1 // Restore ADC Gain/Offset
1317 1 SetADC_GainOffset();
1318 1
1319 1 // Restore vertical position
1320 1 if (Curr_PosV != stMUD.V_POSITION)
1321 1 {
1322 2 stMUD.V_POSITION = Curr_PosV;
1323 2 Set_V_Position();
1324 2 }
1325 1
1326 1 bAutoInProgress = 0;
1327 1
1328 1 return Result;
1329 1 }
1330
1331
1332 unsigned char Auto_Phase_Do(unsigned char NM)
1333 {
1334 1 unsigned char idata ucDetect, ucPhase, ucResult;
1335 1 unsigned long idata ulTemp0, ulTemp1, ulTemp2;
1336 1
1337 1 /*
1338 1 //reduce the bandwidth of ADC to prevent overshoot
1339 1 if(ucMode_Curr <= MODE_1280x1024x75HZ)
1340 1 RTDSetByte(ADC_REG_TEST_E9, 0x08);
1341 1 else if(ucMode_Curr < MODE_1024x0768x70HZ)
1342 1 RTDSetByte(ADC_REG_TEST_E9, 0x00);
C51 COMPILER V7.50 LCD_AUTO 07/28/2008 16:10:51 PAGE 23
1343 1 else
1344 1 RTDSetByte(ADC_REG_TEST_E9, 0x10);
1345 1 */
1346 1
1347 1 if (ERROR_SUCCEED != Measure_PositionN(NM)) return ERROR_ABORT;
1348 1
1349 1 // Set auto-tracking window
1350 1 Data[0] = 6;
1351 1 Data[1] = Y_INC;
1352 1 Data[2] = H_BND_STA_L_75;
1353 1 Data[3] = (unsigned char)(usH_Start + MEAS_H_STA_OFFSET - 2);
1354 1 Data[4] = (unsigned char)(usH_End + MEAS_H_END_OFFSET + 1);
1355 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);
1356 1 Data[6] = 0;
1357 1 RTDWrite(Data);
1358 1
1359 1 RTDSetByte(DIFF_THRED_7E, 0x30);
1360 1
1361 1 ulTemp0 = 0;
1362 1 ucDetect = 0x7b;
1363 1 do
1364 1 {
1365 2 ucResult = COLORS_RED;
1366 2 ucPhase = COLORS_RED;
1367 2 do
1368 2 {
1369 3 RTDSetByte(MARGIN_B_7D, ucPhase);
1370 3 RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
1371 3
1372 3 Wait_Finish();
1373 3 if (ERROR_SUCCEED != Data[0]) return Data[0];
1374 3
1375 3 Read_Auto_Info(1);
1376 3 if (ulTemp0 < ((unsigned long *)Data)[1])
1377 3 {
1378 4 ulTemp0 = ((unsigned long *)Data)[1];
1379 4 ucResult = ucPhase;
1380 4
1381 4 if (0x8000 < ulTemp0) break;
1382 4 }
1383 3
1384 3 if (COLORS_GREEN == ucPhase)
1385 3 ucPhase = COLORS_BLUE;
1386 3 else if (COLORS_RED == ucPhase)
1387 3 ucPhase = COLORS_GREEN;
1388 3 else
1389 3 break;
1390 3 }
1391 2 while (1);
1392 2
1393 2 if (0 != ulTemp0 || 0x7b != ucDetect) break;
1394 2
1395 2 ucDetect = 0x77;
1396 2 }
1397 1 while (1);
1398 1
1399 1 // Abort if no suitable color is found
1400 1 if (0 == ulTemp0) return ERROR_NOTACTIVE;
1401 1
1402 1 // Select color for auto-phase tracking
1403 1 RTDSetByte(MARGIN_B_7D, NM | ucResult);
C51 COMPILER V7.50 LCD_AUTO 07/28/2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -