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

📄 lcd_auto.lst

📁 keil c51平台,此代码可用于学习TFT LCD 之TCON,SCALER,OSD,(本人自己修改)
💻 LST
📖 第 1 页 / 共 5 页
字号:
 272          {
 273   1          unsigned char Result;
 274   1          
 275   1          Result  = Measure_PositionV(NM);
 276   1      
 277   1          if (ERROR_SUCCEED == Result)    
 278   1          {
 279   2              Result  = Measure_PositionH(NM);
 280   2          }
 281   1              
 282   1          return Result;
 283   1      }
 284          
 285          #if (MENU_TYPE == MENU_REL)
 286          //------------------------------------------------------------------//
 287          //                           Auto Clock                             //
 288          //------------------------------------------------------------------//
 289          unsigned char Auto_Clock(void)
 290          {
 291   1          unsigned char   Result, Curr_PosH, Curr_PosV, Curr_Clock, Curr_Phase;   
 292   1          
 293   1          bAutoInProgress = 1;
 294   1          
 295   1          Curr_PosH   = stMUD.H_POSITION;     // Save current stMUD.H_POSITION
 296   1          Curr_PosV   = stMUD.V_POSITION;     // Save current stMUD.V_POSITION
C51 COMPILER V7.50   LCD_AUTO                                                              07/28/2008 16:10:51 PAGE 6   

 297   1          Curr_Clock  = stMUD.CLOCK;          // Save current stMUD.CLOCK 
 298   1          Curr_Phase  = stMUD.PHASE;          // Save current stMUD.PHASE
 299   1      
 300   1          if (ucV_Max_Margin < stMUD.V_POSITION)
 301   1          {
 302   2              stMUD.V_POSITION    = ucV_Max_Margin;
 303   2              Set_V_Position();
 304   2          }
 305   1      
 306   1      //    RTDCodeW(ADC_DEFAULT);
 307   1      
 308   1          ///////////////////////////////
 309   1          //   Measure  NOISE_MARGIN   //
 310   1          ///////////////////////////////
 311   1          Result      = Min_Noise_Margin();   // Data[0] : Noise Margin
 312   1          
 313   1          if (ERROR_SUCCEED == (Result & 0x80))
 314   1          {
 315   2              Result  = Data[0];
 316   2      
 317   2              stMUD.CLOCK &= 0xfc;    // stMUD.CLOCK must be times of 4
 318   2      
 319   2              if (stMUD.CLOCK != Curr_Clock || 28 > stMUD.CLOCK || 228 < stMUD.CLOCK)
 320   2              {
 321   3                  Set_Clock();
 322   3              }
 323   2              
 324   2              ///////////////////////////////
 325   2              //       Adjust Clock        //
 326   2              ///////////////////////////////
 327   2              Result  = Auto_Clock_Do(Result);
 328   2              
 329   2              if (ERROR_SUCCEED != (Result & 0x80))
 330   2              {
 331   3                  if (stMUD.CLOCK != Curr_Clock)
 332   3                  {   
 333   4                      // Fail to find out suitable clock. Restore original clock and H position.
 334   4                      stMUD.CLOCK         = Curr_Clock;
 335   4                      stMUD.H_POSITION    = Curr_PosH;
 336   4      
 337   4                      Set_Clock();
 338   4                      Set_H_Position();
 339   4                  }
 340   3              }
 341   2              else
 342   2              {
 343   3                  if (stMUD.CLOCK != Curr_Clock)
 344   3                  {
 345   4                      stMUD.H_POSITION    = usH_Start + 128 + 64 - usIPH_ACT_STA - (stMUD.CLOCK >> 1);
 346   4      
 347   4                      if (ucH_Max_Margin < stMUD.H_POSITION)
 348   4                          stMUD.H_POSITION    = ucH_Max_Margin;
 349   4                      else if (ucH_Min_Margin > stMUD.H_POSITION)
 350   4                          stMUD.H_POSITION    = ucH_Min_Margin;
 351   4                                      
 352   4                      Set_H_Position();
 353   4      
 354   4                      Save_MUD(ucMode_Curr);
 355   4                  }
 356   3              }
 357   2          }
 358   1      
C51 COMPILER V7.50   LCD_AUTO                                                              07/28/2008 16:10:51 PAGE 7   

 359   1          // Restore ADC Gain/Offset
 360   1          SetADC_GainOffset();
 361   1          
 362   1          // Restore ADC phase 
 363   1          stMUD.PHASE = Curr_Phase;
 364   1          Set_Phase(stMUD.PHASE);
 365   1      
 366   1          // Restore vertical position
 367   1          if (Curr_PosV != stMUD.V_POSITION)
 368   1          {
 369   2              stMUD.V_POSITION    = Curr_PosV;
 370   2              Set_V_Position();
 371   2          }
 372   1      
 373   1          bAutoInProgress = 0;
 374   1      
 375   1          return Result;
 376   1      }
 377          #endif
 378          
 379          void Read_Auto_Info(unsigned char index)
 380          {
 381   1           if(index == 0) return;
 382   1      
 383   1               RTDRead(AUTO_PHASE0_88, 4, Y_INC);
 384   1      
 385   1            Data[index << 2] = Data[3];
 386   1            Data[(index << 2) + 1] = Data[2];
 387   1            Data[(index << 2) + 2] = Data[1];
 388   1            Data[(index << 2) + 3] = Data[0];
 389   1      
 390   1      }
 391          
 392          unsigned char FindColor()
 393          {
 394   1      unsigned long ulTemp0;
 395   1      unsigned char ucDetect,ucResult,ucPhase;
 396   1      
 397   1      RTDSetByte(DIFF_THRED_7E, 0x28);
 398   1      
 399   1          ulTemp0     = 0;
 400   1          ucDetect    = 0x77;
 401   1          do
 402   1          {
 403   2              ucResult    = COLORS_BLUE;
 404   2              ucPhase     = COLORS_BLUE;
 405   2              do
 406   2              {
 407   3                  RTDSetByte(MARGIN_B_7D, ucPhase);
 408   3                  RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
 409   3      
 410   3                  Wait_Finish();
 411   3                  if (ERROR_SUCCEED != Data[0])   return Data[0];
 412   3      
 413   3                  Read_Auto_Info(1);
 414   3      
 415   3                  if (ulTemp0 < ((unsigned long *)Data)[1])
 416   3                  {
 417   4                      ulTemp0     = ((unsigned long *)Data)[1];
 418   4                      ucResult    = ucPhase;
 419   4      
 420   4                      if (0x8000 < ulTemp0)   break;
C51 COMPILER V7.50   LCD_AUTO                                                              07/28/2008 16:10:51 PAGE 8   

 421   4                  }
 422   3      
 423   3                  if (COLORS_BLUE == ucPhase)
 424   3                      ucPhase = COLORS_GREEN;
 425   3                  else if (COLORS_GREEN == ucPhase)
 426   3                      ucPhase = COLORS_RED;
 427   3                  else
 428   3                      break;
 429   3              }
 430   2              while (1);
 431   2      
 432   2              if (0 != ulTemp0 || 0x7b != ucDetect)   break;
 433   2      
 434   2              ucDetect    = 0x77;
 435   2          }
 436   1          while (1);
 437   1      
 438   1          return ERROR_SUCCEED;
 439   1      }
 440          unsigned long GetMaxSum(unsigned char select)
 441          {
 442   1         unsigned char ucPhase,ucDetect;
 443   1         unsigned long ulTemp0;
 444   1         ucPhase = 0; //0,8,16,24
 445   1         ulTemp0 = 0;
 446   1         Set_Phase(ucPhase);
 447   1         ucDetect    = (select == 0) ? 0x77 : 0x7b;
 448   1         
 449   1         while(1)
 450   1         {
 451   2            RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
 452   2            Wait_Finish();
 453   2            if (ERROR_SUCCEED != Data[0])   return Data[0];
 454   2      
 455   2            Read_Auto_Info(1);
 456   2      
 457   2                 if (ulTemp0 < ((unsigned long *)Data)[1])
 458   2             {
 459   3                      ulTemp0     = ((unsigned long *)Data)[1];
 460   3             }
 461   2                 ucPhase += 0x20;
 462   2                 if(ucPhase > 0x60)
 463   2                      break;
 464   2      
 465   2                 Set_Phase(ucPhase);
 466   2              }
 467   1          return ulTemp0;
 468   1      }
 469          //------------------------------------------------------------------//
 470          // Return Message => ERROR_SUCCESS   : Success                      //
 471          //                   ERROR_TOO_SMALL : Measure Result << ACT_WIDTH  //
 472          //                   ERROR_TOO_BIG   : Measure Result >> ACT_WIDTH  //
 473          //                   ERROR_INPUT     : 1. IVS or IHS changed        //
 474          //                                     2. underflow or overflow     //
 475          //                   ERROR_TIMEOUT   : Measure Time_Out             //
 476          //                                     Process Time_Out             //
 477          //                   ERROR_NOTACTIVE : No Avtive Image              //
 478          //------------------------------------------------------------------//
 479          unsigned char Auto_Clock_Do(unsigned char NM)
 480          {
 481   1      #if(0)
              
C51 COMPILER V7.50   LCD_AUTO                                                              07/28/2008 16:10:51 PAGE 9   

                  unsigned char   ucResult;
                  unsigned char   count, delta, stop;    
                      
                  ///////////////////////////////
                  //  Measure (V) Start & End  //
                  ///////////////////////////////
                  ucResult    = Measure_PositionV(NM);
              
                  if (ERROR_SUCCEED != (ucResult & 0x80))
                  {
                      if (ERROR_NOTACTIVE == ucResult)
                      {
                          if (0x80 < stMUD.CLOCK)
                          {
                              stMUD.CLOCK = 0x80;
                              Set_H_Position();
                              Set_Clock();
                          }
                          else
                          {
                              stMUD.CLOCK = 0x80;
                              Set_Clock();
                              Set_H_Position();
                          }
              
                          ucResult    = Measure_PositionV(NM);
                          
                          if (ERROR_SUCCEED != (ucResult & 0x80))     return ucResult;
                      }
                      else
                          return ucResult;
                  }
              
                  NM      = NM + 0x10;    // See Min_Noise_Margin(). Horizontal Measure Result is the same when applying
             - (NM + 0x10)
              
                  count   = 10;
                  do
                  {
                      ///////////////////////////////
                      //  Measure (H) Start & End  //
                      ///////////////////////////////
                      ucResult    = Measure_PositionH(NM);
              
                      if (ERROR_SUCCEED != (ucResult & 0x80))     return ucResult;
                      
                      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 (0xc8 < delta)       // The difference is too large to fine-tune.
                      {
                          if (10 == count)
                          {
                              if (0x80 < stMUD.CLOCK)
                              {
                                  stMUD.CLOCK = 0x80;
                                  Set_H_Position();
C51 COMPILER V7.50   LCD_AUTO                                                              07/28/2008 16:10:51 PAGE 10  

                                  Set_Clock();
                              }
                              else
                              {
                                  stMUD.CLOCK = 0x80;
                                  Set_Clock();
                                  Set_H_Position();
                              }
              
                              continue;
                          }
                          else

⌨️ 快捷键说明

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