C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 1   


C51 COMPILER V9.02, COMPILATION OF MODULE TS_API
OBJECT MODULE PLACED IN .\hex\ts_api.obj
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE TS_Lib\Sources\ts_api.c OMF2 ROM(COMPACT) OPTIMIZE(9,SIZE) BROWSE DEBUG PRI
                    -NT(.\lst\ts_api.lst) OBJECT(.\hex\ts_api.obj)

line level    source

   1          #ifndef _TK_API_C_
   2          #define _TK_API_C_
   3          
   4          /*********************************************************************************************************
             -************/
   5          #include "ca51f_config.h"
   6          #include "includes\ca51f2sfr.h"
   7          #include "includes\ca51f2xsfr.h"
   8          #include "includes\gpiodef_f2.h"
   9          
  10          #include "Library\Includes\rtc.h"               
  11          #include "Library\Includes\system_clock.h"              
  12          #include "Library\includes\uart.h"
  13          #include "includes\system.h"
  14          #include "Library\includes\adc.h"
  15          #include "Library\includes\delay.h"
  16          #include <intrins.h>
  17          /*********************************************************************************************************
             -************/
  18          #include "TS_Lib\Includes\ts_configuration.h"
  19          #include "TS_Lib\Includes\ts_def.h"
  20          #include "TS_Lib\Includes\ts_api.h"
  21          #include "TS_Lib\Includes\ts_service.h" 
  22          /*********************************************************************************************************
             -************/
  23          void Debug_init(void);
  24          void Debug_ParamLoad(void);
  25          
  26          #if SUPPORT_KEY
  27          code unsigned int TS_KEY_CH_INFO_SEQ[][2]=
  28          {
  29                  KEY_SEQ
  30          };
  31          #endif
  32          #if SUPPORT_WHEEL_SLIDER
              code unsigned char TS_WHEEL_SLIDER_CH_SEQ[]=
              {
                      WHEEL_SLIDER0_SEQ,
              };
              code unsigned char WHEEL_SLIDER0_MAX_MIN_TAB[]={WHEEL_SLIDER0_CH_MIN_RATE};
              #else
  39          code unsigned char WHEEL_SLIDER0_MAX_MIN_TAB[1]={0};
  40          #endif  
  41          #if SUPPORT_KEY 
  42          code TYPE_SN MASK_TAB[]=
  43          {
  44                  0x000001,
  45          #if (KEY_CH_COUNT > 1)
  46                  0x000002,
  47          #endif
  48          #if (KEY_CH_COUNT > 2)
  49                  0x000004,
  50          #endif
  51          #if (KEY_CH_COUNT > 3)
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 2   

  52                  0x000008,
  53          #endif
  54          #if (KEY_CH_COUNT > 4)
  55                  0x000010,
  56          #endif
  57          #if (KEY_CH_COUNT > 5)
  58                  0x000020,
  59          #endif
  60          #if (KEY_CH_COUNT > 6)
                      0x000040,
              #endif
  63          #if (KEY_CH_COUNT > 7)
                      0x000080,
              #endif
  66          #if (KEY_CH_COUNT > 8)
                      0x000100,
              #endif
  69          #if (KEY_CH_COUNT > 9)
                      0x000200,
              #endif
  72          #if (KEY_CH_COUNT > 10)
                      0x000400,
              #endif
  75          #if (KEY_CH_COUNT > 11)
                      0x000800,
              #endif
  78          #if (KEY_CH_COUNT > 12)
                      0x001000,
              #endif
  81          #if (KEY_CH_COUNT > 13)
                      0x002000,
              #endif
  84          #if (KEY_CH_COUNT > 14)
                      0x004000,
              #endif
  87          #if (KEY_CH_COUNT > 15)
                      0x008000,
              #endif
  90          #if (KEY_CH_COUNT > 16)
                      0x010000,
              #endif
  93          #if (KEY_CH_COUNT > 17)
                      0x020000,
              #endif
  96          #if (KEY_CH_COUNT > 18)
                      0x040000,
              #endif
  99          #if (KEY_CH_COUNT > 19)
                      0x080000,
              #endif
 102          #if (KEY_CH_COUNT > 20)
                      0x100000,
              #endif
 105          #if (KEY_CH_COUNT > 21)
                      0x200000,
              #endif
 108          #if (KEY_CH_COUNT > 22)
                      0x400000,
              #endif
 111          #if (KEY_CH_COUNT > 23)
                      0x800000,
              #endif
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 3   

 114          
 115          };
 116          code unsigned char AREA_CONFIRM_TIME_TAB[]=
 117          {
 118                  FINGER_TOUCH_CONFIRM_TIME,
 119                  AREA_PNOISE_PLUS_CONFIRM_TIME,
 120                  AREA_PNOISE_CONFIRM_TIME,
 121                  AREA_NNOISE_CONFIRM_TIME,
 122                  AREA_OVERLOW_CONFIRM_TIME,
 123          };
 124          #else
              code unsigned char AREA_CONFIRM_TIME_TAB[1]={0};
              code unsigned long int MASK_TAB[1]={0};
              #endif
 128          void TS_MS_ISR (void)
 129          {
 130   1              static unsigned char xdata ms_cnt = 0;
 131   1              unsigned char i;
 132   1       
 133   1              ms_cnt++;
 134   1              if(ms_cnt >= 4)
 135   1              {
 136   2                      ms_cnt = 0;
 137   2                      for(i = 0; i < TS_Cnt; i++)
 138   2                      {
 139   3                              if(TS_AreaConfirmTimer[i])
 140   3                              {
 141   4                                      TS_AreaConfirmTimer[i]--;
 142   4                              }
 143   3                      }
 144   2      #if SUPPORT_WHEEL_SLIDER        
                              if(TSWheelSlider_TouchConfirmTimer)
                              {
                                      TSWheelSlider_TouchConfirmTimer--;
                              }
              #endif
 150   2      #if SUPPORT_KEY
 151   2      #if SUPPORT_COVER_PANAL_AFTER_POWERON
                              if(PanalCoverJudgeTimer) PanalCoverJudgeTimer--;
              #endif
 154   2      #endif
 155   2      #if SUPPORT_KEY
 156   2      #if ANTI_SPEAKER_EN
                              if(RefChDataTimer) RefChDataTimer--;
              #endif
 159   2      #endif
 160   2              }       
 161   1      }
 162          void TS_HS_ISR (void)
 163          {
 164   1      #if SUPPORT_KEY
 165   1      #if (FINGER_LONG_TOUCH_TIME_LIMIT > 0)
 166   1              unsigned char i;
 167   1      #endif
 168   1      #endif
 169   1              TS_HalfSecCnt++;
 170   1      #if SUPPORT_TOUCH_SLEEP_MODE
                      if(TS_SleepMode)
                      {
                              return;
                      }
              #endif
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 4   

 176   1      #if SUPPORT_KEY
 177   1      #if (FINGER_LONG_TOUCH_TIME_LIMIT > 0)
 178   1              for(i = 0; i < KEY_CH_COUNT; i++)
 179   1              {
 180   2                      if(TSKey_LongTouchLimitTimer[i])
 181   2                      {
 182   3                              TSKey_LongTouchLimitTimer[i]--;
 183   3                      }
 184   2              }               
 185   1      #endif
 186   1      #endif
 187   1      #if SUPPORT_WHEEL_SLIDER        
              #if (WHEEL_SLIDER_LONG_TOUCH_TIME_LIMIT > 0)
                      if(TSWheelSlider_LongTouchLimitTimer)
                      {
                              TSWheelSlider_LongTouchLimitTimer--;
                      }
              #endif
              #endif
 195   1              if(EnterStopScanTimer)
 196   1              {
 197   2                      EnterStopScanTimer--;
 198   2              }       
 199   1      }
 200          void TS_ISR (void)
 201          {       
 202   1              unsigned char index_copy,i;
 203   1              WORD_UNION TS_Data[6];
 204   1              if(TLFLG & (TLERR|TLKOV|TLLOV))
 205   1              {
 206   2                      TLFLG |= TLERR|TLKOV|TLLOV;
 207   2              }
 208   1              index_copy = INDEX;
 209   1              for(i = 0; i < 6; i++)
 210   1              {
 211   2                      if(TKIF & (1<<i))
 212   2                      {
 213   3                              TKIF = (1<<i);  
 214   3                              INDEX = i;
 215   3                              TS_Data[i].bVal[0] = TKMSH;
 216   3                              TS_Data[i].bVal[1] = TKMSL;
 217   3                      }
 218   2              }
 219   1              for(i = 0; i < 6; i++)
 220   1              {
 221   2      #if (TS_ACQ_TIMES == 1)
 222   2                      TS_RawData[TS_Index+i] = TS_Data[i].wVal;
 223   2      #else
                              TS_DataSum[TS_Index+i] += TS_Data[i].wVal;      
              #endif          
 226   2                      if(TS_Index+i == TS_Cnt)
 227   2                      {                       
 228   3                              break;
 229   3                      }       
 230   2              }
 231   1              if(TS_Index+6 > TS_Cnt)
 232   1              {
 233   2      #if (TS_ACQ_TIMES == 1)
 234   2                      TS_CycleScanDoneFlag = 1;       
 235   2      #else
                              TS_Acq_Counter++;
                              if(TS_Acq_Counter >= TS_ACQ_TIMES)
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 5   

                              {
                                      for(i = 0; i < TS_Cnt+1; i++)
                                      {
                                              TS_RawData[i] = TS_DataSum[i];
                                              TS_DataSum[i] = 0;
                                      }
                                      TS_CycleScanDoneFlag = 1;               
                                      TS_Acq_Counter = 0;
                              }       
              #endif          
 248   2                      TS_Index = 0;
 249   2              }
 250   1              else 
 251   1              {
 252   2                      TS_Index += 6;
 253   2              }
 254   1              TS_ScanStart(); 
 255   1              if(TS_HalfSecCnt) TS_HalfSecCnt--;
 256   1              if(MainLoopCnt1 != MainLoopCnt2)
 257   1              {
 258   2                      MainLoopCnt2 = MainLoopCnt1;
 259   2                      WDFLG = 0xA5;
 260   2              }
 261   1              INDEX = index_copy;
 262   1      }
 263          void TS_DataFiltering(void)
 264          {
 265   1              unsigned char i;
 266   1      #if (FILTER_COUNT > 1)
 267   1              unsigned char j;
 268   1              unsigned int DataSum,DataMax,DataMin;
 269   1      #endif
 270   1              for(i = 0; i < TS_Cnt+1; i++)
 271   1              {
 272   2      #if (FILTER_COUNT == 1)
                              TS_PostData[i] = TS_RawData[i];
              #else
 275   2                      TS_FilterPosIdx[i]++;
 276   2                      if(TS_FilterPosIdx[i] >= FILTER_COUNT) 
 277   2                      {
 278   3                              TS_FilterPosIdx[i] = 0;
 279   3                      }
 280   2                      INT3EN = 0;
 281   2                      TS_FilterBuf[i][TS_FilterPosIdx[i]] = TS_RawData[i];
 282   2                      INT3EN = 1; 
 283   2                      
 284   2                      DataSum = 0;
 285   2                      DataMax = 0;
 286   2                      DataMin = 0xFFFF;
 287   2                      for(j = 0; j < FILTER_COUNT; j++)
 288   2                      {
 289   3                              DataSum += TS_FilterBuf[i][j];
 290   3      #if (FILTER_COUNT > 2)
 291   3                              if(TS_FilterBuf[i][j] > DataMax)
 292   3                              {
 293   4                                      DataMax = TS_FilterBuf[i][j];
 294   4                              }
 295   3                              if(TS_FilterBuf[i][j] < DataMin)
 296   3                              {
 297   4                                      DataMin = TS_FilterBuf[i][j];
 298   4                              }
 299   3      #endif
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 6   

 300   3                      }
 301   2      #if (FILTER_COUNT == 2)
                              TS_PostData[i] = (DataSum)/(FILTER_COUNT);      
              #else
 304   2                      TS_PostData[i] = (DataSum - DataMax - DataMin)/(FILTER_COUNT-2);        
 305   2      #endif
 306   2      #endif          
 307   2              }               
 308   1      }
 309          #if SUPPORT_KEY
 310          #if ANTI_SPEAKER_EN
              bit TS_RefChAbnormalJudge(void)
              {
                      unsigned int ref_value,crt_value,delta;
                      
                      if(RefChDataBufIdx == (REF_CH_DATA_BUF_SIZE-1)) 
                      {
                              ref_value = RefChDataBuf[0];
                      }
                      else
                      {
                              ref_value = RefChDataBuf[RefChDataBufIdx + 1];
                      }
                      crt_value = TS_PostData[OPENED_TS_COUNT];
                      if(ref_value > crt_value)
                      {
                              delta = ref_value - crt_value;
                      }
                      else
                      {
                              delta = crt_value - ref_value;
                      }
                      if(delta >= REF_CH_ABNORMAL_THD)                        
                      {
                              return 1;
                      }
                      else
                      {
                              return 0;
                      }
              }
              void TS_RefChCheck(void)
              {
                      if(!RefChDataTimer)
                      {
                              RefChDataTimer = 3;
                              RefChDataBufIdx++;
                              if(RefChDataBufIdx >= REF_CH_DATA_BUF_SIZE)
                              {
                                      RefChDataBufIdx = 0;
                              }
                              RefChDataBuf[RefChDataBufIdx] = TS_PostData[OPENED_TS_COUNT];
                      }       
              }
              #endif
 355          #endif
 356          #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
              unsigned char GetSensAutoTrimRefCH(unsigned int *baseLine)
              {
                      unsigned char i,idx;
                      unsigned int min = 0xffff;
                      for(i = 0; i < TS_Cnt; i++)
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 7   

                      {
                              if(baseLine[i] < min)
                              {
                                      min = baseLine[i];
                                      idx = i;
                              }
                      }
                      return idx;
              }
              #endif
 372          void TS_RunInit(void)
 373          {
 374   1              unsigned char i,j;
 375   1              static unsigned char TS_ScanTimes=0;
 376   1      #if (POWER_ON_WAIT_TK_STABLE_EN)
                      static unsigned char TS_Init_Step_Sub;
                      int TS_Noise_Threshold;
              #endif
 380   1              if(TS_Init_Step == 0)
 381   1              {
 382   2      #if (TS_ACQ_TIMES > 1)
                              for(i = 0; i < TS_Cnt; i++)
                              {       
                                      TS_DataSum[i] = 0;
                              }
                              TS_Acq_Counter = 0;
              #endif
 389   2                      TS_CycleScanDoneFlag = 0;
 390   2                      TS_HalfSecCnt = 0;
 391   2                      TS_Index = 0;
 392   2                      TS_ScanStart(); 
 393   2      #if POWER_ON_WAIT_TK_STABLE_EN
                              TS_Init_Step = 1;               
                              TS_Init_Step_Sub = 0;
                              TS_ScanTimes = 5;
              #else
 398   2                      TS_Init_Step = 2;
 399   2                      TS_ScanTimes = 50;                      
 400   2      #endif
 401   2              }
 402   1      #if POWER_ON_WAIT_TK_STABLE_EN
                      else if(TS_Init_Step == 1)
                      {
                              if(TS_CycleScanDoneFlag)
                              {
                                      TS_CycleScanDoneFlag = 0;
                                      MainLoopCnt1 = MainLoopCnt2 + 1;
                                      if(TS_Init_Step_Sub == 0)
                                      {
                                              if(--TS_ScanTimes)
                                              {                               
                                                      return;
                                              }
                                              for(i = 0; i < TS_Cnt+1; i++)
                                              {
                                                      TS_PostData[i] = TS_RawData[i];
                                              }
                                              TS_Init_Step_Sub = 1;
                                              TS_AreaConfirmTimer[0] = 40;
                                      }                       
                                      else if(TS_Init_Step_Sub == 1)
                                      {
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 8   

                                              if(!TS_AreaConfirmTimer[0])
                                              {
                                                      int delta;
                                                      for(i = 0; i < TS_Cnt; i++)
                                                      {
                                                              delta = (int)TS_PostData[i] - (int)TS_RawData[i];
                                                      #if (SUPPORT_KEY && SUPPORT_WHEEL_SLIDER)
                                                              if(i < KEY_CH_COUNT)
                                                              {
                                                                      TS_Noise_Threshold = (int)(TS_KEY_CH_INFO_SEQ[i][1]/2);
                                                              }
                                                              else
                                                              {
                                                                      TS_Noise_Threshold = (int)(WHEEL_SLIDER0_TOUCH_THD/2);
                                                              }
                                                      #elif SUPPORT_KEY
                                                              TS_Noise_Threshold = (int)(TS_KEY_CH_INFO_SEQ[i][1]/2);                         
                                                      #elif SUPPORT_WHEEL_SLIDER
                                                              TS_Noise_Threshold = (int)(WHEEL_SLIDER0_TOUCH_THD/2);
                                                      #endif
                                                              if((delta > TS_Noise_Threshold) || (delta < -TS_Noise_Threshold))
                                                              {
                                                                      TS_Init_Step_Sub = 0;
                                                                      return;
                                                              }
                                                      }                       
                                                      TS_Init_Step = 2;
                                                      TS_ScanTimes = 10;      
                                              }
                                      }
                              }
                      }
              #endif
 457   1              else if(TS_Init_Step == 2)
 458   1              {
 459   2                      if(TS_CycleScanDoneFlag)
 460   2                      {
 461   3                              TS_CycleScanDoneFlag = 0;
 462   3                              if(--TS_ScanTimes)
 463   3                              {                               
 464   4                                      return;
 465   4                              }
 466   3                              for(i = 0; i < TS_Cnt+1; i++)
 467   3                              {       
 468   4                                      for(j = 0; j < FILTER_COUNT; j++)
 469   4                                      {
 470   5                                              TS_FilterBuf[i][j] = TS_RawData[i];
 471   5                                      }
 472   4                                      TS_FilterPosIdx[i] = 0;
 473   4                                      
 474   4                                      if(i == TS_Cnt) break;
 475   4                                      TS_BaseLineData[i] = TS_RawData[i];                     
 476   4                                      TS_FirstAreaData[i] = TS_RawData[i]; 
 477   4      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                                              TS_PostData2[i] = TS_RawData[i];
              #endif                          
 480   4      #if TK_BASE_TRIM_WHILE_KEY_PRESSED
 481   4                                      RefChDataBak[i] = TS_RawData[OPENED_TS_COUNT];
 482   4                                      TS_BaseLineDataBak[i] = TS_BaseLineData[i];
 483   4      #endif                                  
 484   4                                      
 485   4      #if (SUPPORT_KEY && SUPPORT_WHEEL_SLIDER)
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 9   

                                              if(i < KEY_CH_COUNT)
                                              {
                                                      TSKey_FingerThd[i] = TS_KEY_CH_INFO_SEQ[i][1];
                                                      TS_AreaConfirmTimerSet(i,AREA_PNOISE);
                                              }
                                              else
                                              {
                                                      TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
                                              }
              #elif SUPPORT_KEY
 496   4                                      TSKey_FingerThd[i] = TS_KEY_CH_INFO_SEQ[i][1];
 497   4                                      TS_AreaConfirmTimerSet(i,AREA_PNOISE);                          
 498   4      #elif SUPPORT_WHEEL_SLIDER
                                              TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
              #endif
 501   4                              }       
 502   3      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                                      SensAutoTrimRefCH = GetSensAutoTrimRefCH(TS_BaseLineData);
              #endif
 505   3      #if SUPPORT_KEY
 506   3      #if ANTI_SPEAKER_EN
                                      for(i = 0; i < REF_CH_DATA_BUF_SIZE; i++)
                                      {
                                              RefChDataBuf[i] = TS_PostData[OPENED_TS_COUNT];
                                      }
                                      RefChDataBufIdx = 0;
              #endif          
 513   3      #endif                  
 514   3      #if (DEBUG)
                                      Debug_ParamLoad();
              #endif          
 517   3                              TS_State = TS_DEAL;     
 518   3                      }
 519   2              }
 520   1      }
 521          #if SUPPORT_KEY
 522          #if SUPPORT_ANTI_WATER_FUNCTION
              unsigned char AntiWaterModeGetMaxDeltaCh(void)
              {
                      unsigned char i;
                      unsigned long int CalcTemp1;
                      unsigned int CalcTemp2,CalcTemp3;
                      int Delta;
                      int max_delta;
                      char max_index;
                      max_delta = 0;
                      for(i = 0; i < KEY_CH_COUNT; i++)
                      {
                              if(i == 0)
                              {
                                      Delta = (int)TS_BaseLineData[i] - (int)TS_PostData[i];
                              }
                              else
                              {
                                      CalcTemp1 =     (unsigned long int)TS_PostData[i] * (unsigned long int)TS_BaseLineData[0];
                                      CalcTemp2 =     (unsigned int)(CalcTemp1/TS_BaseLineData[i]);
                                      CalcTemp3 =     TS_PostData[i] + TS_BaseLineData[0] - CalcTemp2;
                                      CalcTemp2 =     (unsigned int)(CalcTemp1/CalcTemp3);    
                                      Delta           =       (int)TS_BaseLineData[0] - (int)CalcTemp2;                                               
                              }
                              if(max_delta < Delta)
                              {
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 10  

                                      max_delta = Delta;
                                      max_index = i;
                              }
                      }
                      return max_index;
              }
              #endif
 555          #endif
 556          #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
              int GetTouchDiffer(unsigned int touchData,unsigned int touchBase,unsigned int baseRef)
              {
                      unsigned long int CalcTemp1;
                      unsigned int CalcTemp2,CalcTemp3;
                      int Delta;
              
                      CalcTemp1 =     (unsigned long int)touchData * (unsigned long int)baseRef;
                      CalcTemp2 =     (unsigned int)(CalcTemp1/touchBase);
                      CalcTemp3 =     touchData + baseRef - CalcTemp2;
                      CalcTemp2 =     (unsigned int)(CalcTemp1/CalcTemp3);    
                      Delta           =       (int)baseRef - (int)CalcTemp2;                                          
              
                      return Delta;
              }
              #endif
 572          #if SUPPORT_KEY
 573          void TSKey_DataDeal(void)
 574          {
 575   1              unsigned char i;
 576   1              unsigned char  TouchArea,NowArea;               
 577   1      
 578   1      #if SUPPORT_COVER_PANAL_AFTER_POWERON
                      unsigned char PanalToggleCount = 0;
              #endif
 581   1              for(i = 0; i < KEY_CH_COUNT; i++)
 582   1              {       
 583   2      #if SUPPORT_ANTI_WATER_FUNCTION
                              if(KeyPressedFlag)
                              {
                                      if(PressedKeyIndex != i)
                                      {
              #if TK_BASE_TRIM_WHILE_KEY_PRESSED                                      
                                              TS_BaseLineData[i] = ((unsigned long int)TS_BaseLineDataBak[i]*TS_PostData[OPENED_TS_COUNT])/RefChData
             -Bak[i];
              #endif          
                                              TS_FirstAreaData[i] = TS_BaseLineData[i];
                                              TS_AreaConfirmTimerSet(i,AREA_PNOISE);          
                                              continue;               
                                      }
                              }
              #endif
 597   2      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                              if(SensAutoTrimRefCH == i)
                              {
                                      TS_PostData2[i] = TS_PostData[i];
                              }
                              else
                              {
                                      TS_PostData2[i] = (int)TS_BaseLineData[i] - GetTouchDiffer(TS_PostData[i],TS_BaseLineData[i],TS_BaseLin
             -eData[SensAutoTrimRefCH]);
                              }
              #endif
 607   2                      TouchArea = TS_GetDataArea(i,TS_FirstAreaData[i],TSKey_NoiseThreshold[i],(bit)(PreKeysFlagSN & MASK_TAB[
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 11  

             -i]));
 608   2      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                              NowArea   = TS_GetDataArea(i,TS_PostData2[i],TSKey_NoiseThreshold[i],(bit)(PreKeysFlagSN & MASK_TAB[i]))
             -;
              #else
 611   2                      NowArea   = TS_GetDataArea(i,TS_PostData[i],TSKey_NoiseThreshold[i],(bit)(PreKeysFlagSN & MASK_TAB[i]));
 612   2      #endif
 613   2                      
 614   2                      if((NowArea != AREA_PNOISE)&&(NowArea != AREA_NNOISE))
 615   2                      {
 616   3                              TS_StableFlag = 0;              
 617   3                      }
 618   2      #if SUPPORT_COVER_PANAL_AFTER_POWERON
                              if((NowArea == AREA_PNOISE_PLUS) || (NowArea == AREA_FINGER_TOUCH))
                              {
                                      PanalToggleCount++;
                              }
              #endif
 624   2                      if(TouchArea == AREA_FINGER_TOUCH)
 625   2                      {
 626   3                              if(NowArea == AREA_FINGER_TOUCH)
 627   3                              {
 628   4                                      if(!(PreKeysFlagSN & MASK_TAB[i]))
 629   4                                      {
 630   5                                              if(!TS_AreaConfirmTimer[i])
 631   5                                              {               
 632   6                                                      PreKeysFlagSN |= MASK_TAB[i];           
 633   6      #if (FINGER_LONG_TOUCH_TIME_LIMIT > 0)
 634   6                                                      TSKey_LongTouchLimitTimer[i] = FINGER_LONG_TOUCH_TIME_LIMIT;
 635   6      #endif
 636   6                                                      TS_AreaConfirmTimer[i] = FINGER_TOUCH_RELEASE_CONFIRM_TIME;     
 637   6                                              }
 638   5                                      }
 639   4                                      else
 640   4                                      {       
 641   5      #if SUPPORT_ANTI_WATER_FUNCTION         
                                                      if(i != AntiWaterModeGetMaxDeltaCh())
                                                      {
                                                              goto ANTI_WATER_MODE_KEY_RELEASE;
                                                      }
              #endif
 647   5      #if TK_BASE_TRIM_WHILE_KEY_PRESSED                                      
 648   5                                              TS_BaseLineData[i] = ((unsigned long int)TS_BaseLineDataBak[i]*TS_PostData[OPENED_TS_COUNT])/RefChDat
             -aBak[i];
 649   5      #endif          
 650   5                                              TS_AreaConfirmTimer[i] = FINGER_TOUCH_RELEASE_CONFIRM_TIME;
 651   5      #if (FINGER_LONG_TOUCH_TIME_LIMIT > 0)
 652   5                                              if(!TSKey_LongTouchLimitTimer[i])
 653   5                                              {
 654   6                                                      PreKeysFlagSN &= ~MASK_TAB[i];
 655   6                                                      TS_FirstAreaData[i] = TS_PostData[i];
 656   6                                                      TS_BaseLineData[i]      = TS_PostData[i];
 657   6                                                      TS_AreaConfirmTimerSet(i,AREA_PNOISE);          
 658   6      #if SUPPORT_ANTI_WATER_FUNCTION
                                                              KeyPressedFlag = 0;
                                                              break;
              #endif                                          
 662   6                                              }                                                       
 663   5      #endif                                  
 664   5                                      }                               
 665   4                              }
 666   3                              else
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 12  

 667   3                              {
 668   4                                      if(PreKeysFlagSN & MASK_TAB[i]) 
 669   4                                      {
 670   5                                              if(!TS_AreaConfirmTimer[i])
 671   5                                              {
 672   6      #if SUPPORT_ANTI_WATER_FUNCTION
              ANTI_WATER_MODE_KEY_RELEASE:                                            
                                                              KeyPressedFlag = 0;
              #endif
 676   6                                                      PreKeysFlagSN &= ~MASK_TAB[i];
 677   6      
 678   6                                                      TS_FirstAreaData[i] = TS_BaseLineData[i];
 679   6                                                      TS_AreaConfirmTimerSet(i,AREA_PNOISE);
 680   6      #if SUPPORT_ANTI_WATER_FUNCTION
                                                              break;
              #endif
 683   6                                              }                                       
 684   5                                      }                       
 685   4                                      else
 686   4                                      {
 687   5      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                                                      TS_FirstAreaData[i] = TS_PostData2[i];
              #else
 690   5                                              TS_FirstAreaData[i] = TS_PostData[i];
 691   5      #endif
 692   5                                              TS_AreaConfirmTimerSet(i,NowArea);
 693   5                                      }       
 694   4                              }       
 695   3                              continue;                                               
 696   3                      }       
 697   2                      else
 698   2                      {
 699   3                              if(NowArea == AREA_FINGER_TOUCH)
 700   3                              {
 701   4      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                                              TS_FirstAreaData[i] = TS_PostData2[i];
              #else
 704   4                                      TS_FirstAreaData[i] = TS_PostData[i];
 705   4      #endif
 706   4                                      TS_AreaConfirmTimerSet(i,AREA_FINGER_TOUCH);
 707   4                                      continue;               
 708   4                              }       
 709   3                              else                    
 710   3                              {
 711   4                                      if(PreKeysFlagSN & MASK_TAB[i]) 
 712   4                                      {
 713   5                                              PreKeysFlagSN &= ~MASK_TAB[i];
 714   5                                              TS_FirstAreaData[i] = TS_BaseLineData[i];
 715   5                                              TS_AreaConfirmTimerSet(i,AREA_PNOISE);                          
 716   5                                      }
 717   4                              }
 718   3                      }
 719   2                      if(PreKeysFlagSN != 0) 
 720   2                      {
 721   3                              TS_FirstAreaData[i] = TS_BaseLineData[i];
 722   3                              TS_AreaConfirmTimerSet(i,AREA_PNOISE);          
 723   3                              continue;                       
 724   3                      }
 725   2      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                              if(TS_AreaDeviateDetection(TS_FirstAreaData[i],TS_PostData2[i],TSKey_NoiseThreshold[i]))           //ÅÐ¶ÏÆ«²îÊÇ
             -·ñÔÚÔÊÐí·¶Î§ÄÚ
              #else
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 13  

 728   2                      if(TS_AreaDeviateDetection(TS_FirstAreaData[i],TS_PostData[i],TSKey_NoiseThreshold[i]))    //ÅÐ¶ÏÆ«²îÊÇ·
             -ñÔÚÔÊÐí·¶Î§ÄÚ
 729   2      #endif
 730   2                      {       
 731   3                              if(!TS_AreaConfirmTimer[i])
 732   3                              {
 733   4                                      TS_FirstAreaData[i] = TS_PostData[i];
 734   4                                      TS_BaseLineData[i]      = TS_PostData[i];
 735   4      #if TK_BASE_TRIM_WHILE_KEY_PRESSED
 736   4                                      RefChDataBak[i] = TS_PostData[OPENED_TS_COUNT];
 737   4                                      TS_BaseLineDataBak[i] = TS_BaseLineData[i];
 738   4      #endif                          
 739   4                                      TS_AreaConfirmTimerSet(i,AREA_PNOISE);  
 740   4                              }       
 741   3                      }
 742   2                      else
 743   2                      {
 744   3      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                                      TS_FirstAreaData[i] = TS_PostData2[i];  
              #else
 747   3                              TS_FirstAreaData[i] = TS_PostData[i];   
 748   3      #endif
 749   3                              TS_AreaConfirmTimerSet(i,NowArea);              
 750   3                      }
 751   2              }               
 752   1      #if SUPPORT_ANTI_WATER_FUNCTION
                      if(KeysFlagSN == 0)
                      {
                              if(PreKeysFlagSN != 0)
                              {
                                      PressedKeyIndex = AntiWaterModeGetMaxDeltaCh();
                                      PreKeysFlagSN = MASK_TAB[PressedKeyIndex];
              #if (FINGER_LONG_TOUCH_TIME_LIMIT > 0)
                                      TSKey_LongTouchLimitTimer[PressedKeyIndex] = FINGER_LONG_TOUCH_TIME_LIMIT;
              #endif
                                      TS_AreaConfirmTimer[PressedKeyIndex] = FINGER_TOUCH_RELEASE_CONFIRM_TIME;       
                                      KeyPressedFlag = 1;
                              }
                      }
              #endif
 767   1      #if SUPPORT_COVER_PANAL_AFTER_POWERON
                      if(!PanalCoverJudgeFlag)
                      {
                              if(PreKeysFlagSN != 0)
                              {
                                      if(KeysFlagSN == 0)
                                      {
                                              PanalCoverJudgeFlag = 1;
                                              PanalCoverJudgeTimer = PANAL_COVER_JUDGE_TIME;          
                                      }
                                      else
                                      {
                                      #if ANTI_SPEAKER_EN
                                              if((PanalToggleCount >= JUDGE_TK_NUM)||(TS_RefChAbnormalJudge()))
                                      #else
                                              if((PanalToggleCount >= JUDGE_TK_NUM))
                                      #endif
                                              {
                                                      PreKeysFlagSN = 0;
                                                      PanalCoverJudgeFlag = 0;
                                                      TS_BaseLineForceUpdate();
                                              }
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 14  

                                              KeysFlagSN  = PreKeysFlagSN;
                                      }
                              }
                              else
                              {
                                      KeysFlagSN  = PreKeysFlagSN;
                              }
                      }
                      else
                      {
                              if(!PanalCoverJudgeTimer)
                              {
                                      PanalCoverJudgeFlag = 0;
                                      KeysFlagSN = PreKeysFlagSN;
                              }
                              else
                              {
                              #if ANTI_SPEAKER_EN
                                      if((PanalToggleCount >= JUDGE_TK_NUM)||(TS_RefChAbnormalJudge()))
                              #else
                                      if((PanalToggleCount >= JUDGE_TK_NUM))
                              #endif          
                                      {
                                              PreKeysFlagSN = 0;
                                              PanalCoverJudgeFlag = 0;
                                              TS_BaseLineForceUpdate();
                                      }                       
                              }
                      }
              #else
 819   1      #if ANTI_SPEAKER_EN
                      if((PreKeysFlagSN != 0)&&(KeysFlagSN == 0))
                      {
                              if(TS_RefChAbnormalJudge())
                              {
                                      PreKeysFlagSN = 0;
                                      
              #if SUPPORT_ANTI_WATER_FUNCTION
                                      KeyPressedFlag = 0;
              #endif
                                      TS_BaseLineForceUpdate();               
                              }
                      }
              #endif
 833   1              KeysFlagSN  = PreKeysFlagSN;
 834   1      
 835   1      #endif
 836   1              if(KeysFlagSN != 0) 
 837   1              {
 838   2                      ActiveTouchType = 1;
 839   2              }
 840   1              else
 841   1              {
 842   2                      ActiveTouchType = 0;
 843   2              }
 844   1      }
 845          #endif
 846          #if SUPPORT_WHEEL_SLIDER
              void TS_WheelSliderDeal(void)
              {
                      unsigned char i;
                      unsigned int   Delta,Position;
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 15  

                      bit WheelSliderTogFlag = 0;
                      TS_BaseCh = KEY_CH_COUNT; 
                      if(!W_S_RefChSet)
                      {
                              W_S_RefChSet = 1;               
                              SetWheelSliderRefCh(WHEEL_SLIDER0_CH_COUNT);
                      }
                      
              #if PRINT_WHEEL_SLIDER_DATA_EN
                      TK_Debug_UartPutChar(0xaa);
                      for(i = TS_BaseCh; i < TS_BaseCh + WHEEL_SLIDER0_CH_COUNT; i++)
                      {                                               
                              if(TS_BaseLineData[i] > TS_PostData[i])
                              {
                                      Delta = (int)TS_BaseLineData[i] - (int)TS_PostData[i];  
                              }
                              else
                              {
                                      Delta = 0;
                              }                                               
                              TK_Debug_UartPutChar(i);
                              TK_Debug_UartPutChar(TS_PostData[i]>>8);
                              TK_Debug_UartPutChar(TS_PostData[i]);                   
                              TK_Debug_UartPutChar(TS_BaseLineData[i]>>8);
                              TK_Debug_UartPutChar(TS_BaseLineData[i]);       
                              TK_Debug_UartPutChar(Delta>>8); 
                              TK_Debug_UartPutChar(Delta);                                                            
                      }                               
              #endif
              #if (WHEEL_OR_SLIDER_DEF0       == SLIDER)
                      Position = SliderTouchJudge(WHEEL_SLIDER0_CH_COUNT,WHEEL_SLIDER0_TOUCH_THD);
              #elif (WHEEL_OR_SLIDER_DEF0     == WHEEL)
                      Position = WheelTouchJudge(WHEEL_SLIDER0_CH_COUNT,WHEEL_SLIDER0_TOUCH_THD);
              #endif
                      if(Position != -1)
                      {
                              TS_StableFlag = 0;
                      }
                      if(WheelSliderState == WHEEL_SLIDER_NO_TOUCH)
                      {
                              if(!WheelSliderTouchFlag)
                              {
                                      if(Position != -1)
                                      {
                                              WheelSliderTouchFlag = 1;       
                                              TSWheelSlider_TouchConfirmTimer = WHEEL_SLIDER_TOUCH_CONFIRM_TIME;                              
                                      }
                                      else
                                      {
                                              for(i = TS_BaseCh; i < TS_BaseCh + WHEEL_SLIDER0_CH_COUNT; i++)
                                              {                                               
                                                      if(TS_FirstAreaData[i] > TS_PostData[i]) 
                                                      {
                                                              Delta   = TS_FirstAreaData[i] - TS_PostData[i];
                                                      }
                                                      else
                                                      {
                                                              Delta   = TS_PostData[i] - TS_FirstAreaData[i];
                                                      }                                       
                                                      if(Delta <= WHEEL_SLIDER0_NOISE_THD) 
                                                      {
                                                              if(!TS_AreaConfirmTimer[i])
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 16  

                                                              {
                                                                      TS_FirstAreaData[i] = TS_PostData[i];
                                                                      TS_BaseLineData[i]      = TS_PostData[i];
                                                                      TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
                                                              }                                                       
                                                      }
                                                      else
                                                      {
                                                              TS_FirstAreaData[i] = TS_PostData[i];
                                                              TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
                                                      }
                                              }
                                      }                       
                              }       
                              else
                              {       
                                      if(Position != -1)
                                      {
                                              if(!TSWheelSlider_TouchConfirmTimer)
                                              {
                                                              WheelSliderState = WHEEL_SLIDER_TOUCH;  
              #if (WHEEL_SLIDER_LONG_TOUCH_TIME_LIMIT > 0)
                                                              TSWheelSlider_LongTouchLimitTimer = WHEEL_SLIDER_LONG_TOUCH_TIME_LIMIT;
              #endif
                                              }       
                                      }
                                      else
                                      {
                                              WheelSliderTouchFlag = 0;
                                              for(i = TS_BaseCh; i < TS_BaseCh + WHEEL_SLIDER0_CH_COUNT; i++)
                                              {
                                                      TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
                                              }
                                      }
                              }                               
                      }
                      else if(WheelSliderState == WHEEL_SLIDER_TOUCH)
                      {               
              #if (WHEEL_SLIDER_LONG_TOUCH_TIME_LIMIT > 0)
                              if(!TSWheelSlider_LongTouchLimitTimer)
                              {
                                      for(i = TS_BaseCh; i < TS_BaseCh + WHEEL_SLIDER0_CH_COUNT; i++)
                                      {
                                              TS_FirstAreaData[i] = TS_PostData[i];
                                              TS_BaseLineData[i]      = TS_PostData[i];
                                      }
                                      WheelSliderTouchFlag = 0;
                                      goto WHEEL_SLIDER_RELEASE;
                              }
              #endif
                              if(WheelSliderTouchFlag)
                              {
                                      if(Position == -1)      
                                      {
                                              WheelSliderTouchFlag = 0;
                                              TSWheelSlider_TouchConfirmTimer = WHEEL_SLIDER_TOUCH_RELEASE_CONFIRM_TIME;              
                                      }
                              }
                              else                                             
                              {
                                      if(Position == -1)      
                                      {
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 17  

                                              if(!TSWheelSlider_TouchConfirmTimer)
                                              {
              WHEEL_SLIDER_RELEASE:
                                                      WheelSliderState = WHEEL_SLIDER_NO_TOUCH;       
                                                      WheelSliderCapRateFilter = 0;
                                                      WheelSliderPosition = -1;
                                                      for(i = TS_BaseCh; i < TS_BaseCh + WHEEL_SLIDER0_CH_COUNT; i++)
                                                      {
                                                              TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
                                                      }
                                              }
                                      }
                                      else
                                      {
                                              WheelSliderTouchFlag = 1;                               
                                      }
                              }               
                      }               
                      if(WheelSliderState == WHEEL_SLIDER_TOUCH)
                      {
                              if(Position != -1)
                              {
                                      WheelSliderPosition = Position;
                              }       
              #if PRINT_WHEEL_SLIDER_POSITION_EN
                              TK_Debug_UartPutChar(WheelSliderPosition/100+0x30);             
                              TK_Debug_UartPutChar((WheelSliderPosition%100)/10+0x30);                
                              TK_Debug_UartPutChar((WheelSliderPosition%10)+0x30);    
              
                              TK_Debug_UartPutChar('\r');     
                              TK_Debug_UartPutChar('\n');     
              #endif
              #if PRINT_WHEEL_SLIDER_RATE_EN
                              {
                                      unsigned char DeltaRate;
                                      DeltaRate = WheelSliderCapRateFilter/4;
                                      TK_Debug_UartPutChar(WheelSliderMaxIdx + 0x30); 
                                      TK_Debug_UartPutChar(' ');
                                              
                                      TK_Debug_UartPutChar(DeltaRate/100+0x30);               
                                      TK_Debug_UartPutChar((DeltaRate%100)/10+0x30);          
                                      TK_Debug_UartPutChar((DeltaRate%10)+0x30);      
                                      TK_Debug_UartPutChar('\r');     
                                      TK_Debug_UartPutChar('\n');                                     
                              }
              #endif
                      }
                      else
                      {
                              WheelSliderPosition = -1;       
                      }
              
                      if(WheelSliderPosition != -1)
                      {
                              ActiveTouchType = 2;
                      }
                      else
                      {
                              ActiveTouchType = 0;
                      }
              }
              #endif  
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 18  

