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

📄 timer1.lst

📁 protues仿真keil程序 初学者的福音
💻 LST
📖 第 1 页 / 共 3 页
字号:
 273   6                          }
 274   5                          else PLed5=0 ;
 275   5                      }
 276   4                      else 
 277   4                      PLed5=1 ;
 278   4                      
 279   4                      if(IsRun[CurrLed])
 280   4                      {
 281   5                          if(TimeDelay[CurrLed]<100)
 282   5                          IsFlash[1]=0 ;
 283   5                          else 
 284   5                          IsFlash[1]=1 ;
 285   5                          DisplayData[0]=CurrLed+1 ;
 286   5                          DisplayData[1]=10 ;
 287   5                          DisplayData[2]=TimeDelay[CurrLed]/10%10 ;
 288   5                          DisplayData[3]=TimeDelay[CurrLed]%10 ;
 289   5                      }
 290   4                      else 
 291   4                      {
 292   5                          DisplayData[0]=0 ;
 293   5                          DisplayData[1]=0 ;
 294   5                          DisplayData[2]=0 ;
 295   5                          DisplayData[3]=0 ;
 296   5                          IsFlash[1]=0 ;
 297   5                      }
 298   4                      
 299   4                  }
 300   3                  
 301   3              }
 302   2              
 303   2              //设置状态
