Chapter 11
else
{
// For other characters, send back the same character.
serial_out = serial_in;
}
// Set a variable to indicate that a byte is ready for transmitting.
data_ready_to_send = 1;
}
}
This function checks the data_ready_to_send variable, which indicates whether
serial_out contains a byte to be sent on the serial port. If data_ready_to_send =
1 and flow_control_input = 0, the function sends the byte and sets
flow_control_output = 1 to enable receiving another byte.
void transmit_serial_data()
{
if (data_ready_to_send == 1)
{
// A byte is ready to send.
// If the flow control input is asserted, send the byte.
// Otherwise wait until the routine is called again.
if (flow_control_input == 0)
{
data_ready_to_send = 0;
while(BusyUSART());
putcUSART(serial_out);
// Tell the remote computer it’s OK to send more data.
flow_control_output = 0;
}
}
}
The options for adding serial ports to an embedded system include using a
microcontroller that has the needed number of ports, using firmware UARTs,
and interfacing to external UARTs.