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

📄 clone.lst

📁 通过遥控红外信号在电器之间传输数据的软件
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   CLONE                                                                 10/25/2006 14:55:44 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE CLONE
OBJECT MODULE PLACED IN .\clone.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\Src\clone.c OMF2 ROM(COMPACT) BROWSE DEBUG PRINT(.\clone.lst) OBJECT(.\c
                    -lone.obj)

line level    source

   1          /*==========================================================================*/
   2          /*
   3          ;     SOURCE_FILE:    Clone.C
   4          ;     APPLICATION:        LPC9XX
   5          ;     COMPONENT:     MAIN,KEY HANDER,INIT
   6          ;     DATE:           16 May 2006
   7          ;
   8          ;     (C) 2006 : CHANGHONG FPD SOFTWARE Lab
   9                 AUTHOR:       DJ
  10          */
  11          /*==========================================================================*/
  12          
  13          
  14          #define _CLONE_C_
  15          /* ======================================= */
  16          // INCLUDE    
  17          /* ======================================= */
  18          #include <REG922.H>
  19          #include "define.h"
  20          #include "clone.h"
  21          #include "driver.h"
  22          
  23          
  24          /* ======================================= */
  25          //STATIC  VARIABLE DEFINE
  26          /* ======================================= */
  27          static Bool             bKeyDetect = FALSE;
  28          static Byte  DATA   ucKeyValue = 0;
  29          static Byte  IDATA  irSendBuffer[16];
  30          static Word IDATA  wWaitRecCount = 0;
  31          static Byte  IDATA  ucWaitAckType = 0;   
  32          static Word IDATA  wMainLoopCount = 0;
  33          //static Byte  IDATA  temp_count = 0;   
  34          
  35          #ifdef DEBUG
              static Byte  IDATA  uctest = 2;   
              #endif
  38          
  39          /* ======================================= */
  40          //FUNCTION DEFINE
  41          /* ======================================= */
  42          static Byte GetKeyValue(void)
  43          {
  44   1          Byte i = 10;
  45   1          Byte keyValue;      
  46   1          keyValue = KEY_NONE;
  47   1          EKBI = 1;
  48   1         while(i--)   ;      //delay a moment
  49   1          EKBI = 0;
  50   1        if(g_bKBI)
  51   1        {
  52   2              g_bKBI = FALSE; 
  53   2             if(PIN_KEY1 == 0)             //key1 pressed
  54   2                 keyValue = KEY_ACTION;        /* Mod By dj 2006-10-25 */
C51 COMPILER V7.50   CLONE                                                                 10/25/2006 14:55:44 PAGE 2   

  55   2           else if(PIN_KEY2 == 0)
  56   2                keyValue = KEY_FUNC_SEL;              
  57   2           else if(PIN_KEY3 == 0)
  58   2                keyValue = KEY_RESET;
  59   2        }
  60   1        return(keyValue);
  61   1      }
  62          /* ======================================= */
  63          
  64          static void KeyScan(void)
  65          {
  66   1        Byte count = 10;
  67   1        Byte checkKeyValue;
  68   1          ucKeyValue = GetKeyValue();
  69   1         if(ucKeyValue == KEY_NONE)         return;
  70   1         else if(ucKeyValue == KEY_FUNC_SEL)
  71   1         {
  72   2              ucKeyValue = KEY_NONE;
  73   2             if((g_ucCloneStatus == CLONE_NONE) ||
  74   2                 (g_ucCloneStatus == CLONE_SEND_PREPARE)  ||
  75   2                 (g_ucCloneStatus == CLONE_REC_PREPARE))
  76   2             {
  77   3               while(count--)
  78   3               {
  79   4                    Delay1ms(100);
  80   4                      ucKeyValue = GetKeyValue();
  81   4                      if(ucKeyValue == KEY_FUNC_SEL)
  82   4                           ucKeyValue = KEY_NONE;              
  83   4                      else
  84   4                              return;
  85   4               }
  86   3             }
  87   2              else
  88   2                   return;
  89   2              ucKeyValue = KEY_FUNC_SEL;      
  90   2         }
  91   1         else
  92   1         {
  93   2            while(count--) ;
  94   2            checkKeyValue =  GetKeyValue();
  95   2            if(ucKeyValue != checkKeyValue)  return;
  96   2         }
  97   1        
  98   1         bKeyDetect = TRUE;
  99   1      }
 100          /* ======================================= */
 101          static void KeyHandler(void)
 102          {
 103   1      #ifdef DEBUG
                        Byte i;
              #endif
 106   1       if(bKeyDetect)
 107   1              bKeyDetect = FALSE;
 108   1       else return;
 109   1      
 110   1       switch(ucKeyValue)
 111   1       {
 112   2             case KEY_FUNC_SEL:
 113   2                 if(g_ucCloneStatus == CLONE_NONE)
 114   2                          g_ucCloneStatus = CLONE_SEND_PREPARE;                       
 115   2                 else if(g_ucCloneStatus == CLONE_SEND_PREPARE)
 116   2                          g_ucCloneStatus = CLONE_REC_PREPARE;
C51 COMPILER V7.50   CLONE                                                                 10/25/2006 14:55:44 PAGE 3   

 117   2                  else if(g_ucCloneStatus == CLONE_REC_PREPARE)          
 118   2                          g_ucCloneStatus = CLONE_SEND_PREPARE;
 119   2              break;
 120   2              
 121   2               case KEY_ACTION:
 122   2      #ifdef DEBUG
                            IRSend_16ByteData(irSendBuffer);
                            uctest++;
                              Delay1ms(200);
              #else
 127   2      
 128   2                      if(g_ucCloneStatus == CLONE_SEND_PREPARE)
 129   2                              g_ucCloneStatus = CLONE_SEND_SEND_READY;
 130   2                      else if(g_ucCloneStatus == CLONE_REC_PREPARE)
 131   2                              g_ucCloneStatus = CLONE_SEND_REC_READY; 
 132   2      #endif
 133   2      
 134   2               break;
 135   2              
 136   2               case KEY_RESET:
 137   2      #ifdef DEBUG
                       uctest = 2;
                         Delay1ms(100);
              #else
 141   2                    GlobalVariableInit();
 142   2      #endif
 143   2               break;
 144   2              
 145   2              default:
 146   2                      break;
 147   2       }
 148   1       
 149   1        ucKeyValue = KEY_NONE;
 150   1      }
 151          /* ======================================= */
 152          static void GlobalVariableInit(void)
 153          {
 154   1              g_bIRDetect = FALSE;
 155   1              g_bI2cError = FALSE;
 156   1              g_bI2cOk = FALSE;
 157   1              g_bKBI = FALSE;
 158   1              g_ucIRRecDataType = REC_NONE;
 159   1              g_ucCloneStatus = CLONE_NONE;
 160   1              g_wCloneNVAddress = 0;
 161   1              g_wTVNVAddress = CLONE_TV_NV_ADDR_START;
 162   1      }
 163           /* ======================================= */
 164          
 165            /* ======================================= */
 166          
 167          static void McuInit(void)
 168           {
 169   1              EA = 0;
 170   1        /* ======================================= */
 171   1       //PIN INIT
 172   1       
 173   1        /*
 174   1            PxM1.y PxM2.y Port output mode
 175   1              0 0 Quasi-bidirectional
 176   1              0 1 Push-pull
 177   1              1 0 Input only (high impedance)
 178   1              1 1 Open drain
C51 COMPILER V7.50   CLONE                                                                 10/25/2006 14:55:44 PAGE 4   

 179   1      
 180   1          P0-----KB0--KB7
 181   1          P1-----RST,INT1,SDA,SCL,RXD,TXD
 182   1      */
 183   1               P0 = 0x00;
 184   1               P1 = BIT2+ BIT3 + BIT6;
 185   1      //this pin open drain
 186   1               P0M2 |= BIT0+ BIT6 + BIT7;        // 3 led pin
 187   1               P1M2 |= BIT2+ BIT3 + BIT6 + BIT7;     //scl , sda , ir_out,led
 188   1      //other pin ----Input only
 189   1        /* ======================================= */
 190   1      //IIC INIT
 191   1      //      EI2C = 1;
 192   1              I2EN = 1;
 193   1              AA = 1;
 194   1              //   CRSEL = 0;
 195   1              I2SCLH = 25;
 196   1              I2SCLL = 25;//70K about
 197   1      /* ======================================= */
 198   1      //INT priority
 199   1              /*
 200   1              IPxH IPx Interrupt priority level
 201   1              0 0 Level 0 (lowest priority)
 202   1              0 1 Level 1
 203   1              1 0 Level 2
 204   1              1 1 Level 3
 205   1              */
 206   1            PT1 = 1;//timer 1 level 1
 207   1            
 208   1            IP0H |= BIT2;//INT1 LEVEL 2 for ir rec     //20060616
 209   1      
 210   1            IP1 |= BIT0;  
 211   1            IP1H |= BIT0;   //priority if the IIC is level 3
 212   1        /* ======================================= */
 213   1        //ADC INIT
 214   1          /*
 215   1             ADCON1  ENBI1 ENADCI1 TMM1 EDGE1 ADCI1 ENADC1 ADCS11 ADCS10 00 00000000
 216   1              ADINS      ADI13 ADI12 ADI11 ADI10 - - - - 00 00000000
 217   1              ADMODA  BNDI1 BURST1 SCC1 SCAN1 - - - - 00 00000000
 218   1              ADMODB   CLK2 CLK1 CLK0 - ENDAC1 - BSA1 - 00 000x0000
 219   1        
 220   1              ADCON1    = 0x05;//Immediate Start mode.  and Enable A/D channel 1.
 221   1              ADINS      = 0x20;//ADI11 key input
 222   1              ADMODA   = 0x10;//single conversion mode 
 223   1              ADMODB   = 0x40;//adc clock is CCLK/3 = 2.46M
 224   1         */
 225   1        /* ======================================= */
 226   1      //TIMER INIT
 227   1             ET1 = 1;//enable timer 1
 228   1              TMOD = 0x11;// mode 1---16bit
 229   1              WDCON &=0xE0;  //Shut down WDT
 230   1        /* ======================================= */
 231   1        //EXTERAL INTERRUPT
 232   1               EX1 = 1;
 233   1               IT1 =  1;       
 234   1        /* ======================================= */
 235   1      //KBI INIT
 236   1              KBMASK = BIT1 + BIT2 + BIT3;
 237   1           EA = 1;        //enable all interrupt
 238   1       }
 239           /* ======================================= */
 240          