C51 COMPILER V9.01   TIMER1                                                                05/06/2012 20:40:06 PAGE 6   

 304   2              else 
 305   2              {
 306   3                  PLed0=1 ;
 307   3                  PLed1=1 ;
 308   3                  PLed2=1 ;
 309   3                  PLed3=1 ;
 310   3                  PLed4=1 ;
 311   3                  PLed5=1 ;
 312   3                  for(i=0;i<6;i++)
 313   3                  {
 314   4                      TimeDelay[i]=TimeSave[i];
 315   4                      IsRun[i]=0 ;
 316   4                  }
 317   3                  
 318   3                  DisplayData[0]=MachineState ;
 319   3                  //显示当前设置哪一路的延时数据
 320   3                  
 321   3                  if(TimeSave[MachineState-1]<100)
 322   3                  IsFlash[1]=0 ;
 323   3                  else 
 324   3                  IsFlash[1]=1 ;
 325   3                  DisplayData[1]=10 ;
 326   3                  
 327   3                  //刚刚进入设置状态,把显示的时间设置为原来设置保存的时间
 328   3                  if(IsSetFirst==1)
 329   3                  {
 330   4                      //设置闪烁位为十位
 331   4                      IsSetFirst=0 ;
 332   4                      DisplayData[2]=TimeSave[MachineState-1]/10%10 ;
 333   4                      DisplayData[3]=TimeSave[MachineState-1]%10 ;
 334   4                      IsFlash[2]=0x01 ;
 335   4                  }
 336   3              }
 337   2          }
 338   1      }
 339          
 340          
 341          //30us执行结束
 342          void FunTimer0(void)interrupt 1 
 343          {
 344   1          TH0=0XeC ;
 345   1          TL0=0X78 ;  
 346   1          //5ms定时中断 4个数码管 所以每个数码管20ms刷新一次。
 347   1          //每到了5ms,就到了该显示1位数据的时间。
 348   1          IsDisplay1BitTime=1 ;
 349   1           if(Time5ms%50==0)
 350   1              {
 351   2                      IsFlashTime=!IsFlashTime ;
 352   2                      if(BeepTimes>0)
 353   2                       {
 354   3                PBeep=BeepTimes%2  ;
 355   3                        BeepTimes--;
 356   3                       }
 357   2      
 358   2                      }
 359   1          //250ms闪烁一次。
 360   1          //每50ms检测一次按键
 361   1          if(Time5ms%10==0)
 362   1          IsScanKeyTime=1 ;
 363   1          //每1000ms
 364   1          if(++Time5ms>=200)
 365   1          {
C51 COMPILER V9.01   TIMER1                                                                05/06/2012 20:40:06 PAGE 7   

 366   2              Time5ms=0 ;
 367   2              IsTime1s=1 ;
 368   2          }
 369   1          
 370   1      }
 371          
 372          
 373          void Display(void)
 374          {
 375   1          PDisplaySeg=BLACK ;
 376   1          //消隐
 377   1          PDisplayBit|=0xf0 ;
 378   1          //高4位清零
 379   1          PDisplayBit&=LedBIt[BitNum];
 380   1          //高4位 送位码
 381   1          if(IsFlashTime&&IsFlash[BitNum])
 382   1          PDisplaySeg=BLACK ;
 383   1          //黑屏用于闪烁
 384   1          else 
 385   1          PDisplaySeg=Led7Code[DisplayData[BitNum]];
 386   1          //送段码
 387   1          
 388   1          //每5ms会自动设置下次显示的数码管位置。
 389   1          if(++BitNum>=4)BitNum=0 ;
 390   1          //为下一个数码管送数据做准备。
 391   1      }
 392          
 393          
 394          void keyScan(void)
 395          {
 396   1          unsigned char ReadData ;
 397   1          
 398   1          //P1口按键检测
 399   1          ReadData=PKeyPort1^0xff ;
 400   1          //
 401   1          KeyPressed1=ReadData&(ReadData^KeyPressing1);
 402   1          KeyPressing1=ReadData ;
 403   1          
 404   1          //P2口按键检测
 405   1          ReadData=PKeyPort2^0xff ;
 406   1          //0000 1110
 407   1          KeyPressed2=ReadData&(ReadData^KeyPressing2)&0x0e ;
 408   1          KeyPressing2=ReadData&0x0e ;
 409   1      }
 410          
 411          
 412          //每隔50ms会执行一次 每次根据按键的值执行对应的键盘子程序
 413          void KeyProgram(void)
 414          {
 415   1          keyScan();
 416   1          //检测一次按键。
 417   1          
 418   1          //P11按下一次的检测 带有消抖功能,消抖时间为50ms。
 419   1          //如果曾经有P11按键按下被检测到了,则现在已经过了50ms再次检测
 420   1          if(IsKeyPressed==1)
 421   1          {
 422   2              IsKeyPressed=0 ;
 423   2              if(KeyPressing1)
 424   2              KeyCode=KeyPressing1 ;
 425   2              if(KeyPressing2)
 426   2              KeyCode=KeyPressing2|0x30 ;
 427   2          }
C51 COMPILER V9.01   TIMER1                                                                05/06/2012 20:40:06 PAGE 8   

 428   1          
 429   1          //有P1P2有任何按键曾经按下,则该端口不为0
 430   1          if(KeyPressed1)IsKeyPressed=1 ;
 431   1          if(KeyPressed2)IsKeyPressed=1 ;
 432   1          //补充根据KeyCode的值执行的函数代码,最后恢复按键的值为0。
 433   1          switch(KeyCode)
 434   1          {
 435   2              
 436   2              case YELLOW :
 437   2              if(MachineState==WORK)
 438   2              {
 439   3                  CurrLed=0 ;
 440   3                  //这一路正在运行
 441   3                  if(IsRun[CurrLed]==1)
 442   3                  {
 443   4                      PLed0=1 ;
 444   4                      IsRun[CurrLed]=0 ;
 445   4                      //停止并数据复位。
 446   4                      TimeDelay[CurrLed]=0 ;
 447   4                  }
 448   3                  else 
 449   3                  {
 450   4                      PLed0=0 ;
 451   4                      IsRun[CurrLed]=1 ;
 452   4                      TimeDelay[CurrLed]=TimeSave[CurrLed];
 453   4                  }
 454   3              }
 455   2              else 
 456   2              {
 457   3                  PLed0=0 ;
 458   3                  MachineState=SET1 ;
 459   3                  if(TimeSave[0]>=100)
 460   3                  TimeSave[0]-=100 ;
 461   3                  IsSetFirst=1 ;
 462   3              }
 463   2              break ;
 464   2              
 465   2              case ORANGE :
 466   2              if(MachineState==WORK)
 467   2              {
 468   3                  CurrLed=1 ;
 469   3                  //这一路正在运行
 470   3                  if(IsRun[CurrLed]==1)
 471   3                  {
 472   4                      PLed1=1 ;
 473   4                      IsRun[CurrLed]=0 ;
 474   4                      //停止并数据复位。
 475   4                      TimeDelay[CurrLed]=0 ;
 476   4                  }
 477   3                  else 
 478   3                  {
 479   4                      PLed1=0 ;
 480   4                      IsRun[CurrLed]=1 ;
 481   4                      TimeDelay[CurrLed]=TimeSave[CurrLed];
 482   4                  }
 483   3              }
 484   2              else 
 485   2              {
 486   3                  PLed1=0 ;
 487   3                  MachineState=SET2 ;
 488   3                  if(TimeSave[1]>=100)
 489   3                  TimeSave[1]-=100 ;
C51 COMPILER V9.01   TIMER1                                                                05/06/2012 20:40:06 PAGE 9   

 490   3                  IsSetFirst=1 ;
 491   3              }
 492   2              break ;
 493   2              
 494   2              case PURPLE :
 495   2              if(MachineState==WORK)
 496   2              {
 497   3                  CurrLed=2 ;
 498   3                  //这一路正在运行
 499   3                  if(IsRun[CurrLed]==1)
 500   3                  {
 501   4                      PLed2=1 ;
 502   4                      IsRun[CurrLed]=0 ;
 503   4                      //停止并数据复位。
 504   4                      TimeDelay[CurrLed]=0 ;
 505   4                  }
 506   3                  else 
 507   3                  {
 508   4                      PLed2=0 ;
 509   4                      IsRun[CurrLed]=1 ;
 510   4                      TimeDelay[CurrLed]=TimeSave[CurrLed];
 511   4                  }
 512   3              }
 513   2              
 514   2              else 
 515   2              {
 516   3                  PLed2=0 ;
 517   3                  MachineState=SET3 ;
 518   3                  if(TimeSave[2]>=100)
 519   3                  TimeSave[2]-=100 ;
 520   3                  IsSetFirst=1 ;
 521   3              }
 522   2              break ;
 523   2              
 524   2              case RED :
 525   2              if(MachineState==WORK)
 526   2              {
 527   3                  CurrLed=3 ;
 528   3                  //这一路正在运行
 529   3                  if(IsRun[CurrLed]==1)
 530   3                  {
 531   4                      PLed3=1 ;
 532   4                      IsRun[CurrLed]=0 ;
 533   4                      //停止并数据复位。
 534   4                      TimeDelay[CurrLed]=0 ;
 535   4                  }
 536   3                  else 
 537   3                  {
 538   4                      PLed3=0 ;
 539   4                      IsRun[CurrLed]=1 ;
 540   4                      TimeDelay[CurrLed]=TimeSave[CurrLed];
 541   4                  }
 542   3              }
 543   2              
 544   2              
 545   2              else 
 546   2              {
 547   3                  PLed3=0 ;
 548   3                  MachineState=SET4 ;
 549   3                  if(TimeSave[3]>=100)
 550   3                  TimeSave[3]-=100 ;
 551   3                  IsSetFirst=1 ;
C51 COMPILER V9.01   TIMER1                                                                05/06/2012 20:40:06 PAGE 10  

⌨️ 快捷键说明

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