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

📄 host.lst

📁 智能数字电流表。双CPU工作
💻 LST
📖 第 1 页 / 共 5 页
字号:
 543          void Hints(uchar *pChar) reentrant
 544          {
 545   1              byte i;
 546   1          TRG = 1;
 547   1              TRG = 0;
 548   1              I_Send('T');
 549   1              Delay(1, 5);
 550   1              for (i=0; i<5; i++)
C51 COMPILER V7.01  HOST                                                                   03/24/2005 22:10:08 PAGE 10  

 551   1              {
 552   2                      I_Send(pChar[4-i]);
 553   2                      rst_wdog();
 554   2              }
 555   1              return;
 556   1      }
 557          
 558          //显示测量数据
 559          void DisplayCurrent()
 560          {
 561   1              uchar i;
 562   1          dword dwCurrent; 
 563   1              dword Count;
 564   1              word wOutput, wALR_L, wALR_H;
 565   1              Count = GetCount();
 566   1      
 567   1              //计算
 568   1              wOutput = Param.wOutput.w;
 569   1              wALR_L = Param.wALR_L.w;
 570   1              wALR_H = Param.wALR_H.w;
 571   1              for (i=0; i<4-Param.PointPos; i++)
 572   1              {
 573   2                      wOutput /= 10;
 574   2                      wALR_L /= 10;
 575   2                      wALR_H /= 10;
 576   2                      rst_wdog();
 577   2              }
 578   1              //计算转换量
 579   1              if (Count >= Param.wZero.dw)
 580   1                  dwCurrent = (Count - Param.wZero.dw) * wOutput * 100 / (Param.wInCount.dw - Param.wZero.dw);
 581   1              Param.Current.w = dwCurrent / 10;
 582   1              if ((dwCurrent % 10) > 4)  //四舍五入
 583   1                  Param.Current.w ++ ;
 584   1              rst_wdog();
 585   1              //报警
 586   1              if (Param.bAlert)
 587   1              {
 588   2                      if (Param.Current.w < wALR_L * 10)   //低报警
 589   2                              JDQL = 0;       
 590   2                  if (Param.Current.w > wALR_L * 12)      //低报警回滞
 591   2                      JDQL = 1;
 592   2                      if (Param.Current.w > wALR_H * 10)   //高报警
 593   2                              JDQH = 0;               
 594   2                      if (Param.Current.w < wALR_H * 8)    //高报警回滞
 595   2                              JDQH = 1;
 596   2                      rst_wdog();
 597   2              }
 598   1              //显示
 599   1              Display(Param.Current.w, 3);
 600   1              //Display(Count, 5);
 601   1              return;
 602   1      }
 603          
 604          uchar GetKeyValue(word *pValue, word Data, uchar uNum) reentrant
 605          {
 606   1              uchar KeyValue, i;
 607   1              uchar CodeIndex[4] = {0, 0, 0 ,0};  //段码下标,依次对应片1, 2, 3, 4
 608   1              uchar uSelIndex = 4;     //片选下标
 609   1              word  Value = 0;
 610   1              
 611   1              //换算得到当前值的下标
 612   1              for (i=0; i<uNum; i++)
C51 COMPILER V7.01  HOST                                                                   03/24/2005 22:10:08 PAGE 11  

 613   1              {
 614   2                      CodeIndex[3-i] = Data % 10 + 1;
 615   2                      Data = Data / 10;
 616   2                      rst_wdog();
 617   2              }
 618   1          
 619   1              while (1)
 620   1              {
 621   2                      KeyValue = P2 & 0xF0;   //去掉低4位
 622   2                      if (KeyValue != 0xF0)
 623   2                      {
 624   3                              Delay(10, 500);
 625   3                              KeyValue = P2 & 0xF0;
 626   3                              switch (KeyValue)
 627   3                              {
 628   4                              case 0xE0:  //左键, 翻数字
 629   4                                  TRG = 1;
 630   4                                      TRG = 0;
 631   4                                      I_Send('S');
 632   4                                      Delay(1, 5);
 633   4                                      I_Send(uSelIndex);
 634   4                                      I_Send(uLEDChar[CodeIndex[uSelIndex - 1]++]);
 635   4                                      CodeIndex[uSelIndex - 1] = CodeIndex[uSelIndex - 1] % 10;
 636   4                                      break;
 637   4                              case 0xD0:  //右键, 翻片子
 638   4                                      uSelIndex ++;
 639   4                                  if (uSelIndex > 4) 
 640   4                                      uSelIndex = 5 - uNum;
 641   4                                      TRG = 1;
 642   4                                      TRG = 0;
 643   4                                      I_Send('S');
 644   4                                      Delay(1, 5);
 645   4                                      I_Send(uSelIndex + 4);
 646   4                                      break;
 647   4                              case 0xB0:  //MENU,取消操作
 648   4                                      TRG = 1;   //停止闪烁
 649   4                                      TRG = 0;   
 650   4                                      I_Send('N');   
 651   4                                      return 0xB0;
 652   4                              case 0x70:  //回车,确认操作
 653   4                                      TRG = 1;  //静止显示
 654   4                                      TRG = 0;
 655   4                                      I_Send('A');
 656   4                                      //计算数据
 657   4                                      for (i=4-uNum; i<4; i++)
 658   4                                           Value = Value * 10 + CodeIndex[i] - 1;
 659   4                                      *pValue = Value;
 660   4                                      changed = 1;
 661   4                                      Delay(50, 1000);
 662   4                                      TRG = 1;   //停止闪烁
 663   4                                      TRG = 0;   
 664   4                                      I_Send('N');  
 665   4                                      return 0x70;
 666   4                              default:
 667   4                                      break;
 668   4                              }
 669   3                      }
 670   2                      rst_wdog();
 671   2              }
 672   1              return 0x70;    
 673   1      }
 674          
