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

📄 pc-pic.lst

📁 This is my code (with PIC 18F458) for Modbus RTU Network. I have written by Ccs laguage
💻 LST
📖 第 1 页 / 共 3 页
字号:
CCS PCH C Compiler, Version 4.065, 9011               13-Mar-09 20:01

               Filename: E:\DIEN TU\PLC\MODBUS\VDK\pc-pic.lst

               ROM used: 1568 bytes (5%)
                         Largest free fragment is 31196
               RAM used: 82 (5%) at main() level
                         119 (8%) worst case
               Stack:    4 worst case (2 in main + 2 for interrupts)

*
0000:  GOTO   0538
*
0008:  MOVWF  05
000A:  MOVFF  FD8,06
000E:  MOVFF  FE0,07
0012:  MOVLB  0
0014:  MOVFF  FE9,0D
0018:  MOVFF  FEA,08
001C:  MOVFF  FE1,09
0020:  MOVFF  FE2,0A
0024:  MOVFF  FD9,0B
0028:  MOVFF  FDA,0C
002C:  MOVFF  FF3,14
0030:  MOVFF  FF4,15
0034:  MOVFF  FFA,16
0038:  MOVFF  00,0F
003C:  MOVFF  01,10
0040:  MOVFF  02,11
0044:  MOVFF  03,12
0048:  MOVFF  04,13
004C:  BTFSS  F9D.5
004E:  GOTO   0058
0052:  BTFSC  F9E.5
0054:  GOTO   013E
0058:  MOVFF  0F,00
005C:  MOVFF  10,01
0060:  MOVFF  11,02
0064:  MOVFF  12,03
0068:  MOVFF  13,04
006C:  BSF    0E.7
006E:  MOVFF  0D,FE9
0072:  MOVFF  08,FEA
0076:  MOVFF  09,FE1
007A:  MOVFF  0A,FE2
007E:  MOVFF  0B,FD9
0082:  MOVFF  0C,FDA
0086:  MOVFF  14,FF3
008A:  MOVFF  15,FF4
008E:  MOVFF  16,FFA
0092:  MOVF   05,W
0094:  MOVFF  07,FE0
0098:  MOVFF  06,FD8
009C:  RETFIE 0
.................... //dung giao tiep voi Pc 
.................... #include <18f4580.h> 
.................... //////// Standard Header file for the PIC18F4580 device //////////////// 
.................... #device PIC18F4580 
.................... #list 
....................  
.................... #include <board.h> 
.................... #byte PortA    = 0xF80 
.................... #byte PortB    = 0xF81 
.................... #byte PortC    = 0xF82 
.................... #byte PortD    = 0xF83 
.................... #byte PortE    = 0xF84 
....................  
.................... #byte TrisA    =0xf92 
.................... #byte TrisB    =0xf93 
.................... #byte TrisC    =0xf94 
.................... #byte TrisD    =0xf95 
.................... #byte TrisE    =0xf96 
....................  
.................... #byte LatA     = 0xF89 
.................... #byte LatB     = 0xF8A 
.................... #byte LatC     = 0xF8B 
.................... #byte LatD     = 0xF8C 
.................... #byte LatE     = 0xF8D 
....................  
.................... #bit trisa4    =TrisA.4 
....................  
.................... #define Button       input(PIN_A4) 
.................... #define Led1On       output_high(pin_d0) 
.................... #define Led1Off      output_low(pin_d0) 
.................... #define Led2On       output_high(pin_d1) 
.................... #define Led2Off      output_low(pin_d1) 
.................... #define Led3On       output_high(pin_d2) 
.................... #define Led3Off      output_low(pin_d2) 
.................... #define Led4On       output_high(pin_d3) 
.................... #define Led4Off      output_low(pin_d3) 
.................... #define Led5On       output_high(pin_d4) 
.................... #define Led5Off      output_low(pin_d4) 
.................... #define Led6On       output_high(pin_d5) 
.................... #define Led6Off      output_low(pin_d5) 
.................... #define Led7On       output_high(pin_d6) 
.................... #define Led7Off      output_low(pin_d6) 
.................... #define Led8On       output_high(pin_d7) 
.................... #define Led8Off      output_low(pin_d7) 
....................  
.................... //void getCRC(int8 *message, int8 length,int8 *check); 
....................  
.................... #include <MODBUS-RTU.c> 
.................... #use delay(clock=40000000) 
.................... #use rs232(baud=9600 , parity=n , xmit=pin_C6 , rcv=pin_C7 ) 
....................  
.................... int16   lengthOfQueryMessage_output=0;  
.................... int16   lengthOfResponseMessage_input=0; 
.................... int16   lengthOfResponseMessage_output=0;  
.................... int16   lengthOfQueryMessage_input=0;  
.................... int8    functionCode_Send=0; 
.................... int8    functionCode_Receive=0; 
....................  
.................... int1   StartQueryMessage=0; 
.................... int1   StartResponseMMessage=0; 
.................... int1   StartReceiveMessage=0; 
.................... int1   status=0;               //0:RDA wait querry message 
....................                               //1:RDA wait response message 
....................  
.................... int8   queryMessage[8];       //phai xac dinh ro so luong 
.................... int8   responseMessage[15];   //phai xac dinh ro so luong 
....................  
.................... int8   value=0; 
.................... int8   count=0; 
.................... int8   Stage_ID=0x01; 
.................... int8   command=0; 
.................... //****************************Receive******************************************* 
....................  
.................... int8   CRC[2]; 
.................... int8   NumberPoint_bits=0; 
.................... int8   NumberPoint_bytes=0; 
.................... int16  StartingAddress=0; 
.................... int16  CoilAddress=0;         //function 05 
.................... int8   ByteCount=0;            //function 01 
.................... //***************************************************************************** 
....................  
.................... void transmit () 
.................... { 
....................    int8 i; 
....................  for (i=0;i<lengthOfResponseMessage_output;i++) 
....................     { 
....................     putc(responseMessage[i]); 
....................     } 
.................... } 
....................  
.................... //****************************************************************************** 
.................... void response(int8 *Message) 
.................... { 
.................... int8 i=0; 
*
050A:  CLRF   52
....................     
....................     for (i=0;i<lengthOfResponseMessage_output;i++) 
050C:  CLRF   52
050E:  MOVF   1E,F
0510:  BNZ   0518
0512:  MOVF   1D,W
0514:  SUBWF  52,W
0516:  BC    0536
....................     { 
....................     putc(Message[i]); 
0518:  CLRF   03
051A:  MOVF   52,W
051C:  ADDWF  50,W
051E:  MOVWF  FE9
0520:  MOVF   51,W
0522:  ADDWFC 03,W
0524:  MOVWF  FEA
0526:  MOVFF  FEF,53
052A:  MOVF   53,W
052C:  BTFSS  F9E.4
052E:  BRA    052C
0530:  MOVWF  FAD
....................     } 
0532:  INCF   52,F
0534:  BRA    050E
.................... } 
0536:  RETLW  00
.................... //****************************************************************************** 
....................  
.................... void getCRC(int8 *message, int8 length,int8 *check) // chuong trinh con tinh CRC 
.................... {    
....................    int16 CRCFull = 0xFFFF; 
*
00BC:  MOVLW  FF
00BE:  MOVWF  x6B
00C0:  MOVWF  x6C
....................    int8 CRCHigh = 0xFF, CRCLow = 0xFF; 
00C2:  MOVWF  x6D
00C4:  MOVWF  x6E
....................    int16 CRCLSB; 
....................    int i,j; 
....................    for ( i = 0; i < length; i++) 
00C6:  CLRF   x71
00C8:  MOVF   x68,W
00CA:  SUBWF  x71,W
00CC:  BC    0118
....................    { 
....................       CRCFull = (int16)(CRCFull ^ message[i]); 
00CE:  CLRF   03
00D0:  MOVF   x71,W
00D2:  ADDWF  x66,W
00D4:  MOVWF  FE9
00D6:  MOVF   x67,W
00D8:  ADDWFC 03,W
00DA:  MOVWF  FEA
00DC:  MOVF   FEF,W
00DE:  XORWF  x6B,F
....................       for (j = 0; j < 8; j++) 
00E0:  CLRF   x72
00E2:  MOVF   x72,W
00E4:  SUBLW  07
00E6:  BNC   0114
....................       { 
....................          CRCLSB = (int16)(CRCFull & 0x0001); 
00E8:  MOVF   x6B,W
00EA:  ANDLW  01
00EC:  MOVWF  x6F
00EE:  CLRF   x70
....................          CRCFull = (int16)((CRCFull >> 1) & 0x7FFF); 
00F0:  BCF    FD8.0
00F2:  RRCF   x6C,W
00F4:  MOVWF  x74
00F6:  RRCF   x6B,W
00F8:  MOVWF  x6B
00FA:  MOVF   x74,W
00FC:  ANDLW  7F
00FE:  MOVWF  x6C
....................          if (CRCLSB == 1) 
0100:  DECFSZ x6F,W
0102:  BRA    0110
0104:  MOVF   x70,F
0106:  BNZ   0110
....................          CRCFull = (int16)(CRCFull ^ 0xA001); 
0108:  MOVLW  01
010A:  XORWF  x6B,F
010C:  MOVLW  A0
010E:  XORWF  x6C,F
....................       } 
0110:  INCF   x72,F
0112:  BRA    00E2
....................    } 
0114:  INCF   x71,F
0116:  BRA    00C8
....................    check[1] = CRCHigh = (int8)((CRCFull >> 8) & 0xFF);  
0118:  MOVLW  01
011A:  ADDWF  x69,W
011C:  MOVWF  FE9
011E:  MOVLW  00
0120:  ADDWFC x6A,W
0122:  MOVWF  FEA
0124:  MOVFF  6C,6D
0128:  MOVFF  6D,FEF
....................    check[0] = CRCLow = (int8)(CRCFull & 0xFF);        
012C:  MOVFF  69,FE9
0130:  MOVFF  6A,FEA
0134:  MOVFF  6B,6E
0138:  MOVFF  6E,FEF
....................  
.................... } 
013C:  RETLW  00
....................  
....................  
....................  
.................... /* 
.................... //****************************************************************************** 
.................... void SendQueryMessage() 
.................... { 
....................    int8 i=0; 
....................  
....................    GetCRC(&queryMessage, (int8)(lengthOfQueryMessage - 2),&CRC); 
....................    queryMessage[lengthOfQueryMessage - 2] = CRC[1]; //CRC LOW FIRST 
....................    queryMessage[lengthOfQueryMessage - 1] = CRC[0]; 
....................    for (i = 0; i < lengthOfQueryMessage; i++) 
....................       { 
....................          putc(queryMessage[i]); 
....................       }    
.................... }*/ 
....................  
.................... //****************************************************************************** 
.................... void ConvertInt16ToByte(int16 value,int8 HiValue,int8 LoValue) 
.................... { 
....................       LoValue = (int8)(value % 256); 
....................       HiValue = (int8)(value / 256); 
.................... } 
.................... //*********************HAM MODBUS*********************************************** 
....................    void ReadCoilStatus(int8 slaveAddress, int16 startingAddress, int16 quantityOfCoils) 
....................    { 
....................             lengthOfQueryMessage_output = 8; 
....................              
....................             if (quantityOfCoils % 8 == 0) 
....................                 lengthOfResponseMessage_input = 5 + quantityOfCoils / 8; 
....................             else 
....................                 lengthOfResponseMessage_input = 6 + quantityOfCoils / 8;   
....................                  
....................             queryMessage[0] = slaveAddress; 
....................             queryMessage[1] = 1;  //function 
....................             ConvertInt16ToByte((int16)startingAddress-1,queryMessage[2],queryMessage[3]); 
....................             ConvertInt16ToByte(quantityOfCoils,queryMessage[4],queryMessage[5]); 
....................             functionCode_Send = 0x01; 
....................            // SendQueryMessage(); 
....................    } 
....................    void ReadInputStatus(int8 slaveAddress, int16 startingAddress, int quantityOfInputs) 
....................    { 
....................    } 
....................    void ReadHoldingRegisters(int8 slaveAddress, int16 startingAddress, int quantityOfRegisters) 
....................    { 
....................    } 
....................    void ReadInputRegisters(int8 slaveAddress, int16 startingAddress, int quantityOfInputRegisters) 
....................    { 
....................    } 
....................    void ForceSingleCoil(int8 slaveAddress, int16 CoilAddress, int DataToWrite) 
....................    { 
....................    } 
....................    void PresetSingleRegister(int8 slaveAddress, int16 RegisterAddress, int8 DataToWrite) 
....................    { 
....................    } 
....................    void ForceMultipleCoils(int8 slaveAddress, int16 StartingAddress, int quantityOfCoils, int8 *ValueToWrite) 
....................    { 
....................    } 
....................    void PresetMultipleRegisters(int8 slaveAddress, int16 StartingAddress, int8 *ValueToWrite[]) 
....................    { 
....................    } 
....................     
....................  
.................... #fuses HS,NOWDT,NOPROTECT,NOLVP 
.................... #use delay(clock=40000000) 
*
04C4:  CLRF   FEA
04C6:  MOVLW  50
04C8:  MOVWF  FE9
04CA:  MOVF   FEF,W
04CC:  BZ    04EA
04CE:  MOVLW  0C
04D0:  MOVWF  01
04D2:  CLRF   00
04D4:  DECFSZ 00,F
04D6:  BRA    04D4
04D8:  DECFSZ 01,F
04DA:  BRA    04D2
04DC:  MOVLW  F7
04DE:  MOVWF  00
04E0:  DECFSZ 00,F
04E2:  BRA    04E0
04E4:  BRA    04E6
04E6:  DECFSZ FEF,F
04E8:  BRA    04CE
04EA:  GOTO   04F4 (RETURN)
.................... #use rs232(baud=9600 , parity=n , xmit=pin_C6 , rcv=pin_C7 ) 
....................  
....................  
.................... int8   receiveMessage[8];//phai o ben nay 
....................  
....................  
.................... //***************************************************************************** 
.................... #int_rda     //gia tri bien trong nay ko xai duoc cho ben kia 
.................... void receive() 
.................... {   
....................     int8 i=0; 
*
013E:  CLRF   x63
....................  
....................    receiveMessage[count]=getc(); 
0140:  CLRF   03
0142:  MOVF   3C,W
0144:  ADDLW  48
0146:  MOVWF  FE9
0148:  MOVLW  00
014A:  ADDWFC 03,W
014C:  MOVWF  FEA
014E:  BTFSS  F9E.5
0150:  BRA    014E
0152:  MOVFF  FAE,FEF
....................    if (receiveMessage[0]==Stage_ID)        //detemine address 
0156:  MOVF   3D,W
0158:  SUBWF  48,W
015A:  BTFSS  FD8.2
015C:  BRA    04BE
....................    { 
....................       count++; 
015E:  INCF   3C,F
....................       if(status==0)        //RDA wait querry message 
0160:  BTFSC  23.3
0162:  BRA    04BE
....................       { 
....................          if(count==2)      //determine command 
0164:  MOVF   3C,W
0166:  SUBLW  02
0168:  BTFSS  FD8.2
016A:  BRA    0288
....................          { 
....................             Switch (receiveMessage[1]) 
....................             { 
016C:  MOVF   49,W
016E:  XORLW  01
0170:  BZ    01B4
0172:  XORLW  03
0174:  BZ    01C0
0176:  XORLW  01
0178:  BZ    01D0
017A:  XORLW  07
017C:  BZ    01DC
017E:  XORLW  01
0180:  BZ    01E8
0182:  XORLW  03

⌨️ 快捷键说明

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