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

📄 lcd_auto.lst

📁 Realtek 公司的RTD2523A芯片原厂source code,没有被修改过的。
💻 LST
📖 第 1 页 / 共 5 页
字号:
                  ///////////////////////////////
                  Result  = Measure_PositionV(NM);
              
                  if (ERROR_SUCCEED != (Result & 0x80))   return Result;
              
                  NM      = NM + 0x10;    // See Min_Noise_Margin(). Horizontal Measure Result is the same when applying
             - (NM + 0x10)
              
                  count   = 10;
                  do
                  {
                      ///////////////////////////////
                      //  Measure (H) Start & End  //
                      ///////////////////////////////
                      Result  = Measure_PositionH(NM);
              
                      if (ERROR_SUCCEED != (Result & 0x80))    return Result;
                      
                      usH_End = usH_End + 1 - usH_Start;
              
                      // H_Active Delta
                      if (usH_End < usIPH_ACT_WID)
                          delta = (usIPH_ACT_WID - usH_End > 0x00ff) ? 0xff : (unsigned char)(usIPH_ACT_WID - usH_End);
                      else 
                          delta = (usH_End - usIPH_ACT_WID > 0x00ff) ? 0xff : (unsigned char)(usH_End - usIPH_ACT_WID);
              
                      /*
                      if ((usIPH_ACT_WID / 3) < delta)    //modified 2003/02/25
                      {
                          return (usH_End < usIPH_ACT_WID) ? ERROR_TOO_SMALL : ERROR_TOO_BIG;
                      }
                      */
                      if (0xc8 < delta)       // The difference is too large to fine-tune.
                      {
                          if (10 == count)
                          {
                              if (0x80 != stMUD.CLOCK)
                              {
                                  stMUD.CLOCK = 0x80;
                                  Set_Clock();
                                  //Set_H_Position();
                              }
              
                              continue;
                          }
                          else
                              return (usH_End < usIPH_ACT_WID) ? ERROR_TOO_SMALL : ERROR_TOO_BIG;
                      }
                      
                      if (1 >= delta)     break;
              
                      delta   = delta + (delta >> 2);
              
                      // Adjust Clock
C51 COMPILER V6.20c  LCD_AUTO                                                              04/15/2004 12:59:06 PAGE 16  

                      if (usH_End < usIPH_ACT_WID)    // delta < 0, Measure < Active
                      {
                          if (800 < usIPH_ACT_WID)
                          {
                              if (228 < (unsigned int)delta + stMUD.CLOCK)    return ERROR_TOO_SMALL;
                          }
                          else
                          {
                              if (178 < (unsigned int)delta + stMUD.CLOCK)    return ERROR_TOO_SMALL;
                          }            
                          stMUD.CLOCK += delta;
                          Set_Clock();
                      }
                      else                            // delta >= 0, Measure >= Active
                      {
                          if (800 < usIPH_ACT_WID)
                          {
                              if (stMUD.CLOCK < (unsigned int)delta + 28)     return ERROR_TOO_BIG;
                          }
                          else
                          {
                              if (stMUD.CLOCK < (unsigned int)delta + 78)     return ERROR_TOO_BIG;
                          }            
                          stMUD.CLOCK -= delta;
                          Set_Clock();
                      }
                  }
                  while (--count);
              
                  if (0 == count)     return ERROR_TIMEOUT;
              
                  stop    = 0;
              
                  while (1)
                  {
                      count   = 0x10;     // Phase 4 ~ 28 step 4 (4,8,12,16,20,24,28)
                      delta   = 0xff;
              
                      while (1)
                      {
                          Set_Phase(count);
                          
                          // Measure usH_Start & usH_End
                          Result  = Measure_PositionH(NM);
              
                          if (ERROR_SUCCEED != (Result & 0x80))
                          {
                              if (ERROR_NOTACTIVE == Result)
                              {
                                  // Input pattern is black/white vertical lines.
                                  if (0x70 == count)
                                  {
                                      Set_Phase(stMUD.PHASE); // Restore phase
                                      break;
                                  }
                                  else
                                  {
                                      count += 0x20;
                                      continue;
                                  }
                              }
              
C51 COMPILER V6.20c  LCD_AUTO                                                              04/15/2004 12:59:06 PAGE 17  

                              Set_Phase(stMUD.PHASE); // Restore phase
              
                              return Result;
                          }
                          
                          usH_End = usH_End + 1 - usH_Start;
                          Result  = usH_End + 0x80 - usIPH_ACT_WID;
                          
                          if (Result < delta)
                          {
                              delta   = Result;       // Save the smallest width
                          }
              
                          if (0x70 == count)
                          {
                              Set_Phase(stMUD.PHASE); // Restore phase
                              break;
                          }
              
                          count += 0x10;
                      }       
              
                      if (0x81 < delta)
                      {
                          stMUD.CLOCK -= 1;
              
                          Set_H_Position();
                          Set_Clock();
              
                          stop    = 1;
                      }
                      else if (0x80 > delta)
                      {
                          if (stop && (0x7f == delta))    break; 
              
                          stMUD.CLOCK += 1;
              
                          Set_Clock();
                          Set_H_Position();
              
                          if (stop)   break;
                      }
                      else    
                          break;
                  }
                  
                  count   = stMUD.PHASE;  // Record Current Phase
                  start   = stMUD.CLOCK;
                  
                  if (ERROR_SUCCEED != FindColor())   return ERROR_ABORT;
                  
                  // Set threshold
                  RTDSetByte(DIFF_THRED_7E, 0x30);
              
                  // Judge if pulse information large enough
                  ulSum       = GetMaxSum(1);
                  if (0xffffffffL == ulSum)       return ERROR_ABORT;
              
                  ulCompare   = GetMaxSum(0);
                  if (0xffffffffL == ulCompare)   return ERROR_ABORT;
              	
                 	if ((460000 < ulSum) || ((460000 > ulSum) && (2000000 < ulCompare)) )
