I'm not sure exactly what functions like 'RS485Slave_Receive' and 'RS485Master_Receive' do, but in general it looks like the master doesn't do anything with dat when it's received from the slave, and for that matter the slave never sends anything. It looks like the master is set up to only send, and the slave only receives. So you would need to have them alternate, or set up a more elaborate communication protocol between them that would ensure both aren't transmitting at the same time. For example the simplest would probably be to have the slave always respond with it's button status immediately after receiving the button status data from the master. This way the master controls the timing, and you should eliminate collisions. (But the 10ms delay may not be long enough.) You would essentially need to duplicate the slave code into the master for setting the LEDs, and then have the slave send data in the same way the master does it after receiving a message from the master. It's hard to be more specific without seeing the entire code. (Sorry, I'm not familiar with the mikroC libraries.)