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

SERIAL RS232 problem

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



Joined: 23 Jun 2016
Posts: 2

View user's profile Send private message

SERIAL RS232 problem
PostPosted: Sun Jun 26, 2016 6:46 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Sun Jun 26, 2016 7:04 pm     Reply with quote

it does not compile.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 26, 2016 8:01 pm     Reply with quote

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