Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp to SX28 — Parallax Forums

Basic Stamp to SX28

FilipeFilipe Posts: 8
edited 2005-07-01 16:33 in General Discussion
Hello I´m new in programming and in this forum !!!

I need make one project with SX20 or 28 but the code i can get are for BS2p :
There is the code:

Could you please help me ?


I´m sorry my English;

Thanks;

Filipe


Ther is the Code:

' 23 - 09 - 2002
' VER 2.01.1


'
[noparse][[/noparse] Title ]
'
' File...... Vehicle Tracker
' Purpose... Detects Intrusion into a vehicle and then sends out an SMS message with the
' vehicle' location using GPS and GSM modules.

' Author.... Ashfaq Juna
' E-mail.... ashfaq_juna@maximhq.com
' Started... V1.00 --- 07 July 2002
' Current....V 2.01.2.E 02 October 2002

' Please note: Portions of the source code were kindly provided by Parallax

' {$STAMP BS2p}


'
[noparse][[/noparse] I/O Definitions ]
'
OWpin CON 15 ' 1-wire device pin
Ignition CON 1 ' Ignition Connection from car
GPSpin CON 0 ' GPS receiver is connected to pin0


'
[noparse][[/noparse] Constants ]
'
OW_FERst CON %0001 ' Front-End Reset
OW_BERst CON %0010 ' Back-End Reset
OW_BitMode CON %0100
OW_HighSpd CON %1000
ReadROM CON $33 ' read ID, serial num, CRC
SearchROM CON $F0 ' search

NoDevice CON %11 ' no device present


