View previous topic :: View next topic |
Author |
Message |
runtime
Joined: 15 Sep 2003 Posts: 36
|
#use rs232 question = received chars as numbers? |
Posted: Mon May 17, 2004 2:55 pm |
|
|
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
|
|
Posted: Mon May 17, 2004 3:19 pm |
|
|
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
|
|
Posted: Mon May 17, 2004 3:25 pm |
|
|
Is there another way instead of using atoi()?
Thank you in advance
Peter |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
|
Posted: Mon May 17, 2004 3:55 pm |
|
|
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
|
|
Posted: Mon May 17, 2004 4:04 pm |
|
|
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
|
|
Posted: Mon May 17, 2004 4:49 pm |
|
|
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 |
|
|
|