An RS-485 Network
, & #"" 0
The network encodes data in ASCII Hex format. Chapter 2 showed .NET code
for converting between binary and ASCII Hex bytes. Microcontroller code can
perform these conversions as well.
The byte_to_ascii_hex function converts a byte (value_to_convert) to two
ASCII hex characters that represent the byte’s value (upper_nibble and
lower_nibble):
byte_to_ascii_hex:
' Represent the byte variable value_to_convert as
' ASCII Hex characters upper_nibble and lower_nibble.
upper_nibble = (value_to_convert & $f0) >> 4
if ((upper_nibble >= 0) AND (upper_nibble <= 9)) then
upper_nibble = upper_nibble + 48
else
' The value is between 10 (a) and 15 (f).
upper_nibble = upper_nibble + 87
endif
lower_nibble = (value_to_convert & $0f)
if ((lower_nibble >= 0) AND (lower_nibble <= 9)) then
lower_nibble = lower_nibble + 48
else
' The value is between 10 (a) and 15 (f).
lower_nibble = lower_nibble + 87
endif
return