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

📄 lcd_auto.lst

📁 液晶显示器程序代码
💻 LST
📖 第 1 页 / 共 5 页
字号:
 271   1          // Translate byte order : RTD little indian -> 8051 big indian
 272   1          Data[4] = Data[3] & 0x0f;
 273   1          Data[5] = Data[2];
 274   1          Data[2] = Data[1] & 0x0f;
 275   1          Data[3] = Data[0];
 276   1          
 277   1          if (0x07FF <= ((unsigned int *)Data)[1])     return  ERROR_NOTACTIVE;
 278   1          
 279   1      
 280   1          RTDRead(VGIP_CTRL_04, 1, N_INC);
 281   1      
 282   1          //if (0x14 == (Data[0] & 0x1c))
 283   1              if (0x08 == (Data[0] & 0x0c))
 284   1          {
 285   2              ((unsigned int *)Data)[1]   += 0x03;
 286   2              ((unsigned int *)Data)[2]   += 0x03;
 287   2          }
 288   1      
 289   1      /*  
 290   1          usH_Start   = MEAS_H_STA_OFFSET < ((unsigned int *)Data)[1] ? ((unsigned int *)Data)[1] - MEAS_H_STA_O
             -FFSET : 0x0000;
 291   1          usH_End     = MEAS_H_END_OFFSET < ((unsigned int *)Data)[2] ? ((unsigned int *)Data)[2] - MEAS_H_END_O
             -FFSET : 0x0fff;
 292   1      
 293   1          if (0x0000 != usH_Start)    usH_Start   = usH_Start + stMUD.H_POSITION - 128;
 294   1          if (0x0fff != usH_End)      usH_End     = usH_End + stMUD.H_POSITION - 128;
 295   1      */        
 296   1      
