PDA

View Full Version : Extracting Digits from SERIN



Hitman
02-08-2007, 04:04 AM
Hello I have (again) A problem with teh BS2.

I want to extract two digits from 'sdata' (see example)

SERIN 9, 396,[STR sdata\8]

I have used '' sdata(0) " and " sdata(1) " but I want them together in one nibble.

E.g. the 'sdata\8' is a date (for example 12-12-07) I want the day so I can compare it with another day·this comes from a DS1302 RTC.

When I use sdata(0)+sdata(1) it just increases. Same as sdata(0+1).
I have looked in the stamp manual but I can't find anything.


Thanks in advance


[Subject added by Moderator]

Post Edited By Moderator (Chris Savage (Parallax)) : 2/7/2007 9:08:58 PM GMT

Unsoundcode
02-09-2007, 12:59 AM
Hi Hitman, Str sdata\8 stores the serial input as an ASCII string 8 bytes long. To arrive at the digit·each ASCII·byte represents you must subtract 48. The the left digit multiplied by 10 plus the right digit of each field will give you the number you require. Here is an example of one way to do it and it assumes that sdata is in the format you show, eg 12-12-07.

sdata VAR Byte(8)
Month VAR Byte
Day VAR Byte
Year VAR Byte

main:

· DEBUGIN STR sdata\8
· Month=((sdata(0)-48)*10) + (sdata(1)-48)
· Day=((sdata(3)-48)*10) + (sdata(4)-48)
· Year=((sdata(6)-48)*10) + (sdata(7)-48)
· DEBUG ? Month,? Day,? Year
· DEBUG "Month + Day = ",DEC month + day

GOTO main

Jeff T.

Hitman
02-09-2007, 11:33 PM
Hi Unsoundcode, I will try this tonight. But so far looks great.

Thanx.

Emile T.

iramsey
02-11-2007, 01:25 AM
Hi,

I have question pertaining to logging data from a gps string. My problem now is verifying that the string is actually stored in the EEprom. I am trying to pull out the·characters 10-16·of the string. The problem with GPS is that it only works outside, therefore my program only has write instructions in it. Can anyone give me a suggetion on how I would verify that this data was actually stored.

//my code
' {$STAMP BS2}
sio···· CON·· 6
gps···· VAR·· Byte(7)
eeAddr· VAR·· Byte(7)
samples CON·· 5
log···· DATA· 5
endLog· CON·· log+samples-1
SERIN 6, 188, [WAIT("GPRMC,"), SKIP 8, STR gps\7]

FOR eeAddr = log TO endLog
WRITE eeAddr, gps
PAUSE 30000
NEXT
STOP

Mike Green
02-11-2007, 01:36 AM
You can read it back with a READ statement and compare byte by byte to the value still in "gps".

iramsey
02-14-2007, 10:46 PM
thanks for the advice. only problem is that I must first run the write program, then take the gps reciever outside to collect me data. I then must bring it back inside to run the read program. won't this wipe away the data the I stored from having gone outside?

Mike Green
02-14-2007, 10:59 PM
You can easily use the same program for both parts if you have an unused I/O pin. Just use a switch or jumper to connect the pin through a 10K resistor to either ground or +5V. At the beginning of your program, check the pin. If it's high, go do the write routines. If it's low, go do the read routines.

Unless the program is very large, it won't affect the low end of program memory when it's downloaded.

TechnoRobbo
02-15-2007, 07:41 AM
SERIN 9, 396,[DEC2 Month,SKIP 1, DEC2 Day,SKIP 1,DEC2 Year]

but I would add a WAIT to synch better with the data:

SERIN 9, 396,[WAIT ("!"),DEC2 Month,SKIP 1, DEC2 Day,SKIP 1,DEC2 Year]

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun


TR