⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mode_detect.~c

📁 液晶显示器程序代码
💻 ~C
📖 第 1 页 / 共 5 页
字号:

    RTDSetByte(IVS_DELAY_8C, PROGRAM_VDELAY);

    usIPV_ACT_STA   = CAP_WIN[ucMode_Curr][3] - PROGRAM_VDELAY - 1;


    RTDSetByte(IHS_DELAY_8D, PROGRAM_HDELAY);

//    usIPH_ACT_STA   = usIPH_ACT_STA + CAPTURE_HDELAY - PROGRAM_HDELAY;
    if(ucMode_Curr < MODE_0800x0600x75HZ)
		Data[0] = 2;
    else if(ucMode_Curr < MODE_1280x1024x75HZ)
		Data[0] = 5;
    else
		Data[0] = 3;

//    Data[0] = 5;
    usIPH_ACT_STA   = usIPH_ACT_STA + Data[0] - PROGRAM_HDELAY;

    // Decide display length (height) and store to usDispLen

    usDispLen   = Mode_Preset[ucMode_Curr][2];

    if (MODE_UNDEFINED0 == ucMode_Curr)         // partical-screen scale-up mode
    {
        if (ucOption & 0x80)    // partial-V
        {           
			if (MIN_DV_TOTAL > (usVsync - 1))
                usDispLen   = (unsigned long)usIPV_ACT_LEN * MIN_DV_TOTAL / (usVsync - 1);
            else
                usDispLen   = usIPV_ACT_LEN;    // No V scale-up
        }
    }
    else if (MODE_UNDEFINED1 == ucMode_Curr)    // partial-screen scale-down mode
    {
        if (ucOption & 0x80)    // partial-V
        {
            usDispLen   = (unsigned long)usIPV_ACT_LEN * MIN_DV_TOTAL / (usVsync - 1);
        }
    } //if (MODE_UNDEFINED0 == ucMode_Curr)         // partical-screen scale-up mode

    if (Mode_Preset[ucMode_Curr][2] < usDispLen)    usDispLen   = Mode_Preset[ucMode_Curr][2];

    // This F/W do not support V scale-up(or bypass) and H scale-down simultaneously
    if (usDispLen >= usIPV_ACT_LEN && Mode_Preset[ucMode_Curr][1] < usIPH_ACT_WID)
    {
        usIPH_ACT_WID   = Mode_Preset[ucMode_Curr][1];
    }

    if (usDispLen > usIPV_ACT_LEN)                      ucOption    |= 0x01;    // bit 0 : V scale-up
    if (usDispLen < usIPV_ACT_LEN)                      ucOption    |= 0x02;    // bit 1 : V scale-down
    if (Mode_Preset[ucMode_Curr][1] > usIPH_ACT_WID)    ucOption    |= 0x04;    // bit 2 : H scale-up
    if (Mode_Preset[ucMode_Curr][1] < usIPH_ACT_WID)    ucOption    |= 0x08;    // bit 3 : H scale-down

    // Set capture window
    Data[0]     = 11;
    Data[1]     = Y_INC;
    Data[2]     = IPH_ACT_STA_06;
    Data[3]     = (unsigned char)usIPH_ACT_STA;
    Data[4]     = (unsigned char)(usIPH_ACT_STA >> 8);
    Data[5]     = (unsigned char)usIPH_ACT_WID;
    Data[6]     = (unsigned char)(usIPH_ACT_WID >> 8);
    Data[7]     = (unsigned char)usIPV_ACT_STA;
    Data[8]     = (unsigned char)(usIPV_ACT_STA >> 8);
    Data[9]     = (unsigned char)usIPV_ACT_LEN;
    Data[10]    = (unsigned char)(usIPV_ACT_LEN >> 8);
    Data[11]    = 0;
    RTDWrite(Data);

    // Set window size before scale-up
    Data[0] = 7;
    Data[1] = Y_INC;
    Data[2] = DRW_BSU_40;

    if (ucOption & 0x08)
    {
        // H scale-down
        Data[3] = (unsigned char)Mode_Preset[ucMode_Curr][1];
        Data[4] = (unsigned char)(Mode_Preset[ucMode_Curr][1] >> 8);
    }
    else
    {
        // No H scale-down
        Data[3] = Data[5];  // (unsigned char)usIPH_ACT_WID;
        Data[4] = Data[6];  // (unsigned char)(usIPH_ACT_WID >> 8);
    }

    if (ucOption & 0x02)
    {
        // V scale-down
        Data[5] = (unsigned char)usDispLen;
        Data[6] = (unsigned char)(usDispLen >> 8);
    }
    else
    {
        // No V scale-down
        Data[5] = Data[9];  // (unsigned char)usIPV_ACT_LEN;
        Data[6] = Data[10]; // (unsigned char)(usIPV_ACT_LEN >> 8);
    }
    Data[7] = 0;
    RTDWrite(Data);

    // Config scaling
    if (ucOption & 0x0a)
        RTDSetBit(SD_CTRL_70, 0xff, 0x01);      // Turn on scale-down
    else
        RTDSetBit(SD_CTRL_70, 0xfe, 0x00);      // Turn off scale-down

    if (ucOption & 0x01)
        RTDSetBit(SCALE_CTRL_15, 0xff, 0x02);   // Turn on V scale-up
    else
        RTDSetBit(SCALE_CTRL_15, 0xfd, 0x00);   // Turn off V scale-up

    if (ucOption & 0x04)
        RTDSetBit(SCALE_CTRL_15, 0xff, 0x01);   // Turn on H scale-up
    else
        RTDSetBit(SCALE_CTRL_15, 0xfe, 0x00);   // Turn off H scale-up

    // Set scale-down coefficient
    Data[0] = 7;
    Data[1] = Y_INC;
    Data[2] = H_SCALE_DL_71;

    if (ucOption & 0x08)    // H scale-down
    {
        // Data[12~15]
        ((unsigned long *)Data)[3]  = (unsigned long)256 * 4096 * usIPH_ACT_WID / Mode_Preset[ucMode_Curr][1];

        // Data[4~5]
        ((unsigned int *)Data)[2]   = (((unsigned long *)Data)[3] >> 8) + 2;

        // H scale-down factor is stored in Data[4] (high-byte) and Data[5] (low-byte)
        Data[3] = Data[5];

        RTDSetBit(VGIP_CTRL_04, 0xff, 0x40);    // Enable H scale-down compensation
    }
    else
    {
        Data[3] = 0x00;
        Data[4] = 0x10;

        RTDSetBit(VGIP_CTRL_04, 0xbf, 0x00);    // Diable H scale-down compensation
    }

    if (ucOption & 0x02)    // V scale-down
    {
        // Data[12~15]
        ((unsigned long *)Data)[3]  = (unsigned long)256 * 4096 * usIPV_ACT_LEN / usDispLen;

        // Data[6~7]
        ((unsigned int *)Data)[3]   = (((unsigned long *)Data)[3] >> 8);

        if (0 == Data[15])      ((unsigned int *)Data)[3]   = ((unsigned int *)Data)[3] - 1;

        // V scale-down factor is stored in Data[6] (high-byte) and Data[7] (low-byte)
        Data[5] = Data[7];

        RTDSetBit(VGIP_CTRL_04, 0xff, 0x80);    // Enable V scale-down compensation
    }
    else
    {
        Data[5] = 0x00;
        Data[6] = 0x10;

        RTDSetBit(VGIP_CTRL_04, 0x7f, 0x00);    // Diable V scale-down compensation
    }
    Data[7] = 0;
    RTDWrite(Data);

    // Set scale-up coefficient
    Data[0] = 8;
    Data[1] = Y_INC;
    Data[2] = HOR_SCA_16;

    if (ucOption & 0x04)    // H scale-up
    {
        // Data[12~15]
        ((unsigned long *)Data)[3]  = (unsigned long)2 * 262144 * usIPH_ACT_WID / Mode_Preset[ucMode_Curr][1];
        ((unsigned long *)Data)[3]  = ((((unsigned long *)Data)[3] >> 1) + (((unsigned long *)Data)[3] & 0x01)) << 6;

        Data[3] = Data[14];
        Data[4] = Data[13];
        Data[7] = Data[15];
    }
    else
    {
        Data[3] = 0xff;
        Data[4] = 0xff;
        Data[7] = 0;
    }

    if (ucOption & 0x01)    // V scale-up
    {
        // Data[12~15]
        ((unsigned long *)Data)[3]  = (unsigned long)2 * 262144 * usIPV_ACT_LEN / usDispLen;
        ((unsigned long *)Data)[3]  = ((((unsigned long *)Data)[3] >> 1) + (((unsigned long *)Data)[3] & 0x01)) << 6;

        Data[5] = Data[14];
        Data[6] = Data[13];
        Data[7] = Data[7] | (Data[15] >> 4);
    }
    else
    {
        Data[5] = 0xff;
        Data[6] = 0xff;
    }
    Data[8] = 0;
    RTDWrite(Data);

    // Set RTD display

    // Switch to FrameSync 1 mode and diable display
    RTDSetByte(VDIS_CTRL_20, 0x28 | DISP_BIT | DISPLAY_PORT);

    Data[0]     = 5;
    Data[1]     = Y_INC;

