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 CCS Technical Support

#use rs232 question = received chars as numbers?

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



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

#use rs232 question = received chars as numbers?
PostPosted: Mon May 17, 2004 2:55 pm     Reply with quote

Hello All,

I have a routine to receive SMS messages and I want to interpret received characters as numbers, numbers range from 15 to 3600.

When the pic receives a string, for example if I sent the message 0015, the pic will see bytes 48 48 49 53 which are the ascii decimal codes for the number. The question is how do I store in an integer variable the number I received = 15?

Thank you in advance
Peter
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 17, 2004 3:19 pm     Reply with quote

Quote:
When the pic receives a string, for example if I sent the message 0015, the pic will see bytes 48 48 49 53 which are the ascii decimal codes for the number. The question is how do I store in an integer variable the number I received = 15?

Use the atol() function. It's in the STDLIB.H file.

See the CCS manual and also the file INPUT.C for an example.

Both of those files are in this folder: c:\Program Files\Picc\Drivers
runtime



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

PostPosted: Mon May 17, 2004 3:25 pm     Reply with quote

Is there another way instead of using atoi()?

Thank you in advance
Peter
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 17, 2004 3:52 pm     Reply with quote

runtime wrote:
Is there another way instead of using atoi()?

Use my adtol() function.
http://www.ccsinfo.com/forum/viewtopic.php?t=17563&highlight=adtol
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Mon May 17, 2004 3:55 pm     Reply with quote

Hey, I'm interested in the SMS thing.... What are you doing? I have a need to connect a digital cell phone to my equipment and have the controller send an SMS through the digital phone all automatically. Have you heard of this function before?

By the way, I would subtract 0x30 from each character, check that the result is >=0 and <=9, then take the first number x 1000, add in the second x 100, the third x 10 and add in the last number.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon May 17, 2004 4:04 pm     Reply with quote

If there is good reason to not use tested code like atoi then roll your own
step1
set accumulator to zero
step2
read byte Ex 48 meaning a zero
multiply accumulator by 10
addin the byte and subtract 48
step 3
if there is another byte goto step2.
Guest








PostPosted: Mon May 17, 2004 4:49 pm     Reply with quote

ljbeng,

yes, I can send an SMS from the PIC, to another phone, you onl need to use the AT+CMGS command:

AT+CMGS="phone #" <enter>
type your message and send a ctrl-z
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