'''GPs'''''''

T9600 CON 240 ' 9600-8-N-1 (matches DEBUG)
N4800 CON 16884
LF CON 10 ' linefeed

FirstSlot CON 1
MaxAddr CON 8-FirstSlot*2048-1
FirstAddr CON 2 ' make room for readings

Comma CON ","

DegSym CON 176 ' degrees symbol
MinSym CON 39 ' minutes symbol
SecSym CON 34 ' seconds symbol


'
END OF GPS CONSTANTS


'
[noparse][[/noparse] Variables ]
'
idx VAR NIB ' loop counter
romData VAR Byte(8) ' ROM data from DS1820
devCheck VAR Nib ' device check return ocde

IntTime VAR Byte ' This is to keep track of time; it will be used to introduce about
' delay. After each delay a message will be sent out with the GPS
' co-ordinate
TimeLimit VAR Byte
ButtonStat VAR NIB
IntrusionStat VAR NIB



'
[noparse][[/noparse] GPS Variables ]
'

flags VAR Byte
valid VAR flags.Bit7

laDeg VAR Byte
laMin VAR Byte
laSec VAR Word ' tenths of seconds
laSLo VAR laSec.LowByte
laSHi VAR laSec.HighByte
laNS VAR flags.Bit0 ' 0 = N

loDeg VAR Byte
loMin VAR Byte
loSec VAR Word ' tenths of seconds
loSLo VAR loSec.LowByte
loSHi VAR loSec.HighByte
loEW VAR flags.Bit1 ' 0 = E

temp VAR Byte
temp2 VAR Word
rdngNum VAR Word



'
[noparse][[/noparse] Initialization ]
'
Initialize:
PAUSE 1000 ' let DEBUG window open
INPUT Ignition ' Defining Pin 1 as an input

IntrusionStat = %00 ' reseting the Intrusion Status register
'iButtonStat= %00 ' resetting the iButton Status register

'
[noparse][[/noparse] Main Code ]

Main:

ButtonStat = %00 'Resetting the Button Status

DEBUG CLS


GOTO DeviceCheck ' look for device
iButtonChecked: IF (devCheck <> NoDevice) THEN Check

SeeAgain:
Condition1: IF ButtonStat <>%11 AND IN1=1 THEN Intrusion ' Intrusion detected
Condition2: IF ButtonStat =%11 AND IN1=1 THEN LetDrive ' Ok to Drive
Condition3: IF ButtonStat =%11 AND IN1=0 THEN LetDriveDelay ' OK to drive, has a 10 second delay

GOTO MAIN



'
[noparse][[/noparse] Subroutines ]
'

'====================================================================================


Intrusion:


IntTime = 0 ' Reseting the 'intrusion timer'
IF IntrusionStat = %11 THEN TwoMinDelay

IntrusionStat = %01 ' Setting the Intrusion Flag
TimeLimit = 25 ' Give approx 25 Seconds time limit to enter a valid key
GOTO DoTimeOut

TwoMinDelay:
TimeLimit = 120 ' Give 120 Seconds time delay before sendin out a new message

DoTimeOut:

GoSub TimeOut

PAUSE 2500 ' 2.5 secons of pause

SmsMessage:

PAUSE 250 '250ms delay for SMS messaging

DEBUG "AT"
PAUSE 1000
DEBUG CR
DEBUG "AT+CMGF=1" 'Making sure that the TC-35 GSM module is in text mode.
'PAUSE 2000
DEBUG CR ' Carraige Return ot 'Enter'
PAUSE 2000
DEBUG "AT+CMGS"
PAUSE 2000
DEBUG 61 'ASCII Equivalent for =
DEBUG 34 'ASCII Equivalent for "
'================================================================================
DEBUG "+44 Your mobile number here" ' Enter the destination mobile phone number here
' +44 is for UK; change for other countries
' e.g.: +92 for Pakistan, +


'================================================================================
DEBUG 34 'ASCII Equivalent for "
DEBUG CR ' Carraige Return ot 'Enter'
PAUSE 2000
PAUSE 1000

GOSUB Datalog 'Get the GPS data and feed it to the TC-35

IntrusionStat=%11
GOTO SeeAgain

'
[noparse][[/noparse] Subroutines ]

' **********************************************
' Extract Latitude and Longitude from GPS string
' **********************************************

DataLog:
SERIN GPSpin,N4800,[noparse][[/noparse]WAIT("$GPRMC"),SPSTR 65]
GOSUB Parse_GPS

' show current reading

DEBUG DEC2 laDeg,":",DEC2 laMin,":"
DEBUG DEC2 laSec / 10,".",DEC1 laSec // 10,Comma
DEBUG "N" + (laNS * 5),Comma
DEBUG DEC3 loDeg,":",DEC2 loMin,":"
DEBUG DEC2 loSec / 10,".",DEC1 loSec // 10,Comma
DEBUG "E" + (loEW * 18)
DEBUG CR

DEBUG 26 'Equivlent for CTRL+Z in ASCII
' At this point an SMS message has been sent out
Return

'=================================================================================


Parse_GPS:

Get_Lat:
GET 10,temp
laDeg = (temp - "0") * 10
GET 11,temp
laDeg = (temp - "0") + laDeg

GET 12,temp
laMin = (temp - "0") * 10
GET 13,temp
laMin = (temp - "0") + laMin

GET 15,temp
temp2 = (temp - "0") * 1000
GET 16,temp
temp2 = (temp - "0") * 100 + temp2

GET 17,temp
temp2 = (temp - "0") * 10 + temp2
GET 18,temp
temp2 = (temp - "0") + temp2
laSec = temp2 * 6 / 10 + 5 / 10 ' temp2 * 0.06 (with rounding)

laNS = 0
GET 20,temp
IF (temp = "N") THEN Get_Long
laNS = 1

Get_Long:
GET 22,temp
loDeg = (temp - "0") * 100
GET 23,temp
loDeg = (temp - "0") * 10 + loDeg
GET 24,temp
loDeg = (temp - "0") + loDeg

GET 25,temp
loMin = (temp - "0") * 10
GET 26,temp
loMin = (temp - "0") + loMin

GET 28,temp
temp2 = (temp - "0") * 1000
GET 29,temp
temp2 = (temp - "0") * 100 + temp2
GET 30,temp
temp2 = (temp - "0") * 10 + temp2
GET 31,temp
temp2 = (temp - "0") + temp2
loSec = temp2 * 6 / 10 + 5 / 10 ' temp2 * 0.06 (with rounding)

loEW = 0
GET 33,temp
IF (temp = "E") THEN Parse_GPS_Done
loEW = 1

Parse_GPS_Done:
RETURN



'==============================================================
TimeOut:

BacktoTimeout:
GOTO DeviceCheck 'Re-check if iButton is OK

TimeOutDone:

DEBUG " In here counting"
DEBUG CR
IF ButtonStat = %11 THEN AllOk ' A valid iButton has been connected
PAUSE 1000 '1 second delay
IntTime = IntTime+1 ' Increment
IF IntTime => TimeLimit THEN TimeOutComp ' Send out another message with the position
GOTO BacktoTimeOut 'Keep counting the time until time is !!

TimeOutComp:

Return
'==============================================================

LetDrive:

IF IN1=1 then LetDrive 'If Ignition is switched OFF
GOTO LEtDriveDelay

LetDriveDelay:

' This Subroutine caters for Stalls etc..

Pause 5000
IF IN1=1 THEN LetDrive ' let the user drive car
IntrusionStat= %00 ' Reset Instrusion Flag
ButtonStat = %00 ' Reset Button Status flaf
GOTO Main

'==============================================================

' This subroutine checks to see if any 1-Wire devices are present on the
' bus. It does NOT search for ROM codes
'
DeviceCheck:

devCheck = 0
OWOUT OWpin,OW_FERst,[noparse][[/noparse]SearchROM] ' reset and start search
OWIN OWpin,OW_BitMode,[noparse][[/noparse]devCheck.Bit1,devCheck.Bit0]

IF (devCheck <> NoDevice) THEN Check
IF IntrusionStat <> %00 THEN TimeoutDone ' If Intrusion already logged, return to 'timeout'

DEVICECHECKDONE: GOTO SeeAgain

Check:

DisplayROM:

'DEBUG "Dallas 1-Wire ID : "
OWOUT OWpin,OW_FERst,[noparse][[/noparse]ReadROM] ' send Read ROM command
OWIN OWpin,OW_BERst,[noparse][[/noparse]STR romData\8] ' read serial number & CRC

IF romData(0) <> $03 THEN CheckSecond
IF romData(1) <> $F0 THEN CheckSecond
IF romData(2) <> $BC THEN CheckSecond
IF romData(3) <> $08 THEN CheckSecond
IF romData(4) <> $10 THEN CheckSecond
IF romData(5) <> $00 THEN CheckSecond
IF romData(6) <> $00 THEN CheckSecond
IF romData(7) <> $30 THEN CheckSecond

GOTO ButtonOK

CheckSecond:

IF romData(0) <> $01 THEN BadButton
IF romData(1) <> $68 THEN BadButton
IF romData(2) <> $21 THEN BadButton
IF romData(3) <> $24 THEN BadButton
IF romData(4) <> $08 THEN BadButton
IF romData(5) <> $00 THEN BadButton
IF romData(6) <> $00 THEN BadButton
IF romData(7) <> $31 THEN BadButton

GOTO ButtonOK

BadButton:
ButtonStat = %01

If IntrusionStat <> %00 THEN BacktoTimeout

GOTO SeeAgain

ButtonOK:
ButtonStat = %11
IntrusionStat=%00



GOTO SeeAgain

'At this stage we have ascertained that the user is authorised. We now need to detect when
' the vehicle is stopped. Wait for another 25s (to allow for situations such as a 'Stall)
' and start monitoring again.
' This will be catered by another '''Subroutine'''

'==============================================================

AllOk:
ButtonStat = %11
IntrusionStat = %00

Goto SeeAgain

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-01 16:24
    Hello,

    ·· There is no question it will take some work on your part to convert this to work on the SX.· Of course there is the SX/B compiler available to you.· I would suggest reading the help file included to see what kinds of changes you're going to have to make.· If you don't have any experience programming the SX, then this isn't something you will be able to do overnight.· You can find help with that in our SX programming books.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • FilipeFilipe Posts: 8
    edited 2005-07-01 16:33
    Thanks;

    Filipe
Sign In or Register to comment.