C51 COMPILER V7.50   CLONE                                                                 10/25/2006 14:55:44 PAGE 5   

 241           Byte CalculateCheckSum(Byte DataNum,Byte *pbuffer)
 242          {     
 243   1          Byte i;
 244   1          Word TempSum = 0;
 245   1          for(i = 0;i < DataNum;i++)
 246   1          {
 247   2              TempSum += *pbuffer;
 248   2              pbuffer++;              
 249   2          }
 250   1          return((Byte)TempSum);      
 251   1      }
 252          /* ======================================= */
 253          
 254          static Bool VerifyCheckSum(CHECK_SUM_TYPE type)
 255          {
 256   1           Byte temp;
 257   1             switch(type)
 258   1             {
 259   2               case CHECK_ADDRESS:
 260   2                              if(CalculateCheckSum(2,&irRecBuffer[2]) == irRecBuffer[4])
 261   2                                return(TRUE); 
 262   2                              break;
 263   2                case CHECK_N_BYTE:
 264   2                             temp = irRecBuffer[2];//data byte numbers
 265   2                              if(CalculateCheckSum(temp,&irRecBuffer[3]) == irRecBuffer[temp + 3])
 266   2                                return(TRUE);         
 267   2                              break;          
 268   2               case CHECK_16_BYTE:
 269   2                            if(CalculateCheckSum(16,&irRecBuffer[2]) == irRecBuffer[18])
 270   2                                return(TRUE);
 271   2                              break;  
 272   2                  default:
 273   2                              break;
 274   2              }
 275   1               return(FALSE);  
 276   1      }
 277          /* ======================================= */
 278          static Bool CheckRecAck(WAIT_ACK_TYPE type)
 279          {
 280   1              switch(type)
 281   1              {
 282   2                  case SEND_SENDREADY_WAITACK:
 283   2                      if(g_ucIRRecDataType == REC_REC_READY)//get ack
 284   2                      {
 285   3                              g_ucCloneStatus = CLONE_SEND_DATA;
 286   3                              g_wTVNVAddress = CLONE_TV_NV_ADDR_START;
 287   3                              g_wCloneNVAddress = 0;
 288   3                            return(TRUE);
 289   3                      }
 290   2                      break;  
 291   2      /*              
 292   2                  case SEND_ADDRESS_WAITACK:
 293   2                      if(g_ucIRRecDataType == REC_REC_READY)//get ack
 294   2                      {
 295   2                              g_ucCloneStatus = CLONE_SEND_DATA;
 296   2                             return(TRUE);
 297   2                      }
 298   2                      break;
 299   2      */              
 300   2                  case SEND_DATA_WAITACK:
 301   2                      if(g_ucIRRecDataType == REC_REC_READY)//get ack
 302   2                      {
C51 COMPILER V7.50   CLONE                                                                 10/25/2006 14:55:44 PAGE 6   

 303   3                            if(g_wTVNVAddress > CLONE_TV_NV_ADDR_END)
 304   3                            {
 305   4                                 g_ucCloneStatus = CLONE_SEND_END;
 306   4                            }
 307   3                          else
 308   3                          {
 309   4                                g_ucCloneStatus = CLONE_SEND_DATA;
 310   4                          }
 311   3                         return(TRUE);
 312   3                      }               
 313   2                      break;
 314   2                              
 315   2                  case SEND_RECREADY_WAITACK:
 316   2                      if(g_ucIRRecDataType == REC_SEND_READY)
 317   2                      {
 318   3                         IRSend_RecReady();
 319   3                       CloneStatusToRecData();
 320   3                         return(TRUE);
 321   3                      }       
 322   2                              break;
 323   2                      default:
 324   2                              break;
 325   2      
 326   2              }
 327   1             return(FALSE);
 328   1      }

⌨️ 快捷键说明

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