CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I would like to allow communication between the PIC and PLC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mikroserdar



Joined: 05 Dec 2011
Posts: 2
Location: İSTANBUL

View user's profile Send private message Send e-mail MSN Messenger

I would like to allow communication between the PIC and PLC
PostPosted: Mon Dec 05, 2011 12:37 pm     Reply with quote

Hello to everyone.
I work as a project. My goal is to the PLC with Modbus protocol communication between the PIC. RS-232 communication between the PIC and the PLC will be with. I think this PLC communicates with Modbus protocol. PIC'ten code will be sent to the PLC. In addition, the PIC side of the LED lights up when it comes to information, the PIC PLC. I wonder Is there a sample code or where to start with your hand. Have you got a sample code and diagrams, or on the Internet.

good work
mikroserdar



Joined: 05 Dec 2011
Posts: 2
Location: İSTANBUL

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Dec 05, 2011 12:43 pm     Reply with quote

In addition to spelling, I have added some information. I work as a project. My goal is to the PLC with Modbus protocol communication between the PIC. RS-232 communication between the PIC and the PLC will be with. I think this PLC communicates with Modbus protocol. When a button is pressed PIC'ten code will be sent to the PLC. In addition, the PIC PLC information requested by the LED lights up when it comes to the PIC. In addition, the value read from the PLC to any PIC side of the display seven segment display. I wonder Is there a sample code or where to start with your hand. Have you got a sample code and diagrams, or on the Internet. I think the CCS C and write. good work
Lemosek



Joined: 15 Oct 2011
Posts: 36

View user's profile Send private message

PostPosted: Mon Dec 05, 2011 1:01 pm     Reply with quote

Hello,
In the Example directory of your installation CCS you find modbus master and slave example.

I write something similar:

Code:

#define MODBUS_TYPE MODBUS_TYPE_SLAVE
#define MODBUS_SERIAL_RX_BUFFER_SIZE 64
#define MODBUS_SERIAL_BAUD 57600
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA
#define MODBUS_SERIAL_ENABLE_PIN   PIN_D5   // Controls DE pin for RS485
#define MODBUS_SERIAL_RX_ENABLE    PIN_D5   // Controls RE pin for RS485
#define MODBUS_ADDRESS 0x05
#include "modbus.c"


   while(1)
   {

     some code
   

      wait = 1;
      while(wait)
      {
         if(modbus_kbhit())
            if((modbus_rx.address == MODBUS_ADDRESS) || modbus_rx.address == 0)
               wait = 0;
      }   
         
     
      MODBUS_rsp();   

     
   }
}


void MODBUS_rsp(void)
{
   if((modbus_rx.address == MODBUS_ADDRESS) || modbus_rx.address == 0)
      {
         switch(modbus_rx.func)
         {
            case FUNC_READ_HOLDING_REGISTERS:
               if(modbus_rx.data[0] || modbus_rx.data[2] ||
                  modbus_rx.data[1] > 9 || modbus_rx.data[3]+modbus_rx.data[1] > 16)
                  modbus_exception_rsp(MODBUS_ADDRESS,modbus_rx.func,ILLEGAL_DATA_ADDRESS);
               else
               {
       
                  modbus_read_holding_registers_rsp(MODBUS_ADDRESS,(modbus_rx.data[3]*2),temp+modbus_rx.data[1]);
         
               }   
               break;
            case FUNC_READ_INPUT_REGISTERS:
            case FUNC_READ_COILS:   
            case FUNC_READ_DISCRETE_INPUT:   
            case FUNC_WRITE_SINGLE_COIL:     
            case FUNC_WRITE_SINGLE_REGISTER:
            case FUNC_WRITE_MULTIPLE_COILS:
            case FUNC_WRITE_MULTIPLE_REGISTERS:
            default: 
               modbus_exception_rsp(MODBUS_ADDRESS,modbus_rx.func,ILLEGAL_FUNCTION);
         }
      }

}




This is not full code but only some parts.

Best regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group