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

📄 ht1621.lst

📁 stc15单片机测试程序V1.0版
💻 LST
📖 第 1 页 / 共 2 页
字号:
 138          
 139          //Synchro:low=9ms,high=4.5/2.25ms,low=0.5626ms
 140          //Bit0:high=0.5626ms,low=0.5626ms
 141          //Bit1:high=1.6879ms,low=0.5626ms
 142          //frame space = 23 ms or 96 ms
 143          
 144          /******************** 红外采样时间宏定义, 用户不要随意修改      *******************/
 145          
 146          #if ((D_TIMER0 <= 250) && (D_TIMER0 >= 60))
 147                  #define D_IR_sample                     D_TIMER0                //定义采样时间,在60us~250us之间
 148          #endif
 149          
 150          #define D_IR_SYNC_MAX           (15000/D_IR_sample)     //SYNC max time
 151          #define D_IR_SYNC_MIN           (9700 /D_IR_sample)     //SYNC min time
 152          #define D_IR_SYNC_DIVIDE        (12375/D_IR_sample)     //decide data 0 or 1
 153          #define D_IR_DATA_MAX           (3000 /D_IR_sample)     //data max time
 154          #define D_IR_DATA_MIN           (600  /D_IR_sample)     //data min time
 155          #define D_IR_DATA_DIVIDE        (1687 /D_IR_sample)     //decide data 0 or 1
 156          #define D_IR_BIT_NUMBER         32                                      //bit number
 157          
 158          //*******************************************************************************************
 159          //**************************** IR RECEIVE MODULE ********************************************
 160          
 161          void IR_RX_HT6121(void)
 162          {
 163   1              uchar   SampleTime;
 164   1      
 165   1              IR_SampleCnt++;                                                 //Sample + 1
 166   1      
 167   1              F0 = P_IR_RX_temp;                                              //Save Last sample status
 168   1              P_IR_RX_temp = P_IR_RX;                                 //Read current status
 169   1              if(F0 && !P_IR_RX_temp)                                 //Last sample is high,and current sample is low, so is fall edge
 170   1              {
 171   2                      SampleTime = IR_SampleCnt;                      //get the sample time
 172   2                      IR_SampleCnt = 0;                                       //Clear the sample counter
 173   2      
 174   2                               if(SampleTime > D_IR_SYNC_MAX)         B_IR_Sync = 0;  //large the Maxim SYNC time, then error
 175   2                      else if(SampleTime >= D_IR_SYNC_MIN)                                    //SYNC
 176   2                      {
 177   3                              if(SampleTime >= D_IR_SYNC_DIVIDE)
 178   3                              {
C51 COMPILER V9.01   HT1621                                                                05/20/2012 12:25:30 PAGE 4   

 179   4                                      B_IR_Sync = 1;                                  //has received SYNC
 180   4                                      IR_BitCnt = D_IR_BIT_NUMBER;    //Load bit number
 181   4                              }
 182   3                      }
 183   2                      else if(B_IR_Sync)                                              //has received SYNC
 184   2                      {
 185   3                              if(SampleTime > D_IR_DATA_MAX)          B_IR_Sync=0;    //data samlpe time to large
 186   3                              else
 187   3                              {
 188   4                                      IR_DataShit >>= 1;                                      //data shift right 1 bit
 189   4                                      if(SampleTime >= D_IR_DATA_DIVIDE)      IR_DataShit |= 0x80;    //devide data 0 or 1
 190   4                                      if(--IR_BitCnt == 0)                            //bit number is over?
 191   4                                      {
 192   5                                              B_IR_Sync = 0;                                  //Clear SYNC
 193   5                                              if(~IR_DataShit == IR_data)             //判断数据正反码
 194   5                                              {
 195   6                                                      if((IR_UserH == (User_code / 256)) &&
 196   6                                                              IR_UserL == (User_code % 256))
 197   6                                                                      B_IrUserErr = 0;        //User code is righe
 198   6                                                      else    B_IrUserErr = 1;        //user code is wrong
 199   6                                                              
 200   6                                                      IR_code      = IR_data;
 201   6                                                      B_IR_Press   = 1;                       //数据有效
 202   6                                              }
 203   5                                      }
 204   4                                      else if((IR_BitCnt & 7)== 0)            //one byte receive
 205   4                                      {
 206   5                                              IR_UserL = IR_UserH;                    //Save the User code high byte
 207   5                                              IR_UserH = IR_data;                             //Save the User code low byte
 208   5                                              IR_data  = IR_DataShit;                 //Save the IR data byte
 209   5                                      }
 210   4                              }
 211   3                      }
 212   2              }
 213   1      }
 214          
 215          
 216          /**************** Timer初始化函数 ******************************/
 217          void InitTimer(void)
 218          {
 219   1              TMOD = 0;               //for STC15Fxxx系列     Timer0 as 16bit reload timer.
 220   1              TH0 = Timer0_Reload / 256;
 221   1              TL0 = Timer0_Reload % 256;
 222   1              ET0 = 1;
 223   1              TR0 = 1;
 224   1      
 225   1              EA  = 1;
 226   1      }
 227          
 228          
 229          /********************** Timer0中断函数************************/
 230          void timer0 (void) interrupt 1
 231          {
 232   1              IR_RX_HT6121();
 233   1      }
 234          
 235          
 236          /********************** 模拟串口相关函数************************/
 237          
 238          void    BitTime(void)   //位时间函数
 239          {
 240   1              uint i;
C51 COMPILER V9.01   HT1621                                                                05/20/2012 12:25:30 PAGE 5   

 241   1              i = ((MAIN_Fosc / 100) * 104) / 140000 - 1;             //根据主时钟来计算位时间
 242   1              while(--i);
 243   1      }
 244          
 245          //模拟串口发送
 246          void    Tx1Send(uchar dat)              //9600,N,8,1         发送一个字节
 247          {
 248   1              uchar   i;
 249   1              EA = 0;
 250   1              P_TXD1 = 0;
 251   1              BitTime();
 252   1              for(i=0; i<8; i++)
 253   1              {
 254   2                      if(dat & 1)             P_TXD1 = 1;
 255   2                      else                    P_TXD1 = 0;
 256   2                      dat >>= 1;
 257   2                      BitTime();
 258   2              }
 259   1              P_TXD1 = 1;
 260   1              EA = 1;
 261   1              BitTime();
 262   1              BitTime();
 263   1      }
 264          
 265          void PrintString(unsigned char code *puts)              //发送一串字符串
 266          {
 267   1          for (; *puts != 0;  puts++)  Tx1Send(*puts);        //遇到停止符0结束
 268   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    358    ----
   CONSTANT SIZE    =     72    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      7    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      4    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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