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

📄 modedet.c

📁 keil C51 LCD 驱动源码,其中还有I2C驱动,ADC驱动,键盘操作等,是一个完整的keil源代码,供大家参考
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************
   +----------------------------------------------------------------------+
   | Copyright Trumpion Microelectronics Inc. 1999                        |
   | Trumpion Microelectronics Inc. reserves the right to change products |
   | or specifications without notice.                                    |
   +----------------------------------------------------------------------+
   Project    : LCD monitor
   Version    : 0.94
   File Name  : modedet.c
   Functions  : mode detect, mode change and free run routines
   Revision   :

   1999-05-18  OriginalTeam    First Created
   2000-07-17  Bill Tseng      Modified for Zurac-II
****************************************************************************/

//=========================================================================
// include files                                                          =
//=========================================================================
#include  "lib\extent.h"
#include  "lib\wreg516.h"
#include  "lib\declare.h"

#include  "lib\global.h"
#include  "lib\modedata.h"
#include  "lib\initial.h"
#include  "lib\eeprom.h"
#include  "lib\ttfc.h"
#include  "lib\osdm.h"
#include  "lib\osdmenu.h"
#include  "lib\key.h"
#include  "lib\adc.h"
#include  "lib\modedet.h"
#include  "lib\hwmd.h"
#include  "LIB\MISC.H"
#include  "LIB\DEFINE.H"
#include  <intrins.h>

//extern  Byte    RangeDetect(void);
extern  void    SetHorPosition(Bool,Bool);
extern  Bool    autofunction(Bool);



