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

📄 zdjjc.lst

📁 织带机产量检测系统的监测终端。RS-485总线
💻 LST
📖 第 1 页 / 共 4 页
字号:
 602   3                      case 3:  //确认
 603   3                                       //保存波特率
 604   3                                       C24SetBuf (BAUD_RATE, &BaudIndex, 1);
 605   3                           EX1 = TRUE; //重开脉冲采样
 606   3                           displayBuf[6] = 0x08;
 607   3                           curKey = NO_KEY;
 608   3                           return;
 609   3                 }
 610   2                     curKey = NO_KEY; 
 611   2               }
 612   1      }
 613          
C51 COMPILER V7.50   ZDJJC                                                                 02/27/2006 21:10:46 PAGE 11  

 614          void SetAddress (uchar uAddress)
 615          {
 616   1              uchar idata CodeIndex[3] = {0, 0 ,0};  //段码下标,依次对应片3, 4, 5
 617   1              uchar data Index = 3;  //片选下标
 618   1              uchar i;
 619   1              uint Value = 0;
 620   1      
 621   1              //显示地址
 622   1              displayBuf[0] = SEVEN_BLK1[10];
 623   1              IntToLED (uAddress, 5, FALSE);
 624   1      
 625   1              //换算得到当前值的下标
 626   1              for (i=5; i>2; i--)
 627   1              {
 628   2                      CodeIndex[i-3] = uAddress % 10 + 1;
 629   2                      uAddress = uAddress / 10;
 630   2              } 
 631   1      
 632   1              while (TRUE)
 633   1              {
 634   2                     Delay (100, 100);
 635   2                         switch (curKey)
 636   2                     {
 637   3                      case 0:  //光标移动
 638   3                           Index ++;
 639   3                                   if (Index > 5)
 640   3                                       Index = 3;
 641   3                                   displayBuf[6] = 0x08 >> (Index - 3);    
 642   3                           break;
 643   3                      case 1:  //数字翻动
 644   3                           displayBuf[Index] = SEVEN_BLK1[CodeIndex[Index-3]++];
 645   3                           CodeIndex[Index - 3] = CodeIndex[Index - 3] % 10;
 646   3                           break;
 647   3                      case 2:
 648   3                           break;
 649   3                      case 3:  //确认
 650   3                                   //计算地址
 651   3                                       for (i=0; i<3; i++)
 652   3                                           Value = Value * 10 + CodeIndex[i] - 1;
 653   3                                       if (Value > 0 && Value < 248)
 654   3                                       {
 655   4                                           //保存地址
 656   4                                           Address = Value;
 657   4                                           C24SetBuf (ADDRESS, &Address, 1);
 658   4                                       }
 659   3                                       else
 660   3                                       {
 661   4                                           for (i=0; i<5; i++)
 662   4                                               {
 663   5                                                displayBuf[i+1] = ErrorHint[i]; 
 664   5                                               }
 665   4                                               Delay (100, 350);
 666   4                                       }        
 667   3                                       curKey = NO_KEY;
 668   3                                       SetBaud ();
 669   3                                       return;
 670   3                 }
 671   2                     curKey = NO_KEY; 
 672   2              }
 673   1      
 674   1      }
 675          
