View previous topic :: View next topic |
Author |
Message |
mikroserdar
Joined: 05 Dec 2011 Posts: 2 Location: İSTANBUL
|
I would like to allow communication between the PIC and PLC |
Posted: Mon Dec 05, 2011 12:37 pm |
|
|
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
|
|
Posted: Mon Dec 05, 2011 12:43 pm |
|
|
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
|
|
Posted: Mon Dec 05, 2011 1:01 pm |
|
|
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 |
|
|
|