This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Computer COM port & microcontroller COM port ??

Hi all,

I have written a program in VC++ to write a char array of 13 bytes on COM port using 9600-N-8-1 parameters.

when i send this to my target device it responds, but same program when i send through 89S51 my device does not respond.To set 9600-N-8-1 i have written 0xFD value.

Can anyone no the reason for such strange behaviour.

Please let me know....

rutu.

Parents
  • You may be close with the unsigned/signed issue as 'c' promotes chars to ints in some instances. Therefore since it converted your 0xbf to 0xffbf try declaring your array as unsigned char.
    I'm not expert with Keil, but maybe it's default char is signed char, in other compilers the default can be unsigned char. I do know that in VC++6 that the default is signed char!

    Failing that, since I'm feeling generous today:

    unsigned char hex_xlate[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};


    void phex(unsigned char val)
    {
    putchar(hex_xlate[val>>4]);
    putchar(hex_xlate[val & 0x0f]);
    }

    Not necessarily the best or most efficient means, but simple to understand

Reply
  • You may be close with the unsigned/signed issue as 'c' promotes chars to ints in some instances. Therefore since it converted your 0xbf to 0xffbf try declaring your array as unsigned char.
    I'm not expert with Keil, but maybe it's default char is signed char, in other compilers the default can be unsigned char. I do know that in VC++6 that the default is signed char!

    Failing that, since I'm feeling generous today:

    unsigned char hex_xlate[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};


    void phex(unsigned char val)
    {
    putchar(hex_xlate[val>>4]);
    putchar(hex_xlate[val & 0x0f]);
    }

    Not necessarily the best or most efficient means, but simple to understand

Children
  • "You may be close with the unsigned/signed issue as 'c' promotes chars to ints in some instances."

    The problem is that Keil 'C' does NOT promote chars to ints in this situation. printf() is receiving a char but expecting an int. You have to use the correct format specification for a char.

    "Therefore since it converted your 0xbf to 0xffbf try declaring your array as unsigned char."

    How could that possibly help?

    "I'm not expert with Keil, but maybe it's default char is signed char, in other compilers the default can be unsigned char."

    What difference could that possibly make?