C51 COMPILER V7.50   ZDJJC                                                                 02/27/2006 21:10:46 PAGE 12  

 676          void KeyProc ()
 677          {
 678   1           if (curKey !=NO_KEY)
 679   1               {
 680   2                       Delay (100, 100);
 681   2                       switch (curKey)
 682   2                       {
 683   3                       case 0:
 684   3                              ET0 = FALSE;
 685   3                              PulseAct = 0;
 686   3                              RunStatus = TRUE;               
 687   3                                      displayBuf[6] = 0x01;
 688   3                              break;
 689   3                   case 1:
 690   3                          ET0 = FALSE;
 691   3                          PulseCount = 0; 
 692   3                          PulseTotal = 0;
 693   3                              RunStatus = FALSE;
 694   3                              displayBuf[6] = 0x02;
 695   3                              break;
 696   3                       case 2:
 697   3                              ET0 = FALSE; //关闭脉冲采样
 698   3                              EX1 = FALSE; 
 699   3                              displayBuf[6] = 0x04;
 700   3                              //进入设置状态
 701   3                              SetAddress (Address);
 702   3                              break;
 703   3                       case 3:
 704   3                              EX1 = TRUE; //重开脉冲采样
 705   3                              displayBuf[6] = 0x08;
 706   3                              break;
 707   3                       }
 708   2                       curKey = NO_KEY;
 709   2               }
 710   1      }
 711          
 712          void SaveCurrData () reentrant
 713          { 
 714   1               uchar data CurrData[10];
 715   1               uchar data Time[7];
 716   1      
 717   1               //保存当前班数据   
 718   1               //织带长度
 719   1               CurrData[0] = RunLength.b[0];
 720   1               CurrData[1] = RunLength.b[1];
 721   1               //织带累计时间
 722   1               CurrData[2] = RunTime.b[0];
 723   1               CurrData[3] = RunTime.b[1];
 724   1               //调试带长度
 725   1               CurrData[4] = DebugLength.b[0];
 726   1               CurrData[5] = DebugLength.b[1];
 727   1               //调试带累计时间
 728   1               CurrData[6] = DebugTime.b[0];
 729   1               CurrData[7] = DebugTime.b[1];
 730   1               //异常脉冲次数 
 731   1               CurrData[8] = PulseCheat.b[0];
 732   1               CurrData[9] = PulseCheat.b[1];
 733   1      
 734   1               C24SetBuf(RECORD_ROOT+RecordIndex*32, CurrData, 10);
 735   1      
 736   1               //累计停机次数
 737   1               CurrData[0] = 0;
C51 COMPILER V7.50   ZDJJC                                                                 02/27/2006 21:10:46 PAGE 13  

 738   1               CurrData[1] = curMotorStopCount;
 739   1               //累计停机时间
 740   1               CurrData[2] = curMotorStopTimeLength.b[0];
 741   1               CurrData[3] = curMotorStopTimeLength.b[1];
 742   1               //经线断次数
 743   1               CurrData[4] = JingCutCount;
 744   1               //经线断时间
 745   1               CurrData[5] = JingCutTime;
 746   1               //纬线断次数
 747   1               CurrData[6] = WeiCutCount;
 748   1               //纬线断时间
 749   1               CurrData[7] = WeiCutTime;
 750   1               //底线断次数
 751   1               CurrData[8] = DiCutCount;
 752   1               //底线断时间
 753   1               CurrData[9] = DiCutTime;
 754   1      
 755   1               C24SetBuf(RECORD_ROOT+RecordIndex*32+10, CurrData, 10); 
 756   1      
 757   1               //卷绕断次数
 758   1           CurrData[0] = JuanCutCount;
 759   1               //卷绕断时间
 760   1               CurrData[1] = JuanCutTime;
 761   1      
 762   1               //班开始结束时间
 763   1               C24GetBuf (GROUP_TIME+GroupIndex*4, Time, 4);
 764   1               CurrData[2] = Time[0];
 765   1               CurrData[3] = Time[1];
 766   1               CurrData[4] = Time[2];
 767   1               CurrData[5] = Time[3];
 768   1               //当班日期
 769   1               v_Get1302(Time); 
 770   1               CurrData[6] = Time[3];
 771   1               CurrData[7] = Time[4];
 772   1               CurrData[8] = Time[5];
 773   1               CurrData[9] = Time[6];
 774   1      
 775   1               C24SetBuf(RECORD_ROOT+RecordIndex*32+20, CurrData, 10); 
 776   1      }
 777          
 778          
 779          void UartInt(void) interrupt 4
 780          {
 781   1               if (RI)
 782   1               {
 783   2                       RI = FALSE;
 784   2                       IsReceive= TRUE;
 785   2                       UartBuf[Rindex] = SBUF;   //写缓冲区
 786   2                       if (Rindex == 1)
 787   2                       {
 788   3                           //读命令
 789   3                           if (UartBuf[1] == 0x80 ||
 790   3                                   UartBuf[1] == 0x82 ||
 791   3                                       UartBuf[1] == 0x85) 
 792   3                                       UartLength = 4;      
 793   3                                
 794   3                               if (UartBuf[1] == 0x84 ||
 795   3                                   UartBuf[1] == 0x87)
 796   3                                       UartLength = 5;    
 797   3      
 798   3                               if (UartBuf[1] == 0x81 ||
 799   3                                   UartBuf[1] == 0x83)
C51 COMPILER V7.50   ZDJJC                                                                 02/27/2006 21:10:46 PAGE 14  

 800   3                                   UartLength = 22; 
 801   3      
 802   3                           if (UartBuf[1] == 0x86)
 803   3                                   UartLength = 11;
 804   3                                       
 805   3                                       
 806   3                               if (UartBuf[1] == 0x88)
 807   3                                   UartLength = 6;     
 808   3                       }
 809   2      
 810   2                       Rindex ++;
 811   2                      
 812   2                       if (Rindex == UartLength)
 813   2                       {
 814   3                               Rindex = 0;
 815   3                               RecOver = TRUE;
 816   3                       }
 817   2               }
 818   1      
 819   1               if (TI)
 820   1               {
 821   2                       TI = FALSE; 
 822   2                       
 823   2                       EN_SEND = TRUE;
 824   2                       
 825   2                       Tindex ++;
 826   2                       
 827   2                       if (Tindex < UartLength)
 828   2                       {
 829   3                           SBUF = UartBuf[Tindex];
 830   3                               TrasOver = FALSE;
 831   3                       }
 832   2                       else
 833   2                       {
 834   3                               EN_SEND = FALSE;
 835   3                               TrasOver = TRUE;
 836   3                               RecOver = FALSE;
 837   3                               Tindex = 0;
 838   3                       }     
 839   2               }
 840   1      }
 841          
 842          void ModbusProcess(void)
 843          {
 844   1           uchar data QueryIndex;
 845   1           uchar idata *pBuf;
 846   1           uchar idata Time[7];
 847   1               uchar data RxAddress;
 848   1               WordType CRC;
 849   1      
 850   1               REN = FALSE;
 851   1               if (UartBuf[0] == Address || 
 852   1                   UartBuf[0] == 0 ||
 853   1                       UartBuf[0] == 0xFF)  //比较地址
 854   1               {
 855   2                       //计算校验码
 856   2                       CRC.w = CRC16(UartBuf, UartLength-2);
 857   2                       if (CRC.b[0] == UartBuf[UartLength-2] &&                 //比较校验码
 858   2                           CRC.b[1] == UartBuf[UartLength-1])
 859   2                   {
 860   3                           RxAddress = UartBuf[0];  //保存旧地址 
 861   3                               UartBuf[0] = Address;    //写地址
C51 COMPILER V7.50   ZDJJC                                                                 02/27/2006 21:10:46 PAGE 15  

 862   3      
 863   3                               Tindex = 0;
 864   3                               
 865   3                               //判断命令号
 866   3                               switch (UartBuf[1])
 867   3                               {
 868   4                               case 0x80:
 869   4                                     pBuf = UartBuf+2;
 870   4                                    //读交班时间
 871   4                                        C24GetBuf (GROUP_TIME, pBuf, 17);
 872   4                                        UartLength = 22;
 873   4                                        //写班号
 874   4                                        UartBuf[19] = GroupIndex;
 875   4                                    break;
 876   4                               case 0x81:
 877   4                                    pBuf = UartBuf+2; 
 878   4                                    //写交班时间
 879   4                                    C24SetBuf (GROUP_TIME, pBuf, 17);
 880   4                                    UartLength = 4;
 881   4                                    break;
 882   4                               case 0x82:
 883   4                                    pBuf = UartBuf+2;
 884   4                                    //读当前设备各数据
 885   4                                        C24GetBuf (TERM_H, pBuf, 18);
 886   4                                        UartBuf[6] = 0x00;
 887   4                                        if (!motorStatus)
 888   4                                            UartBuf[6] |= 0x01;
 889   4                                        if (RunStatus)
 890   4                                            UartBuf[6] |= 0x02;
 891   4                                        UartLength = 22;
 892   4                                    break;
 893   4                           case 0x83:
 894   4                                pBuf = UartBuf+4; 
 895   4                                //写当前设备各数据
 896   4                                C24SetBuf (KVALUE_H, pBuf, 2);   //写K值
 897   4                                        pBuf = pBuf+3; 
 898   4                                        C24SetBuf (BAUD_RATE, pBuf, 1);   //写波特率
 899   4                                        pBuf = pBuf+1;
 900   4                                        C24SetBuf (ADDRESS, pBuf, 5);   //写地址等
 901   4                                UartLength = 4;
 902   4                                GetEEPromData ();  //重新读数据
 903   4                                        InitBaud(); 
 904   4                                    break;
 905   4                               case 0x84:

⌨️ 快捷键说明

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