View previous topic :: View next topic |
Author |
Message |
jpvr
Joined: 18 Mar 2007 Posts: 9
|
Using getc() and putc() with Hexa data for RS232 ? |
Posted: Sun Mar 18, 2007 7:38 am |
|
|
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 |
|
|
Ttelmah Guest
|
|
Posted: Sun Mar 18, 2007 8:06 am |
|
|
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
|
|
Posted: Sun Mar 18, 2007 8:19 am |
|
|
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
|
|
Posted: Sun Mar 18, 2007 9:26 am |
|
|
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
|
|
Posted: Sun Mar 18, 2007 10:14 am |
|
|
Hi Ttelmah,
Thank you very much for all this precisions.
Have a nice week end,
Jean - Pierre |
|
|
|