/************************************************************************/
/* Function    : ModeDetect                                             */
/* Description : Mode detection & mode change                           */
/*       Input : None                                                   */
/*      Output : none                                                   */
/************************************************************************/
void ModeDetect( void )
{   
    Byte   sts, src;
    
    if( FgHWMDInt )
    {
        FgHWMDInt = 0;
        src = HWMD_ReadStatus();                   /* clear  Zurac interrupt */
        EX0 = 1;                                   /* enable INT0  interrupt */
        if( (SyncSource & 0x03)==0x00 )
        {
            LastHCountH = 0;
            LastVCountH = 0;
            LastHPol = 0;
            LastVPol = 0;
            SyncSource = 0x80;                     /* switch to SOG (Csync/DE + VsyncSep) */
            AdcSync(2);                            /* set ADC sync source to SOG */
            HWMD_ChangeSource();
            MuteTimer = TIME_200MS;
        }
    }
    if( (MuteTimer==0) && FgModeDetect )
    {
        FgModeDetect = 0;

        sts = HWMD_VideoStatus();
        HCountH = HWMD_HfHigh();
        VCountH = HWMD_VfHigh();
        CurrentHPol = sts & 0x01;
        CurrentHPol = ~CurrentHPol;
        CurrentVPol = (sts & 0x02) >> 1;
        CurrentVPol = ~CurrentVPol;

        if( (SyncSource & 0x03)==0x03 )            /* check Seperate (Hsync + Vsync) */
        {
            if( HCountH==0xFF || VCountH==0xFF )   /* no Seperate signal */
            {
                FgSepSignal = 0;                   /* clear Seperate signal flag */
                if( InputSource==INPUT_ANALOG )
                {
                    SyncSource = 0xA1;             /* switch to Composite (Hsync + VsyncSep) */
                    AdcSync(1);                    /* set ADC sync source to Composite */
                    HWMD_ChangeSource();
                    MuteTimer = TIME_100MS;
                }
            }
            else
            {
                FgSepSignal = 1;                   /* set Seperate signal flag */
                SetModeChangeStatus();
//algu 1205                FgPowerUP = 0;
//algu 1205                FgPowerUP1 = 0;
                return;
            }
        }
        else if( (SyncSource & 0x03)==0x01 )       /* check Composite (Hsync + VsyncSep) */
        {
            if( HCountH==0xFF || VCountH==0xFF )   /* no Composite signal */
            {
                FgCompSignal = 0;                  /* clear Composite signal flag */
                SyncSource = 0x80;                 /* switch to SOG (Csync/DE + VsyncSep) */
                AdcSync(2);                        /* set ADC sync source to SOG */
                HWMD_ChangeSource();
                MuteTimer = TIME_100MS;
                StableCnt = 0;
                FgSWChange = 0;
            }
            else
            {
                FgCompSignal = 1;                  /* set Composite signal flag */
                SetModeChangeStatus();
//algu 1205                FgPowerUP = 0;
//algu 1205                FgPowerUP1 = 0;
                return;
            }
        }
        else if( (SyncSource & 0x03 )==0x00 )
        {             
            if( !FgSWChange )
            {
                tempHCountH = HCountH;
                tempVCountH = VCountH;
                tempHPol = CurrentHPol;
                tempVPol = CurrentVPol;
                FgSWChange = 1;
                MuteTimer = TIME_100MS;
                StableCnt = 0;
            }
            else
            {
                if( (tempHCountH != HCountH) || (tempVCountH != VCountH)
                     || (HCountH == 0xFF) || (VCountH == 0xFF)
                     || (tempHPol != CurrentHPol) || (tempVPol != CurrentVPol)
                     || ((sts & 0x04) == 0) || (HCountH < 0x20)  || (VCountH<0x66))
                {
                    FgSWChange = 0;
                    FgSogSignal = 0;               /* clear SOG signal flag */
                    LastHCountH = 0x00;
                    LastVCountH = 0x00;
                    LastHPol = 0;
                    LastVPol = 0;
                    SyncSource = 0xA3;             /* switch to Seperate (Hsync + Vsync) */
                    AdcSync(0);                    /* set ADC sync source to Seperate */
                    HWMD_ChangeSource();
                    MuteTimer = TIME_100MS;
                }
                else
                {
                    if( ++StableCnt >= 3 )
                    {
                        FgSWChange = 0;
                        FgSogSignal = 1;           /* set SOG signal flag */
                        MuteTimer = TIME_100MS;
                        StableCnt = 0;
                        SetModeChangeStatus();
//algu 1205                        FgPowerUP = 0;
//algu 1205                        FgPowerUP1 = 0;
                        return;
                    }
                    else
                        MuteTimer = TIME_30MS;
                }
            }
        }
        if( (FgSepSignal || FgCompSignal || FgSogSignal )==0)
        {
            if( !FgNoSignal )
            {
                FgNoSignal = 1;                    /* set no signal(Sep,Comp,SOG) flag */
                FgModeChange = 1;                  /* set mode change flag */
                SyncSource = 0xA3;                 /* switch to Seperate (Hsync + Vsync) */
                AdcSync(0);                        /* set ADC sync source to Seperate */
                HWMD_ChangeSource();
                MuteTimer = TIME_100MS;
            }
//          if(FgPowerUP)
//          {
//              PromptTimer = TIME_3SEC;
//              FgPowerUP =0;
//              FgModeChange =0;
//          }
//          else if( FgPowerUP1)
//          {
//              if(PromptTimer==0)
//              {
//                   FgPowerUP1 =0;
//                   FgNoSignal = 0;
//              }
//              FgModeChange =0;
//          }
        }
    }

}

