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

📄 lcd_auto.lst

📁 keil c51平台,此代码可用于学习TFT LCD 之TCON,SCALER,OSD,(本人自己修改)
💻 LST
📖 第 1 页 / 共 5 页
字号:
              
              #else
 842   1          unsigned char   Result;
 843   1          unsigned char   count, delta, stop,start;    
 844   1          unsigned long   ulSum,ulCompare;
 845   1              ulCompare = 0;
 846   1              ulSum = 0;
 847   1              
 848   1          ///////////////////////////////
 849   1          //  Measure (V) Start & End  //
 850   1          ///////////////////////////////
C51 COMPILER V7.50   LCD_AUTO                                                              07/28/2008 16:10:51 PAGE 15  

 851   1          Result  = Measure_PositionV(NM);
 852   1      
 853   1          if (ERROR_SUCCEED != (Result & 0x80))   return Result;
 854   1      
 855   1          NM      = NM + 0x10;    // See Min_Noise_Margin(). Horizontal Measure Result is the same when applying
             - (NM + 0x10)
 856   1      
 857   1          count   = 10;
 858   1          do
 859   1          {
 860   2                 
 861   2              ///////////////////////////////
 862   2              //  Measure (H) Start & End  //
 863   2              ///////////////////////////////
 864   2              Result  = Measure_PositionH(NM);
 865   2      
 866   2              if (ERROR_SUCCEED != (Result & 0x80))    return Result;
 867   2              
 868   2              usH_End = usH_End + 1 - usH_Start;
 869   2                
 870   2              // H_Active Delta
 871   2              if (usH_End < usIPH_ACT_WID)
 872   2                  delta = (usIPH_ACT_WID - usH_End > 0x00ff) ? 0xff : (unsigned char)(usIPH_ACT_WID - usH_End);
 873   2              else 
 874   2                  delta = (usH_End - usIPH_ACT_WID > 0x00ff) ? 0xff : (unsigned char)(usH_End - usIPH_ACT_WID);
 875   2      
 876   2              //if (0xc0 < delta)       // The difference is too large to fine-tune.
 877   2              if((usIPH_ACT_WID/3) < delta)  //modified 2003/02/25
 878   2              {
 879   3                  return (usH_End < usIPH_ACT_WID) ? ERROR_TOO_SMALL : ERROR_TOO_BIG;
 880   3              }
 881   2              
 882   2              if (1 >= delta)     break;  // 1023,1024,1025,1026,1027
 883   2              
 884   2              delta   = delta + (delta >> 2);//& 0xfe;  // 4n number
 885   2              
 886   2              // Adjust Clock
 887   2              if (usH_End < usIPH_ACT_WID)    // delta < 0, Measure < Active
 888   2              {
 889   3                  if ((228 - stMUD.CLOCK) < delta)    return ERROR_TOO_SMALL;
 890   3          
 891   3                  stMUD.CLOCK  += delta;
 892   3                      
 893   3                  Set_Clock();
 894   3                  Set_H_Position();
 895   3              }
 896   2              else                            // delta >= 0, Measure >= Active
 897   2              {
 898   3                  if ((stMUD.CLOCK - 28) < delta)     return ERROR_TOO_BIG;
 899   3          
 900   3                  stMUD.CLOCK -= delta;
 901   3                      
 902   3                  Set_H_Position();
 903   3                  Set_Clock();
 904   3              }   
 905   2          }
 906   1          while (--count);
 907   1      
 908   1          if (0 == count)  return ERROR_TIMEOUT;
 909   1      
 910   1          stop    = 0;
 911   1      
