Serial Port Complete - Latest Microcontroller projects

(lily) #1
An RS-485 Network

switch (lower_nibble)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
{
lower_nibble -= 48;
break;
}
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
{
lower_nibble -= 87;
break;
}
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
{
lower_nibble -= 55;
break;
}
default:
{
lower_nibble = -1;
break;
}
}
if ((upper_nibble > -1) && (lower_nibble > -1))
return_value = (upper_nibble << 4) + lower_nibble;
else
return_value = -1;

return return_value;
}

$ 
  8 

$


Firmware must decode received data to find out if it contains a supported com-
mand.
Free download pdf