/************************************************************************/
/* Function    : ModeChangeMode                                         */
/* Description : Change Mode                                            */
/*       Input : None                                                   */
/*      Output : none                                                   */
/************************************************************************/
void ModeChangeMode( void )
{
    Bool   btmp;

    FgSaveData=0;
    if( FgNoSignal)
    {
        if( FgPowerOff )  return;

	if ( FgBurnin && FgPowerBurnin  )
	{
		ZuracFreeRun(L0_NO_SIGNAL);
		OSDNumber=L0_NO_SIGNAL;
	//	FgPowerBurnin = 0;
		FgShowBurnin = 1;
		OSDMaxValue = 4;
	}
	else
		OSDNumber=L9_NOOSD;
	PromptTimer=TIME_1SEC;
        if( FgPowerStby )
        {
             SystemPowerOn();           
             PowerLedPower(1);       // off Power-LED
             PowerLedSleep(0);       // off Sleep-LED
             FgPowerOff   = 0;
             FgPowerStby  = 0;
             FgFreeRun    = 0;
        }
    }
    else
    {
       
       if( FgPowerOff )  return;
       OSDNumber = L0_NOOSD;
       ModeFindMode();
       
       FgPowerBurnin=0;         //algu 1130
       
       if( FgPowerStby )
       {
             SystemPowerOn();           
             PowerLedPower(1);       // off Power-LED
             PowerLedSleep(0);       // off Sleep-LED
             FgPowerOff   = 0;
             FgPowerStby  = 0;
             FgFreeRun    = 0;
       }
             
       switch( RangeDetect() )
       {
        
          case Over_Range_Mode :
                OSDNumber=L9_OVERRANGE;
                PromptTimer=TIME_1SEC;
                return;

          case No_Signal_Mode :
                OSDNumber=L9_NOOSD;
                PromptTimer=TIME_1SEC;
                FgPowerStby=0;
                return;
          
          case Unknow_Mode :
                OSDNumber=L9_UNKNOWN_MODE;
                PromptTimer=TIME_1SEC;
                return;
          
          case Fail_Safe_Mode :
                OSDNumber=L9_FAILSAFE;
                PromptTimer=TIME_1SEC;
                break;
          
       }   
       

          PowerBacklight(0);         /* Backlight power-off */
          PowerPanel(0);             /* Panel power-off  */
          if( FgPowerStby )
          {
             SystemPowerOn();           
             PowerLedPower(1);       // off Power-LED
             PowerLedSleep(0);       // off Sleep-LED
             FgPowerOff   = 0;
             FgPowerStby  = 0;
             FgFreeRun    = 0;
          }
          FgNoSignal = 0;
          FgFreeRun  = 0;
          FgInterlace = 0;
          
          if( ModeCounter==41 )  FgInterlace = 1;   /* for 8514A */

          ResetScaler();

#if (OUTPUT_MODE==OUTPUT_SXGA)
          if( PanelType==PANEL_SAMSUNG )
             Delay( 100 );
#endif
          if( InputSource==INPUT_ANALOG )
          {
             EepromTimingRecall( ModeCounter );
             PowerAdc(1);        /* ADC power-on */
//           PowerDvi(2);        /* DVI power-off or standby */         // Vincent Because no this kind of chip
             ShortDelay(3);
             ADC9884(ModeCounter);
             Ttfc( ModeCounter,1 );
             Zurac0Atoggle();
          }
          else
          {
             EepromTimingDefault( ModeCounter );
#if (ADC_CHIP==ADI_9887)
             ADC9884(ModeCounter);   // for ADI_9887 digital mode
#endif
             PowerAdc(2);         /* ADC power-off or standby */
             ShortDelay(5);
             Ttfc( ModeCounter,1 );
             Zurac0Atoggle();
          }

          PowerPanel(1);          /* Panel power-on */
          MUTEEnable();
          OsdInitCtrl();          /* OSD control register data */

          if(( ModeInfo & 0x80) !=0)
          {
             FgAutoAdj=1;
             if( autofunction( FgAutoAdj ) )
             {
                FgAutoAdj=0;
                ModeInfo = ModeInfo&0x7F;
                btmp = FgFacMode;
                FgFacMode=0;
                EepromTimingStore( ModeCounter );     /* save Hpos,Vpos,Phase,Clock */
                FgFacMode=btmp;
             }
          }

             Delay(50);

//        if( FgGammaEnable)  ZuracInitGamma();
//        VideoDecoder(0,0);

//        ShortDelay(50);
#if (PANEL_DEFAULT==PANEL_HANNSTAR)
          Delay(125);
#endif
          if( FgHWMDInt==0 )
             PowerBacklight(1);      /* back light on */
          PowerLedSleep(0);       // off Sleep-LED

          MUTEDisable();

//          SetHorPosition(INCREASE,0);
//          SetHorPosition(DECREASE,0);

⌨️ 快捷键说明

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