C51 COMPILER V7.50   LCD_AUTO                                                              07/28/2008 16:10:51 PAGE 16  

 912   1          while (1)
 913   1          {
 914   2              count   = 0x10;     // Phase 4 ~ 28 step 4 (4,8,12,16,20,24,28)
 915   2              delta   = 0xff;
 916   2      
 917   2              while (1)
 918   2              {
 919   3                        
 920   3      
 921   3                  Set_Phase(count);
 922   3                  
 923   3                  // Measure usH_Start & usH_End
 924   3                  Result  = Measure_PositionH(NM);
 925   3      
 926   3                  if (ERROR_SUCCEED != (Result & 0x80))
 927   3                  {
 928   4                      if (ERROR_NOTACTIVE == Result)
 929   4                      {
 930   5                          // Input pattern is black/white vertical lines.
 931   5                          if (0x70 == count)
 932   5                          {
 933   6                              Set_Phase(stMUD.PHASE); // Restore phase
 934   6                              break;
 935   6                          }
 936   5                          else
 937   5                          {
 938   6                              count += 0x20;
 939   6                              continue;
 940   6                          }
 941   5                      }
 942   4      
 943   4                      Set_Phase(stMUD.PHASE); // Restore phase
 944   4      
 945   4                      return Result;
 946   4                  }
 947   3                  
 948   3                  usH_End = usH_End + 1 - usH_Start;
 949   3      
 950   3                  Result  = (usH_End < usIPH_ACT_WID)
 951   3                          ? 0x80 - (unsigned char)(usIPH_ACT_WID - usH_End)
 952   3                          : 0x80 + (unsigned char)(usH_End - usIPH_ACT_WID);
 953   3                  
 954   3                  if (Result < delta)
 955   3                  {
 956   4                      delta   = Result;       // Save the smallest width
 957   4                  }
 958   3      
 959   3                  if (0x70 == count)
 960   3                  {
 961   4                      Set_Phase(stMUD.PHASE); // Restore phase
 962   4                      break;
 963   4                  }
 964   3      
 965   3                  count += 0x10;
 966   3              }
 967   2              
 968   2              if (0x81 < delta)
 969   2              {
 970   3                  stMUD.CLOCK -= 1;
 971   3      
 972   3                  Set_H_Position();
 973   3                  Set_Clock();
C51 COMPILER V7.50   LCD_AUTO                                                              07/28/2008 16:10:51 PAGE 17  

 974   3      
 975   3                  stop    = 1;
 976   3              }
 977   2              else if (0x80 > delta)
 978   2              {
 979   3                  if (stop && (0x7f == delta))    break; 
 980   3      
 981   3                  stMUD.CLOCK += 1;
 982   3      
 983   3                  Set_Clock();
 984   3                  Set_H_Position();
 985   3      
 986   3                  if (stop)   break;
 987   3              }
 988   2              else    
 989   2                  break;
 990   2          }
 991   1      
 992   1              
 993   1          count = stMUD.PHASE;  // Record Current Phase
 994   1          start = stMUD.CLOCK ;
 995   1                  
 996   1              if(FindColor() != ERROR_SUCCEED) return ERROR_ABORT;
 997   1      // Set threshold
 998   1          RTDSetByte(DIFF_THRED_7E, 0x30);
 999   1      