1037          void TS_init(void)
1038          {
1039   1              unsigned char i,ch_idx;
1040   1      #if (DEBUG)
                      Debug_init();
              #endif
1043   1      
1044   1              TS_Cnt          = OPENED_TS_COUNT;
1045   1              ch_idx = 0;
1046   1              for(i = 0;i < OPENED_TS_COUNT; i++)
1047   1              {
1048   2      #if (SUPPORT_KEY && SUPPORT_WHEEL_SLIDER)
                              if(i < KEY_CH_COUNT)
                              {
                                      TS_CH[ch_idx++] = TS_KEY_CH_INFO_SEQ[i][0];
                                      TSKey_NoiseThreshold[i] = (int)(((unsigned long int)TS_KEY_CH_INFO_SEQ[i][1]*TK_NOISE_THD_RATE)/100);
                              }
                              else
                              {
                                      TS_CH[ch_idx++] = TS_WHEEL_SLIDER_CH_SEQ[i-KEY_CH_COUNT];
                              }
              #elif SUPPORT_KEY
1059   2                      TS_CH[ch_idx++] = TS_KEY_CH_INFO_SEQ[i][0];
1060   2                      TSKey_NoiseThreshold[i] = (int)(((unsigned long int)TS_KEY_CH_INFO_SEQ[i][1]*TK_NOISE_THD_RATE)/100);
1061   2      #elif SUPPORT_WHEEL_SLIDER
                              TS_CH[ch_idx++] = TS_WHEEL_SLIDER_CH_SEQ[i];
              #endif
1064   2              }
1065   1              
1066   1      #if (RTC_CLK_SELECT == IRCL)
1067   1              CKCON |= ILCKE;
1068   1              CKSEL |= RTCKS(1);
1069   1      #elif (RTC_CLK_SELECT == XOSCL) 
                      CKCON |= XLCKE;
                      while(!(CKCON & XLSTA));
              #endif
1073   1      
1074   1              RTCON = RTCE(1) | MSE(1) | HSE(1) | SCE(0) | MCE(0) | HCE(0);
1075   1              RTMSS = 0;
1076   1              
1077   1              INT8EN = 1;                     
1078   1              
1079   1              TS_IO_init();
1080   1              
1081   1              
1082   1              TKCFG = TKDIV(TKDIV_VAL)|TKTMS(TKTMS_VAL);              
1083   1      #if (TK_CHARGE_REF_SELECT == SOURCE_VDD)
                      TKCON = TKST(0)|TKIE(1)|TMEN(0)|TWKE(0)|VRS(VRS_VAL);
                      TKPWC = TKPC(TK_PC_VAL)|VDS(0)|VIRS(0)|TKPWS(0)|TKCVS(0);               
              #elif (TK_CHARGE_REF_SELECT == SOURCE_INNER) 
1087   1              TKCON = TKST(0)|TKIE(1)|TMEN(0)|TWKE(0)|VRS(0);
1088   1              TKPWC = TKPC(TK_PC_VAL)|VDS(VDS_VAL)|VIRS(VIRS_VAL)|TKPWS(1)|TKCVS(1);          
1089   1      #endif
1090   1              
1091   1              INT3EN = 1; 
1092   1              
1093   1              TS_CycleScanDoneFlag = 0;
1094   1      #if SUPPORT_KEY
1095   1              KeysFlagSN = 0;
1096   1              PreKeysFlagSN = 0;
1097   1      #endif  
1098   1              ActiveTouchType = 0;
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 19  

1099   1      #if SUPPORT_KEY
1100   1      #if SUPPORT_COVER_PANAL_AFTER_POWERON
                      PanalCoverJudgeFlag = 0;
              #endif
1103   1      #endif
1104   1      #if SUPPORT_TOUCH_SLEEP_MODE
                      EnterStopScanTimer = ENTER_STOP_MODE_TIME;
                      TS_SleepEn = 1;
                      TS_SleepMode = 0;
              #endif
1109   1      #if SUPPORT_WHEEL_SLIDER
                      W_S_RefChSet = 0;
              
                      WheelSliderState = WHEEL_SLIDER_NO_TOUCH;
                      WheelSliderTouchFlag = 0;
                      WheelSliderPosition = -1;               
                      WheelSliderCapRateFilter = 0;
              #endif
1117   1              TS_State = TS_INIT;
1118   1              TS_Init_Step = 0;
1119   1      #if SUPPORT_KEY
1120   1      #if ANTI_SPEAKER_EN     
                      RefChDataTimer = 0;
              #endif
1123   1      #endif
1124   1              MainLoopCnt1 = MainLoopCnt2 = 0;
1125   1              Feed_Wdt_Flag = 0xA5;
1126   1      #if SUPPORT_KEY 
1127   1      #if GENERATE_TS_KEY_EN
1128   1              TK_State = TK_STATE_RELEASE;
1129   1              TS_Key = 0;
1130   1      #endif
1131   1      #endif
1132   1      }
1133          
1134          void TS_Action(void)
1135          {       
1136   1              switch(TS_State)
1137   1              {
1138   2                      case TS_INIT:
1139   2                              TS_RunInit();                   
1140   2                              break;
1141   2                      case TS_DEAL:           
1142   2                              if(TS_CycleScanDoneFlag)
1143   2                              {                       
1144   3                                      TS_CycleScanDoneFlag = 0;               
1145   3      #if SUPPORT_KEY
1146   3      #if ANTI_SPEAKER_EN
                                              TS_RefChCheck();
              #endif
1149   3      #endif
1150   3                                      TS_DataFiltering();
1151   3                                      TS_StableFlag = 1;
1152   3      #if SUPPORT_KEY 
1153   3                                      if(ActiveTouchType != 2)
1154   3                                      {
1155   4                                              TSKey_DataDeal();       
1156   4                                      }
1157   3      #endif
1158   3                                      Feed_Wdt_Flag |= 0xA5;
1159   3                                      MainLoopCnt1 = MainLoopCnt2 + 1;
1160   3      #if (DEBUG)
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 20  

                                              Debug_ParamLoad();
              #endif          
1163   3      #if SUPPORT_WHEEL_SLIDER
                                              if(ActiveTouchType != 1)
                                              {
                                                      TS_WheelSliderDeal();
                                              }
              #endif                          
1169   3      #if SUPPORT_TOUCH_SLEEP_MODE
                                              if(!TS_StableFlag || !TS_SleepEn || (PCON & BIT2))      // ÔÚ·ÂÕæÄ£Ê½²»½øÈëSTOPÄ£Ê½
                                              {
                                                      EnterStopScanTimer = ENTER_STOP_MODE_TIME;
                                              }                       
                                              if(!EnterStopScanTimer&&TS_SleepEn)
                                              {
              #if ENTER_SLEEP_PRINT_EN
                                                      TK_Debug_UartPutChar('s');      
                                                      TK_Debug_UartPutChar('l');      
                                                      TK_Debug_UartPutChar('e');      
                                                      TK_Debug_UartPutChar('e');      
                                                      TK_Debug_UartPutChar('p');      
                                                      TK_Debug_UartPutChar('\r');     
                                                      TK_Debug_UartPutChar('\n');             
                                                      Delay_ms(1);
              #endif
                                                      TS_EnterSleepMode();            
              #if ENTER_SLEEP_PRINT_EN                                        
                                                      TK_Debug_UartPutChar('e');      
                                                      TK_Debug_UartPutChar('x');      
                                                      TK_Debug_UartPutChar('i');      
                                                      TK_Debug_UartPutChar('t');      
                                                      TK_Debug_UartPutChar('\r');     
                                                      TK_Debug_UartPutChar('\n');             
              #endif
                                              }
              #endif                                                                          
1197   3                              }
1198   2                              if(TS_HalfSecCnt >= 5)
1199   2                              {
1200   3                                      TKCON = 0;
1201   3                                      TKIF = 0x3F;
1202   3                                      TS_init();
1203   3                              }
1204   2                              break;
1205   2                      default:
1206   2                              break;
1207   2              }
1208   1      
1209   1      #if SUPPORT_KEY 
1210   1      #if GENERATE_TS_KEY_EN
1211   1              TS_GetKey();
1212   1      #endif
1213   1      #endif
1214   1      }
1215          #if SUPPORT_TOUCH_SLEEP_MODE
              void TS_SleepScanStart(void)
              {       
                      unsigned char i;        
                      for(i = 0; i < 6; i++)                                  
                      {
                              INDEX = i;
                              if(TS_Index + i < TS_Cnt)
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 21  

                              {
                                      TKCHS = MPOL(0) | NPOL(1) | TKCHS((TS_CH[TS_Index+i])+1); 
                              }
                              else
                              {
                                      TKCHS = 0; 
                              }
                      }
                      TKCON |= TKST(1);       
              }
              
              #if (TS_SLEEP_MODE_DEBUG)
              void Uart_Debug_THD(unsigned char ch, unsigned int val, unsigned int pval, unsigned int nval)
              {
              //      ËµÃ÷£º´®¿Ú´òÓ¡µÄÊýÖµÎª¶ÔÓ¦Í¨µÀÊÖÖ¸°´ÏÂºóµÄ´¥ÃþÊý¾Ý±ä»¯Á¿£¨²îÖµ£©£¬´¥ÃþÊý¾Ý±ä»¯Á¿´óÓÚÉèÖÃµÄÃÅÏÞÖµÊ±£¬ÍË³
             -öÊ¡µçÄ£Ê½        
                      if((val <= pval)||(val >= nval))
                      {
                              if(val <= pval)
                              {
                                      #ifdef PRINT_EN
                                      uart_printf("TS_CH%d = %3d   ",(int)TS_CH[ch],(pval-val));
                                      #endif
                              }
                              if(val >= nval)
                              {
                                      #ifdef PRINT_EN
                                      uart_printf("TS_CH%d = %3d   ",(int)TS_CH[ch],(val-nval));
                                      #endif
                              }
                      }       
                      else
                      {
                              #ifdef PRINT_EN
                              uart_printf("TS_CH%d = %3d   ",(int)TS_CH[ch],(int)(0));
                              #endif
                      }
                      if(ch == (TS_Cnt-1))
                      {
                              #ifdef PRINT_EN
                              uart_printf("\n");
                              #endif
                      }
              }
              #endif
              
              #if SET_THRESHOLD_EACH_CHANNEL
              code unsigned char TS_KEY_SLEEP_THD[OPENED_TS_COUNT] = SLEEP_CH_THD_SEQ;
              #endif
              void TS_EnterSleepMode(void)
              {
              //Ê¡µçÄ£Ê½²ÎÊýÅäÖÃ
                      #define STOP_TKDIV_VAL                  0
                      #define STOP_TKTMS_VAL                  15              //·ÅµçÊ±¼ä
                      #define STOP_VRS_VAL                    7               //±È½ÏÆ÷ãÐÖµ    
                      unsigned char TS_SampleComplete = 0,i;
                      unsigned int xdata WakeUp_PThdVal[OPENED_TS_COUNT];
                      unsigned int xdata WakeUp_NThdVal[OPENED_TS_COUNT];     
                      WORD_UNION TS_Data;
              
              #if (!TS_SLEEP_MODE_DEBUG)      
                      Sys_Clk_Set_TFRC();
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 22  

                      #if (SYSCLK_SRC == PLL)
                      PLLCON = 0;
                      #endif  
              #endif
                      
                      TKCON = 0;
                      TKIF = 0x3F;
                      
                      TS_SleepMode = 1;
                      
                      RTCON &=  ~(MSE(1) | HSE(1));
                      RTCIF = RTC_MF | RTC_HF;        
                      
                      TKCON = (TKCON&0xF8) | VRS(STOP_VRS_VAL);
                      TKCON &= ~TKIE(1);
                      TKCFG = TKDIV(STOP_TKDIV_VAL)|TKTMS(STOP_TKTMS_VAL);            
              
              #if (OPENED_TS_COUNT%6 == 0)
                      TKMTS = (SLEEP_MODE_SCAN_INTERVAL_TIME*6)/(OPENED_TS_COUNT);
              #else
                      TKMTS = (SLEEP_MODE_SCAN_INTERVAL_TIME)/((OPENED_TS_COUNT/6)+1);
              #endif
                      
                      TKPWC = TKPC(1)|VDS(0)|VIRS(0)|TKPWS(0)|TKCVS(0);               //Ê¡µçÉèÎªVDD³äµç
              
              #if (!TS_SLEEP_MODE_DEBUG)      
                      LVDCON = 0;             
                      I2CCON = 0;
                      CKCON = 0;
                      MECON |= BIT6;  
                      PWCON = (PWCON&0xF0)|0x07;      
              #endif
              
                      TS_Index = 0;
                      TS_SleepScanStart();
                      WDFLG = 0xA5;
                      
                      RTCON |= HSE(1);
                      
                      while(1)
                      {
                      #if (!TS_SLEEP_MODE_DEBUG)              
                              if(TS_SampleComplete)
                              {
                                      CKCON &= ~TFCKE;                
                              #if (RTC_CLK_SELECT == IRCL)
                                      CKSEL = (CKSEL&0xF8) | CKSEL_IRCL;      //ÏµÍ³Ê±ÖÓÇÐ»»µ½IRCL    
                              #elif (RTC_CLK_SELECT == XOSCL) 
                                      CKSEL = (CKSEL&0xF8) | CKSEL_XOSCL;     //ÇÐ»»ÏµÍ³Ê±ÖÓµ½XOSCL   
                              #endif  
                                      EA = 0;
                                      PCON = (PCON&0x84) | 0x02;
                                      _nop_();
                                      _nop_();
                                      _nop_();
                                      CKCON |= TFCKE;                                         //Ê¹ÄÜTFRCÊ±ÖÓ
                                      CKSEL = (CKSEL&0xF8) | CKSEL_TFRC;      //ÇÐ»»ÏµÍ³Ê±ÖÓµ½TFRC            
                                      EA = 1;
                              }
                      #endif
                              if(TS_HalfSecCnt >= 5)
                              {
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 23  

                                      break;
                              }
                              if(TKIF != 0)
                              {
                                      if(TS_HalfSecCnt) TS_HalfSecCnt--;
                                      for(i = 0; i < 6; i++)
                                      {
                                              if(TKIF & (1<<i))
                                              {
                                                      TKIF = (1<<i);  
                                                      INDEX = i;
                                                      TS_Data.bVal[0] = TKMSH;
                                                      TS_Data.bVal[1] = TKMSL;
              
                                                      if(TS_SampleComplete == 0)
                                                      {
                                                      #if SET_THRESHOLD_EACH_CHANNEL
                                                              WakeUp_PThdVal[TS_Index+i] = TS_Data.wVal - TS_KEY_SLEEP_THD[TS_Index+i];
                                                              WakeUp_NThdVal[TS_Index+i] = TS_Data.wVal + TS_KEY_SLEEP_THD[TS_Index+i];
                                                      #else
                                                              WakeUp_PThdVal[TS_Index+i] = TS_Data.wVal - SLEEP_TOUTH_THD;
                                                              WakeUp_NThdVal[TS_Index+i] = TS_Data.wVal + SLEEP_TOUTH_THD;
                                                      #endif
                                                      }
                                                      else 
                                                      {
                                                      #if (TS_SLEEP_MODE_DEBUG)
                                                              Uart_Debug_THD(TS_Index+i,TS_Data.wVal,WakeUp_PThdVal[TS_Index+i],WakeUp_NThdVal[TS_Index+i]);
                                                              continue;               //Ê¡µçÄ£Ê½´¥Ãþµ÷ÊÔ£¬²»ÍË³öÊ¡µçÄ£Ê½¡£ÔÚµ÷ÊÔ½áÊøÇë¹Ø±Õµ÷ÊÔ
                                                      #endif  
                                                              
                                                              if((TS_Data.wVal <= WakeUp_PThdVal[TS_Index+i])||(TS_Data.wVal >= WakeUp_NThdVal[TS_Index+i]))
                                                              {
                                                                      goto SLEEP_EXIT;                        
                                                              }
                                                      }
                                              }
                                      }
                                      if(TS_Index+6 < TS_Cnt)
                                      {
                                              TS_Index += 6;
                                      }
                                      else 
                                      {
                                              TS_Index = 0;
                                              if(TS_SampleComplete == 0)
                                              {
                                                      TS_SampleComplete = 1;                          
                                                      TKCON |= TMEN(1);                                       
                                              }
                                      }
                                      TS_SleepScanStart();    
                                      WDFLG = 0xA5;
                              }
                      /*
                              ÔÚ´¥ÃþÊ¡µçÄ£Ê½ÏÂ£¬ÈôÒªÏìÓ¦Íâ²¿ÖÐ¶Ï£¬ÓÃ»§ÐèÔÚ½øÈë´¥ÃþÊ¡µçÄ£Ê½Ö®Ç°×ÔÐÐ¿ªÆô¶ÔÓ¦
                              µÄÍâ²¿ÖÐ¶Ï¡£ÈôÐèÍË³ö¸ÃÊ¡µçÄ£Ê½£¬ÓÃ»§½öÐèÔÚÊ¡µçº¯ÊýÑ­»·ÄÚÌí¼ÓÌõ¼þÅÐ¶Ï£¬Ìø³öÑ­
                              »·±ã¿É¡£ÍË³ö´¥ÃþÊ¡µçÄ£Ê½ºó£¬ÐèÇå³ýÅÐ¶Ï±êÖ¾£¬²¢¸ù¾Ý²úÆ·µÄÊµ¼Ê×´¿ö¾ö¶¨ÊÇ·ñÒª¹Ø
                              ±ÕÍâ²¿ÖÐ¶Ï¡£ÒÔÍâ²¿ÖÐ¶Ï0ÎªÀý£º¶¨Òå±äÁ¿int_flag£¬¸Ã±äÁ¿ÔÚINT0ÖÐ¶Ï·þÎñ³ÌÐòÀïÖÃ1£¬
                              ÍË³öÊ¡µçÄ£Ê½ºóint_flagÒªÖÃ0¡£
                              if(int_flag == 1)
                              {
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 24  

                                      goto SLEEP_EXIT;
                              }
                      */      
                      }
              SLEEP_EXIT:
                      TKCON = 0;
                      TKIF = 0x3F;
                      PWCON = (PWCON&0xF0)|0x0D;      
              #if (SYSCLK_SRC == PLL)
                      Sys_Clk_Set_PLL(PLL_Multiple);
              #elif (SYSCLK_SRC == IRCH)      
                      Sys_Clk_Set_IRCH();
              #endif
              
                      TKCFG = TKDIV(TKDIV_VAL)|TKTMS(TKTMS_VAL);              
              #if (TK_CHARGE_REF_SELECT == SOURCE_VDD)
                      TKCON = TKST(0)|TKIE(1)|TMEN(0)|TWKE(0)|VRS(VRS_VAL);
                      TKPWC = TKPC(TK_PC_VAL)|VDS(0)|VIRS(0)|TKPWS(0)|TKCVS(0);               
              #elif (TK_CHARGE_REF_SELECT == SOURCE_INNER) 
                      TKCON = TKST(0)|TKIE(1)|TMEN(0)|TWKE(0)|VRS(0);
                      TKPWC = TKPC(TK_PC_VAL)|VDS(VDS_VAL)|VIRS(VIRS_VAL)|TKPWS(1)|TKCVS(1);          
              #endif
              
                      RTCON |= HSE(1)|MSE(1);
                      TS_Index = 0;
                      TS_ScanStart();
                      EnterStopScanTimer = ENTER_STOP_MODE_TIME;
                      TS_SleepMode = 0;
              #ifdef LVD_RST_ENABLE
                      LVDCON = 0xE1;  //ÉèÖÃLVD¸´Î»µçÑ¹Îª2V
              #endif                                                  
              }
              #endif
