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

📄 autofunc.lst

📁 MSTARXX.rar
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V8.18   AUTOFUNC                                                              09/29/2009 23:58:04 PAGE 1   


C51 COMPILER V8.18, COMPILATION OF MODULE AUTOFUNC
OBJECT MODULE PLACED IN ..\..\1out\AutoFunc.obj
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE ..\..\pc\AutoFunc.c BROWSE INCDIR(..\..\inc) DEBUG OBJECTEXTEND PRINT(..\..
                    -\1out\AutoFunc.lst) OBJECT(..\..\1out\AutoFunc.obj)

line level    source

   1          
   2          #define _AUTOFUNC_C_
   3          
   4          #include <math.h>
   5          #include "types.h"
   6          #include "board.h"
   7          #if VGA_ENABLE
   8          
   9          #include "global.h"
  10          #include "ms_reg.h"
  11          #include "adjust.h"
  12          #include "ms_rwreg.h"
  13          #include "misc.h"
  14          #include "DEBUG.h"
  15          #include "power.h"
  16          #include "AutoFunc.h"
  17          #include "detect.h"
  18          #include "panel.h"
  19          #include "mstar.h"
  20          ///////////////////////////////////////////////////////////////////////////////
  21          // <Function>: msAutoGeometry
  22          //
  23          // <Description>: Auto geometry for analog port.
  24          ///////////////////////////////////////////////////////////////////////////////
  25          #define ThresholdData 0x20
  26          
  27          #if(ENABLE_WATCH_DOG)
  28          void Delay1ms_WatchDog( WORD wValue )
  29          {
  30   1          WatchDogClear();
  31   1          while( wValue )
  32   1          {
  33   2              if( wValue > 500 )
  34   2              {
  35   3                  Delay1ms(500);
  36   3                  wValue -= 500;
  37   3                  WatchDogClear();
  38   3              }
  39   2              else
  40   2              {
  41   3                  Delay1ms(wValue);
  42   3                  wValue = 0;
  43   3              }
  44   2          }
  45   1          WatchDogClear();
  46   1      }
  47          #endif
  48          BOOL msAutoGeometry(AutoTuneType AutoParam)
  49          {
  50   1          BYTE ucBank; // bank buffer
  51   1          BYTE ucBk0_01;
  52   1          BYTE ucBk1_01;
  53   1          BYTE ucVSyncTime; // VSync time
  54   1      
C51 COMPILER V8.18   AUTOFUNC                                                              09/29/2009 23:58:04 PAGE 2   

  55   1          ucBank = msReadByte(BK0_00_REGBK); // store bank
  56   1      
  57   1          // Disable DB buffer
  58   1          msWriteByte( BK0_00_REGBK, REG_BANK1_ADC_ACE_MCU ); // bank 1
  59   1          ucBk1_01 = msReadByte( BK1_01_DBFC);
  60   1          msWriteByte( BK1_01_DBFC, 0x00 );
  61   1      
  62   1          msWriteByte( BK0_00_REGBK, REG_BANK_SCALER ); // bank 0
  63   1          ucBk0_01 = msReadByte( BK0_01_DBFC);
  64   1          msWriteByte( BK0_01_DBFC, 0x00 );
  65   1          msAdjustAdcGain(0x80, 0x80, 0x80);
  66   1          msAdjustAdcOffset(0x90, 0x90, 0x90);
  67   1      
  68   1          ucVSyncTime = msCalculateVSyncTime(); // get VSync time
  69   1      
  70   1           // auto position valid data theshold
  71   1          if (AutoParam & AUTO_TUNE_VALID_DATA)
  72   1              if (msAutoSetValidData(ucVSyncTime+3) == FALSE) AutoParam = AUTO_TUNE_NULL;
  73   1          else // fixed valid data
  74   1              msWriteByte(BK0_CC_AOVDV, ThresholdData); // set valid data threshold
  75   1      
  76   1          // auto horizontal total
  77   1          if (AutoParam & AUTO_TUNE_FREQ)
  78   1              if (msAutoTuneHTotal(ucVSyncTime*2) == FALSE) AutoParam = AUTO_TUNE_NULL;
  79   1      
  80   1          // auto phase
  81   1          if (AutoParam & AUTO_TUNE_PHASE)
  82   1              if (msAutoTunePhase(ucVSyncTime+3) == FALSE) AutoParam = AUTO_TUNE_NULL;
  83   1      
  84   1          // auto position
  85   1          if (AutoParam & AUTO_TUNE_POSITION)
  86   1              if (msAutoTunePosition(ucVSyncTime) == FALSE) AutoParam = AUTO_TUNE_NULL;
  87   1      
  88   1          msWriteByte(BK0_00_REGBK, REG_BANK_SCALER); // select register bank scaler
  89   1          msWriteByte(BK0_C8_ATGCTRL, 0x11); // enable auto gain function
  90   1      
  91   1          // auto RGB offset
  92   1          if (AutoParam & AUTO_TUNE_RGB_OFFSET)
  93   1              if (msAutoTuneOffset(ucVSyncTime) == FALSE)
  94   1                  AutoParam= AUTO_TUNE_NULL; // auto-tune ADC offset
  95   1      
  96   1          // auto RGB gain
  97   1          if (AutoParam & AUTO_TUNE_RGB_GAIN)
  98   1              if (msAutoTuneGain(ucVSyncTime) == FALSE)
  99   1                  AutoParam= AUTO_TUNE_NULL; // auto-tune ADC gain
 100   1      
 101   1      /*
 102   1          if (AutoParam & AUTO_TUNE_YUV_COLOR)
 103   1              if (msAutoColorYUV(ucVSyncTime) == FALSE)
 104   1                  AutoParam= AUTO_TUNE_NULL; // auto-tune ADC gain
 105   1      */
 106   1      
 107   1          msWriteByte(BK0_00_REGBK, REG_BANK_SCALER); // select register bank scaler
 108   1          msWriteByte(BK0_C8_ATGCTRL, 0x00); // disable auto gain function
 109   1          msWriteByte(BK0_CC_AOVDV, 0x40); // set valid data threshold
 110   1      
 111   1          msAdjustAdcGain(g_PcSetting.AdcRedGain, g_PcSetting.AdcGreenGain, g_PcSetting.AdcBlueGain);
 112   1          msAdjustAdcOffset(g_PcSetting.AdcRedOffset, g_PcSetting.AdcGreenOffset, g_PcSetting.AdcBlueOffset);
 113   1         // Recover DB buffer setting
 114   1          msWriteByte( BK0_01_DBFC, ucBk0_01);
 115   1      
 116   1          msWriteByte( BK0_00_REGBK, REG_BANK1_ADC_ACE_MCU ); // bank 1
C51 COMPILER V8.18   AUTOFUNC                                                              09/29/2009 23:58:04 PAGE 3   

 117   1          msWriteByte( BK1_01_DBFC, ucBk1_01);
 118   1      
 119   1          msWriteByte(BK0_00_REGBK, ucBank); // recovery bank
 120   1      
 121   1          if (AutoParam) // success
 122   1              return TRUE;
 123   1          else // fail
 124   1          {
 125   2              putstr("\r\nAuto failed");
 126   2              return FALSE;
 127   2          }
 128   1      }
 129          
 130          ///////////////////////////////////////////////////////////////////////////////
 131          // <Function>: msAutoCheckSyncLoss
 132          //
 133          // <Description>: Check Sync loss status.
 134          //
 135          // <Returns> :
 136          ///////////////////////////////////////////////////////////////////////////////
 137          BOOL msAutoCheckSyncLoss(void)
 138          {
 139   1      //#if UseINT
 140   1          if (g_bInputTimingChangeFlag)
 141   1          {
 142   2          #ifdef AUTO_DEBUG_EN
                      putstr("\r\ng_bInputTimingChange=1");
                      printf("\r\nVt=%x",msGetVerticalTotal());
                  #endif
 146   2              return TRUE;
 147   2          }
 148   1      //#endif
 149   1      
 150   1          // check H/VSync change
 151   1          if ((abs(g_wHorizontalPeriod - msGetHorizontalPeriod()) > HPeriod_Torlance) ||
 152   1              (abs(g_wVerticalTotal - msGetVerticalTotal()) > VTotal_Torlance))
 153   1          {
 154   2              SrcFlags|= bHSyncLoss;
 155   2              SrcFlags|= bVSyncLoss;
 156   2              g_bInputTimingChangeFlag = 1;
 157   2          #ifdef AUTO_DEBUG_EN
                      printf("\r\nHP=%x",msGetHorizontalPeriod());
                      printf("\r\nVt=%x",msGetVerticalTotal());
                  #endif
 161   2              return TRUE;
 162   2          }
 163   1      
 164   1          return FALSE;
 165   1      }
 166          
 167          ///////////////////////////////////////////////////////////////////////////////
 168          // <Function>: msAutoSetValidData
 169          //
 170          // <Description>: Auto set valid data value.
 171          //
 172          // <Parameter>:  -  <Flow>  -  <Description>
 173          //-----------------------------------------------------------------------------
 174          //  ucVSyncTime  -    In    -   VSync time
 175          ///////////////////////////////////////////////////////////////////////////////
 176          BOOL msAutoSetValidData(BYTE ucVSyncTime)
 177          {
 178   1          BYTE ucValidData; // valide dataa value
C51 COMPILER V8.18   AUTOFUNC                                                              09/29/2009 23:58:04 PAGE 4   

 179   1          BYTE ucPhaseIndex; // phase index
 180   1      
 181   1          WORD wComapreHPos; // compare horizontal position
 182   1      
 183   1          BYTE ucBank = msReadByte( BK0_00_REGBK);
 184   1      
 185   1          msWriteByte( BK0_00_REGBK, REG_BANK_SCALER );
 186   1      
 187   1          for (ucValidData=0x04; ucValidData!=0x10; ucValidData++)
 188   1          {
 189   2              msWriteByte(BK0_CC_AOVDV, ucValidData << 4); // set valid data threshold
 190   2      
 191   2              msAdjustAdcPhase(0x00); // set phase
 192   2              Delay1ms_WatchDog(ucVSyncTime);
 193   2              wComapreHPos = msAutoGetPosition(BK0_D0_AOHST_L, ucVSyncTime); // horizontal position
 194   2              for (ucPhaseIndex=0x01; ucPhaseIndex!=0x10; ucPhaseIndex++)
 195   2              {
 196   3                  msAdjustAdcPhase(ucPhaseIndex * 4); // set phase
 197   3                  Delay1ms_WatchDog(ucVSyncTime);
 198   3                  if (abs(wComapreHPos - msAutoGetPosition(BK0_D0_AOHST_L, ucVSyncTime)) > 3) // check lose data
 199   3                      break;
 200   3      
 201   3                  if (msAutoCheckSyncLoss()) // check Sync change
 202   3                  {
 203   4                      msWriteByte( BK0_00_REGBK, ucBank );
 204   4                  #ifdef AUTO_DEBUG_EN
                              putstr("\r\nmsAutoSetValidData() failed");
                          #endif
 207   4                      return FALSE;
 208   4                  }
 209   3              } // for
 210   2      
 211   2              if (ucPhaseIndex == 0x10)
 212   2                  break;
 213   2          } // for
 214   1      
 215   1          msWriteByte( BK0_00_REGBK, ucBank );
 216   1          return TRUE;
 217   1      }
 218          
 219          ///////////////////////////////////////////////////////////////////////////////
 220          // <Function>: autoWaitStatusReady
 221          //
 222          // <Description>: Wait for status ready.
 223          //
 224          // <Parameter>:  -  <Flow>  -  <Description>
 225          //-----------------------------------------------------------------------------
 226          //   ucRegIndex  -    In    -   Register index
 227          //   ucRegMask   -    In    -   Status mask
 228          ///////////////////////////////////////////////////////////////////////////////
 229          void msAutoWaitStatusReady(BYTE ucRegIndex, BYTE ucRegMask)
 230          {
 231   1          WORD wDummy = 250; // loop dummy
 232   1      
 233   1      #if ENABLE_MCU_USE_INTERNAL_CLOCK
 234   1          wDummy = 1000;
 235   1      #endif
 236   1      
 237   1          while (!(msReadByte(ucRegIndex) & ucRegMask) && (wDummy--)) ;
 238   1      }
 239          
 240          ///////////////////////////////////////////////////////////////////////////////