1000   1              ulSum = GetMaxSum(1); //judge if pulse information large enough
1001   1          ulCompare = GetMaxSum(0);
1002   1      
1003   1              if((ulSum > 460000) || ((ulSum < 460000) && (ulCompare > 4000000)) )
1004   1              {
1005   2                      
1006   2                      ulCompare = 0;    
1007   2                      //    ulSum = 0;//GetMaxSum(0);
1008   2                      //////////////////////////////////////////////
1009   2                      if(0x80 < (start - 2) || 0x80 > start)
1010   2                      {
1011   3                              stMUD.CLOCK = 0x80;
1012   3                              Set_H_Position();
1013   3                              Set_Clock();
1014   3                              ulSum = GetMaxSum(0);
1015   3                              
1016   3                              if(ulCompare < ulSum)
1017   3                              {
1018   4                                      ulCompare = ulSum;
1019   4                                      Result = stMUD.CLOCK;
1020   4                              }
1021   3      
1022   3                              stMUD.CLOCK = start + 1;
1023   3                      }
1024   2                      else
1025   2                      {
1026   3                              stMUD.CLOCK = start;
1027   3                              Set_H_Position();
1028   3                              Set_Clock();
1029   3                              ulSum = GetMaxSum(0);
1030   3                      }
1031   2                      ////////////////////////////////////////////////
1032   2                      
1033   2                      while(1)
1034   2                      {
1035   3                              if(ulCompare < ulSum)
C51 COMPILER V7.50   LCD_AUTO                                                              07/28/2008 16:10:51 PAGE 18  

1036   3                              {
1037   4                                      ulCompare = ulSum;
1038   4                                      Result = stMUD.CLOCK;
1039   4                              }
1040   3                              if(stMUD.CLOCK == start - 2)
1041   3                                      break;    
1042   3      
1043   3                              stMUD.CLOCK -= 1;
1044   3                              Set_Clock();
1045   3                              Set_H_Position();
1046   3                              ulSum = GetMaxSum(0);        
1047   3                      }
1048   2                      stMUD.CLOCK = Result;
1049   2                      stMUD.PHASE = count;
1050   2                      Set_Clock();
1051   2                      Set_H_Position();
1052   2                      Set_Phase(stMUD.PHASE);
1053   2          }  
1054   1      
1055   1      
1056   1      #endif
1057   1          return (28 > stMUD.CLOCK) ? ERROR_TOO_BIG : (228 < stMUD.CLOCK) ? ERROR_TOO_SMALL : ERROR_SUCCEED;
1058   1      }
1059          
1060          //------------------------------------------------------------------//
1061          //                          Auto Position                           //
1062          //------------------------------------------------------------------//
1063          unsigned char Auto_Position(void)
1064          {
1065   1          unsigned char   Result, Curr_PosH, Curr_PosV;
1066   1      
1067   1          bAutoInProgress = 1;
1068   1      
1069   1          Curr_PosH   = stMUD.H_POSITION;     // Save current stMUD.H_POSITION
1070   1          Curr_PosV   = stMUD.V_POSITION;     // Save current stMUD.V_POSITION
1071   1      
1072   1          if (ucV_Max_Margin < stMUD.V_POSITION)
1073   1          {
1074   2              stMUD.V_POSITION    = ucV_Max_Margin;
1075   2              Set_V_Position();
1076   2          }
1077   1      
1078   1      //    RTDCodeW(ADC_DEFAULT);
1079   1      
1080   1          ///////////////////////////////
1081   1          //   Measure  NOISE_MARGIN   //
1082   1          ///////////////////////////////
1083   1          Result  = Min_Noise_Margin();
1084   1      
1085   1          if (ERROR_SUCCEED == (Result & 0x80))
1086   1          {   
1087   2              ///////////////////////////////
1088   2              //    Adjust (H/V)Position   //
1089   2              ///////////////////////////////
1090   2              Result  = Auto_Position_Do(Data[0]);    // Noise margin returned by Min_Noise_Margin() is saved in
             - Data[0];
1091   2          }
1092   1      
1093   1          if (ERROR_SUCCEED == (Result & 0x80))
1094   1          {
1095   2              Save_MUD(ucMode_Curr);
1096   2          }
C51 COMPILER V7.50   LCD_AUTO                                                              07/28/2008 16:10:51 PAGE 19  

1097   1          else
1098   1          {
1099   2              stMUD.H_POSITION    = Curr_PosH;
1100   2              stMUD.V_POSITION    = Curr_PosV;
1101   2      
1102   2              Set_H_Position();
1103   2              Set_V_Position();
1104   2          }
1105   1          
1106   1          // Restore ADC Gain/Offset
1107   1          SetADC_GainOffset();
1108   1      
1109   1          bAutoInProgress = 0;
1110   1      
1111   1          return Result;
1112   1      }
1113          
1114          //------------------------------------------------------------------//
1115          // Return Message => ERROR_SUCCESS   : Success                      //
1116          //                   ERROR_SUCCESS_1 : Vertical Start > Max         //
1117          //                   ERROR_SUCCESS_2 : Vertical Start < Min         //
1118          //                   ERROR_SUCCESS_4 : Vertical Start/End Fail      //
1119          //                   ERROR_SUCCESS_8 : Horizontal Start > Max       //
1120          //                   ERROR_SUCCESS_16: Horizontal Start < Min       //
1121          //                   ERROR_SUCCESS_32: Horizontal Start/End Fail    //
1122          //                   ERROR_INPUT     : 1. IVS or IHS changed        //

⌨️ 快捷键说明

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