C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 1   


C51 COMPILER V9.52.0.0, COMPILATION OF MODULE IRSCAN
OBJECT MODULE PLACED IN .\Output\IRScan.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\User\Source\Function\IRScan.c LARGE OMF2 WARNINGLEVEL(0) BROWSE INCDIR(.
                    -.\Library\FU68xx_Hardware_Driver\Include;..\User\Include) DEBUG PRINT(.\Listing\IRScan.lst) OBJECT(.\Output\IRScan.obj)

line level    source

   1          /**************************** (C) COPYRIGHT 2015 Fortiortech shenzhen *****************************
   2          * File Name          : IRScan.c
   3          * Author             : Billy Long Fortiortech  Market Dept
   4          * Version            : V1.0
   5          * Date               : 01/07/2015
   6          * Description        : This file contains main function used for Motor Control.
   7          ***************************************************************************************************
   8          * All Rights Reserved
   9          **************************************************************************************************/ 
  10          
  11          
  12          /* Includes -------------------------------------------------------------------------------------*/
  13          #include <FU68xx_2.h>
  14          #include <Myproject.h>
  15          
  16          
  17          /* Private typedef ------------------------------------------------------------------------------*/
  18          /* Private define -------------------------------------------------------------------------------*/
  19          /* Private macro --------------------------------------------------------------------------------*/
  20          /* Private variables ----------------------------------------------------------------------------*/
  21          IRScan_TypeDef xdata IRScan;
  22          IRControl_TypeDef xdata IRControl;
  23          IRControl_AutoPowerDef AutoPowerState;
  24          uint16 PowerUpTimeCount=0;                              //上电一分钟计时
  25          uint8   NatureWinFlag = 0;
  26          uint32  dimmer_cnt = 0;
  27          int8  dimmer_level = 30;
  28          uint8 natural_mode = 0;
  29          uint32 dimmer_interval = 0;
  30          const uint8 code NatureWinCode[9]={1,3,7,5,2,8,6,4,9};
  31          
  32          #define BYTE0(dwTemp)       (*((char *)(&dwTemp)))
  33          #define BYTE1(dwTemp)       (*((char *)(&dwTemp) + 1))
  34          #define BYTE2(dwTemp)       (*((char *)(&dwTemp) + 2))
  35          #define BYTE3(dwTemp)       (*((char *)(&dwTemp) + 3))
  36          
  37          /* Private function prototypes ------------------------------------------------------------------*/
  38          /* Private functions ----------------------------------------------------------------------------*/
  39          
  40          /*-------------------------------------------------------------------------------------------------
  41                  Function Name : void IRInit(void)
  42                  Description   : 
  43                  Input         : 无
  44            Output                                :       无
  45          -------------------------------------------------------------------------------------------------*/
  46          void IRInit(void)
  47          {
  48   1              IRScan.BitValue = 0;
  49   1              IRScan.BitCnt = 0;
  50   1              IRScan.Bit0Cnt = 0;
  51   1              IRScan.ByteValue = 0;
  52   1              IRScan.UserCode = 0;
  53   1              IRScan.DataCode = 0;
  54   1              IRScan.IRReceiveFlag = 0;
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 2   

  55   1              IRScan.CurrentUserCode =0;
  56   1              IRScan.OldDataCodeMixTimes = 0;
  57   1              IRScan.CurrentDataCode = 0;
  58   1              IRScan.OverFlowStatus=0;
  59   1      
  60   1              IRScan.TempDataCode[0]=0;
  61   1              IRScan.TempDataCode[1]=0;       
  62   1              IRScan.TempDataCode[2]=0;
  63   1              IRScan.TempDataCode[3]=0;               
  64   1              IRScan.DataCodeNum = 0;
  65   1              
  66   1              IRScan.DataCodeLengthCover = 1;
  67   1              IRScan.UserCodeLengthCover = 1;
  68   1              IRScan.DataCodeLengthCover = (IRScan.DataCodeLengthCover<<(DataCodeLength))-1;
  69   1              IRScan.UserCodeLengthCover = (IRScan.UserCodeLengthCover<<(UserCodeLength))-1;
  70   1              
  71   1              IRControl.FlagONOFF = 0;
  72   1              IRControl.FlagFR = 0;
  73   1              IRControl.FlagSpeed = 0;
  74   1              IRControl.TargetSpeed = 0;
  75   1              IRControl.ONOFFStatus =0;
  76   1              IRControl.FlagNatureWind =0;
  77   1              IRControl.FlagLED =0;
  78   1              IRControl.FlagAutoPower =0;
  79   1              IRControl.FlagUserCodeSave = 0;
  80   1              IRControl.FlagUserCodeRead = 1;                         //上电读出一次UserCode
  81   1              IRControl.LEDONOFFStatus = 0;
  82   1              
  83   1              mcFRState.OldTargetSpeed = 1;
  84   1              mcFRState.FR = 0;
  85   1              mcFRState.FlagFR = 0;
  86   1              mcFRState.FRStatus = 0;
  87   1              
  88   1              AutoPowerState.FlagAutoPower=0;
  89   1              AutoPowerState.Timer10sec=0;
  90   1              AutoPowerState.ShutDowntime=2;
  91   1              AutoPowerState.CurrentTime=0;
  92   1              
  93   1              #if (Motor_Speed_Control_Mode == SPEED_LOOP_CONTROL)
  94   1              {
  95   2                      IRControl.SpeedLevel[0] = MOTOR_SPEED_LEVEL_0;
  96   2                      IRControl.SpeedLevel[1] = MOTOR_SPEED_LEVEL_1;
  97   2                      IRControl.SpeedLevel[2] = MOTOR_SPEED_LEVEL_2;
  98   2                      IRControl.SpeedLevel[3] = MOTOR_SPEED_LEVEL_3;
  99   2                      IRControl.SpeedLevel[4] = MOTOR_SPEED_LEVEL_4;
 100   2                      IRControl.SpeedLevel[5] = MOTOR_SPEED_LEVEL_5;
 101   2                      IRControl.SpeedLevel[6] = MOTOR_SPEED_LEVEL_6;
 102   2              IRControl.SpeedLevel[7] = MOTOR_SPEED_LEVEL_7;
 103   2                      IRControl.SpeedLevel[8] = MOTOR_SPEED_LEVEL_8;
 104   2                      IRControl.SpeedLevel[9] = MOTOR_SPEED_LEVEL_9;
 105   2              }
 106   1              #elif (Motor_Speed_Control_Mode == POWER_LOOP_CONTROL)
                      { 
                              IRControl.SpeedLevel[0] = MOTOR_POWER_LEVEL_0;
                              IRControl.SpeedLevel[1] = MOTOR_POWER_LEVEL_1;
                              IRControl.SpeedLevel[2] = MOTOR_POWER_LEVEL_2;
                              IRControl.SpeedLevel[3] = MOTOR_POWER_LEVEL_3;
                              IRControl.SpeedLevel[4] = MOTOR_POWER_LEVEL_4;
                              IRControl.SpeedLevel[5] = MOTOR_POWER_LEVEL_5;
                              IRControl.SpeedLevel[6] = MOTOR_POWER_LEVEL_6;
                      }
                      #endif
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 3   

 117   1      }
 118          
 119          
 120          /*-------------------------------------------------------------------------------------------------
 121                  Function Name : void IRValue(void)
 122                  Description   : 红外接收头解码
 123                  Input         : 无
 124            Output                                :       无
 125          -------------------------------------------------------------------------------------------------*/
 126          
 127          //void IRValue(void)
 128          //{
 129          //              uint8 tempof1=0;
 130          //        uint8 tempof2=0;
 131          //      
 132          //              IRScan.Bit0Cnt = TIM3_ARR;
 133          //              if(IRScan.BitCnt==0)
 134          //              {                       
 135          //                      if((IRScan.Bit0Cnt<=TempBit1stLeadMax)&&(IRScan.Bit0Cnt>=TempBit1stLeadMin))
 136          //                      {
 137          //                              IRScan.BitCnt++;
 138          //                      }
 139          //              }
 140          //              else
 141          //              {
 142          //                      if((IRScan.Bit0Cnt >= TempBit0CntMin)&&(IRScan.Bit0Cnt <= TempBit0CntMax))
 143          //                      {
 144          //                              IRScan.BitValue = 1;
 145          //                      }
 146          //                      else
 147          //                      {
 148          //                              IRScan.BitValue = 0;
 149          //                      }                       
 150          //                      
 151          //                      if(IRScan.BitCnt<=16)
 152          //                      {
 153          //                              IRScan.ByteValue += (IRScan.BitValue << (16-IRScan.BitCnt));
 154          //                              IRScan.BitCnt ++;               
 155          //                              if(IRScan.BitCnt == 16)
 156          //                              {
 157          //                                      IRScan.UserCode = IRScan.ByteValue;
 158          //                                      IRScan.ByteValue = 0;
 159          //                              }
 160          //                      }
 161          //                      else
 162          //                      {
 163          //                              IRScan.ByteValue += (IRScan.BitValue << (16-(IRScan.BitCnt-16)));
 164          //                              IRScan.BitCnt ++;               
 165          //                              
 166          //                              if(IRScan.BitCnt == 32)
 167          //                              {
 168          //                                      IRScan.DataCode = IRScan.ByteValue;
 169          //                                      IRScan.ByteValue = 0;                   
 170          //                                      IRScan.BitCnt = 0;              
 171          //                                      
 172          //                                      tempof2 = (uint8)IRScan.DataCode;
 173          //                                tempof1 = IRScan.DataCode>>8;
 174          //                                      //tempof1 = 0xff -tempof1-1;
 175          //                                      tempof1 = 0xff -tempof1;
 176          //                      
 177          //                                      if((tempof1 == tempof2)&&(IRScan.UserCode==UserCodeDef))
 178          //                                      {
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 4   

 179          //                                              IRScan.IRReceiveFlag = 1;
 180          //                                      }
 181          //                              }
 182          //                      }               
 183          //              
 184          //              }
 185          //}
 186          
 187          /*-------------------------------------------------------------------------------------------------
 188                  Function Name : void SetSpeed(uint8 SpeedLevel)
 189                  Description   : 速度设置
 190                  Input         : SpeedLevel：速度挡位
 191                  Output            :     无
 192          -------------------------------------------------------------------------------------------------*/
 193          void SetSpeed(uint8 SpeedLevel)
 194          {
 195   1              IRControl.TargetSpeed = SpeedLevel;
 196   1              if(!mcSpeedRamp.FlagONOFF)
 197   1              {
 198   2      //              IRControl.ONOFFStatus =1;
 199   2      //              IRControl.FlagONOFF = 1;
 200   2                      mcSpeedRamp.FlagONOFF = 1;
 201   2              }
 202   1              IRControl.FlagSpeed = 1;
 203   1              mcFRState.OldTargetSpeed = IRControl.TargetSpeed;
 204   1              //SetBuzzer(1,1);
 205   1      }
 206          
 207          /*-------------------------------------------------------------------------------------------------
 208                  Function Name : void SetAutoPower(uint16 Time)
 209                  Description   : 定时设置
 210                  Input         : Time：定时时长
 211                  Output            :     无
 212          -------------------------------------------------------------------------------------------------*/
 213          void SetAutoPower(uint16 Time)
 214          {
 215   1              IRControl.FlagAutoPower = 1;
 216   1              AutoPowerState.ShutDowntime = Time;
 217   1              //SetBuzzer(1,1);
 218   1      }
 219          
 220          /*-------------------------------------------------------------------------------------------------
 221                  Function Name : void RFValue(void)
 222                  Description   : RF接收头解码
 223                  Input         : 无
 224            Output                                :       无
 225          -------------------------------------------------------------------------------------------------*/
 226          void RFValue(void)
 227          {
 228   1              static uint8 IRLastBitValue = 0;
 229   1          static uint8 UserSavedStatus = 0;
 230   1          
 231   1          static uint8 first_receive_falg = 0;
 232   1          static uint8 RF_cnt = 0;
 233   1          
 234   1          uint8 i = 0;
 235   1          
 236   1          IRScan.Bit0Cnt = TIM3__ARR-TIM3__DR; //获取低电平时长 （PWM周期 - 高电平时长）上升沿到上升沿
 237   1          if(IRScan.BitCnt==0)
 238   1          {                   
 239   2              if((IRScan.Bit0Cnt <= TempLeadCodeMax)&&(IRScan.Bit0Cnt >= TempLeadCodeMin))//引导码
 240   2              {
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 5   

 241   3                  IRScan.BitCnt++;
 242   3              }
 243   2          }
 244   1          if(IRScan.BitCnt==1)
 245   1          {
 246   2              IRScan.Bit0Cnt = TIM3__DR;
 247   2              if((IRScan.Bit0Cnt >= TempBitValue1Min)&&(IRScan.Bit0Cnt <= TempBitValue1Max))
 248   2              {
 249   3                IRLastBitValue = 1;                   //最后一位数据为1
 250   3              }
 251   2              else if((IRScan.Bit0Cnt >= TempBitValue0Min)&&(IRScan.Bit0Cnt <= TempBitValue0Max))
 252   2              {
 253   3                IRLastBitValue = 0;                           //最后一位数据为0
 254   3              }              
 255   2          }
 256   1              
 257   1              if(IRScan.BitCnt>=1)
 258   1              {
 259   2                      IRScan.Bit0Cnt = TIM3__DR;
 260   2                      if((IRScan.Bit0Cnt >= TempBitValue1Min)&&(IRScan.Bit0Cnt <= TempBitValue1Max))
 261   2                      {
 262   3                              //当前数据为1
 263   3                              IRScan.BitValue = 1;
 264   3                      }
 265   2                      else if((IRScan.Bit0Cnt >= TempBitValue0Min)&&(IRScan.Bit0Cnt <= TempBitValue0Max))
 266   2                      {
 267   3                              //当前数据为0
 268   3                              IRScan.BitValue = 0;
 269   3                      }                       
 270   2                              
 271   2              if(IRScan.BitCnt<=AllCodeLength+2) //获取所有数据
 272   2              {
 273   3                  IRScan.ByteValue += (IRScan.BitValue << (AllCodeLength-IRScan.BitCnt+2));
 274   3                  
 275   3                  IRScan.BitCnt ++;
 276   3                  if(IRScan.BitCnt == AllCodeLength+2) //接收完成
 277   3                  {
 278   4                      IRScan.ByteValue += IRLastBitValue;
 279   4                      IRScan.UserCode = (((IRScan.ByteValue << 6) & 0xFFFF0000) >> 16);
 280   4                      IRScan.DataCode = ((IRScan.ByteValue << 6) & 0x0000FFC0);
 281   4                      IRScan.ByteValue = 0;
 282   4      //                uart_buf[0] = (IRScan.UserCode&0xFF00)>>8;
 283   4      //                uart_buf[1] = (IRScan.UserCode&0x00FF);
 284   4      //                uart_buf[2] = (IRScan.DataCode&0xFF00)>>8;
 285   4      //                uart_buf[3] = (IRScan.DataCode&0x00FF);
 286   4      //                for(i=0;i<4;i++)
 287   4      //                {
 288   4      //                    UT_DR = uart_buf[i];
 289   4      //                    while(!TI);                                       //等待发送完成
 290   4      //                    TI = 0;                                                   //发送完成中断标志位清零        
 291   4      //                }
 292   4                      if(IRScan.UserCode!=IRScan.CurrentUserCode)//地址码不一样，对码
 293   4                      {
 294   5                          if(!UserSavedStatus)
 295   5                          {
 296   6                              //地址码与当前地址不一致时执行读出地址码
 297   6                              IRControl.FlagUserCodeRead=1; 
 298   6                              IRScan.OverFlowStatus =1;
 299   6                          }
 300   5                      }
 301   4                      else //地址码一样 数据有效 包括地址码为0
 302   4                      {
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 6   

 303   5                          if(IRScan.CurrentDataCode!=IRScan.DataCode)
 304   5                          {
 305   6                              IRScan.CurrentDataCode=IRScan.DataCode;
 306   6                              IRScan.ValidDataCnt = 1;
 307   6                              IRScan.DiffFlag = 1;
 308   6                              //IRScan.IRReceiveFlag = 1;     
 309   6                          }
 310   5                          else
 311   5                          {
 312   6                              if(((IRDATAMASK&IRScan.DataCode) == IRDIMEERADD) || ((IRDATAMASK&IRScan.DataCode) 
             -== IRDIMEERSUB))//调光一直响应
 313   6                              {
 314   7                                  if(dimmer_interval > 1000)
 315   7                                  {
 316   8                                      dimmer_interval = 0;
 317   8                                      IRScan.IRReceiveFlag = 1;
 318   8                                  }
 319   7                              }
 320   6                              else
 321   6                              {
 322   7                                  if(IRScan.DiffFlag == 1)
 323   7                                  {
 324   8                                      IRScan.ValidDataCnt++;
 325   8                                      if(IRScan.ValidDataCnt >= 2)
 326   8                                      {
 327   9                                          IRScan.IRReceiveFlag = 1; 
 328   9                                          IRScan.ValidDataCnt =0;
 329   9                                          IRScan.DiffFlag = 0;
 330   9                                      }
 331   8                                  }
 332   7                              }
 333   6                          }
 334   5                      }
 335   4                      
 336   4                      if((IRScan.DataCode == IRLEARN)&&(IRScan.OverFlowStatus==1))//接收到遥控学习指令
 337   4                      {
 338   5                          IRScan.OldDataCodeMixTimes++;
 339   5                          if(IRScan.OldDataCodeMixTimes > 1)
 340   5                          {
 341   6                              IRScan.OverFlowStatus = 0;
 342   6                              if((!UserSavedStatus)&&(Time.PowerUpTimeCount<30000))//上电30秒内
 343   6                              {
 344   7                                  SetBuzzer(5,3);
 345   7                                  IRScan.CurrentUserCode = IRScan.UserCode;
 346   7                                  IRControl.FlagUserCodeSave=1;       
 347   7                                  BZScan.FlagBZ = 1;
 348   7                                  BZScan.BZMultitimes=1;
 349   7                                  UserSavedStatus = 1; 
 350   7                              }
 351   6                              IRScan.OldDataCodeMixTimes =0;            
 352   6                          }                    
 353   5                      }
 354   4                      else
 355   4                      {
 356   5                          IRScan.OldDataCodeMixTimes =0;           
 357   5                      }
 358   4                      IRScan.BitCnt = 0;
 359   4                  }
 360   3              } 
 361   2          }
 362   1      }
 363          
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 7   

 364          /*-------------------------------------------------------------------------------------------------
 365                  Function Name : void IRScanControl(void)
 366                  Description   : 遥控信号处理
 367                  Input         : 无
 368                  Output            :     无
 369          -------------------------------------------------------------------------------------------------*/
 370          uint16 Temp_Dir = 0; 
 371          uint16 Temp_Level = 0;
 372          uint16 Temp_Data = 0;
 373          
 374          //void IRScanControl(void)
 375          //{
 376          //      if(IRScan.IRReceiveFlag)
 377          //      {
 378          //              switch(IRScan.DataCode)
 379          //              {
 380          //                      case IRONOFF:
 381          //                      {
 382          //                              if(!IRControl.FlagUserCodeSave)
 383          //                              {
 384          ////                                    if(IRControl.ONOFFStatus)
 385          //                                      if(mcSpeedRamp.FlagONOFF == 1)
 386          //                                      {
 387          ////                                            IRControl.ONOFFStatus = 0;
 388          //                                              IRControl.TargetSpeed = 0;
 389          //                                              mcSpeedRamp.FlagONOFF = 0;
 390          //                                              
 391          //                                              //在反转过程中关机时退出反转状态
 392          //                                              mcFRState.FlagFR = 0;           
 393          //                                              mcFRState.FRStatus = 0;
 394          //                                              
 395          //                                      }
 396          //                                      else
 397          //                                      {
 398          //                                              //关机状态执行开机
 399          ////                                            IRControl.ONOFFStatus =1;
 400          ////                                            IRControl.FlagONOFF = 1;
 401          //                                              
 402          //                                              mcSpeedRamp.FlagONOFF = 1;
 403          //                                              if(mcFRState.OldTargetSpeed == 0)
 404          //                                              {
 405          //                                                      mcFRState.OldTargetSpeed = 1;
 406          //                                              }
 407          //                                              IRControl.TargetSpeed = mcFRState.OldTargetSpeed;
 408          //                                      }
 409          //                                      SetBuzzer(1,1);
 410          //                                      NatureWinFlag =0;               
 411          //                                      IRControl.FlagSpeed = 1;
 412          //                              }
 413          //                              break;
 414          //                      }
 415          ////                    case IRFR:      
 416          ////                    {
 417          ////                            IRControl.FlagFR = 1;
 418          ////                            SetBuzzer(1,1);
 419          ////                            break;
 420          ////                    }
 421          //                      case IRLED:     
 422          //                      {
 423          //                              IRControl.FlagLED=1;
 424          //                              SetBuzzer(1,1); 
 425          //                              break;
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 8   

 426          //                      }
 427          //                      case IRSpeed1:  
 428          //                      {
 429          //                              SetSpeed(1);
 430          //                              NatureWinFlag =0;
 431          //                              break;
 432          //                      }
 433          //                      case IRSpeed2:  
 434          //                      {
 435          //                              SetSpeed(2);
 436          //                              NatureWinFlag =0;
 437          //                              break;
 438          //                      }
 439          //                      case IRSpeed3:           
 440          //                      {
 441          //                              SetSpeed(3);
 442          //                              NatureWinFlag =0;
 443          //                              break;
 444          //                      }
 445          //                      case IRSpeed4:           
 446          //                      {
 447          //                              SetSpeed(4);
 448          //                              NatureWinFlag =0;
 449          //                              break;
 450          //                      }
 451          //                      case IRSpeed5:           
 452          //                      {
 453          //                              SetSpeed(5);
 454          //                              NatureWinFlag =0;
 455          //                              break;
 456          //                      }               
 457          //                      case IRSpeed6:           
 458          //                      {
 459          //                              SetSpeed(6);
 460          //                              NatureWinFlag =0;
 461          //                              break;
 462          //                      }                        
 463          ////                    case IRAUTOPOWER1H:     
 464          ////                    {
 465          ////                            SetAutoPower(360);              //1H
 466          ////                            break;
 467          ////                    }                               
 468          ////                    case IRAUTOPOWER3H:     
 469          ////                    {
 470          ////                            SetAutoPower(720);              //2H
 471          ////                            break;
 472          ////                    }                                
 473          ////                    case IRAUTOPOWER6H:     
 474          ////                    {
 475          ////                            SetAutoPower(1440);             //4H
 476          ////                            break;
 477          ////                    }
 478          ////                    case IRNatureWind:
 479          ////                    {
 480          ////                             if(!IRControl.ONOFFStatus)
 481          ////                             {
 482          ////                                    IRControl.ONOFFStatus =1;
 483          ////                                    IRControl.FlagONOFF = 1;                
 484          ////                             }
 485          ////                             if(!NatureWinFlag)
 486          ////                             {
 487          ////                                    NatureWinFlag=1;
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 9   

 488          ////                                    IRControl.FlagSpeed = 1;
 489          ////                                    IRControl.TargetSpeed = 1;
 490          ////                             }
 491          ////                             SetBuzzer(1,1);
 492          ////                            break;
 493          ////                    }
 494          //                      default:
 495          //                      break;           
 496          //              }
 497          //              IRScan.IRReceiveFlag = 0;
 498          //      }       
 499          //}
 500          
 501          void IRScanControl(void)
 502          {
 503   1          uint16 temp_datacode = 0;
 504   1              if(IRScan.IRReceiveFlag)
 505   1              {
 506   2              SetBuzzer(1,1); 
 507   2              //temp_datacode = (IRDIRMASK&IRScan.DataCode);
 508   2              //if(Temp_Dir != temp_datacode)
 509   2              {
 510   3                  //Temp_Dir = temp_datacode;
 511   3                  switch(IRDIRMASK&IRScan.DataCode)//风向
 512   3                  {
 513   4                      case IRFRCW:
 514   4                          if(mcFRState.FR==CCW)
 515   4                              IRControl.FlagFR = 1;
 516   4                          break;
 517   4                      case IRFRCCW:
 518   4                          if(mcFRState.FR==CW)
 519   4                              IRControl.FlagFR = 1;
 520   4                          break;
 521   4                  }
 522   3              }
 523   2              
 524   2              temp_datacode = (IRLEVELMASK&IRScan.DataCode);
 525   2              if(Temp_Level != temp_datacode)
 526   2              {
 527   3                  Temp_Level = temp_datacode;
 528   3                  switch(IRScan.DataCode&IRLEVELMASK) //转速
 529   3                  {
 530   4                      case IRALLOFF://关机
 531   4                          if(!IRControl.FlagUserCodeSave)
 532   4                          {
 533   5                              if(mcSpeedRamp.FlagONOFF == 1)
 534   5                              {
 535   6          //                                          IRControl.ONOFFStatus = 0;
 536   6                                  IRControl.TargetSpeed = 0;
 537   6                                  mcSpeedRamp.FlagONOFF = 0;
 538   6                                  
 539   6                                  //在反转过程中关机时退出反转状态
 540   6                                  mcFRState.FlagFR = 0;               
 541   6                                  mcFRState.FRStatus = 0;
 542   6                                  
 543   6                              }
 544   5                              NatureWinFlag =0;               
 545   5                              IRControl.FlagSpeed = 1;
 546   5                          }
 547   4                          break;
 548   4                      case IRSpeed1: //风速1
 549   4                          SetSpeed(1);
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 10  

 550   4                          NatureWinFlag =0;
 551   4                          break;
 552   4                      case IRSpeed2://风速2
 553   4                          SetSpeed(2);
 554   4                          NatureWinFlag =0;
 555   4                          break;
 556   4                      case IRSpeed3://风速3
 557   4                          SetSpeed(3);
 558   4                          NatureWinFlag =0;
 559   4                          break;
 560   4                      case IRSpeed4://风速4
 561   4                          SetSpeed(4);
 562   4                          NatureWinFlag =0;
 563   4                          break;
 564   4                      case IRSpeed5://风速5
 565   4                          SetSpeed(5);
 566   4                          NatureWinFlag =0;
 567   4                          break;
 568   4                      case IRSpeed6://风速6
 569   4                          SetSpeed(6);
 570   4                          NatureWinFlag =0;
 571   4                          break;
 572   4                      case IRSpeed7://风速7
 573   4                          SetSpeed(7);
 574   4                          NatureWinFlag =0;
 575   4                          break;
 576   4                      case IRSpeed8://风速8
 577   4                          SetSpeed(8);
 578   4                          NatureWinFlag =0;
 579   4                          break;
 580   4                      case IRSpeed9:
 581   4                          SetSpeed(9);//风速9
 582   4                          NatureWinFlag =0;
 583   4                          break;
 584   4                      case IRNatureWind3://自然风3
 585   4                          natural_mode = 3;
 586   4                          if(!IRControl.ONOFFStatus)
 587   4                          {
 588   5                              IRControl.ONOFFStatus =1;
 589   5                              IRControl.FlagONOFF = 1;                
 590   5                          }
 591   4                          if(!NatureWinFlag)
 592   4                          {
 593   5                              NatureWinFlag=1;
 594   5                              IRControl.FlagSpeed = 1;
 595   5                              IRControl.TargetSpeed = 1;
 596   5                          }
 597   4                          break;
 598   4                      case IRNatureWind6://自然风6
 599   4                          natural_mode = 6;
 600   4                          if(!IRControl.ONOFFStatus)
 601   4                          {
 602   5                              IRControl.ONOFFStatus =1;
 603   5                              IRControl.FlagONOFF = 1;                
 604   5                          }
 605   4                          if(!NatureWinFlag)
 606   4                          {
 607   5                              NatureWinFlag=1;
 608   5                              IRControl.FlagSpeed = 1;
 609   5                              IRControl.TargetSpeed = 1;
 610   5                          }
 611   4                          break;
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 11  

 612   4                      case IRNatureWind9://自然风9  
 613   4                          natural_mode = 9;
 614   4                          if(!IRControl.ONOFFStatus)
 615   4                          {
 616   5                              IRControl.ONOFFStatus =1;
 617   5                              IRControl.FlagONOFF = 1;                
 618   5                          }
 619   4                          if(!NatureWinFlag)
 620   4                          {
 621   5                              NatureWinFlag=1;
 622   5                              IRControl.FlagSpeed = 1;
 623   5                              IRControl.TargetSpeed = 1;
 624   5                          }
 625   4                          break;
 626   4                      default:
 627   4                          break;
 628   4                  }
 629   3              }
 630   2             
 631   2              //temp_datacode = (IRDATAMASK&IRScan.DataCode);
 632   2              //if(Temp_Data != temp_datacode)
 633   2              {
 634   3                  //Temp_Data = temp_datacode;
 635   3                  switch(IRDATAMASK&IRScan.DataCode)
 636   3                  {
 637   4                      case IRAUTOPOWER0H:
 638   4                          SetAutoPower(0);            //1H定时
 639   4                          break;
 640   4                      case IRAUTOPOWER1H:
 641   4                          SetAutoPower(720);          //1H定时
 642   4                          break;
 643   4                      case IRAUTOPOWER2H:
 644   4                          SetAutoPower(1440);         //2H定时
 645   4                          break;
 646   4                      case IRAUTOPOWER4H:
 647   4                          SetAutoPower(2880);         //4H定时
 648   4                          break;
 649   4                      case IRLEDDIM:              //调光开关
 650   4                          IRControl.FlagLED = 1;
 651   4                          break;
 652   4                      case IRLED:                 //普通开关
 653   4                          IRControl.FlagLED = 1;
 654   4                          dimmer_level = 30;
 655   4                          break;
 656   4                      case IRDIMEERADD:           //调光+
 657   4                                              if(dimmer_level == 1)
 658   4                                                      dimmer_level = 40;
 659   4      
 660   4                                              if(dimmer_level == 30)
 661   4                              dimmer_level = 30;
 662   4                                              else
 663   4                                                      dimmer_level--;
 664   4                          break;
 665   4                      case IRDIMEERSUB:           //调光-
 666   4                                              if(dimmer_level == 39)
 667   4                                                      dimmer_level = 0;
 668   4                          
 669   4                                              if(dimmer_level == 25)
 670   4                                                      dimmer_level = 25;
 671   4                                              else
 672   4                                                  dimmer_level++;
 673   4                          break;
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 12  

 674   4                      default:
 675   4                          break;
 676   4                  }
 677   3              }
 678   2              IRScan.DataCode = 0;
 679   2              IRScan.IRReceiveFlag = 0;
 680   2          }   
 681   1      }
 682          /*-------------------------------------------------------------------------------------------------
 683                  Function Name : void AutoPowerControl(void)
 684                  Description   : 自动控制开关机
 685                  Input         : 无
 686            Output                                :       无
 687          -------------------------------------------------------------------------------------------------*/
 688          void AutoPowerControl(void)
 689          {
 690   1                      if(IRControl.FlagAutoPower)
 691   1                      {
 692   2      //                      if(AutoPowerState.FlagAutoPower)
 693   2      //                      {
 694   2      //                              AutoPowerState.FlagAutoPower=0;
 695   2      //                      }
 696   2      //                      else
 697   2      //                      {
 698   2      //                              AutoPowerState.FlagAutoPower=1;
 699   2      //                      }
 700   2                  if(AutoPowerState.ShutDowntime > 0)
 701   2                  {
 702   3                      AutoPowerState.FlagAutoPower=1;
 703   3                  }
 704   2                  else
 705   2                  {
 706   3                      AutoPowerState.FlagAutoPower=0;
 707   3                  }
 708   2                              
 709   2                              AutoPowerState.Timer10sec=0;                    //每次按遥控重新计时
 710   2                              AutoPowerState.CurrentTime=0;
 711   2                              
 712   2                              IRControl.FlagAutoPower=0;                      
 713   2                      }
 714   1               //自动关机
 715   1               if(AutoPowerState.FlagAutoPower&&IRControl.ONOFFStatus)
 716   1                      {
 717   2                              AutoPowerState.Timer10sec++;
 718   2                              //if(AutoPowerState.Timer10sec>10000)
 719   2                              if(AutoPowerState.Timer10sec>100)
 720   2                              {
 721   3                                      AutoPowerState.Timer10sec=0;
 722   3                                      AutoPowerState.CurrentTime++;
 723   3                                      if(AutoPowerState.CurrentTime>=AutoPowerState.ShutDowntime)
 724   3                                      {
 725   4      //                                              if(IRControl.ONOFFStatus)
 726   4      //                                              {
 727   4                                                              IRControl.ONOFFStatus = 0;
 728   4                                                              IRControl.TargetSpeed = 0;
 729   4      //                                              }
 730   4      //                                              else
 731   4      //                                              {
 732   4      //                                                      IRControl.ONOFFStatus =1;
 733   4      //                                                      PIControlTime = SPEED_LOOP_TIME;
 734   4      //                                                      IRControl.TargetSpeed = MOTOR_POWER_LEVEL_1;
 735   4      //                                              }
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 13  

 736   4                                               IRControl.FlagONOFF = 1;                       
 737   4                                               SetBuzzer(1,1);
 738   4                                               IRControl.FlagSpeed = 1;
 739   4                                               AutoPowerState.CurrentTime=0;
 740   4                                               AutoPowerState.FlagAutoPower = 0;
 741   4                                      }
 742   3                              }
 743   2                      }
 744   1                      else
 745   1                      {
 746   2                              AutoPowerState.FlagAutoPower=0;
 747   2                              AutoPowerState.Timer10sec=0;
 748   2                              AutoPowerState.ShutDowntime=0;
 749   2                              AutoPowerState.CurrentTime=0;
 750   2                      }
 751   1      }
 752          
 753          /*-------------------------------------------------------------------------------------------------
 754                  Function Name : uint8 GetUserCode(void)
 755                  Description   : LED显示，IO口电平变化实现
 756                  Input         : 无
 757            Output                                :       无
 758          -------------------------------------------------------------------------------------------------*/
 759          void LEDDisplay(void)
 760          {
 761   1      //      static uint8 LEDDiaplayStatus=0;
 762   1              
 763   1              if(IRControl.FlagLED)
 764   1              {
 765   2                      if(IRControl.LEDONOFFStatus==0)
 766   2                      {
 767   3                              ResetLEDPin;
 768   3                              IRControl.LEDONOFFStatus=1;
 769   3                      }
 770   2                      else 
 771   2                      {
 772   3                              SetLEDPin;
 773   3                              IRControl.LEDONOFFStatus=0;
 774   3                      }
 775   2                      IRControl.FlagLED = 0;
 776   2              }
 777   1              
 778   1      }
 779          
 780          void NatureWind(void)
 781          {
 782   1              static uint16 NatureWindCnt=0;
 783   1              static uint8  NatureWindStep=0;
 784   1              if((!NatureWinFlag)||(IRControl.FlagFR)||(!IRControl.ONOFFStatus)||(mcState!=mcRun))
 785   1              {
 786   2                      NatureWindCnt = 0;
 787   2                      NatureWindStep = 0;
 788   2                      return;
 789   2              }
 790   1              else
 791   1              {
 792   2                      NatureWindCnt++;
 793   2              }
 794   1              if(NatureWindCnt>8000)
 795   1              {
 796   2                      NatureWindCnt = 0;
 797   2                      if(++NatureWindStep>=natural_mode)      NatureWindStep=0;
C51 COMPILER V9.52.0.0   IRSCAN                                                            09/25/2018 16:17:03 PAGE 14  

 798   2                      IRControl.TargetSpeed = NatureWinCode[NatureWindStep];
 799   2                      IRControl.FlagSpeed = 1;
 800   2              }
 801   1      }
 802          
 803          void Dimmer_Control(void)
 804          {
 805   1          if(IRScan.IRReceiveFlag == 0)
 806   1          {
 807   2              dimmer_interval++;
 808   2          }
 809   1          dimmer_cnt++;
 810   1          if(IRControl.LEDONOFFStatus==1)
 811   1          {
 812   2              if(dimmer_level == 30)
 813   2              {
 814   3                  ResetLEDPin;
 815   3              }
 816   2              else if(dimmer_level == 25)
 817   2              {
 818   3                  SetLEDPin;
 819   3              }
 820   2              else
 821   2              {
 822   3                  if(dimmer_cnt == dimmer_level)
 823   3                  {
 824   4                      ResetLEDPin;
 825   4                  }
 826   3                  else if (dimmer_cnt == dimmer_level+1)
 827   3                  {
 828   4                      SetLEDPin;
 829   4                  }   
 830   3                  else if(dimmer_cnt == dimmer_level + 39)
 831   3                  {
 832   4                      ResetLEDPin;
 833   4                  }
 834   3                  else if (dimmer_cnt == dimmer_level+40)
 835   3                  {
 836   4                      SetLEDPin;
 837   4                  } 
 838   3              }
 839   2          }
 840   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2265    ----
   CONSTANT SIZE    =      9    ----
   XDATA SIZE       =    117       3
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


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