![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
willie.ar
Joined: 21 Jan 2004 Posts: 15 Location: Argentina
|
sending out hex values thru the rs232 |
Posted: Mon Jul 12, 2004 5:22 pm |
|
|
I'm trying to transmit the hex values of a table (or binary values, as you prefer) to the RS232 port and, whatever I do, I get the ASCII values of the chars instead.
Example: If the value of the variable is 10 then I get 2 bytes (31,30).
try this
INT tabla[47]={
1,10,10,10,10,64,65,66,67,68,
69,70,71,72,73,74,75,76,77,78,
79,80,81,82,83,84,85,86,87,88,
87,86,85,84,83,82,81,80,79,78,
77,76,75,74,73,72,71
};
for (byte_cntr=0;byte_cntr<47; byte_cntr++)
Printf("%02X", tabla[byte_cntr]);
what am I doing wrong ???
following is the full code
////////////////////////////////////////////////////////////////
#include <16F628.h>
#fuses HS, NOLVP, NOWDT, PUT, NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=19200, xmit=PIN_B2, RCV=PIN_B1, parity=N, bits=8, errors)
#include <stdlib.h>
#include <input.c>
unsigned int cont,byte_cntr; // 0-255
INT tabla[47]={
1,10,10,10,10,64,65,66,67,68,
69,70,71,72,73,74,75,76,77,78,
79,80,81,82,83,84,85,86,87,88,
87,86,85,84,83,82,81,80,79,78,
77,76,75,74,73,72,71
};
char comando;
///////////////////////////////////////////////////////////////////////////////
void main() {
// iniciar variables
cont=0;
printf("reset \r\n");
do {
if(kbhit())
{
comando=getc();
if(comando=='I') // send data
{output_LOW(PIN_B3);
for (byte_cntr=0;byte_cntr<47; byte_cntr++)
Printf("%02X", tabla[byte_cntr]);
DELAY_MS(200);
output_HIGH(PIN_B3);
}
}
} while (TRUE);
} |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 12, 2004 5:25 pm |
|
|
Don't use printf(). Use putc() instead. |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Jul 12, 2004 5:27 pm |
|
|
If you use
Printf("%c", tabla[byte_cntr]);
you will get only one character with the ASCII value of 10. |
|
![](templates/subSilver/images/spacer.gif) |
Guest Guest
|
A hex on that hex stuff |
Posted: Mon Jul 12, 2004 6:26 pm |
|
|
I am writing bytes to EEPROM, and reading them back and checking them with RS-232. I am using the following form of the printf command with success. (PCM version 3.187 I think, don't have the code and stuff with me now)
byte data_byte;
int16 data_address;
data_byte = read_ext_eeprom(data_address);
printf("%2x", data_byte);
Is "%2x" THAT different than "%02X" ?
I got stuck on this once and ended up using "putc()" instead. |
|
![](templates/subSilver/images/spacer.gif) |
willie.ar
Joined: 21 Jan 2004 Posts: 15 Location: Argentina
|
|
Posted: Mon Jul 12, 2004 9:14 pm |
|
|
thanks all of you for your quick response.
putc() works fine. I didn't try it before because the reference manual says the parameter should be an 8 bit character, so it`s a bit confusing...
also what Haplo says refers to a char (it works too).
the ASCII character chart included in the ref manual just define chars up to dec 127 only, that`s why I thought that char did not refer to the hole range.
thanks again.
W |
|
![](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
|