View previous topic :: View next topic |
Author |
Message |
willie.ar
Joined: 21 Jan 2004 Posts: 15 Location: Argentina
|
receiving binary data thru the rs232 |
Posted: Mon Jul 26, 2004 12:45 pm |
|
|
I'm having troubles to get binary data thru the RS232.
Data entering the port may be any value from 0 to 255 (not only ascii chars). I need to store that data, then get it back and finally output it to an OUTPUT_PIN at a different rate.
I'm wondering if getc() is the right function for that or if it only works within the simbol's range.
data received from the port could be defined as char or as unsigned in the same way?
I'm using 16F628, CCS PCM v3.180. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Jul 26, 2004 1:14 pm |
|
|
Getc() should work fine. Either an unsigned int or a char will hold any byte. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Mon Jul 26, 2004 1:15 pm |
|
|
From what I know, RS232 sends data in the form of ASCII text. The PIC will most likely receive it as text characters as well. You could use atoi() to convert it, and store it, to a hex number (int8) and then, later, push the individual bits out to a port pin.
Remember, that a Text '1' is a hex 0x31 whereas a Number '1' is 0x01. A Text '21' is a hex 0x32, 0x31 (two bytes) whereas the Number '21' is 0x15 (one byte). The atoi() function will convert this for you.
Ronald |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jul 26, 2004 1:45 pm |
|
|
Quote: | From what I know, RS232 sends data in the form of ASCII text. The PIC will most likely receive it as text characters as well. |
This is an incorrect statement. It sends it as a data byte. It is up to the programmer to know how the data is being sent and how to interpret it. Otherwise, it would be quite difficult to do binary file transfers via RS232! |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Mon Jul 26, 2004 1:58 pm |
|
|
rnielsen wrote: | From what I know, RS232 sends data in the form of ASCII text.
Ronald |
A byte is a byte is a byte. It is how you interpret the data that makes the difference. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
|