C51 COMPILER V6.20c  LCD_AUTO                                                              04/15/2004 12:59:06 PAGE 18  

              	{
                      ulCompare = 0;    
              
                      //////////////////////////////////////////////
                      if (0x80 < (start - 2) || 0x80 > start)
                      {
                          stMUD.CLOCK = 0x80;
              
                          Set_H_Position();
                          Set_Clock();
                          
                          ulSum   = GetMaxSum(0);
                          if (0 == ulSum)     return ERROR_ABORT;
              			
                          if (ulCompare < ulSum)
                          {
                              ulCompare   = ulSum;
                              Result      = stMUD.CLOCK;
                          }
              
                          stMUD.CLOCK = start + 1;
                      }
                      else
                      {
                          stMUD.CLOCK = start;
              
                          Set_H_Position();
                          Set_Clock();
              
                          ulSum   = GetMaxSum(0);
                          if (0 == ulSum)     return ERROR_ABORT;
                      }
                      ////////////////////////////////////////////////
              
                      do
                      {
                          if (ulCompare < ulSum)
                          {
                              ulCompare = ulSum;
                              Result = stMUD.CLOCK;
                          }
                          
                          if (stMUD.CLOCK == start - 2)   break;    
              
                          stMUD.CLOCK -= 1;
                          Set_Clock();
                          Set_H_Position();
              
                          ulSum = GetMaxSum(0);
                      }
                      while (ulSum);
              
                      if (0 == ulSum)     return ERROR_ABORT;
              
                      stMUD.CLOCK = Result;
                      stMUD.PHASE = count;
                      Set_Clock();
                      Set_H_Position();
                      Set_Phase(stMUD.PHASE);
                  }  
              
                  return (28 > stMUD.CLOCK) ? ERROR_TOO_BIG : (228 < stMUD.CLOCK) ? ERROR_TOO_SMALL : ERROR_SUCCEED;
C51 COMPILER V6.20c  LCD_AUTO                                                              04/15/2004 12:59:06 PAGE 19  

              
              #endif
1100   1      }
1101          
1102          /*
1103          //------------------------------------------------------------------//
1104          //                          Auto Position                           //
1105          //------------------------------------------------------------------//
1106          unsigned char Auto_Position(void)
1107          {
1108              unsigned char   Result, Curr_PosH, Curr_PosV;
1109          
1110              bAutoInProgress = 1;
1111          
1112              Curr_PosH   = stMUD.H_POSITION;     // Save current stMUD.H_POSITION
1113              Curr_PosV   = stMUD.V_POSITION;     // Save current stMUD.V_POSITION
1114          
1115              if (ucV_Max_Margin < stMUD.V_POSITION)
1116              {
1117                  stMUD.V_POSITION    = ucV_Max_Margin;
1118                  Set_V_Position();
1119              }
1120          
1121              RTDCodeW(ADC_DEFAULT);
1122          
1123              ///////////////////////////////
1124              //   Measure  NOISE_MARGIN   //
1125              ///////////////////////////////
1126              Result  = Min_Noise_Margin();
1127          
1128              if (ERROR_SUCCEED == (Result & 0x80))
1129              {   
1130                  ///////////////////////////////
1131                  //    Adjust (H/V)Position   //
1132                  ///////////////////////////////
1133                  Result  = Auto_Position_Do(Data[0]);    // Noise margin returned by Min_Noise_Margin() is saved in
             - Data[0];
1134              }
1135          
1136              if (ERROR_SUCCEED == (Result & 0x80))
1137              {
1138                  Save_MUD(ucMode_Curr);
1139              }
1140              else
1141              {
1142                  stMUD.H_POSITION    = Curr_PosH;
1143                  stMUD.V_POSITION    = Curr_PosV;
1144          
1145                  Set_H_Position();
1146                  Set_V_Position();
1147              }
1148              
1149              // Restore ADC Gain/Offset
1150              SetADC_GainOffset();

⌨️ 快捷键说明

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