1441          /*********************************************************************************************************
             -************/
1442          #if SUPPORT_KEY 
1443          #if GENERATE_TS_KEY_EN
1444          #if GENERATE_DOUBLE_KEY_EN
              typedef struct 
              {       
                      unsigned char   TogKeyNum;
                      unsigned char   TogKeyList[2];
              }
              T_TogKeyInfo;
              #endif
1452          code unsigned char TS_KEY_TAB[]=
1453          {
1454                  K1,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24
1455          };
1456          #if GENERATE_DOUBLE_KEY_EN
              void TS_GetTogKeyInfor(T_TogKeyInfo *pKeyInfo)
              {
                      unsigned char i,index;
                      pKeyInfo->TogKeyNum = 0;
                      index = 0;
                      for(i = 0; i < KEY_CH_COUNT; i++)
                      {
                              if(KeysFlagSN & MASK_TAB[i])
                              {
                                      pKeyInfo->TogKeyNum++;
                                      
                                      if(pKeyInfo->TogKeyNum <= 2)
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 25  

                                      {
                                              pKeyInfo->TogKeyList[index++] = TS_KEY_TAB[i];
                                      }
                              }
                      }
              }
              #endif
1476          #if PRINT_TS_KEY_EN
              void Hex2CharPrint(unsigned int integar)
              {
                      unsigned char CharBuf[4];
                      unsigned char i, temp;
                      for(i = 0; i < 4; i++)
                      {
                              temp = (unsigned char)(integar&0x0F);
                              if(temp >= 0x0A)
                              {
                                      CharBuf[i] = (temp - 0x0A) + 'A';
                              }
                              else
                              {
                                      CharBuf[i] = temp + '0';
                              }
                              integar >>= 4;
                      }
                      TK_Debug_UartPutChar('0');      
                      TK_Debug_UartPutChar('x');      
                      TK_Debug_UartPutChar(CharBuf[2]);
                      TK_Debug_UartPutChar(CharBuf[1]);
                      TK_Debug_UartPutChar(CharBuf[0]);
              }
              #endif
