Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 13


 while(1)
{
serial_communications();


// Add other tasks here.
}

void serial_communications(void)
{
switch (network_state)
{
case 'r':
{
receive_serial_data();
break;
}
case 'd':
{
check_response_delay();
break;
}
case 't':
{
transmit_serial_data();
break;
}
default:
break;
}
}

"    
On receiving a valid command, the code calls the prepare_to_respond function,
which either starts the delay timer and sets network_state to “d” or sets
network_state to “t” as appropriate.
If delay_before_responding is defined, on receiving a valid command, the
device starts a timer and serial communications enter the “d” state. On each
pass through the task loop, the code calls check_response_delay to find out if
the delay time has elapsed. If so, the routine stops the timer and switches to the
“t” state.
Free download pdf