C51 COMPILER V9.51   WHEEL_SLIDER                                                          06/07/2018 14:54:02 PAGE 1   


C51 COMPILER V9.51, COMPILATION OF MODULE WHEEL_SLIDER
OBJECT MODULE PLACED IN .\hex\wheel_slider.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE TS_Lib\Sources\wheel_slider.c OMF2 ROM(COMPACT) OPTIMIZE(9,SIZE) BROWSE DEB
                    -UG PRINT(.\lst\wheel_slider.lst) TABS(2) OBJECT(.\hex\wheel_slider.obj)

line level    source

   1          /*********************************************************************************************************
             -************/
   2          #include "ca51f_config.h"
   3          #include "includes\ca51f2sfr.h"
   4          #include "includes\ca51f2xsfr.h"
   5          #include "includes\gpiodef_f2.h"
   6          #include "Library\includes\uart.h"
   7          /*********************************************************************************************************
             -************/
   8          #include "TS_Lib\Includes\ts_configuration.h"
   9          #include "TS_Lib\Includes\ts_def.h"
  10          #include "TS_Lib\Includes\ts_api.h"
  11          #include "TS_Lib\Includes\ts_service.h"     
  12          /*********************************************************************************************************
             -************/
  13          code unsigned char *pXSFR[]=
  14            {
  15              &P70F,
  16              &P67F,
  17              &P66F,
  18              &P37F,
  19              &P36F,
  20              &P33F,
  21              &P32F,
  22              &P47F,
  23              &P46F,
  24              &P45F,
  25              &P44F,
  26              &P43F,
  27              &P42F,
  28              &P41F,
  29              &P40F,
  30              &P34F,
  31              &P35F,
  32              &P56F,
  33              &P50F,
  34              &P51F,
  35              &P52F,
  36              &P53F,
  37              &P54F,
  38              &P55F,
  39            };
  40          void TS_IO_init(void)
  41          {
  42   1        unsigned char i;
  43   1        unsigned char *pPinS;
  44   1        GPIO_Init(P57F,P57_CAP_SETTING);
  45   1        for(i = 0; i < TS_Cnt; i++)
  46   1        {
  47   2          pPinS = pXSFR[TS_CH[i]];
  48   2          *pPinS = OUTPUT;
  49   2        }
  50   1      }
  51          void TS_CfgPinFunc(unsigned char idx,unsigned char Func)
C51 COMPILER V9.51   WHEEL_SLIDER                                                          06/07/2018 14:54:02 PAGE 2   

  52          {
  53   1        unsigned char *pPinS;
  54   1        pPinS = pXSFR[TS_CH[idx]];
  55   1        *pPinS = Func;
  56   1      }
  57          void TS_DataFiltering(void)
  58          {
  59   1        unsigned char i;
  60   1        for(i = 0; i < TS_Cnt; i++)
  61   1        {
  62   2          TS_FilterBuf[i] -= TS_FilterBuf[i]/FilterCount;
  63   2          TS_FilterBuf[i] += TS_RawData[i];   
  64   2          TS_PostData[i]  = TS_FilterBuf[i]/FilterCount;                
  65   2        }   
  66   1      }
  67          void TS_RawDataCalibrate(unsigned int data1, unsigned int data2)
  68          {
  69   1        unsigned char i;
  70   1      
  71   1        for(i = 0; i < TS_Cnt; i++)
  72   1        {
  73   2          TS_RawData[i] = ((unsigned long int)TS_RawData[i]*(unsigned long int)data2)/data1;      
  74   2        } 
  75   1      }
  76          void TS_CheckRefCh(void)
  77          {
  78   1        int  Delta;
  79   1        int  DeltaCmp;
  80   1        unsigned char i;
  81   1        
  82   1        TS_RefFilterBuf -= TS_RefFilterBuf/FilterCount;
  83   1        TS_RefFilterBuf += TS_RefChRawData;   
  84   1        TS_RefPostData  = TS_RefFilterBuf/FilterCount;    
  85   1        Delta = (int)TS_RefPostData - (int)TS_RefChBaseLineData;  
  86   1        DeltaCmp = TS_RefChBaseLineData>>4;
  87   1        if(!TS_RefCHBaseLineAdjuTimer)
  88   1        {
  89   2          TS_RefCHBaseLineAdjuTimer = 2;
  90   2          if(Delta > 0)
  91   2          {
  92   3            TS_RefChBaseLineData++; 
  93   3          }
  94   2          else if(Delta < 0)
  95   2          {
  96   3            TS_RefChBaseLineData--; 
  97   3          }       
  98   2        }
  99   1        if((Delta >= DeltaCmp) || (Delta <= -DeltaCmp))
 100   1        {
 101   2          TS_ForbidTimer = 3;
 102   2          KeysFlagSN = 0;
 103   2          for(i = 0; i < Key_Cnt; i++)
 104   2          {
 105   3            TS_FirstAreaData[i] = TS_BaseLineData[i];
 106   3            TS_AreaConfirmTimerSet(i,AREA_PNOISE);      
 107   3          }
 108   2        }
 109   1        else
 110   1        {
 111   2          TS_RawDataCalibrate(TS_RefPostData,TS_RefChBaseLineData); 
 112   2        }
 113   1      }
