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.
You should better use an other terminal program than Hyperterminal (which shows only printable ascii). ..as I wrote before look at http://www.docklight.de (in english). It will show you ascii/hex/binary!
Hi, Yes i have modified the putchar function keeping only single SUB=c loop.I have also downloaded docklight but still not used. Just check my prog. and let me know if i am making some mistake.The aim of this program is to output the array of 13 character size (0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xBF,0x0A}on the RS232 port at 9600bps,NOPARITY,8bit data,1 stop bit. #include<reg52.h> #include<stdio.h> char m_Write[13]={0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xBF,0x0A}; char loop=13; void main(void) { SCON=0x50; TMOD |=0x20; TH1=0xFD; TR1=1; TI=1; while(1) { while(loop--) putchar(m_Write[13-loop]); loop=13; } } and what modification is required to output the same data in ascii. like 4005000000000000000079BF0A the above data. rutu
Milan G asked higher up in this thread "Do You have correct HW? ->MAX232..." You never answered I am starting to suspect that you are one of those "no RS232 transciever is required" ill informed people. Erik
As stated previously regarding printf.., to print in hex: for (loop=0;loop< 13;loop++) { printf("%02x",m_write[loop]); } where %02x means hex,zero padded for two chars. a little reading on printf might explain things. if you don't want to use printf (I uses a lot of code memory) try writing your own printhex: hint: split the byte into two lots of 4 bits if the 4 bit nibble is 0..9 add '0', if 10..15 add 'A'. Do this for both 4 bit nibbles. Job done.
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.
#include<reg52.h> #include<stdio.h> char m_Write[13]={0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xBF,0x0A}; char loop=13; void main(void) { SCON=0x50; TMOD |=0x20; TH1=0xFD; TR1=1; TI=1; while(1) { while(loop--) putchar(m_Write[13-loop]); loop=13; } }
#include<reg52.h> #include<stdio.h> static unsigned char m_Write[13] = {0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xBF,0x0A}; void main(void) { unsigned char loop; SCON=0x50; TMOD |=0x20; TH1=0xFD; TR1=1; TI=1; while(1) { for (loop = 13; loop; loop--) { putchar(m_Write[13-loop]); } } }
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
"printf("%02x",m_write[loop]);" This should be: printf("%02bx",m_write[loop]);
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?
I guess ur COM device uses stream CTRL.
Whatis this stream CTRL ? can you please clearify it or give me the links where i can find more info.