C51 COMPILER V7.06   LCD_AUTO                                                              11/21/2005 13:47:25 PAGE 6   

 297   1          usH_Start   = (((unsigned int *)Data)[1] + stMUD.H_POSITION) >= (128 + MEAS_H_STA_OFFSET)
 298   1                      ? (((unsigned int *)Data)[1] + stMUD.H_POSITION) - (128 + MEAS_H_STA_OFFSET) : 0x0000;
 299   1          usH_End     = (((unsigned int *)Data)[2] + stMUD.H_POSITION) >= (128 + MEAS_H_END_OFFSET)
 300   1                      ? (((unsigned int *)Data)[2] + stMUD.H_POSITION) - (128 + MEAS_H_END_OFFSET) : 0x0fff;
 301   1      
 302   1          return ERROR_SUCCEED;
 303   1      }
 304          
 305          //---------------Measure Vertical & Horizontal Position-------------//
 306          // Return Message => ERROR_SUCCESS   : Success                      //
 307          //                   ERROR_INPUT     : 1. IVS or IHS changed        //
 308          //                                     2. underflow or overflow     //
 309          //                   ERROR_TIMEOUT   : Measure Time_Out             //
 310          //                   ERROR_NOTACTIVE : No Avtive Image              //
 311          //------------------------------------------------------------------//
 312          unsigned char Measure_PositionN(unsigned char NM)
 313          {
 314   1          unsigned char Result;
 315   1          
 316   1          Result  = Measure_PositionV(NM);
 317   1      
 318   1          if (ERROR_SUCCEED == Result)    
 319   1          {
 320   2              Result  = Measure_PositionH(NM);
 321   2          }
 322   1              
 323   1          return Result;
 324   1      }
 325          
 326          /*
 327          //------------------------------------------------------------------//
 328          //                           Auto Clock                             //
 329          //------------------------------------------------------------------//
 330          unsigned char Auto_Clock(void)
 331          {
 332              unsigned char   Result, Curr_PosH, Curr_PosV, Curr_Clock, Curr_Phase;   
 333              
 334              bAutoInProgress = 1;
 335              
 336              Curr_PosH   = stMUD.H_POSITION;     // Save current stMUD.H_POSITION
 337              Curr_PosV   = stMUD.V_POSITION;     // Save current stMUD.V_POSITION
 338              Curr_Clock  = stMUD.CLOCK;          // Save current stMUD.CLOCK 
 339              Curr_Phase  = stMUD.PHASE;          // Save current stMUD.PHASE
 340          
 341              if (ucV_Max_Margin < stMUD.V_POSITION)
 342              {
 343                  stMUD.V_POSITION    = ucV_Max_Margin;
 344                  Set_V_Position();
 345              }
 346          
 347              RTDCodeW(ADC_DEFAULT);
 348          
 349              ///////////////////////////////
 350              //   Measure  NOISE_MARGIN   //
 351              ///////////////////////////////
 352              Result      = Min_Noise_Margin();   // Data[0] : Noise Margin
 353              
 354              if (ERROR_SUCCEED == (Result & 0x80))
 355              {
 356                  Result  = Data[0];
 357          
 358                  stMUD.CLOCK &= 0xfc;    // stMUD.CLOCK must be times of 4
C51 COMPILER V7.06   LCD_AUTO                                                              11/21/2005 13:47:25 PAGE 7   

 359          
 360                  if (stMUD.CLOCK != Curr_Clock || 28 > stMUD.CLOCK || 228 < stMUD.CLOCK)
 361                  {
 362                      Set_Clock();
 363                  }
 364                  
 365                  ///////////////////////////////
 366                  //       Adjust Clock        //
 367                  ///////////////////////////////
 368                  Result  = Auto_Clock_Do(Result);
 369                  
 370                  if (ERROR_SUCCEED != (Result & 0x80))
 371                  {
 372                      if (stMUD.CLOCK != Curr_Clock)
 373                      {   
 374                          // Fail to find out suitable clock. Restore original clock and H position.
 375                          stMUD.CLOCK         = Curr_Clock;
 376                          stMUD.H_POSITION    = Curr_PosH;
 377          
 378                          Set_Clock();
 379                          Set_H_Position();
 380                      }
 381                  }
 382                  else
 383                  {
 384                      if (stMUD.CLOCK != Curr_Clock)
 385                      {
 386                          stMUD.H_POSITION    = usH_Start + 128 + 64 - usIPH_ACT_STA - (stMUD.CLOCK >> 1);
 387          
 388                          if (ucH_Max_Margin < stMUD.H_POSITION)
 389                              stMUD.H_POSITION    = ucH_Max_Margin;
 390                          else if (ucH_Min_Margin > stMUD.H_POSITION)
 391                              stMUD.H_POSITION    = ucH_Min_Margin;
 392                                          
 393                          Set_H_Position();
 394          
 395                          Save_MUD(ucMode_Curr);
 396                      }
 397                  }
 398              }
 399          
 400              // Restore ADC Gain/Offset
 401              SetADC_GainOffset();
 402              
 403              // Restore ADC phase 
 404              stMUD.PHASE = Curr_Phase;
 405              Set_Phase(stMUD.PHASE);
 406          
 407              // Restore vertical position
 408              if (Curr_PosV != stMUD.V_POSITION)
 409              {
 410                  stMUD.V_POSITION    = Curr_PosV;
 411                  Set_V_Position();
 412              }
 413          
 414              bAutoInProgress = 0;
 415          
 416              return Result;
 417          }
 418          */
 419          void Read_Auto_Info(unsigned char index)
 420          {
C51 COMPILER V7.06   LCD_AUTO                                                              11/21/2005 13:47:25 PAGE 8   

 421   1           if(index == 0) return;
 422   1      
 423   1               RTDRead(AUTO_PHASE0_88, 4, Y_INC);
 424   1      
 425   1            Data[index << 2] = Data[3];
 426   1            Data[(index << 2) + 1] = Data[2];
 427   1            Data[(index << 2) + 2] = Data[1];
 428   1            Data[(index << 2) + 3] = Data[0];
 429   1      
 430   1      }
 431          
 432          unsigned char FindColor()
 433          {
 434   1      unsigned long ulTemp0;
 435   1      unsigned char ucDetect,ucResult,ucPhase;
 436   1      
 437   1      RTDSetByte(DIFF_THRED_7E, 0x28);
 438   1      
 439   1          ulTemp0     = 0;
 440   1          ucDetect    = 0x77;
 441   1          do
 442   1          {
 443   2              ucResult    = COLORS_BLUE;
 444   2              ucPhase     = COLORS_BLUE;
 445   2              do
 446   2              {
 447   3                  RTDSetByte(MARGIN_B_7D, ucPhase);
 448   3                  RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
 449   3      
 450   3                  Wait_Finish();
 451   3                  if (ERROR_SUCCEED != Data[0])   return Data[0];
 452   3      
 453   3                  Read_Auto_Info(1);
 454   3      
 455   3                  if (ulTemp0 < ((unsigned long *)Data)[1])
 456   3                  {
 457   4                      ulTemp0     = ((unsigned long *)Data)[1];
 458   4                      ucResult    = ucPhase;
 459   4      
 460   4                      if (0x8000 < ulTemp0)   break;
 461   4                  }
 462   3      
 463   3                  if (COLORS_BLUE == ucPhase)
 464   3                      ucPhase = COLORS_GREEN;
 465   3                  else if (COLORS_GREEN == ucPhase)
 466   3                      ucPhase = COLORS_RED;
 467   3                  else
 468   3                      break;
 469   3              }
 470   2              while (1);
 471   2      
 472   2              if (0 != ulTemp0 || 0x7b != ucDetect)   break;
 473   2      
 474   2              ucDetect    = 0x77;
 475   2          }
 476   1          while (1);
 477   1      
 478   1          return ERROR_SUCCEED;
 479   1      }
 480          unsigned long GetMaxSum(unsigned char select)
 481          {
 482   1         unsigned char ucPhase,ucDetect;
C51 COMPILER V7.06   LCD_AUTO                                                              11/21/2005 13:47:25 PAGE 9   

 483   1         unsigned long ulTemp0;
 484   1         ucPhase = 0; //0,8,16,24
 485   1         ulTemp0 = 0;
 486   1         Set_Phase(ucPhase);
 487   1         ucDetect    = (select == 0) ? 0x77 : 0x7b;
 488   1         
 489   1      #if(HARDWARE_AUTO)
 490   1      
 491   1         RTDSetByte(HW_AUTO_PHASE_9E,0x07);  //Step 8 auto phase
 492   1         Wait_For_IVS();
 493   1         //Wait_For_Event(EVENT_IVS);
 494   1         RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);  //Auto start
 495   1         //Wait_For_Event(EVENT_IVS);
 496   1         Wait_For_IVS();
 497   1         for(ucPhase = 0;ucPhase < 4; ucPhase++)
 498   1         {
 499   2             //Wait_For_Event(EVENT_IVS);
 500   2                 Wait_For_IVS();
 501   2             Read_Auto_Info(1);
 502   2      
 503   2             if(ulTemp0 < ((unsigned long *)Data)[1])
 504   2             {
 505   3               ulTemp0   = ((unsigned long *)Data)[1] & 0xffffff00;
 506   3             }
 507   2         }
 508   1         RTDSetByte(HW_AUTO_PHASE_9E,0x00);  //Switch back to software auto phase
 509   1         Wait_Finish();
 510   1         if(ERROR_SUCCEED != Data[0])     return (Data[0] & 0x000000ff);
 511   1         
 512   1      #else
                 while(1)
                 {
                    RTDSetByte(AUTO_ADJ_CTRL_7F, ucDetect);
                    Wait_Finish();
                    if (ERROR_SUCCEED != Data[0])   return Data[0];
              
                    Read_Auto_Info(1);
              
                         if (ulTemp0 < ((unsigned long *)Data)[1])
                     {
                              ulTemp0     = ((unsigned long *)Data)[1];
                     }
                         ucPhase += 0x20;
                         if(ucPhase > 0x60)
                              break;
              
                         Set_Phase(ucPhase);
                      }
              #endif
 532   1          return ulTemp0;
 533   1      }
 534          //------------------------------------------------------------------//
 535          // Return Message => ERROR_SUCCESS   : Success                      //
 536          //                   ERROR_TOO_SMALL : Measure Result << ACT_WIDTH  //
 537          //                   ERROR_TOO_BIG   : Measure Result >> ACT_WIDTH  //
 538          //                   ERROR_INPUT     : 1. IVS or IHS changed        //
 539          //                                     2. underflow or overflow     //
 540          //                   ERROR_TIMEOUT   : Measure Time_Out             //
 541          //                                     Process Time_Out             //
 542          //                   ERROR_NOTACTIVE : No Avtive Image              //
 543          //------------------------------------------------------------------//
 544          unsigned char Auto_Clock_Do(unsigned char NM)
C51 COMPILER V7.06   LCD_AUTO                                                              11/21/2005 13:47:25 PAGE 10  

 545          {
 546   1      #if(0)
              
                  unsigned char   ucResult;
                  unsigned char   count, delta, stop;    
                      

⌨️ 快捷键说明

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