Serial Port Complete - Latest Microcontroller projects

(lily) #1
Ports for Embedded Systems

 #define flow_control_input PORTBbits.RB4
#define flow_control_output PORTBbits.RB5


// Configure the flow-control pins as one input and one output.

TRISBbits.TRISB4 = 1;
TRISBbits.TRISB5 = 0;

byte data_ready_to_send = 0;

// Assert the flow-control output to enable receiving data on the serial port.

flow_control_output = 0
This task loop calls two routines in an endless loop:
while(1)
{
receive_serial_data();
transmit_serial_data();
}
This function looks for a new received byte on the serial port. If a byte has
arrived, the routine reads it.
void receive_serial_data(void)
{
if (PIR1bits.RCIF == 1)
{
// A byte has been received. Read it.

serial_in = getcUSART();

// Tell the remote computer to stop sending data.

flow_control_output = 1;

// Set serial_out to a character code to send on the serial port.

if ((serial_in > 96) & (serial_in < 123))
{
// The received character code was lower case (a-z).
// Send back the character in upper case.

serial_out = serial_in - 32;
}
Free download pdf