I have trouble displaying a certain hex string on an LCD. The hex string comes from a external display device that communicates with a serial display.

With the oscilloscope, the data from the display looks like this: 5A A5 20 81 00 80 28.

enter image description here

I have an USB-RS232 connector like in this datasheet:


With this cable, I could see the correct hex data in the RealTerm serial terminal on my PC.

However, when I want to display the hex string on a LCD display with a PIC microcontroller, to test if the connection is correct, I get the following hex string: "58d5eefdfdd7 0a9..." (I'm not sure if more data is following, because the LCD doens't have more space to display).

The display wires are connected directly to the PCB with the PIC and the LCD.

I use MCC. The baud rate of the PIC matches the display (9600). I get the same result regardless of the choosen data polarity in MCC(inverted or noninverted). I think that is all the relevant settings.

I use the following code fragment:

while (1)
        volatile uint8_t tmp = EUSART1_Read();
        char hex[2];
        sprintf(hex, "%2x", tmp);

So I get data coming from the display. Those 58 and D5 seem to be related to 5A and A5. It is as if there is some pattern to the errors, but I fail to see it.

  • 2
    \$\begingroup\$ Two characters is not enough to hold a string with two characters as there is no room for null terminator. It may overwrite something in the stack or something may overwrite the null terminator so the string can be arbitrarily long so it never terminates. \$\endgroup\$ – Justme Aug 16 '20 at 14:52

10110001101010111101110111111011111110111010111 = 58d5eefdfdd7

10110101010010100100000100000010000000010 = 5A A5 20 81 00 80 28

Try 1’s complement


... fe956b7dfbfd

No correlation

but looks bit wise inverted and glitch on byte sync. Or ?

Investigate for reasons

  • \$\begingroup\$ I couldn't really follow you HEX -> binary translation? \$\endgroup\$ – Mike Aug 18 '20 at 5:35
  • \$\begingroup\$ The spacing and number of ‘0’ ‘s in your 1st binary string matches the same of mentally inverted ‘1’s in the second string match yet the Hex does not match, so it is out of sync and inverted . Why? \$\endgroup\$ – Tony Stewart EE75 Aug 18 '20 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.