1501          void TS_GetKey(void)
1502          {
1503   1              static unsigned int KeyBak;     
1504   1              static bit LongFlag;
1505   1      #if GENERATE_DOUBLE_KEY_EN
                      T_TogKeyInfo KeyInfo;
                      TS_GetTogKeyInfor(&KeyInfo);
              #else
1509   1              static unsigned char KeyidxBak;
1510   1              unsigned char i;
1511   1      #endif
1512   1              TS_Key = 0;     
1513   1              if(TK_State == TK_STATE_RELEASE)
1514   1              {
1515   2      #if GENERATE_DOUBLE_KEY_EN
                              if(KeyInfo.TogKeyNum != 0)
                              {                       
                                      if(KeyInfo.TogKeyNum == 1)
                                      {
                                              KeyBak = (unsigned int)KeyInfo.TogKeyList[0];
                                              TK_State = TK_STATE_SINGLE_KEY_PRESS;                           
                                      }
                                      else if(KeyInfo.TogKeyNum == 2)
                                      {
                                              KeyBak = ((unsigned int)KeyInfo.TogKeyList[0]<<5)|(unsigned int)KeyInfo.TogKeyList[1];
                                              TK_State = TK_STATE_DOUBLE_KEY_PRESS;
                                      }
                                      TS_Key = KeyBak;
                                      LongFlag = 0;
                                      TS_LongKeyTimer = TS_LONG_START_TIME;
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 26  

                              }
              #else
1533   2                      if(KeysFlagSN != 0)
1534   2                      {
1535   3                              for(i = 0; i < KEY_CH_COUNT; i++)
1536   3                              {
1537   4                                      if(KeysFlagSN & MASK_TAB[i])
1538   4                                      {
1539   5                                              KeyidxBak = i;
1540   5                                              KeyBak = TS_KEY_TAB[i];
1541   5                                              break;
1542   5                                      }               
1543   4                              }                               
1544   3                              TS_Key = KeyBak;
1545   3                              LongFlag = 0;
1546   3                              TS_LongKeyTimer = TS_LONG_START_TIME;
1547   3                              TK_State = TK_STATE_SINGLE_KEY_PRESS;           
1548   3                      }
1549   2      #endif
1550   2              }
1551   1              else if(TK_State == TK_STATE_SINGLE_KEY_PRESS)
1552   1              {
1553   2      #if GENERATE_DOUBLE_KEY_EN      
                              if(KeyInfo.TogKeyNum == 1)
                              {
                                      if(KeyBak == (unsigned int)KeyInfo.TogKeyList[0])
                                      {
                                              if(!TS_LongKeyTimer)
                                              {
                                                      if(!LongFlag)
                                                      {
                                                              LongFlag = 1;
                                                              TS_Key = KeyBak | KEY_LONG_START;
                                                      }
                                                      else
                                                      {
                                                              TS_Key = KeyBak | KEY_LONG;
                                                      }
                                                      TS_LongKeyTimer = TS_LONG_TIME;
                                              }                               
                                      }
                                      else 
                                      {
                                              if(!LongFlag)
                                              {
                                                      TS_Key = KeyBak | KEY_BREAK;
                                              }
                                              else
                                              {
                                                      TS_Key = KeyBak | KEY_LONG_BREAK;
                                              }
                                              TK_State = TK_STATE_RELEASE;
                                      }
                              }
                              else if(KeyInfo.TogKeyNum == 2)
                              {
                                      KeyBak = ((unsigned int)KeyInfo.TogKeyList[0]<<5) | (unsigned int)KeyInfo.TogKeyList[1];
                                      TK_State = TK_STATE_DOUBLE_KEY_PRESS;
                                      TS_Key = KeyBak;
                                      LongFlag = 0;
                                      TS_LongKeyTimer = TS_LONG_START_TIME;
                              }
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 27  

                              else if(KeyInfo.TogKeyNum == 0)
                              {
                                      if(!LongFlag)
                                      {
                                              TS_Key = KeyBak | KEY_BREAK;
                                      }
                                      else
                                      {
                                              TS_Key = KeyBak | KEY_LONG_BREAK;
                                      }
                                      TK_State = TK_STATE_RELEASE;
                              }
              #else
1606   2                      if(KeysFlagSN & MASK_TAB[KeyidxBak])
1607   2                      {
1608   3                                      if(!TS_LongKeyTimer)
1609   3                                      {
1610   4                                              if(!LongFlag)
1611   4                                              {
1612   5                                                      LongFlag = 1;
1613   5                                                      TS_Key = KeyBak | KEY_LONG_START;
1614   5                                              }
1615   4                                              else
1616   4                                              {
1617   5                                                      TS_Key = KeyBak | KEY_LONG;
1618   5                                              }
1619   4                                              TS_LongKeyTimer = TS_LONG_TIME;
1620   4                                      }                                       
1621   3                      }
1622   2                      else
1623   2                      {
1624   3                              if(!LongFlag)
1625   3                              {
1626   4                                      TS_Key = KeyBak | KEY_BREAK;
1627   4                              }
1628   3                              else
1629   3                              {
1630   4                                      TS_Key = KeyBak | KEY_LONG_BREAK;
1631   4                              }
1632   3                              TK_State = TK_STATE_RELEASE;                    
1633   3                      }
1634   2      #endif
1635   2              }
1636   1      #if GENERATE_DOUBLE_KEY_EN      
                      else if(TK_State == TK_STATE_DOUBLE_KEY_PRESS)
                      {
                              if(KeyInfo.TogKeyNum == 2)
                              {
                                      if(KeyBak == ((unsigned int)KeyInfo.TogKeyList[0]<<5)|(unsigned int)KeyInfo.TogKeyList[1])
                                      {
                                              if(!TS_LongKeyTimer)
                                              {
                                                      if(!LongFlag)
                                                      {
                                                              LongFlag = 1;
                                                              TS_Key = KeyBak | KEY_LONG_START;
                                                      }
                                                      else
                                                      {
                                                              TS_Key = KeyBak | KEY_LONG;
                                                      }
                                                      TS_LongKeyTimer = TS_LONG_TIME;
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 28  

                                              }                                       
                                      }
                              }
                              else if(KeyInfo.TogKeyNum == 0)
                              {
                                      if(!LongFlag)
                                      {
                                              TS_Key = KeyBak | KEY_BREAK;
                                      }
                                      else
                                      {
                                              TS_Key = KeyBak | KEY_LONG_BREAK;
                                      }
                                      TK_State = TK_STATE_RELEASE;            
                              }
                      }
              #endif
1672   1      #if PRINT_TS_KEY_EN
                      if(TS_Key != 0)
                      {
                              if((TS_Key & 0xFF00) == 0)
                              {
              #if GENERATE_DOUBLE_KEY_EN      
                                      if(TS_Key > 0x1F)
                                      {
                                              TK_Debug_UartPutChar('d');      
                                              TK_Debug_UartPutChar('o');      
                                              TK_Debug_UartPutChar('u');      
                                              TK_Debug_UartPutChar('b');      
                                              TK_Debug_UartPutChar('l');      
                                              TK_Debug_UartPutChar('e');                      
                                      }
                                      else
                                      {
                                              TK_Debug_UartPutChar('s');      
                                              TK_Debug_UartPutChar('i');      
                                              TK_Debug_UartPutChar('n');      
                                              TK_Debug_UartPutChar('g');      
                                              TK_Debug_UartPutChar('l');      
                                              TK_Debug_UartPutChar('e');              
                                      }
                                      TK_Debug_UartPutChar(' ');      
              #endif
                                      TK_Debug_UartPutChar('k');      
                                      TK_Debug_UartPutChar('e');      
                                      TK_Debug_UartPutChar('y');      
                                      TK_Debug_UartPutChar(' ');      
                                      TK_Debug_UartPutChar('=');      
                                      TK_Debug_UartPutChar(' ');      
                                      Hex2CharPrint(TS_Key);
                                      TK_Debug_UartPutChar('\r');     
                                      TK_Debug_UartPutChar('\n');     
                              }
                              else if(TS_Key & KEY_BREAK)
                              {
                                      TK_Debug_UartPutChar('k');      
                                      TK_Debug_UartPutChar('e');      
                                      TK_Debug_UartPutChar('y');      
                                      TK_Debug_UartPutChar(' ');      
                                      TK_Debug_UartPutChar('u');      
                                      TK_Debug_UartPutChar('p');      
                                      TK_Debug_UartPutChar('\r');     
C51 COMPILER V9.02   TS_API                                                                12/25/2025 18:50:27 PAGE 29  

                                      TK_Debug_UartPutChar('\n');                             
                              }
                              else if(TS_Key & KEY_LONG_START)
                              {
                                      TK_Debug_UartPutChar('l');      
                                      TK_Debug_UartPutChar('o');      
                                      TK_Debug_UartPutChar('n');      
                                      TK_Debug_UartPutChar('g');      
                                      TK_Debug_UartPutChar(' ');      
                                      TK_Debug_UartPutChar('s');      
                                      TK_Debug_UartPutChar('t');      
                                      TK_Debug_UartPutChar('a');      
                                      TK_Debug_UartPutChar('r');      
                                      TK_Debug_UartPutChar('t');      
                                      TK_Debug_UartPutChar('\r');     
                                      TK_Debug_UartPutChar('\n');                     
                              }
                              else if(TS_Key & KEY_LONG)
                              {
                                      TK_Debug_UartPutChar('l');      
                                      TK_Debug_UartPutChar('o');      
                                      TK_Debug_UartPutChar('n');      
                                      TK_Debug_UartPutChar('g');      
                                      TK_Debug_UartPutChar('\r');     
                                      TK_Debug_UartPutChar('\n');                     
                              }
                      }
              #endif
1745   1      }
1746          #endif
1747          #endif
1748          /*********************************************************************************************************
             -************/
1749          
1750          /*********************************************************************************************************
             -************/
1751          #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1703    ----
   CONSTANT SIZE    =     60    ----
   XDATA SIZE       =    205    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     12      26
   IDATA SIZE       =      9    ----
   BIT SIZE         =      3    ----
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


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