That said, if you describe what you're trying to do, maybe one of us can make some suggestions since it is possible to attach external memory to a Stamp. It just doesn't work as more RAM as far as the program is concerned. You can't have variables there for example.
You had mentioned using two BS2s, one BS2E is much cheaper than two BS2s.
Might this indicate some minor lack of efficiency in our educational system, or is an endictment of government bureaucracy as a whole? [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ·"If you build it, they will come."
OR SOMEBODY can help me decrease this program memory
MY basic stamp still have 4 world 2 byte to use our sensor is sht11 and i want to measure the temperature only
MODE4:
ShtData PIN 1 ' bi-directional data
Clock PIN 0
ShtTemp CON %00011 ' read temperature
ShtHumi CON %00101 ' read humidity
ShtStatW CON %00110 ' status register write
ShtStatR CON %00111 ' status register read
ShtReset CON %11110 ' soft reset
Ack CON 0
NoAck CON 1
No CON 0
Yes CON 1
DegSym CON 186 ' degrees symbol for DEBUG
ioByte VAR Byte ' data from/to SHT11
ackBit VAR Bit ' ack/nak from/to SHT11
toDelay VAR Byte ' timeout delay timer
timeOut VAR Bit ' timeout status
soT VAR Word ' temp counts from SHT11
tC VAR Word ' temp - Celcius
tF VAR Word ' temp - Fahrenheit
soRH VAR Word ' humidity counts
rhLin VAR Word ' humidity; linearized
rhTrue VAR Word ' humidity; compensated
status VAR Byte
Initialize:
GOSUB SHT_Connection_Reset ' reset device connection
PAUSE 250 ' let DEBUG window open
Main:
DO WHILE IN0 <> 0 AND IN1 <> 0 AND IN2 <> 0
SEROUT 14, 84, [noparse][[/noparse]22, 12] ' Initialize LCD
PAUSE 5
SEROUT 14, 84, [noparse][[/noparse]"tC = " ,CLREOL, DEC tC, DegSym, "C", CR,"RhLin=" ,DEC rhLin,"% "]
GOSUB SHT_Measure_Humidity
GOSUB SHT_Measure_Temp
PAUSE 1000
LOOP
END
SHT_Connection_Reset:
SHIFTOUT ShtData, Clock, LSBFIRST, [noparse][[/noparse]$FFF\9]
'
SHT_Start:
INPUT ShtData ' let pull-up take high
LOW Clock
HIGH Clock
LOW ShtData
LOW Clock
HIGH Clock
INPUT ShtData
LOW Clock
RETURN
SHT_Measure_Temp:
GOSUB SHT_Start ' alert device
ioByte = ShtTemp ' temperature command
GOSUB SHT_Write_Byte ' send command
GOSUB SHT_Wait ' wait for measurement
ackBit = Ack ' another read follows
GOSUB SHT_Read_Byte ' get MSB
soT.HIGHBYTE = ioByte
ackBit = NoAck ' last read
GOSUB SHT_Read_Byte ' get LSB
soT.LOWBYTE = ioByte
tC = soT ** $1999 - 400 ' convert to tenths C
tF = soT ** $2E14 - 400 ' convert to tenths F
RETURN
SHT_Measure_Humidity:
GOSUB SHT_Start ' alert device
ioByte = ShtHumi ' humidity command
GOSUB SHT_Write_Byte ' send command
GOSUB SHT_Wait ' wait for measurement
ackBit = Ack ' another read follows
GOSUB SHT_Read_Byte ' get MSB
soRH.HIGHBYTE = ioByte
ackBit = NoAck ' last read
GOSUB SHT_Read_Byte ' get LSB
soRH.LOWBYTE = ioByte
rhTrue = (tC - 250) * (soRH ** $34) + rhLin
RETURN
SHT_Write_Status:
GOSUB SHT_Start ' alert device
ioByte = ShtStatW
GOSUB SHT_Write_Byte ' send command
ioByte = status
GOSUB SHT_Write_Byte
RETURN
SHT_Read_Status:
GOSUB SHT_Start ' alert device
ioByte = ShtStatW ' write to status reg cmd
GOSUB SHT_Read_Byte ' send command
ackBit = NoAck ' only one byte to read
GOSUB SHT_Read_Byte
RETURN
SHT_Write_Byte:
SHIFTOUT ShtData, Clock, MSBFIRST, [noparse][[/noparse]ioByte] ' send byte
SHIFTIN ShtData, Clock, LSBPRE, [noparse][[/noparse]ackBit\1] ' get ack bit
RETURN
SHT_Read_Byte:
SHIFTIN ShtData, Clock, MSBPRE, [noparse][[/noparse]ioByte] ' get byte
SHIFTOUT ShtData, Clock, LSBFIRST, [noparse][[/noparse]ackBit\1] ' send ack bit
INPUT ShtData ' release data line
RETURN
SHT_Wait:
INPUT ShtData ' data line is input
timeOut = No ' assume no timeout
FOR toDelay = 1 TO 250 ' wait ~1/4 second
IF (ShtData = 0) THEN EXIT
PAUSE 1
NEXT
IF (toDelay = 250) THEN timeOut = Yes ' loop completed = timeout
RETURN
SHT_Soft_Reset:
GOSUB SHT_Connection_Reset ' reset the connection
ioByte = ShtReset ' reset command
ackBit = NoAck ' only one byte to send
GOSUB SHT_Write_Byte ' send it
PAUSE 11 ' wait at least 11 ms
RETURN
Heater_On:
status = %00000100 ' heater bit = On
GOSUB SHT_Write_Status
RETURN
Heater_Off:
status = %00000000 ' heater bit = Off
GOSUB SHT_Write_Status
RETURN
Here's a couple links to threads talking about streamlining the SHT11 code to save RAM by recycling variables in formulas.
http://forums.parallax.com/showthread.php?p=826300
Look at the last post of this one to see some streamlined code. It will read 4 SHT11 sensors and display the results in the debug screen. By streamlining how the formulas work to eliminate extra variables, RAM space was freed up. See Tracy Allen's comments about reducing the accuracy to gain additional space.
Comments
That said, if you describe what you're trying to do, maybe one of us can make some suggestions since it is possible to attach external memory to a Stamp. It just doesn't work as more RAM as far as the program is concerned. You can't have variables there for example.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
Might this indicate some minor lack of efficiency in our educational system, or is an endictment of government bureaucracy as a whole? [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
MY basic stamp still have 4 world 2 byte to use our sensor is sht11 and i want to measure the temperature only
MODE4:
ShtData PIN 1 ' bi-directional data
Clock PIN 0
ShtTemp CON %00011 ' read temperature
ShtHumi CON %00101 ' read humidity
ShtStatW CON %00110 ' status register write
ShtStatR CON %00111 ' status register read
ShtReset CON %11110 ' soft reset
Ack CON 0
NoAck CON 1
No CON 0
Yes CON 1
DegSym CON 186 ' degrees symbol for DEBUG
ioByte VAR Byte ' data from/to SHT11
ackBit VAR Bit ' ack/nak from/to SHT11
toDelay VAR Byte ' timeout delay timer
timeOut VAR Bit ' timeout status
soT VAR Word ' temp counts from SHT11
tC VAR Word ' temp - Celcius
tF VAR Word ' temp - Fahrenheit
soRH VAR Word ' humidity counts
rhLin VAR Word ' humidity; linearized
rhTrue VAR Word ' humidity; compensated
status VAR Byte
Initialize:
GOSUB SHT_Connection_Reset ' reset device connection
PAUSE 250 ' let DEBUG window open
Main:
DO WHILE IN0 <> 0 AND IN1 <> 0 AND IN2 <> 0
SEROUT 14, 84, [noparse][[/noparse]22, 12] ' Initialize LCD
PAUSE 5
SEROUT 14, 84, [noparse][[/noparse]"tC = " ,CLREOL, DEC tC, DegSym, "C", CR,"RhLin=" ,DEC rhLin,"% "]
GOSUB SHT_Measure_Humidity
GOSUB SHT_Measure_Temp
PAUSE 1000
LOOP
END
SHT_Connection_Reset:
SHIFTOUT ShtData, Clock, LSBFIRST, [noparse][[/noparse]$FFF\9]
'
SHT_Start:
INPUT ShtData ' let pull-up take high
LOW Clock
HIGH Clock
LOW ShtData
LOW Clock
HIGH Clock
INPUT ShtData
LOW Clock
RETURN
SHT_Measure_Temp:
GOSUB SHT_Start ' alert device
ioByte = ShtTemp ' temperature command
GOSUB SHT_Write_Byte ' send command
GOSUB SHT_Wait ' wait for measurement
ackBit = Ack ' another read follows
GOSUB SHT_Read_Byte ' get MSB
soT.HIGHBYTE = ioByte
ackBit = NoAck ' last read
GOSUB SHT_Read_Byte ' get LSB
soT.LOWBYTE = ioByte
tC = soT ** $1999 - 400 ' convert to tenths C
tF = soT ** $2E14 - 400 ' convert to tenths F
RETURN
SHT_Measure_Humidity:
GOSUB SHT_Start ' alert device
ioByte = ShtHumi ' humidity command
GOSUB SHT_Write_Byte ' send command
GOSUB SHT_Wait ' wait for measurement
ackBit = Ack ' another read follows
GOSUB SHT_Read_Byte ' get MSB
soRH.HIGHBYTE = ioByte
ackBit = NoAck ' last read
GOSUB SHT_Read_Byte ' get LSB
soRH.LOWBYTE = ioByte
rhTrue = (tC - 250) * (soRH ** $34) + rhLin
RETURN
SHT_Write_Status:
GOSUB SHT_Start ' alert device
ioByte = ShtStatW
GOSUB SHT_Write_Byte ' send command
ioByte = status
GOSUB SHT_Write_Byte
RETURN
SHT_Read_Status:
GOSUB SHT_Start ' alert device
ioByte = ShtStatW ' write to status reg cmd
GOSUB SHT_Read_Byte ' send command
ackBit = NoAck ' only one byte to read
GOSUB SHT_Read_Byte
RETURN
SHT_Write_Byte:
SHIFTOUT ShtData, Clock, MSBFIRST, [noparse][[/noparse]ioByte] ' send byte
SHIFTIN ShtData, Clock, LSBPRE, [noparse][[/noparse]ackBit\1] ' get ack bit
RETURN
SHT_Read_Byte:
SHIFTIN ShtData, Clock, MSBPRE, [noparse][[/noparse]ioByte] ' get byte
SHIFTOUT ShtData, Clock, LSBFIRST, [noparse][[/noparse]ackBit\1] ' send ack bit
INPUT ShtData ' release data line
RETURN
SHT_Wait:
INPUT ShtData ' data line is input
timeOut = No ' assume no timeout
FOR toDelay = 1 TO 250 ' wait ~1/4 second
IF (ShtData = 0) THEN EXIT
PAUSE 1
NEXT
IF (toDelay = 250) THEN timeOut = Yes ' loop completed = timeout
RETURN
SHT_Soft_Reset:
GOSUB SHT_Connection_Reset ' reset the connection
ioByte = ShtReset ' reset command
ackBit = NoAck ' only one byte to send
GOSUB SHT_Write_Byte ' send it
PAUSE 11 ' wait at least 11 ms
RETURN
Heater_On:
status = %00000100 ' heater bit = On
GOSUB SHT_Write_Status
RETURN
Heater_Off:
status = %00000000 ' heater bit = Off
GOSUB SHT_Write_Status
RETURN
http://forums.parallax.com/showthread.php?p=826300
Look at the last post of this one to see some streamlined code. It will read 4 SHT11 sensors and display the results in the debug screen. By streamlining how the formulas work to eliminate extra variables, RAM space was freed up. See Tracy Allen's comments about reducing the accuracy to gain additional space.
ftp.parallax.com/forums/default.aspx?f=5&m=398907
another thread with some info
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Williams
WBA Consulting
WBA-TH1M Sensirion SHT11 Module
Special Olympics Polar Bear Plunge, Mar 20, 2010