![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
soaf Guest
|
Change format on RS232 OUT |
Posted: Tue Jan 27, 2004 5:45 am |
|
|
Hi,
When I code :
foobyte = 43;
printf("d%", foo);
On the SIO module
on the upper windows I read 43
on the lower windows I read 34 33
I would like to read 43 on the lower windows
How I can eliminate the two 3 ?
Thank in advance for your help |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: Change format on RS232 OUT |
Posted: Tue Jan 27, 2004 6:10 am |
|
|
soaf wrote: | Hi,
When I code :
foobyte = 43;
printf("d%", foo);
On the SIO module
on the upper windows I read 43
on the lower windows I read 34 33
I would like to read 43 on the lower windows
How I can eliminate the two 3 ?
Thank in advance for your help |
The upper window is showing the ASCII 'text'. The lower window is showing the two bytes involved. When you print the number '43', what is sent, is the character '4', followed by the character '3'. These characters, are respectively '0x34', and '0x33'. This is what the bottom window shows.
If you want to send the actual value '43', as a single byte, then use:
putc(foo);
or
printf("%1c",foo);
This will result in the upper window showing '+' (since ASCII 43, is the character '+'), and the lower window showing 2B (since 43 decimal is 2B in hex).
If however you want to send the two 'nibbles', then use:
printf("%1c%1c",foo/16,foo&0xF);
which will result in the upper window showing odd 'control' characters (will depend on the character set selected), and the lower window showing '04 03'.
Be sure that this is really what you want though, since few programs will be designed to receive data in this format...
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|