C51 COMPILER V7.01  HOST                                                                   03/24/2005 22:10:08 PAGE 12  

 675          void KeyResult(uchar uKey, uchar uMenu, uchar uEnter, word Value) reentrant
 676          {
 677   1              dword wInCount;
 678   1              uchar uKeyValue;
 679   1          if (uKey == 0xB0)   //MENU,取消操作
 680   1          {
 681   2                       rst_wdog();
 682   2               KeyFuncIndex = uMenu;    //跳到上一层
 683   2               KeyFuncPtr = KeyTab[KeyFuncIndex].CurrentOperate;
 684   2               (*KeyFuncPtr)();  //执行
 685   2              }
 686   1              
 687   1              if (uKey == 0x70)   //回车,确认操作
 688   1              {
 689   2                      if (uEnter == 7)
 690   2                      {
 691   3                              //计算输入值并保存
 692   3                              Param.wInput.w = Value;
 693   3                              wInCount = GetCount();
 694   3                              
 695   3                              if (wInCount < 14158)  //小于标称值20%
 696   3                              {       
 697   4                                      Hints(In_LHint);
 698   4                                      return;
 699   4                              }
 700   3                              if (wInCount > 21236)  //大于标称值20%
 701   3                              {
 702   4                                      Hints(In_HHint);
 703   4                                      return;
 704   4                              }
 705   3                              
 706   3                              Param.wInCount.dw = wInCount;
 707   3                              Param.bAlert = 0;   //关闭报警
 708   3                              JDQL = 1;
 709   3                              JDQH = 1;
 710   3                              rst_wdog();
 711   3                      }
 712   2                      if (uEnter == 26)
 713   2                      {
 714   3                          Param.wOutput.w = Value;
 715   3                          Param.bAlert = 0;   //关闭报警
 716   3                          JDQL = 1;
 717   3                              JDQH = 1;
 718   3                              rst_wdog();
 719   3                  }
 720   2                      if (uEnter == 23)
 721   2                      {
 722   3                          Param.wALR_L.w = Value;
 723   3                              rst_wdog();
 724   3                      }
 725   2                      if (uEnter == 22)
 726   2                      {
 727   3                              if (Value <= Param.wOutput.w)
 728   3                              Param.wALR_H.w = Value;
 729   3                          else
 730   3                              Param.wALR_H.w = Param.wOutput.w;
 731   3                              rst_wdog();
 732   3                  }
 733   2                      if (uEnter == 19)
 734   2                      {
 735   3                          if (Value <256)
 736   3                              Param.bAddress = Value;
C51 COMPILER V7.01  HOST                                                                   03/24/2005 22:10:08 PAGE 13  

 737   3                              rst_wdog();
 738   3                      }
 739   2                      if (uEnter == 4)
 740   2                      {
 741   3                              if ((Param.Password.w == Value) || (Value == 0))      //密码核对
 742   3                      {
 743   4                              uKeyValue = GetKeyValue(&Value, Value, 4);
 744   4                              if (uKeyValue == 0x70)
 745   4                              {
 746   5                                      if (Value != 0)
 747   5                                      {
 748   6                                      Param.Password.w = Value;      //设置密码
 749   6                                      rst_wdog();
 750   6                          } 
 751   5                          }
 752   4                  }
 753   3                      else 
 754   3                      {
 755   4                              Hints(ErrorHint);
 756   4                              Delay(30, 1000);
 757   4                      }
 758   3                      }
 759   2      
 760   2                      changed = 1;
 761   2                      KeyFuncIndex = uEnter;    //跳到...
 762   2              KeyFuncPtr = KeyTab[KeyFuncIndex].CurrentOperate;
 763   2              (*KeyFuncPtr)();  //执行
 764   2              }
 765   1              return;
 766   1      }
 767          
 768          //测量BUSY的量(查询方式)
 769          dword GetCount ()
 770          {
 771   1              uchar i = 5;
 772   1              dword Counts[5], AddCount = 0;
 773   1              WordType Count;   //记数值
 774   1              TMOD = 0x01;   //定时器
 775   1              while (i--)
 776   1              {
 777   2                 TL0 = 0;
 778   2                 TH0 = 0;       //初始化 
 779   2                 while (!BUSY);
 780   2                 //开计数器 
 781   2                 TR0 = 1;
 782   2                 while (BUSY);
 783   2                 TR0 = 0;  //关闭计数器
 784   2                 Count.b[1] = TL0;
 785   2                 Count.b[0] = TH0;
 786   2                 if (Count.w >= 24651)
 787   2                     Counts[i] = Count.w - 24651;
 788   2                 else
 789   2                     i++;             
 790   2                 rst_wdog();
 791   2              }       
 792   1              
 793   1              for(i=0; i<5; i++)
 794   1              {
 795   2                      AddCount += Counts[i];
 796   2                      rst_wdog();
 797   2              }
 798   1              AddCount = AddCount / 10;
C51 COMPILER V7.01  HOST                                                                   03/24/2005 22:10:08 PAGE 14  

 799   1              return AddCount;
 800   1      }
 801          
 802          void OptionProg() reentrant
 803          {
 804   1              if (changed && !flag)
 805   1              {
 806   2                      //提示保存
 807   2                      Hints(SaveHint);
 808   2                      while (1)
 809   2                      {
 810   3                              uchar KeyValue;
 811   3                              KeyValue = P2 & 0xF0;   //去掉低4位
 812   3                              if (KeyValue != 0xF0)
 813   3                              {
 814   4                                      Delay(10, 500);
 815   4                                      KeyValue = P2 & 0xF0;
 816   4                                      while ((P2 & 0xF0) != 0xF0)

⌨️ 快捷键说明

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