C51 COMPILER V8.18   AUTOFUNC                                                              09/29/2009 23:58:04 PAGE 5   

 241          // <Function>: autoWaitStatusReady
 242          //
 243          // <Description>: Wait for status ready.
 244          //
 245          // <Returns> : Auto position value.
 246          //
 247          // <Parameter>:  -  <Flow>  -  <Description>
 248          //-----------------------------------------------------------------------------
 249          //   ucRegIndex  -    In    -   Register index
 250          //   ucVSyncTime -    In    -   VSync time
 251          ///////////////////////////////////////////////////////////////////////////////
 252          WORD msAutoGetPosition(BYTE ucRegIndex, BYTE ucVSyncTime)
 253          {
 254   1          WORD wComparePos, wAutoPos; // position buffer
 255   1          BYTE ucDummy = 20; // loop dummy
 256   1          BYTE ucCount = 0; // counter of compare alike
 257   1      
 258   1          BYTE ucBank = msReadByte( BK0_00_REGBK);
 259   1      
 260   1          msWriteByte( BK0_00_REGBK, REG_BANK_SCALER );
 261   1      
 262   1          while(ucDummy--)
 263   1          {
 264   2              msAutoWaitStatusReady(BK0_CB_ATOCTRL, _BIT1); // auto position result ready
 265   2      
 266   2              wAutoPos = msReadWord(ucRegIndex+1); // get auto position
 267   2              if (wAutoPos == wComparePos) // match
 268   2                  ucCount++;
 269   2              else // different
 270   2              {
 271   3                  ucCount = 0; // reset counter
 272   3                  wComparePos = wAutoPos; // reset position
 273   3              }
 274   2      
 275   2              if (ucCount == 3) // match counter ok
 276   2                  break;
 277   2      
 278   2              if (msAutoCheckSyncLoss()) // check no signal
 279   2              {
 280   3                  msWriteByte( BK0_00_REGBK, ucBank );
 281   3                  return -1; // return fail
 282   3              }
 283   2      
 284   2              Delay1ms_WatchDog(ucVSyncTime); // wait next frame
 285   2          } // while
 286   1      
 287   1          msWriteByte( BK0_00_REGBK, ucBank );
 288   1          return wAutoPos;
 289   1      }
 290          
 291          ///////////////////////////////////////////////////////////////////////////////
 292          // <Function>: autoWaitStatusReady
 293          //
 294          // <Description>: Wait for status ready.
 295          //
 296          // <Parameter>:  -  <Flow>  -  <Description>
 297          //-----------------------------------------------------------------------------
 298          //  ucVSyncTime  -    In    -   VSync time
 299          ///////////////////////////////////////////////////////////////////////////////
 300          BOOL msAutoTunePosition(BYTE ucVSyncTime)
 301          {
 302   1          WORD wPosBff; // position buffer
C51 COMPILER V8.18   AUTOFUNC                                                              09/29/2009 23:58:04 PAGE 6   

 303   1          BYTE ucBank;
 304   1      
 305   1      #ifdef AUTO_DEBUG_EN
                  printf("\r\nmsAutoTunePosition(%d)", ucVSyncTime);
              #endif
 308   1      
 309   1      
 310   1          ucBank = msReadByte( BK0_00_REGBK);
 311   1          msWriteByte( BK0_00_REGBK, REG_BANK_SCALER );
 312   1      

⌨️ 快捷键说明

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