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 support@ccsinfo.com

Using getc() and putc() with Hexa data for RS232 ?

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



Joined: 18 Mar 2007
Posts: 9

View user's profile Send private message Send e-mail

Using getc() and putc() with Hexa data for RS232 ?
PostPosted: Sun Mar 18, 2007 7:38 am     Reply with quote

Dear All,


Please, can you tell me if this is possible to send and receive data in hexa decimal format with getc() and putc() over the RS232 UART of a pic ???

I post this message because it seems that this two function deals only
with character format and I am not able to find a rapid method for
converting Hexa to ( and from ) Ascii with this two command ...

Thank you for your help,

Jean - Pierre Wink
Ttelmah
Guest







PostPosted: Sun Mar 18, 2007 8:06 am     Reply with quote

That is what printf is for..

printf("%2x",val);

You can of course print the values with putc, but then you will have to call a binary to hex conversion routine first,and send the two values. The printf code, does exactly that.

Best Wishes
jpvr



Joined: 18 Mar 2007
Posts: 9

View user's profile Send private message Send e-mail

PostPosted: Sun Mar 18, 2007 8:19 am     Reply with quote

Hello,

thank you for the answer.

So, then I can use printf() for sending the value but for receiving the
hexa data, what is the function ???

Must I use getc() with an aditionnal conversion routine ???
Ttelmah
Guest







PostPosted: Sun Mar 18, 2007 9:26 am     Reply with quote

Yes. There have been efficient hextobin routines published here (there is a set in the code forum). There is a simple 'gethex' routine to get (and echo back) two hex digits from getc, and convert the result to a byte, in input.c

Best Wishes
jpvr



Joined: 18 Mar 2007
Posts: 9

View user's profile Send private message Send e-mail

PostPosted: Sun Mar 18, 2007 10:14 am     Reply with quote

Hi Ttelmah,


Thank you very much for all this precisions.

Have a nice week end,

Jean - Pierre
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