Shop OBEX P1 Docs P2 Docs Learn Events
big Brother and big Sister pls help me.( very Long) — Parallax Forums

big Brother and big Sister pls help me.( very Long)

ArchiverArchiver Posts: 46,084
edited 2003-12-08 15:41 in General Discussion
Hi All,

I'm a student from singapore currently doing my project on "SMS control and
Monitoring"
So far i think l'm doing quite well as i'm very new to STAMP.
i'm able to sms and receive a reply to my handphone with the temperature
reading.

I have brought : BS2p40 starter kit
siemens modem
DS1624 (temperature sensor)
Amulet LCD.

As i had use up all 26 variable, l'm now in a lost.....
i did some research and i got three methods here.
- use multi-banking ( i don't think i can use this)
- use scratchpad RAM (will this help?)
- EEPROM (24LC32) ( i dun noe how to use it)

i have attach the source code below pls advise me.
i need to reduce the variable for other use.

\
'{$STAMP BS2p}

'pin0 and pin 3
Siemens modem
'pin 8 and pin 9
DS 1624
'pin 16
Amulet LCD

'============Setting for Siemens modem=================
SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGF=1", CR] 'set text mode
SERIN 3, 18447, [noparse][[/noparse]WAIT("OK")] 'wait for text mode ok reply

'===========Declaring Variable=======================
Number_Str VAR Byte(3) 'for temperature reading
SerString VAR Byte(5) 'for password
MessageAddress VAR Byte(9) 'address to reply SMS
Value1 VAR Byte 'convert to Decimal1
Value2 VAR Byte 'convert to Decimal2

'============temperature variable==============
ADR VAR Byte
DAT VAR Byte
OUT CON 1
IN CON 0
SDA_OUT VAR OUT8
SCL_OUT VAR OUT9
SDA_IN VAR IN8
SDA_DIR VAR DIR8
SCL_DIR VAR DIR9
T VAR Word
O_BYTE VAR Byte
I_BYTE VAR Byte
N VAR Byte

Main:
SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGL=", 34,"rec unread", 34, CR] 'read unread msg,stored
it to be forever UNREAD
SERIN 3,18447,1000, Main,[noparse][[/noparse]WAIT ("+CMGL:"), WAIT(","), WAIT(","), SKIP 4, STR
MessageAddress\8\0, WAIT(13, 10)]

'======password
SERIN 3, 18447,1000, Main, [noparse][[/noparse]WAIT("z"),STR SerString\4] 'if "z" no appear,
program goes back to function start
IF SerString(0) = "t" OR "T" THEN loop2
IF SerString(0) <> "t" OR "T" THEN LCDerror
loop2:
IF SerString(1) = "e" OR "E" THEN loop3
IF SerString(1) <> "e" OR "E" THEN LCDerror
'IF SerString(1) <> "E" THEN LCDerror
loop3:
IF SerString(2) = "m" OR "M" THEN loop4
IF SerString(2) <> "m" OR "M" THEN LCDerror
loop4:
IF SerString(3) = "p" OR "P" THEN Temperature 'loop5
IF SerString(3) <> "p" OR "P" THEN LCDerror
GOTO Main
'
\
--
LCDdisplay:
SEROUT 16,1,[noparse][[/noparse]215,48,48, STR Number_Str\2," Degree Celsius",0] 'using
RS232; Baud rate=115200
SEROUT 16,1,[noparse][[/noparse]215,48,50, STR Number_Str\2," Degree Celsius",0]
GOTO send_sms
RETURN
'
\
--
send_sms:
SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGF=1", CR] 'set text mode
PAUSE 300
SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGS=", 34,"+65", STR MessageAddress\8, 34,CR] 'send msg
command
PAUSE 1000
SEROUT 0, 18447, [noparse][[/noparse]"Temp=", STR Number_Str," Degree Celsius", 26]
RETURN

'
\
----
LCDerror:
SEROUT 16,1,[noparse][[/noparse]215,48,48,"Invalid Password",0]
SEROUT 16,1,[noparse][[/noparse]215,48,50,"Invalid Password",0]
GOSUB Invalid_password_smsSend
RETURN
'
\
Invalid_password_smsSend:
SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGF=1", CR] 'set text mode
PAUSE 300
SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGS=", 34,"+65", STR MessageAddress\8, 34,CR] 'send
msg command
PAUSE 1000
SEROUT 0, 18447, [noparse][[/noparse]"Invalid password",26]
RETURN
'
\
Temperature:
DIRS=$0000 ' start with DIR8 and DIR9 as inputs
GOSUB CONFIG ' configure DS1624 for 1SHOT operation
'FOR ADR=0 TO 9 ' make ten measurements
GOSUB INIT ' initiate a conversion
GOSUB MEAS ' fetch the result
'DEBUG ?T.BYTE1
'DEBUG ?T.BYTE0
DAT = T.BYTE1
GOSUB EE_WRITE ' save high byte to the DS1624 EEPROM
PAUSE 1000
'NEXT
'FOR ADR=0 TO 9 ' now fetch each from EEPROM and display
GOSUB EE_READ
DAT=I_BYTE
Value1 = DAT DIG 1 ' Tens
Value2 = DAT DIG 0 ' Ones
Number_Str(0)= Value1 + 48
Number_Str(1)= Value2 + 48
'DEBUG STR Number_Str
'NEXT
GOTO LCDdisplay
'
\
CONFIG: ' configures DS1624 in 1SHOT temperature conversion mode
GOSUB START
O_BYTE=$90
GOSUB OUT_BYTE
GOSUB NACK
O_BYTE=$AC 'Access Config
GOSUB OUT_BYTE
GOSUB NACK
O_BYTE=$01 '1 SHOT mode
GOSUB OUT_BYTE
GOSUB NACK
GOSUB SSTOP
PAUSE 30 ' wait for EEPROM to program
RETURN
'
\
INIT: ' causes DS1624 to initiate a conversion
GOSUB START
O_BYTE=$90 ' write
GOSUB OUT_BYTE
GOSUB NACK
O_BYTE=$EE ' Start Conversion
GOSUB OUT_BYTE
GOSUB NACK
GOSUB SSTOP
PAUSE 1000 ' wait 1000 ms for conversion to complete
RETURN
'
\
MEAS: ' fetches temperature result. Value returned in T_HI and T_LO
GOSUB START
O_BYTE=$90 ' write
GOSUB OUT_BYTE
GOSUB NACK
O_BYTE=$AA ' Fetch Temperature
GOSUB OUT_BYTE
GOSUB NACK
GOSUB START ' read
O_BYTE= $91 '!@#$%^
GOSUB OUT_BYTE
GOSUB NACK
GOSUB IN_BYTE ' fetch the two byte reading
GOSUB ACK ' acknowledge each byte
T.BYTE1 = I_BYTE ' high byte
GOSUB IN_BYTE
GOSUB ACK
T.BYTE0 = I_BYTE
GOSUB SSTOP
RETURN
'
\
EE_READ: ' fetches content location ADR in DS1624 EEPROM
' result returned in DAT
GOSUB START
O_BYTE=$90 ' write
GOSUB OUT_BYTE
GOSUB NACK
O_BYTE=$17 ' access EEPROM
GOSUB OUT_BYTE
GOSUB NACK
O_BYTE=ADR ' specify address to read
' DEBUG ?ADR
GOSUB OUT_BYTE
GOSUB NACK
GOSUB START ' now read
O_BYTE=$91 '!@#$%^
GOSUB OUT_BYTE
GOSUB NACK
GOSUB IN_BYTE
DAT = I_BYTE
GOSUB SSTOP
RETURN
'
\
EE_WRITE: ' writes content of DAT to specified address ADR
GOSUB START
O_BYTE=$90 ' write
GOSUB OUT_BYTE
GOSUB NACK
O_BYTE=$17 ' Access Memory
GOSUB OUT_BYTE
GOSUB NACK
O_BYTE=ADR ' address
'DEBUG ?ADR
GOSUB OUT_BYTE
GOSUB NACK
O_BYTE=DAT ' data to write
'DEBUG HEX2 ?DAT
GOSUB OUT_BYTE
GOSUB NACK
GOSUB SSTOP
PAUSE 15 ' wait for EEPROM to program
RETURN
'
\
OUT_BYTE: ' sends content of O_BYTE, most sig byte first
FOR N=7 TO 0
BRANCH (O_BYTE>>N)&$01, [noparse][[/noparse]OUT_0, OUT_1]
'
\
OUT_0:
GOSUB LO_SDA
'DEBUG "0"
GOTO OUT_BYTE_1
'
\
OUT_1:
GOSUB HI_SDA
'DEBUG "1"
GOTO OUT_BYTE_1
'
\
OUT_BYTE_1:
GOSUB CLK
GOSUB HI_SDA
NEXT
'DEBUG CR
RETURN
'
\
IN_BYTE: ' receives a byte, most sig byte first.
' result returned in I_BYTE
GOSUB HI_SDA
I_BYTE=0
FOR N=0 TO 7
GOSUB HI_SCL
I_BYTE= (I_BYTE<<1) | SDA_IN
'DEBUG DEC SDA_IN
GOSUB LO_SCL
NEXT
'DEBUG CR
RETURN
'
\
NACK: ' clock pulse while SDA in high impdeance to allow
' slave to acknowledge by bringing SDA low
GOSUB HI_SDA
GOSUB CLK
RETURN
'
\
ACK: ' clock pulse while SDA low to acknowledge receipt of
' a byte from the slave
GOSUB LO_SDA
GOSUB CLK
GOSUB HI_SDA
RETURN
'
\
CLK: ' momentarily bring SCL high
GOSUB HI_SCL
GOSUB LO_SCL
RETURN
'
\
START: ' bring SDA from high to low while SCL is high
GOSUB LO_SCL
GOSUB HI_SDA
GOSUB HI_SCL
GOSUB LO_SDA 'SDA transition to low when SCL high
GOSUB LO_SCL
RETURN
'
\
SSTOP: ' bring SDA from low to high while SCL is high
GOSUB LO_SCL
GOSUB LO_SDA 'be sure SDA is in low state
GOSUB HI_SCL
GOSUB HI_SDA 'SDA transition to high when SCL is high
RETURN 'both SDA and SCL left in high-Z
'
\
LO_SDA:
SDA_OUT=0
SDA_DIR=OUT
RETURN
'
\
LO_SCL:
SCL_OUT=0
SCL_DIR=OUT
RETURN
'
\
HI_SDA:
SDA_DIR=IN
RETURN
'
\
HI_SCL:
SCL_DIR=IN
RETURN




Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-12-08 15:41
    Ben,

    I looked at the code, and I don't know enough to comment much. I have never
    done anything like what you are doing. However, is the password always the
    same? You could store the password with a DATA command and use 3 less bytes.
    What about the message address? If it is always the same, you could store
    that with a DATA command too. When you need to use the DATA, make a small
    loop witht he READ command.

    Hope this helps,

    Jonathan

    www.madlabs.info

    Original Message
    From: "lim EngTat" <benzlim83@y...>
    To: <basicstamps@yahoogroups.com>; <sswanson@p...>;
    <tracy@e...>
    Sent: Sunday, December 07, 2003 8:30 AM
    Subject: [noparse][[/noparse]basicstamps] big Brother and big Sister pls help me.( very Long)


    > Hi All,
    >
    > I'm a student from singapore currently doing my project on "SMS control
    and Monitoring"
    > So far i think l'm doing quite well as i'm very new to STAMP.
    > i'm able to sms and receive a reply to my handphone with the temperature
    reading.
    >
    > I have brought : BS2p40 starter kit
    > siemens modem
    > DS1624 (temperature sensor)
    > Amulet LCD.
    >
    > As i had use up all 26 variable, l'm now in a lost.....
    > i did some research and i got three methods here.
    > - use multi-banking ( i don't think i can use this)
    > - use scratchpad RAM (will this help?)
    > - EEPROM (24LC32) ( i dun noe how to use it)
    >
    > i have attach the source code below pls advise me.
    > i need to reduce the variable for other use.
    >
    >

    > '{$STAMP BS2p}
    >
    > 'pin0 and pin 3
    Siemens modem
    > 'pin 8 and pin 9
    DS 1624
    > 'pin 16
    Amulet LCD
    >
    > '============Setting for Siemens modem=================
    > SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGF=1", CR] 'set text mode
    > SERIN 3, 18447, [noparse][[/noparse]WAIT("OK")] 'wait for text mode ok reply
    >
    > '===========Declaring Variable=======================
    > Number_Str VAR Byte(3) 'for temperature reading
    > SerString VAR Byte(5) 'for password
    > MessageAddress VAR Byte(9) 'address to reply SMS
    > Value1 VAR Byte 'convert to Decimal1
    > Value2 VAR Byte 'convert to Decimal2
    >
    > '============temperature variable==============
    > ADR VAR Byte
    > DAT VAR Byte
    > OUT CON 1
    > IN CON 0
    > SDA_OUT VAR OUT8
    > SCL_OUT VAR OUT9
    > SDA_IN VAR IN8
    > SDA_DIR VAR DIR8
    > SCL_DIR VAR DIR9
    > T VAR Word
    > O_BYTE VAR Byte
    > I_BYTE VAR Byte
    > N VAR Byte
    >
    > Main:
    > SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGL=", 34,"rec unread", 34, CR] 'read unread
    msg,stored it to be forever UNREAD
    > SERIN 3,18447,1000, Main,[noparse][[/noparse]WAIT ("+CMGL:"), WAIT(","), WAIT(","), SKIP 4,
    STR MessageAddress\8\0, WAIT(13, 10)]
    >
    > '======password
    > SERIN 3, 18447,1000, Main, [noparse][[/noparse]WAIT("z"),STR SerString\4] 'if "z" no
    appear, program goes back to function start
    > IF SerString(0) = "t" OR "T" THEN loop2
    > IF SerString(0) <> "t" OR "T" THEN LCDerror
    > loop2:
    > IF SerString(1) = "e" OR "E" THEN loop3
    > IF SerString(1) <> "e" OR "E" THEN LCDerror
    > 'IF SerString(1) <> "E" THEN LCDerror
    > loop3:
    > IF SerString(2) = "m" OR "M" THEN loop4
    > IF SerString(2) <> "m" OR "M" THEN LCDerror
    > loop4:
    > IF SerString(3) = "p" OR "P" THEN Temperature 'loop5
    > IF SerString(3) <> "p" OR "P" THEN LCDerror
    > GOTO Main
    >
    '

    > LCDdisplay:
    > SEROUT 16,1,[noparse][[/noparse]215,48,48, STR Number_Str\2," Degree Celsius",0]
    'using RS232; Baud rate=115200
    > SEROUT 16,1,[noparse][[/noparse]215,48,50, STR Number_Str\2," Degree Celsius",0]
    > GOTO send_sms
    > RETURN
    >
    '

    > send_sms:
    > SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGF=1", CR] 'set text mode
    > PAUSE 300
    > SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGS=", 34,"+65", STR MessageAddress\8, 34,CR]
    'send msg command
    > PAUSE 1000
    > SEROUT 0, 18447, [noparse][[/noparse]"Temp=", STR Number_Str," Degree Celsius", 26]
    > RETURN
    >
    >
    '

    > LCDerror:
    > SEROUT 16,1,[noparse][[/noparse]215,48,48,"Invalid Password",0]
    > SEROUT 16,1,[noparse][[/noparse]215,48,50,"Invalid Password",0]
    > GOSUB Invalid_password_smsSend
    > RETURN
    >
    '

    > Invalid_password_smsSend:
    > SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGF=1", CR] 'set text mode
    > PAUSE 300
    > SEROUT 0, 18447, [noparse][[/noparse]"AT+CMGS=", 34,"+65", STR MessageAddress\8, 34,CR]
    'send msg command
    > PAUSE 1000
    > SEROUT 0, 18447, [noparse][[/noparse]"Invalid password",26]
    > RETURN
    >
    '

    > Temperature:
    > DIRS=$0000 ' start with DIR8 and DIR9 as inputs
    > GOSUB CONFIG ' configure DS1624 for 1SHOT operation
    > 'FOR ADR=0 TO 9 ' make ten measurements
    > GOSUB INIT ' initiate a conversion
    > GOSUB MEAS ' fetch the result
    > 'DEBUG ?T.BYTE1
    > 'DEBUG ?T.BYTE0
    > DAT = T.BYTE1
    > GOSUB EE_WRITE ' save high byte to the DS1624 EEPROM
    > PAUSE 1000
    > 'NEXT
    > 'FOR ADR=0 TO 9 ' now fetch each from EEPROM and display
    > GOSUB EE_READ
    > DAT=I_BYTE
    > Value1 = DAT DIG 1 ' Tens
    > Value2 = DAT DIG 0 ' Ones
    > Number_Str(0)= Value1 + 48
    > Number_Str(1)= Value2 + 48
    > 'DEBUG STR Number_Str
    > 'NEXT
    > GOTO LCDdisplay
    >
    '

    > CONFIG: ' configures DS1624 in 1SHOT temperature conversion mode
    > GOSUB START
    > O_BYTE=$90
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > O_BYTE=$AC 'Access Config
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > O_BYTE=$01 '1 SHOT mode
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > GOSUB SSTOP
    > PAUSE 30 ' wait for EEPROM to program
    > RETURN
    >
    '

    > INIT: ' causes DS1624 to initiate a conversion
    > GOSUB START
    > O_BYTE=$90 ' write
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > O_BYTE=$EE ' Start Conversion
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > GOSUB SSTOP
    > PAUSE 1000 ' wait 1000 ms for conversion to complete
    > RETURN
    >
    '

    > MEAS: ' fetches temperature result. Value returned in T_HI and T_LO
    > GOSUB START
    > O_BYTE=$90 ' write
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > O_BYTE=$AA ' Fetch Temperature
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > GOSUB START ' read
    > O_BYTE= $91 '!@#$%^
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > GOSUB IN_BYTE ' fetch the two byte reading
    > GOSUB ACK ' acknowledge each byte
    > T.BYTE1 = I_BYTE ' high byte
    > GOSUB IN_BYTE
    > GOSUB ACK
    > T.BYTE0 = I_BYTE
    > GOSUB SSTOP
    > RETURN
    >
    '

    > EE_READ: ' fetches content location ADR in DS1624 EEPROM
    > ' result returned in DAT
    > GOSUB START
    > O_BYTE=$90 ' write
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > O_BYTE=$17 ' access EEPROM
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > O_BYTE=ADR ' specify address to read
    > ' DEBUG ?ADR
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > GOSUB START ' now read
    > O_BYTE=$91 '!@#$%^
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > GOSUB IN_BYTE
    > DAT = I_BYTE
    > GOSUB SSTOP
    > RETURN
    >
    '

    > EE_WRITE: ' writes content of DAT to specified address ADR
    > GOSUB START
    > O_BYTE=$90 ' write
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > O_BYTE=$17 ' Access Memory
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > O_BYTE=ADR ' address
    > 'DEBUG ?ADR
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > O_BYTE=DAT ' data to write
    > 'DEBUG HEX2 ?DAT
    > GOSUB OUT_BYTE
    > GOSUB NACK
    > GOSUB SSTOP
    > PAUSE 15 ' wait for EEPROM to program
    > RETURN
    >
    '

    > OUT_BYTE: ' sends content of O_BYTE, most sig byte first
    > FOR N=7 TO 0
    > BRANCH (O_BYTE>>N)&$01, [noparse][[/noparse]OUT_0, OUT_1]
    >
    '

    > OUT_0:
    > GOSUB LO_SDA
    > 'DEBUG "0"
    > GOTO OUT_BYTE_1
    >
    '

    > OUT_1:
    > GOSUB HI_SDA
    > 'DEBUG "1"
    > GOTO OUT_BYTE_1
    >
    '

    > OUT_BYTE_1:
    > GOSUB CLK
    > GOSUB HI_SDA
    > NEXT
    > 'DEBUG CR
    > RETURN
    >
    '

    > IN_BYTE: ' receives a byte, most sig byte first.
    > ' result returned in I_BYTE
    > GOSUB HI_SDA
    > I_BYTE=0
    > FOR N=0 TO 7
    > GOSUB HI_SCL
    > I_BYTE= (I_BYTE<<1) | SDA_IN
    > 'DEBUG DEC SDA_IN
    > GOSUB LO_SCL
    > NEXT
    > 'DEBUG CR
    > RETURN
    >
    '

    > NACK: ' clock pulse while SDA in high impdeance to allow
    > ' slave to acknowledge by bringing SDA low
    > GOSUB HI_SDA
    > GOSUB CLK
    > RETURN
    >
    '

    > ACK: ' clock pulse while SDA low to acknowledge receipt of
    > ' a byte from the slave
    > GOSUB LO_SDA
    > GOSUB CLK
    > GOSUB HI_SDA
    > RETURN
    >
    '

    > CLK: ' momentarily bring SCL high
    > GOSUB HI_SCL
    > GOSUB LO_SCL
    > RETURN
    >
    '

    > START: ' bring SDA from high to low while SCL is high
    > GOSUB LO_SCL
    > GOSUB HI_SDA
    > GOSUB HI_SCL
    > GOSUB LO_SDA 'SDA transition to low when SCL high
    > GOSUB LO_SCL
    > RETURN
    >
    '

    > SSTOP: ' bring SDA from low to high while SCL is high
    > GOSUB LO_SCL
    > GOSUB LO_SDA 'be sure SDA is in low state
    > GOSUB HI_SCL
    > GOSUB HI_SDA 'SDA transition to high when SCL is high
    > RETURN 'both SDA and SCL left in high-Z
    >
    '

    > LO_SDA:
    > SDA_OUT=0
    > SDA_DIR=OUT
    > RETURN
    >
    '

    > LO_SCL:
    > SCL_OUT=0
    > SCL_DIR=OUT
    > RETURN
    >
    '

    > HI_SDA:
    > SDA_DIR=IN
    > RETURN
    >
    '

    > HI_SCL:
    > SCL_DIR=IN
    > RETURN
    >
    >
    >
    >
    >
    > Do you Yahoo!?
    > New Yahoo! Photos - easier uploading and sharing
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
Sign In or Register to comment.