C51 COMPILER V9.51   WHEEL_SLIDER                                                          06/07/2018 14:54:02 PAGE 3   

 114          unsigned char TS_GetDataArea(unsigned char ts_ch,unsigned int ts_data)
 115          {
 116   1        #define NOISE_THRESHOLD_RATE              15    //噪声门限值比率，当数据变化量在此范围内，视为噪声
 117   1        int Delta;
 118   1        int NoiseThd,FingerThd;
 119   1        
 120   1        Delta   = (int)TS_BaseLineData[ts_ch] - (int)ts_data;
 121   1        FingerThd = TSKey_FingerThd[ts_ch];   
 122   1        if(KeysFlagSN & MASK_TAB[ts_ch])
 123   1        {
 124   2          FingerThd = (FingerThd*80)/100; 
 125   2        }
 126   1        NoiseThd  =   (TSKey_FingerThd[ts_ch]*NOISE_THRESHOLD_RATE)/100;  
 127   1        
 128   1        if(Delta >= FingerThd)  return AREA_FINGER_TOUCH; 
 129   1        else if(Delta > NoiseThd) return AREA_PNOISE_PLUS; 
 130   1        else if(Delta >= 0)     return AREA_PNOISE;
 131   1        else if(Delta >= -NoiseThd) return AREA_NNOISE;
 132   1        else            return AREA_OVER_LOW;
 133   1      }
 134          unsigned char TS_AreaDeviateDetection(  unsigned char ts_ch,unsigned int cmp_data,unsigned int real_data)
 135          { 
 136   1        #define AREA_PERMITTED_DEVIATION_RATE     15 
 137   1        int Delta,permit_devia;
 138   1        permit_devia = (TSKey_FingerThd[ts_ch]*AREA_PERMITTED_DEVIATION_RATE)/100;
 139   1        Delta   = (int)cmp_data - (int)real_data;
 140   1        if((Delta <= permit_devia) && (Delta >= -permit_devia))
 141   1        {
 142   2          return 1;
 143   2        }
 144   1        else
 145   1        {
 146   2          return 0; 
 147   2        }   
 148   1      }
 149          void TS_AreaConfirmTimerSet(unsigned char ts_ch, unsigned char area)
 150          {
 151   1        switch(area)
 152   1        {
 153   2          case AREA_FINGER_TOUCH:
 154   2            TS_AreaConfirmTimer[ts_ch] = FingerTouchConfirmTime;
 155   2            break;
 156   2          case AREA_PNOISE_PLUS:
 157   2            TS_AreaConfirmTimer[ts_ch] = AreaPnosePlusConfirmTime;
 158   2            break;
 159   2          case AREA_PNOISE:
 160   2            TS_AreaConfirmTimer[ts_ch] = AreaPnoseConfirmTime;
 161   2            break;
 162   2          case AREA_NNOISE:
 163   2            TS_AreaConfirmTimer[ts_ch] = AreaNnoseConfirmTime;
 164   2            break;
 165   2          case AREA_OVER_LOW:
 166   2            TS_AreaConfirmTimer[ts_ch] = AreaOverLowConfirmTime;
 167   2            break;
 168   2          default:
 169   2            break;
 170   2        }
 171   1      }
 172          void SetWheelSliderRefCh(void)
 173          {
 174   1        unsigned char num,i,j;
 175   1        unsigned int MinVal;
C51 COMPILER V9.51   WHEEL_SLIDER                                                          06/07/2018 14:54:02 PAGE 4   

 176   1        TS_BaseCh = Key_Cnt; 
 177   1        for(num = 0; num < WHEEL_SLIDER_COUNT; num++)
 178   1        {
 179   2          MinVal = 0xFFFF;
 180   2          for(i = TS_BaseCh,j=0; i < TS_BaseCh + SLIDER_CH_COUNT[num]; i++,j++)
 181   2          {
 182   3            if(TS_BaseLineData[i] < MinVal)
 183   3            {
 184   4              WheelSliderRefCh[num] = j;
 185   4              MinVal = TS_BaseLineData[i];
 186   4            }
 187   3          }
 188   2          TS_BaseCh += SLIDER_CH_COUNT[num];
 189   2        } 
 190   1      }
 191          int WheelSliderTouchJudge(unsigned char num)
 192          {
 193   1        unsigned char i;
 194   1        unsigned long int CalcTemp1;
 195   1        unsigned int CalcTemp2,CalcTemp3;
 196   1        unsigned char DeltaRate;
 197   1        int  Delta;
 198   1        unsigned int  MaxDelta1,MaxDelta2/*,MaxDelta3*/;
 199   1        unsigned char Maxidx1,Maxidx2/*,Maxidx3*/;
 200   1        int Position,PosOffset;
 201   1        unsigned char *pMinRate;
 202   1        
 203   1        pMinRate = WHEEL_SLIDER_MIN_RATE[num];
 204   1        MaxDelta1 = MaxDelta2 = /*MaxDelta3 =*/ 0;
 205   1      
 206   1      /*  
 207   1        if(num == PRINT_CH)
 208   1        {
 209   1          Uart0_PutChar(0xaa);
 210   1          for(i = 0; i < SLIDER_CH_COUNT[num]; i++) 
 211   1          {
 212   1            Uart0_PutChar(TS_PostData[TS_BaseCh + i]>>8);
 213   1            Uart0_PutChar(TS_PostData[TS_BaseCh + i]);
 214   1            Uart0_PutChar(TS_BaseLineData[TS_BaseCh + i]>>8);
 215   1            Uart0_PutChar(TS_BaseLineData[TS_BaseCh + i]);    
 216   1          }   
 217   1        }
 218   1      */
 219   1      #if PRINT_WHEEL_SLIDER_DATA_EN
                if(num == PRINT_WHEEL_SLIDER_NUM)
                {
                  Uart0_PutChar(0xaa);
                  for(i = TS_BaseCh; i < TS_BaseCh + SLIDER_CH_COUNT[num]; i++)
                  {           
                    Delta   = (int)TS_BaseLineData[i] - (int)TS_PostData[i];      
                    Uart0_PutChar(i);
                    Uart0_PutChar(TS_PostData[i]>>8);
                    Uart0_PutChar(TS_PostData[i]);      
                    Uart0_PutChar(TS_BaseLineData[i]>>8);
                    Uart0_PutChar(TS_BaseLineData[i]);  
                    if(Delta < 0)
                    {
                      Uart0_PutChar(0);
                      Uart0_PutChar(0);
                    }
                    else
                    {
C51 COMPILER V9.51   WHEEL_SLIDER                                                          06/07/2018 14:54:02 PAGE 5   

                      Uart0_PutChar(Delta>>8);  
                      Uart0_PutChar(Delta);         
                    }         
                  }       
                }
              #endif
 244   1        for(i = 0; i < SLIDER_CH_COUNT[num]; i++) 
 245   1        { 
 246   2          if(i == WheelSliderRefCh[num])  
 247   2          {
 248   3            Delta     =   (int)TS_BaseLineData[TS_BaseCh + WheelSliderRefCh[num]] - (int)TS_PostData[TS_BaseCh + Wheel
             -SliderRefCh[num]];  
 249   3          }
 250   2          else
 251   2          {
 252   3            CalcTemp1 =   (unsigned long int)TS_PostData[TS_BaseCh + i] * (unsigned long int)TS_BaseLineData[TS_Base
             -Ch + WheelSliderRefCh[num]];
 253   3            CalcTemp2 =   (unsigned int)(CalcTemp1/TS_BaseLineData[TS_BaseCh + i]);
 254   3            CalcTemp3 =   TS_PostData[TS_BaseCh + i] + TS_BaseLineData[TS_BaseCh + WheelSliderRefCh[num]] - CalcTemp
             -2;
 255   3            CalcTemp2 =   (unsigned int)(CalcTemp1/CalcTemp3);  
 256   3            Delta     =   (int)TS_BaseLineData[TS_BaseCh + WheelSliderRefCh[num]] - (int)CalcTemp2;         
 257   3          }
 258   2          if(Delta < 0) Delta = 0;
 259   2      /*    
 260   2          if(num == PRINT_CH)
 261   2          {
 262   2            Uart0_PutChar(Delta); 
 263   2          }
 264   2      */    
 265   2          
 266   2          if(Delta > MaxDelta1)
 267   2          {
 268   3      //      Maxidx3 = Maxidx2;  MaxDelta3 = MaxDelta2;
 269   3            Maxidx2 = Maxidx1;  MaxDelta2 = MaxDelta1;
 270   3            Maxidx1 = i;        MaxDelta1 = Delta;
 271   3          }
 272   2          else if(Delta > MaxDelta2)
 273   2          {
 274   3      //      Maxidx3 = Maxidx2;  MaxDelta3 = MaxDelta2;
 275   3            Maxidx2 = i;        MaxDelta2 = Delta;
 276   3          }
 277   2      //    else if(Delta > MaxDelta3)
 278   2      //    {
 279   2      //      Maxidx3 = i;        MaxDelta3 = Delta;
 280   2      //    }
 281   2        }
 282   1        if((WHEEL_OR_SLIDER_DEF[num] == SLIDER)&&((Maxidx1 == 0)||(Maxidx1 == (SLIDER_CH_COUNT[num]-1))))
 283   1        {
 284   2          if((MaxDelta1) < (WHEEL_SLIDER_TOUCH_THD[num]>>1))
 285   2          {
 286   3            return -1;
 287   3          }
 288   2        }
 289   1        else
 290   1        {
 291   2          if((MaxDelta1 + MaxDelta2) < WHEEL_SLIDER_TOUCH_THD[num])
 292   2          {
 293   3            return -1;
 294   3          }   
 295   2        }
 296   1      
C51 COMPILER V9.51   WHEEL_SLIDER                                                          06/07/2018 14:54:02 PAGE 6   

 297   1        Delta = MaxDelta1 - (WHEEL_SLIDER_TOUCH_THD[num]>>1);
 298   1        DeltaRate = (Delta*10)/MaxDelta1;
 299   1        if(DeltaRate > 31) DeltaRate = 31;
 300   1        
 301   1        CalcTemp2 = ((unsigned int)WHEEL_SLIDER_TOUCH_THD[num]*(32-DeltaRate))>>6;
 302   1        
 303   1        MaxDelta1 += CalcTemp2;
 304   1        MaxDelta2 += CalcTemp2;   
 305   1      
 306   1        DeltaRate = ((unsigned int)MaxDelta2<<7)/MaxDelta1;
 307   1        if(WheelSliderCapRateFilter[num] == 0)
 308   1        {
 309   2          WheelSliderCapRateFilter[num] = DeltaRate*WHEEL_SLIDER_POSITION_FILTER_COUNT;
 310   2        }
 311   1        else
 312   1        {
 313   2          WheelSliderCapRateFilter[num] -= WheelSliderCapRateFilter[num]/WHEEL_SLIDER_POSITION_FILTER_COUNT;
 314   2          WheelSliderCapRateFilter[num] += DeltaRate; 
 315   2        }
 316   1        DeltaRate = WheelSliderCapRateFilter[num]/WHEEL_SLIDER_POSITION_FILTER_COUNT;
 317   1      #if PRINT_WHEEL_SLIDER_RATE_EN
                  Uart0_PutChar(Maxidx1 + 0x30);  
                  Uart0_PutChar(' ');
                  
                  Uart0_PutChar(DeltaRate/100+0x30);    
                  Uart0_PutChar((DeltaRate%100)/10+0x30);   
                  Uart0_PutChar((DeltaRate%10)+0x30); 
                  Uart0_PutChar('\r');  
                  Uart0_PutChar('\n');  
              #endif
 327   1        
 328   1      
 329   1        if(WHEEL_OR_SLIDER_DEF[num] == SLIDER)
 330   1        {
 331   2          Position = Maxidx1*64;
 332   2          if(Maxidx1 == 0)
 333   2          {
 334   3            if(DeltaRate < pMinRate[0])
 335   3            {
 336   4              DeltaRate = pMinRate[0];
 337   4            }
 338   3            Position = ((DeltaRate - pMinRate[0])*32)/(128-pMinRate[0]);
 339   3          }
 340   2          else if(Maxidx1 == (SLIDER_CH_COUNT[num]-1))
 341   2          {
 342   3            if(DeltaRate < pMinRate[SLIDER_CH_COUNT[num]-1])
 343   3            {
 344   4              DeltaRate = pMinRate[SLIDER_CH_COUNT[num]-1];
 345   4            }
 346   3            Position -= ((DeltaRate - pMinRate[SLIDER_CH_COUNT[num]-1])*32)/(128-pMinRate[SLIDER_CH_COUNT[num]-1]);
 347   3          }
 348   2          else
 349   2          {
 350   3            if(DeltaRate < pMinRate[Maxidx1]) DeltaRate = pMinRate[Maxidx1];
 351   3            PosOffset = ((DeltaRate - pMinRate[Maxidx1])*32)/(128-pMinRate[Maxidx1]);
 352   3            if(Maxidx1 < Maxidx2)
 353   3            {
 354   4              Position += PosOffset;
 355   4            }
 356   3            else
 357   3            {
 358   4              Position -= PosOffset;
C51 COMPILER V9.51   WHEEL_SLIDER                                                          06/07/2018 14:54:02 PAGE 7   

 359   4            }
 360   3          }
 361   2      
 362   2        }
 363   1        else if(WHEEL_OR_SLIDER_DEF[num] == WHEEL)
 364   1        {
 365   2          bit dir_flag;
 366   2          Position = Maxidx1*64;
 367   2          if(DeltaRate < pMinRate[Maxidx1]) DeltaRate = pMinRate[Maxidx1];
 368   2          PosOffset = ((DeltaRate - pMinRate[Maxidx1])*32)/(128-pMinRate[Maxidx1]);
 369   2          
 370   2          if((Maxidx1 == 0) && (Maxidx2 == (SLIDER_CH_COUNT[num]-1))) dir_flag = 0;
 371   2          else if((Maxidx1 == (SLIDER_CH_COUNT[num]-1)) && (Maxidx2 == 0)) dir_flag = 1;
 372   2          else if(Maxidx1 < Maxidx2) dir_flag = 1;
 373   2          else dir_flag = 0;
 374   2          
 375   2          if(dir_flag)
 376   2          {
 377   3            Position += PosOffset;
 378   3          }
 379   2          else
 380   2          {
 381   3            if(Position == 0)
 382   3            {
 383   4              Position = SLIDER_CH_COUNT[num]*64-1;
 384   4            }
 385   3            Position -= PosOffset;
 386   3          }
 387   2      
 388   2        }
 389   1        return Position;
 390   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1933    ----
   CONSTANT SIZE    =     72    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      42
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       1
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