#if (DISP_ALIGN)

    Data[2]     = DH_ACT_STA_27;

    // DH_ACT_STA store in Data[4~5] (H~L)
    ((unsigned int *)Data)[2]   = (unsigned int)DH_ACT_END_POS - Mode_Preset[ucMode_Curr][1];

    Data[3]     = Data[5];

#else

    Data[2]     = DH_ACT_END_29;

    // DH_ACT_STA store in Data[4~5] (H~L)
    ((unsigned int *)Data)[2]   = (unsigned int)DH_ACT_STA_POS + Mode_Preset[ucMode_Curr][1];

    Data[3]     = Data[5];

#endif

    Data[5]     = 5;
    Data[6]     = Y_INC;
    Data[7]     = DV_ACT_END_34;

    // DV_ACT_END store in Data[10~11] (H~L)
    ((unsigned int *)Data)[5]   = (unsigned int)DV_ACT_STA_POS + usDispLen;

    Data[8]     = Data[11];
    Data[9]     = Data[10];
    Data[10]    = 0;
    RTDWrite(Data);

    // Get standard DH_TOTAL
    usDH_Total  = Mode_Preset[ucMode_Curr][0];

    // Switch to FrameSync 1 mode and enable display
//    if (PANEL_OFF == bPANEL_PWR)
    if (_OFF == bPanel_Status)
        RTDSetByte(VDIS_CTRL_20, 0x29 | DISP_BIT | DISPLAY_PORT);
    else
        RTDSetByte(VDIS_CTRL_20, 0x2b | DISP_BIT | DISPLAY_PORT);


    if (Mode_Preset[ucMode_Curr][3])
    {
        // Use preset DCLK M/N code
        Data[0] = 6;
        Data[1] = Y_INC;
        Data[2] = DPLL_CTRL_D0;
        Data[3] = 0x11;
        Data[4] = (unsigned char)(Mode_Preset[ucMode_Curr][3] >> 8);
        Data[5] = (unsigned char)Mode_Preset[ucMode_Curr][3];
        Data[6] = 0;
        RTDWrite(Data);
    }
    else
    {
     /*
        if (VGA_Mode[ucMode_Curr][4])
        {
            ((unsigned int *)Data)[0]   = (unsigned long)8 * usDH_Total * USER_MODE_NCODE * usDispLen 
                                        / ((unsigned long)usIPV_ACT_LEN * VGA_Mode[ucMode_Curr][4]);
        }
        else
        {
*/
            ((unsigned int *)Data)[0]   = (unsigned long)8 * usDH_Total * USER_MODE_NCODE * usDispLen 
                                        / ((unsigned long)usIPV_ACT_LEN * usHsync);
//        }


        //Original Formula : DPM/Ich = 17.6 must be constant
		//Ich = DPM * 10 / 176
		//2*Ich = DPM * 20 / 176 , set D0[0] to 0, then I = 2 * Ich
		//I  = 2 * Ich = 2.5u + D0[3]*2.5u + D0[4]*5u + D0[5]*10u + D0[6]*20u + D0[7]*30u(A)
		//2I = 4 * Ich = 5u + D0[3]*5u + D0[4]*10u + D0[5]*20u + D0[6]*40u + D0[7]*60u(A)
        Data[15] = ((unsigned int *)Data)[0] >> 2;
		Data[5] = (unsigned int)Data[15] * 40 / 176 - 5; //Calculate the 4*Ich,
		Data[6] = 0x00;
		if(Data[5] > 60)
		{
		    Data[5] -= 60;
			Data[6] |= 0x80; 
		}

		if(Data[5] > 40)
		{
		    Data[5] -= 40;
			Data[6] |= 0x40;
		}
		 
   	    if(Data[5] > 20)
		{
		    Data[5] -= 20;
			Data[6] |= 0x20;
		}

		if(Data[5] > 10)
		{
		    Data[5] -= 10;
			Data[6] |= 0x10;
		}

		if(Data[5] > 5)
		{
		    Data[5] -= 5;
			Data[6] |= 0x08;
		}
		

		Data[0] = 7;
		Data[1] = Y_INC;
		Data[2] = DPLL_CTRL_D0;
		Data[3] = Data[6];
		Data[4] = Data[15] - 2;
		Data[5] = 0x10 | (USER_MODE_NCODE - 2);//Offset Frequency Direction set to Downward
		//Data[5] = (USER_MODE_NCODE - 2);//Offset Frequency Direction set to Downward
		Data[6] = 0x04;
		Data[7] = 0;
		RTDWrite(Data);

 
//        ucDebug_Value0 = Data[4];
   //     ucDebug_Value1 = Data[5];
       
        //More precise Dclk in KHz
		((unsigned long*)Data)[0] = (unsigned long)24576000 / usIPV_ACT_LEN * usDispLen / usHsync * usDH_Total ;
        //((unsigned long*)Data)[0] = (unsigned long)49152000 / usIPV_ACT_LEN * usDispLen / usHsync * usDH_Total ;
		//set M/N code Dclk
		((unsigned long*)Data)[1] = (unsigned long)12288000 * (Data[15] + 1) / USER_MODE_NCODE;
        //((unsigned long*)Data)[1] = (unsigned long)24576000 * (Data[15] + 1) / USER_MODE_NCODE;
		((unsigned long*)Data)[2] = ((unsigned long*)Data)[1] - ((unsigned long*)Data)[0]; //Dclk offset
		((unsigned long*)Data)[3] = ((unsigned long*)Data)[1] >> 15; //Offset resolution equal to (Dclk / 2^15)
        
		((unsigned long*)Data)[3] = ((((unsigned long*)Data)[2] << 1)/ ((unsigned long*)Data)[3]) & 0x00000fff; //Calculate the Dclk offset
        //((unsigned long*)Data)[3] = (((unsigned long*)Data)[2] / ((unsigned long*)Data)[3]) & 0x00000fff; //Calculate the Dclk offset

		RTDSetByte(DCLK_OFFSET_LSB_9A,(unsigned char)((unsigned long*)Data)[3]);  //Set the Dclk offset
//        ucDebug_Value0 = (unsigned char)(((unsigned long*)Data)[3]);
		//RTDSetBit(DCLK_OFFSET_MSB_9B,0xf0,(unsigned char)(((unsigned long*)Data)[3] >> 8) | 0x20);
		RTDSetBit(DCLK_OFFSET_MSB_9B,0xf0,(unsigned char)(((unsigned long*)Data)[3] >> 8) | 0x20);
//        ucDebug_Value1 = (unsigned char)((((unsigned long*)Data)[3] >> 8) | 0x20);
        RTDSetBit(FX_LST_LEN_H_5A,0xff,0x08); //Enable DDS Spread Spectrum Output Function
		RTDSetBit(DPLL_N_D2,0xff,0x20); //DPLL Spread Spectrum Enable
		RTDSetBit(DPLL_FILTER_D3,0x7f,0x00); //Enable DPll output

}
        
   
    //usDH_Total  = usDH_Total

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -