Serial Port Complete - Latest Microcontroller projects

(lily) #1
An RS-485 Network

 void respond_to_command(void)
{
// On receiving a valid command, call a routine to handle the specific command.
// Every command begins with a COMMAND_START code, the node's address,
// and a command code.


int received_data;

if (received_command[0] == COMMAND_START)
{
if (received_command[1] == MY_ADDRESS)
{
// Respond to supported commands.

switch (received_command[2])
{
case '1':
{
command_write_byte();
break;
}
case '2':
{
command_read_byte();
break;
}
// Add additional supported commands here.

default:
{
initialize_serial_buffers;
break;
}
}
}
else
{
initialize_serial_buffers;
}
}
Free download pdf