|
|
View previous topic :: View next topic |
Author |
Message |
jcerbaro
Joined: 23 Jun 2016 Posts: 2
|
SERIAL RS232 problem |
Posted: Sun Jun 26, 2016 6:46 pm |
|
|
Hello!
I want to send a NUMBER (from 0 to 255) via serial port, from my PC.
I tried in every way, but it's not working!
Let's say the number I want is 123 (decimal).
The serial won't never send the CHAR from the ASCII equivalent of 123. It will send '1' , '2' , '3'.
So... I must detect the arriving of the three chars and send them to a vector for later turn it into the integer 123.
My idea below is not working. Please, I really need some help!
PS: if someone can give me an ideia of how I can force the serial do send the CHAR 123, instead of '1', '2', '3', would be great.
Code: | #int_rda
void uart_read(void)
{
received = getc();
uart_int[j] = received - 48;
j++;
if (j == 4)
j=0;
//At this point, my vector uart_int should always have the received characters, one in each position.
} |
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Jun 26, 2016 7:04 pm |
|
|
it does not compile. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 26, 2016 8:01 pm |
|
|
Quote: |
how I can force the serial do send the CHAR 123, instead of '1', '2', '3',
would be great. |
Use putc() to send the byte. Example:
Code: | int8 value;
value = 123;
putc(value); |
|
|
|
|
|
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
|