SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 313 | Next

Jan Axelson

"Serial Port Complete: COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems"


 initialize_serial_buffers:
command_index = 0
response_index = 0
received_command[0]= 0
return
 void initialize_serial_buffers(void)
{
command_index = 0;
response_index = 0;
received_command[0]= '\0';
}
An RS-485 Network
311
3  &
The routine below handles the write_byte command. The routine sets a port
bit to match bit 0 of the received byte and prepares to send a response to the
primary node. For testing, the port bit can control an LED. A real-world application
can use the received data in any way it wants.
 command_write_byte:
' A write_byte command has been received.
select case received_command[3]
case "b"
' Get the data to write.
' Convert the received ASCII Hex bytes to a byte value.
upper_nibble = received_command[4]
lower_nibble = received_command[5]
gosub ascii_hex_to_byte
' Set bit 0 of PortB to match bit 0 in the received byte.
if ((converted_byte & 1) = 1) then
high PORTB.0
else
low PORTB.0
endif
gosub prepare_response
' Add more cases as needed.
case else
end select
return
Chapter 13
312
 void command_write_byte(void)
{
int received_data;
switch (received_command[3])
{
case 'b':
{
// Get the data to write.
received_data = ascii_hex_to_byte(received_command[4],
received_command[5]);
if (received_data > -1)
{
// The received data was valid.
// Set a port bit to match bit 0 of the received byte.


Pages:
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325