📄 frame_sync.lst
字号:
267 2 break;
268 2 }
269 1
270 1 if(Data[0] & 0x03)
271 1 return 1; // Frame sync fail
272 1 #if(SPREAD_SPECTRUM)
273 1 else if(usDelta < usBuffer) //Get more margin of Framesync
274 1 {
275 2 //usDelta -= 2;
276 2 if(TestSync(usDelta - 4)) return 2;
277 2
278 2 if(Data[0] & 0x03)
279 2 TestSync(usDelta);
280 2 else
281 2 usDelta -= 2;
282 2
283 2 }
284 1 else//(usDelta > usBuffer) //Get more margin of Framesync
285 1 {
286 2 //usDelta += 2;
287 2 if(TestSync(usDelta + 4)) return 2;
288 2
289 2 if(Data[0] & 0x03)
290 2 TestSync(usDelta);
291 2 else
292 2 usDelta += 2;
293 2 }
294 1 #endif
295 1
296 1 // ucDebug_Value0 = ucTemp;
297 1 #if(FIX_LAST_DHT)
//Disable spread spectrum
C51 COMPILER V7.06 FRAME_SYNC 11/21/2005 13:47:25 PAGE 6
#if(SPREAD_SPECTRUM)
RTDSetBit(SPREAD_SPECTRUM_99,0x0f,0x00);
RTDSetBit(DCLK_OFFSET_MSB_9B,0xff,0x20);
#endif
//Read the last line information , read back data equal to half last line length
RTDRead(LAST_LINE_H_2C, 1, N_INC);
usMax_Last_Line = (unsigned int)(Data[0] & 0xf8) << 2;
RTDRead(LAST_LINE_L_26, 1, N_INC);
usMax_Last_Line = usMax_Last_Line + (Data[0] / 8);
//Read the last line information when frequency offset set one more step
RTDSetByte(DCLK_OFFSET_LSB_9A,(unsigned char)(usDelta + 1));
RTDSetBit(DCLK_OFFSET_MSB_9B,0xf0,(unsigned char)(((usDelta + 1) >> 8) & 0x07) | 0x20);
Wait_For_Event(EVENT_IVS);
Wait_For_Event(EVENT_IVS);
RTDRead(LAST_LINE_H_2C, 1, N_INC);
usMin_Last_Line = (unsigned int)(Data[0] & 0xf8) << 2;
RTDRead(LAST_LINE_L_26, 1, N_INC);
usMin_Last_Line = usMin_Last_Line + (Data[0] / 8);
//Calculate the difference of last line when increase one offset step
if(usMin_Last_Line < usMax_Last_Line)
usMin_Last_Line = usMax_Last_Line - usMin_Last_Line;
else
usMin_Last_Line = usDH_Total/2 - usMin_Last_Line + usMax_Last_Line;
if(FIX_LAST_DHT > usMax_Last_Line)
{
if((FIX_LAST_DHT - usMax_Last_Line) > (usDH_Total / 4))
{ //decrease the last line, decrease the DClk
Data[0] = (unsigned int)(usMax_Last_Line + (usDH_Total / 2 - FIX_LAST_DHT)) / usMin_Last_Line;
usDelta = usDelta + Data[0];
}
else
{ //increase the last line, increase the DClk
Data[0] = (unsigned int)(FIX_LAST_DHT - usMax_Last_Line) / usMin_Last_Line;
usDelta = usDelta - (Data[0] + 1);
}
}
else
{
if((usMax_Last_Line - FIX_LAST_DHT) > (usDH_Total / 4))
{ //increase the last line, increase the DClk
Data[0] = (unsigned int)(FIX_LAST_DHT + (usDH_Total / 2 - usMax_Last_Line)) / usMin_Last_Line;
usDelta = usDelta - (Data[0] + 1);
}
else
{ //decrease the last line, decrease the DClk
Data[0] = (usMax_Last_Line - FIX_LAST_DHT) / usMin_Last_Line;
Data[11] = Data[0];
usDelta += Data[0];
}
}
C51 COMPILER V7.06 FRAME_SYNC 11/21/2005 13:47:25 PAGE 7
//Enable the apread spectrum again
#if (SPREAD_SPECTRUM)
RTDSetBit(SPREAD_SPECTRUM_99,0x0f,(DCLK_SPRED_RANGE << 4));
if(TestSync(usDelta + DCLK_OFFSET[DCLK_SPRED_RANGE]))
return 2;
if(Data[0] & 0x03)
{
if(TestSync((Data[0] & 0x02) ? (usDelta + DCLK_OFFSET[DCLK_SPRED_RANGE] - 1)
: (usDelta + DCLK_OFFSET[DCLK_SPRED_RANGE] + 1))) //Fine tune Dclk offse
-t
return 2;
else
{
if(Data[0] & 0x03)
return 1; //frame sync fail!
else
return 0;
}
}
#else
if(TestSync(usDelta)) return 2;
#endif
RTDSetByte(FX_LST_LEN_L_59,(unsigned char)(FIX_LAST_DHT << 1));
RTDSetBit(FX_LST_LEN_H_5A,0x08,(unsigned char)((FIX_LAST_DHT >> 7) & 0x07));
RTDRead(DV_ACT_END_34, 2, Y_INC);
Data[2] = Data[1] & 0x07;
Data[3] = Data[0];
Data[4] = ((Data[1] & 0xf0) >> 4); //Measure result of last 16 line of DVTotal, including the un-c
-omplete last line
// Get Output_Active Height
((unsigned int *)Data)[1] = ((unsigned int *)Data)[1] - DV_ACT_STA_POS;
// Original Idea :
// DVTotal = Output_Active_Line * (Input_Total_Line / Input_Active_Line)
usDelta = (unsigned long)usVsync * ((unsigned int *)Data)[1] / usIPV_ACT_LEN;
usDelta = (usDelta & 0xfff0 | Data[4]);
RTDSetByte(FIX_DVTOTAL_LSB_97,(unsigned char)usDelta);
RTDSetByte(FIX_DVTOTAL_MSB_98,(unsigned char)((usDelta >> 8) & 0x07));
RTDSetBit(SPREAD_SPECTRUM_99,0xfc,0x03); //Frequency Synthesis select N = 4
RTDSetBit(DCLK_OFFSET_MSB_9B,0xff,0x20);
// RTDSetBit(FX_LST_LEN_H_5A,0xff,0x10); //Enable the Fixed DVTOTAL & Last Line Lenghth Fucntion
// RTDSetBit(FX_LST_LEN_H_5A,0xff,0x10); //Enable the Fixed DVTOTAL & Last Line Lenghth Fucntion
return 0;
#else
417 1
418 1 #if (SPREAD_SPECTRUM)
419 1 RTDSetBit(SPREAD_SPECTRUM_99,0x0f,(DCLK_SPRED_RANGE << 4));
420 1 if(TestSync(usDelta + DCLK_OFFSET[DCLK_SPRED_RANGE]))
421 1 return 2;
C51 COMPILER V7.06 FRAME_SYNC 11/21/2005 13:47:25 PAGE 8
422 1
423 1 if(Data[0] & 0x03)
424 1 {
425 2 if(TestSync((Data[0] & 0x02) ? (usDelta + DCLK_OFFSET[DCLK_SPRED_RANGE] - 1)
426 2 : (usDelta + DCLK_OFFSET[DCLK_SPRED_RANGE] + 1))) //Fine tune Dclk offs
-et
427 2 return 2;
428 2 else
429 2 {
430 3 if(Data[0] & 0x03)
431 3 return 1; //frame sync fail!
432 3 else
433 3 return 0;
434 3 }
435 2
436 2 }
437 1 #else
return 0;
#endif
440 1 return 0;
441 1 #endif
442 1
443 1 }
444
445
446
447
448 void Adjust_I_Code(void)
449 {
450 1 // Calculate the IHF in KHz
451 1 ((unsigned int*)Data)[0] = 24576/usHsync; //Input Horizontal Frequency
452 1 //Formula: I_Correction = CE * 2 * Fav(253687) * 100 / IHF / 2^(I_Code - 34)
453 1 //Data[2] : I_Code = 14; I_Code[13] = 0;
454 1
455 1 ucI_Code = 14;
456 1 Data[2] = ((unsigned long)ucCE_Value * 50737400 / (unsigned long)((unsigned int*)Data)[0]) >> 20;
457 1 Data[3] = (I_Correction == 0) ? (ucPE_Level ? (Correct_Amount - ucP_Corr) : ((ucP_Corr >> 2) + 10)) :
458 1 I_Correction;
459 1
460 1 while(1)
461 1 {
462 2
463 2 if(Data[2] > Data[3])
464 2 {
465 3 Data[2] = Data[2] >> 1;
466 3 ucI_Code -= 1;
467 3
468 3 if(Data[2] <= Data[3])
469 3 break;
470 3 }
471 2 else
472 2 {
473 3 if((Data[2] << 1) > Data[3])
474 3 break;
475 3 else
476 3 {
477 4 Data[2] = Data[2] << 1;
478 4 ucI_Code += 1;
479 4 }
480 3 }
481 2 }
482 1 // ucDebug_Value1 = ucP_Corr;
C51 COMPILER V7.06 FRAME_SYNC 11/21/2005 13:47:25 PAGE 9
483 1
484 1
485 1 if((unsigned char)((unsigned int)Data[2]*3/2) <= Data[3]) // Judge if I_Code[13] set to 1 will more
- close to 155
486 1 {
487 2 ucI_Code |= 0x80;
488 2 // ucDebug_Value2 = ((unsigned char)((unsigned int)Data[2]*3) >> 1);
489 2 }
490 1 else
491 1 {
492 2 // ucDebug_Value2 = Data[2];
493 2 }
494 1
495 1
496 1 }
C51 COMPILER V7.06 FRAME_SYNC 11/21/2005 13:47:25 PAGE 10
ASSEMBLY LISTING OF GENERATED OBJECT CODE
; FUNCTION Com0042 (BEGIN)
0000 L?0067:
0000 L?0068:
0000 7800 R MOV R0,#LOW usDelta
0002 E6 MOV A,@R0
0003 FE MOV R6,A
0004 08 INC R0
0005 E6 MOV A,@R0
0006 FF MOV R7,A
0007 22 RET
0008 L?0069:
0008 L?0070:
0008 E4 CLR A
0009 93 MOVC A,@A+DPTR
000A 7800 R MOV R0,#LOW usDelta+01H
000C 26 ADD A,@R0
000D FF MOV R7,A
000E E4 CLR A
000F 18 DEC R0
0010 36 ADDC A,@R0
0011 22 RET
0012 L?0072:
0012 7800 R MOV R0,#LOW usDelta+01H
0014 26 ADD A,@R0
0015 F6 MOV @R0,A
0016 18 DEC R0
0017 74FF MOV A,#0FFH
0019 36 ADDC A,@R0
001A F6 MOV @R0,A
001B 22 RET
; FUNCTION Com0042 (END)
; FUNCTION Frame_Sync_Detector (BEGIN)
; SOURCE LINE # 16
; SOURCE LINE # 17
; SOURCE LINE # 18
0000 200003 E JB bPower_Status,$ + 6H
0003 020000 R LJMP ?C0001
0006 200003 E JB bStable,$ + 6H
0009 020000 R LJMP ?C0001
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -