CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

sending out hex values thru the rs232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
willie.ar



Joined: 21 Jan 2004
Posts: 15
Location: Argentina

View user's profile Send private message

sending out hex values thru the rs232
PostPosted: Mon Jul 12, 2004 5:22 pm     Reply with quote

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);

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 12, 2004 5:25 pm     Reply with quote

Don't use printf(). Use putc() instead.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon Jul 12, 2004 5:27 pm     Reply with quote

If you use

Printf("%c", tabla[byte_cntr]);

you will get only one character with the ASCII value of 10.
Guest
Guest







A hex on that hex stuff
PostPosted: Mon Jul 12, 2004 6:26 pm     Reply with quote

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.
willie.ar



Joined: 21 Jan 2004
Posts: 15
Location: Argentina

View user's profile Send private message

PostPosted: Mon Jul 12, 2004 9:14 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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