How to combine two programs into one? Please help - Thank you
guy20sanjose
Posts: 13
Anyone know how to combine these two programs into one program so it can be download to the BS2e ?
Program 1:
' {$STAMP BS2e}
'
' P4 -> ULN2003.1, ULN2003.16 -> Phase 1 (Black)
' P5 -> ULN2003.2, ULN2003.15 -> Phase 2 (Orange)
' P6 -> ULN2003.3, ULN2003.14 -> Phase 3 (Brown)
' P7 -> ULN2003.4, ULN2003.13 -> Phase 4 (Yellow)
'
[ I/O Definitions ]
Phase VAR OUTB ' phase control outputs
'
[ Constants ]
'
[ Variables ]
idx VAR Byte ' loop counter
stpIdx VAR Nib ' step pointer
stpDelay VAR Byte ' delay for speed control
'
[ EEPROM Data ]
Steps DATA %0011, %0110, %1100, %1001
'
[ Initialization ]
Setup:
DIRB = %1111 ' make P4..P7 outputs
stpDelay = 10 ' set step delay
'
[ Program Code ]
Main:
FOR idx = 1 TO 1//4 ' one revolution
GOSUB Step_Fwd ' rotate clockwise
NEXT
PAUSE 1000 ' wait 1/2 second
FOR idx = 1 TO 1//4 ' one revolution
GOSUB Step_Fwd1 ' rotate counter-clockwise
NEXT
PAUSE 1000 ' wait 1/2 second
GOTO Main
END
'
[ Subroutines ]
' Turn stepper clockwise one full step (7.5 degrees)
Step_Fwd:
stpIdx = stpIdx + 1 // 4 ' point to next step
GOTO Do_Step
' Turn stepper counter-clockwise one full step (7.5 degrees)
Step_Fwd1:
stpIdx = stpIdx + 1 // 4 ' point to previous step
GOTO Do_Step
' Read new step data and output to pins
Do_Step:
READ (Steps + stpIdx), Phase ' output new phase data
PAUSE stpDelay ' pause between steps
RETURN
Program 2
' RelativeHumidityReading.bs2
' Displays relative humidity in the Debug Terminal or the Parallax Serial LCD.
LCD PIN 0 ' Serial output to LCD
time VAR Word
humidity VAR Word
LcdBaud CON 84 ' Baud rate of LCD
RHconstant CON 12169 ' Relative Humidity Constant * 10
LcdCls CON $0C ' Clear LCD (use PAUSE 5 after)
LcdCR CON $0D ' Move pos 0 of next line
LcdBLon CON $11 ' Backlight on
LcdBLoff CON $12 ' Backlight off
LcdOff CON $15 ' LCD off
LcdOn1 CON $16 ' LCD on; cursor off, blink off
LcdLine1 CON $80 ' Move to line 0, position 0
LcdLine2 CON $9A ' Move to line 1, position 5
HIGH Lcd ' Setup serial output pin
PAUSE 100
SEROUT Lcd, LcdBaud, [LcdOn1] ' Initialize LCD
PAUSE 250
SEROUT Lcd, LcdBaud, [LcdBLon] ' Turn Backlight on
PAUSE 5
SEROUT Lcd, LcdBaud, [LcdCls] ' Clear LCD
PAUSE 5
DO
HIGH 7
PAUSE 1
RCTIME 7, 1, time
time = time * 10
humidity = (time - RHconstant) / 24
' Debug Display:
DEBUG HOME, "Relative Humidity = ", DEC humidity, "%"
' LCD Display:
SEROUT Lcd, LcdBaud, [LcdLine1, "RelativeHumidity",
LcdLine2, DEC humidity, "%" ]
PAUSE 100
IF humidity < 40 THEN
HIGH 13
PAUSE 2000
IF humidity > 40 THEN
LOW 13
PAUSE 1000
ENDIF
ENDIF
LOOP
Thanks so much
Program 1:
' {$STAMP BS2e}
'
' P4 -> ULN2003.1, ULN2003.16 -> Phase 1 (Black)
' P5 -> ULN2003.2, ULN2003.15 -> Phase 2 (Orange)
' P6 -> ULN2003.3, ULN2003.14 -> Phase 3 (Brown)
' P7 -> ULN2003.4, ULN2003.13 -> Phase 4 (Yellow)
'
[ I/O Definitions ]
Phase VAR OUTB ' phase control outputs
'
[ Constants ]
'
[ Variables ]
idx VAR Byte ' loop counter
stpIdx VAR Nib ' step pointer
stpDelay VAR Byte ' delay for speed control
'
[ EEPROM Data ]
Steps DATA %0011, %0110, %1100, %1001
'
[ Initialization ]
Setup:
DIRB = %1111 ' make P4..P7 outputs
stpDelay = 10 ' set step delay
'
[ Program Code ]
Main:
FOR idx = 1 TO 1//4 ' one revolution
GOSUB Step_Fwd ' rotate clockwise
NEXT
PAUSE 1000 ' wait 1/2 second
FOR idx = 1 TO 1//4 ' one revolution
GOSUB Step_Fwd1 ' rotate counter-clockwise
NEXT
PAUSE 1000 ' wait 1/2 second
GOTO Main
END
'
[ Subroutines ]
' Turn stepper clockwise one full step (7.5 degrees)
Step_Fwd:
stpIdx = stpIdx + 1 // 4 ' point to next step
GOTO Do_Step
' Turn stepper counter-clockwise one full step (7.5 degrees)
Step_Fwd1:
stpIdx = stpIdx + 1 // 4 ' point to previous step
GOTO Do_Step
' Read new step data and output to pins
Do_Step:
READ (Steps + stpIdx), Phase ' output new phase data
PAUSE stpDelay ' pause between steps
RETURN
Program 2
' RelativeHumidityReading.bs2
' Displays relative humidity in the Debug Terminal or the Parallax Serial LCD.
LCD PIN 0 ' Serial output to LCD
time VAR Word
humidity VAR Word
LcdBaud CON 84 ' Baud rate of LCD
RHconstant CON 12169 ' Relative Humidity Constant * 10
LcdCls CON $0C ' Clear LCD (use PAUSE 5 after)
LcdCR CON $0D ' Move pos 0 of next line
LcdBLon CON $11 ' Backlight on
LcdBLoff CON $12 ' Backlight off
LcdOff CON $15 ' LCD off
LcdOn1 CON $16 ' LCD on; cursor off, blink off
LcdLine1 CON $80 ' Move to line 0, position 0
LcdLine2 CON $9A ' Move to line 1, position 5
HIGH Lcd ' Setup serial output pin
PAUSE 100
SEROUT Lcd, LcdBaud, [LcdOn1] ' Initialize LCD
PAUSE 250
SEROUT Lcd, LcdBaud, [LcdBLon] ' Turn Backlight on
PAUSE 5
SEROUT Lcd, LcdBaud, [LcdCls] ' Clear LCD
PAUSE 5
DO
HIGH 7
PAUSE 1
RCTIME 7, 1, time
time = time * 10
humidity = (time - RHconstant) / 24
' Debug Display:
DEBUG HOME, "Relative Humidity = ", DEC humidity, "%"
' LCD Display:
SEROUT Lcd, LcdBaud, [LcdLine1, "RelativeHumidity",
LcdLine2, DEC humidity, "%" ]
PAUSE 100
IF humidity < 40 THEN
HIGH 13
PAUSE 2000
IF humidity > 40 THEN
LOW 13
PAUSE 1000
ENDIF
ENDIF
LOOP
Thanks so much
Comments
Maybe you're not clear on how to run these from different banks?
At long last (!), they put a link to that great N&V article along with the other resources on the BS2e page --
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol3/col/nv87.pdf
Thanks guys,
Im trying to run a stepper, read a humid sensor and control a water pump from the reading of humid sensor. What codes I should use when I combining them?
Thanks
http://www.savagecircuits.com/forums/showthread.php?145-Episode-5-Merging-Programs-Part-1-of-2
http://www.savagecircuits.com/forums/showthread.php?146-Episode-6-Merging-Programs-Part-2-of-2
Thanks so much, I don't know why the program below only run the Main- End , but not the DO LOOP ? Anybody has any idea?
' {$STAMP BS2e}
' {$PBASIC 2.5}
'
' P4 -> ULN2003.1, ULN2003.16 -> Phase 1 (Black)
' P5 -> ULN2003.2, ULN2003.15 -> Phase 2 (Orange)
' P6 -> ULN2003.3, ULN2003.14 -> Phase 3 (Brown)
' P7 -> ULN2003.4, ULN2003.13 -> Phase 4 (Yellow)
'
[ I/O Definitions ]
Phase VAR OUTB ' phase control outputs
LCD PIN 0 ' Serial output to LCD
'
[ Constants ]
LcdBaud CON 84 ' Baud rate of LCD
RHconstant CON 12169 ' Relative Humidity Constant * 10
LcdCls CON $0C ' Clear LCD (use PAUSE 5 after)
LcdCR CON $0D ' Move pos 0 of next line
LcdBLon CON $11 ' Backlight on
LcdBLoff CON $12 ' Backlight off
LcdOff CON $15 ' LCD off
LcdOn1 CON $16 ' LCD on; cursor off, blink off
LcdLine1 CON $80 ' Move to line 0, position 0
LcdLine2 CON $9A ' Move to line 1, position 5
'
[ Variables ]
idx VAR Byte ' loop counter
stpIdx VAR Nib ' step pointer
stpDelay VAR Byte ' delay for speed control
time VAR Word
humidity VAR Word
'
[ EEPROM Data ]
Steps DATA %0011, %0110, %1100, %1001
'
[ Initialization ]
Setup:
DIRB = %1111 ' make P4..P7 outputs
stpDelay = 10 ' set step delay
HIGH Lcd ' Setup serial output pin
PAUSE 100
SEROUT Lcd, LcdBaud, [LcdOn1] ' Initialize LCD
PAUSE 250
SEROUT Lcd, LcdBaud, [LcdBLon] ' Turn Backlight on
PAUSE 5
SEROUT Lcd, LcdBaud, [LcdCls] ' Clear LCD
PAUSE 5
'
[ Program Code ]
Main:
FOR idx = 1 TO 1//4 ' one revolution
GOSUB Step_Fwd ' rotate clockwise
NEXT
PAUSE 1000 ' wait 1/2 second
FOR idx = 1 TO 1//4 ' one revolution
GOSUB Step_Fwd1 ' rotate counter-clockwise
NEXT
PAUSE 1000 ' wait 1/2 second
GOTO Main
END
DO
HIGH 9
PAUSE 1
RCTIME 9, 1, time
time = time * 10
humidity = (time - RHconstant) / 24
' Debug Display:
DEBUG HOME, "Relative Humidity = ", DEC humidity, "%"
' LCD Display:
SEROUT Lcd, LcdBaud, [LcdLine1, "RelativeHumidity",
LcdLine2, DEC humidity, "%" ]
PAUSE 100
IF humidity < 40 THEN
HIGH 13
PAUSE 2000
IF humidity > 40 THEN
LOW 13
PAUSE 1000
ENDIF
ENDIF
LOOP
In this case, what should I do to combine these two programs? What LOOP I should try? Thanks