We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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.
Actually I should have said.... if the 4 bit nibble is 0..9 add '0', if 10..15 add 'A'-10. Do this for both 4 bit nibbles. '0' = 0x30 = ASCII 0. In C, '0' is a character value. Job done.
Hi, Erik i do have MAX232 onboard so no problem with hardware. Russell, i implemented as per your direction using %02x, it works fine till m_Write[10] which is 0x79 then after for m_Write[11] i get "ffbf".I suspect it is because of unsigned char which can show til 127(Decimal). What i get is 40050000000079FFBF0A What i want is 40050000000079BF0A Also i tried with %x to avoid "0" (zero)padding in between, but then also for 0xBF it outputs "ffbf" instead of only "bf" About spliting of byte idea, i thing that is good, but need to work on that. Jon , thankx for your correction but my real need is to output hex values on rs232. rutu
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
"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?