Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 13


byte command_index;
char command_response[6];
char network_state = 'r';
char received_command[6];
byte response_index = 0;
unsigned char serial_in;

// Define the driver-enable line and disable the driver.

#if defined(firmware_driver_enable)
TRISBbits.TRISB3 = 0;
driver_enable = 0;
#endif

// Output port bit used only for testing:

TRISBbits.TRISB0 = 0;
PORTBbits.RB0 = 0;

'    


A task loop can handle network communications and other activities. In the
example below, the serial_communications routine implements a state machine
with three states. In state “r”, the device is waiting to receive data. In state “d”,
the device has received a command and is delaying before responding to allow
the primary node time to disable its driver. If the primary node disables its
driver immediately after transmitting, the firmware can be configured so it
never enters state “d”. In state “t”, the device is ready to transmit data.
Free download pdf