PDA

View Full Version : Help wanted urgently with merging 2 basic stamp 2 programs..



proGodLik3
09-26-2008, 04:53 PM
Hi anyone has an idea of how to link 2 bs2 files together and display the values in the same debug screen
Or is there a way the 2 programs below can be merge into 1 program??

A: accelerometer program

' ================================================== =======================
'
' File....... H48C_3-Axis.BS2
' Purpose.... Hitachi H48C 3-Axis Accelerometer Demonstration
' Author..... Copyright (c) 2005-2006 Parallax, Inc.
' E-mail..... support@parallax.com
' Started....
' Updated.... 02 FEB 2006
'
' {$STAMP BS2p}
' {$PBASIC 2.5}
'
' ================================================== =======================


' -----[ Program Description ]---------------------------------------------
'
' Test program for the H48C 3-Axis Accelerometer module.
'
' Connections:
'
' +------------+
' | * |
' CLK | o o | Vdd (+5v)
' | +--+ |
' DIO [ o | | o | CS\
' | +--+ |
' Vss | o o | 0G (free-fall indication)
' | |
' +------------+
'
' How it Works:
'
' An onboard MCP3204 12-bit ADC is used to read the VRef, X-, Y-, and
' Z-axis outputs from the Hitachi H48C accelerometer. The reference
' voltage output from H48C is 1.65 volts (3.3 / 2).
'
' After reading the reference voltage and an output channel the g-force
' for the channel is calculated with this formula:
'
' axis - vref 3.3
' G = ----------- x ------
' 4095 0.3663
'
' For use in the program the forumla can be simplified to:
'
' G = (axis - vref) x 0.0022
'
' To allow the display of fractional g-force in the integer system of the
' BASIC Stamp we multiply 0.0022 by 100 -- this will allow us to display
' g-force in 0.01g units.


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Dio PIN 15 ' data to/from module
Clk PIN 14 ' clock output
CS PIN 13 ' active-low chip select


' -----[ Constants ]-------------------------------------------------------

XAxis CON 0 ' adc channels
YAxis CON 1
ZAxis CON 2
VRef CON 3

Cnt2Mv CON $CE4C ' counts to millivolts
' 0.80586 with **
GfCnv CON $3852 ' g-force conversion
' 0.22 with **

' -----[ Variables ]-------------------------------------------------------

axis VAR Nib ' axis selection
rvCount VAR Word ' ref voltage adc counts
axCount VAR Word ' axis voltage adc counts
mVolts VAR Word ' millivolts
gForce VAR Word ' axis g-force

dValue VAR Word ' display value
dPad VAR Nib ' display pad


' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization ]--------------------------------------------------

Reset:
HIGH CS ' deselect module
DEBUG CLS, ' paint display
" "

' -----[ Program Code ]----------------------------------------------------

Main:
FOR axis = XAxis TO ZAxis ' loop through each axis
GOSUB Get_H48C ' read vRef & axis counts

dValue = rvCount ' display vRef count
DEBUG CRSRXY, 0, 0
GOSUB RJ_Print

dValue = axCount ' display axis count
DEBUG CRSRXY, 0, (1 + axis)
GOSUB RJ_Print

mVolts = rvCount ** Cnt2Mv ' convert vref to mv
DEBUG CRSRXY, 7, 0, ' display
DEC (mVolts / 1000), ".",
DEC3 mVolts

mVolts = axCount ** Cnt2Mv ' convert axis to mv
DEBUG CRSRXY, 7, (1 + axis),
DEC (mVolts / 1000), ".",
DEC3 mVolts

' calculate g-force
' -- "gForce" is signed word

IF (axCount >= rvCount) THEN
gForce = (axCount - rvCount) ** GfCnv ' positive g-force
ELSE
gForce = -((rvCount - axCount) ** GfCnv) ' negative g-force
ENDIF
DEBUG CRSRXY, 14, (1 + axis), ' display g-force
" " + (gForce.BIT15 * 13),
DEC1 (ABS(gForce) / 100), ".",
DEC2 ABS(gForce)
NEXT
PAUSE 2000
GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Reads VRef and selected H48C axis through an MCP3204 ADC
' -- pass axis (0 - 2) in "axis"
' -- returns reference voltage counts in "rvCount"
' -- returns axis voltage counts in "axCounts"

Get_H48C:
LOW CS
SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, VRef\3] ' select vref register
SHIFTIN Dio, Clk, MSBPOST, [rvCount\13] ' read ref voltage counts
HIGH CS
PAUSE 1
LOW CS
SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, axis\3] ' select axis
SHIFTIN Dio, Clk, MSBPOST, [axCount\13] ' read axis voltage counts
HIGH CS
RETURN

' -------------------------------------------------------------------------

' Right-justify value in 5-digit field
' -- move cursor first, then call with value in "dValue"

RJ_Print:
LOOKDOWN dValue, >=[10000, 1000, 100, 10, 0], dPad
DEBUG REP " "\dPad, DEC dValue
RETURN

B: thermometer program

' {$STAMP BS2p}
' {$PBASIC 2.5}
' Program: DS1620.BS2 (interface DS1620 digital thermometer to BS2)
' This program interfaces the DS1620 Digital Thermometer to
' the BS2. Input and output routines can be combined to set
' the '1620 for thermometer or thermostat operation, read
' or write nonvolatile temperature setpoints and configuration
' data. In addition to using the BS2's new Shiftin and Shiftout
' instructions to communicate with the 1620, this program uses
' new math and display operators that work with signed integers.
' This makes it relatively easy to convert between degrees C and
' F and to display both positive and negative temperature
' readings. Note that after math operations on negative numbers
' it's necessary to "extend the sign bits." All this means is
' setting all of the bits to the left of actual value to 1s.
' Also note the use of the new */ (pronounced 'star-slash')
' operator. This works like multiplying by an integer (0-255)
' and a fraction (in units of 1/256). For example, to multiply
' 17 by Pi (approx 3.1416) would be written "17 */ $0324."
' The second value is written in hex to emphasize that it's being
' split into bytes: $03 is the integer and $24/$100 is the fraction.
' In the C-to-F conversion below, we multiply the C value by 1.8
' with "*/ $01CC" since $CC/$FF (204/256) = 0.8.
' ===================== Define Pins and Variables ================
DQ CON 2 ' Pin 2 <=> DQ.
CLOCK CON 1 ' Pin 1 => CLK.
RST CON 0 ' Pin 0 => RST (high = active).
DSdata VAR Word ' Word variable to hold 9-bit data.
Sign VAR DSdata.BIT8 ' Sign bit of raw temperature data.
T_sign VAR Bit ' Saved sign bit for converted temperature.
' ===================== Define DS1620 Constants ===================
' >>> Constants for configuring the DS1620
Rconfig CON $AC ' Protocol for 'Read Configuration.'
Wconfig CON $0C ' Protocol for 'Write Configuration.'
CPU CON %10 ' Config bit: serial thermometer mode.
NoCPU CON %00 ' Config bit: standalone thermostat mode.
OneShot CON %01 ' Config bit: one conversion per start request.
Cont CON %00 ' Config bit: continuous conversions after start.
' >>> Constants for serial thermometer applications.
StartC CON $EE ' Protocol for 'Start Conversion.'
StopC CON $22 ' Protocol for 'Stop Conversion.'
Rtemp CON $AA ' Protocol for 'Read Temperature.'
' >>> Constants for programming thermostat functions.
RhiT CON $A1 ' Protocol for 'Read High-Temperature Setting.'
WhiT CON $01 ' Protocol for 'Write High-Temperature Setting.'
RloT CON $A2 ' Protocol for 'Read Low-Temperature Setting.'
WloT CON $02 ' Protocol for 'Write Low-Temperature Setting.'

' ===================== Begin Program ============================
LOW RST ' Deactivate '1620 for now.
HIGH CLOCK ' Put clock in starting state.
PAUSE 100 ' Let things settle down a moment.
HIGH RST ' Activate the '1620 and set it for continuous..
SHIFTOUT DQ,CLOCK,LSBFIRST,[Wconfig,CPU+Cont] ' ..temp conversions.
LOW RST ' Done--deactivate.
PAUSE 50 ' Wait for the EEPROM to self-program.
HIGH RST ' Now activate it again and send the..
SHIFTOUT DQ,CLOCK,LSBFIRST,[StartC] ' Send start-conversion protocol.
LOW RST ' Done--deactivate.
' The loop below continuously reads the latest temperature from
' the DS1620.
again:
PAUSE 2000 ' Wait a second between readings.
HIGH RST ' Activate the '1620.
SHIFTOUT DQ,CLOCK,LSBFIRST,[Rtemp] ' Request to read temperature.
SHIFTIN DQ,CLOCK,LSBPRE,[DSdata\9] ' Get the temperature reading.
LOW RST
T_sign = Sign ' Save the sign bit of the reading.
DSdata = DSdata/2 ' Scale reading to whole degrees C.
IF T_sign = 0 THEN no_neg1
DSdata = DSdata | $FF00 ' Extend sign bits for negative temps.
no_neg1:
DEBUG SDEC DSdata,".",CR ' Show signed temperature in C.
DSdata = (DSdata */ $01CC) ' Multiply by 1.8.
IF T_sign = 0 THEN no_neg2 ' If negative, extend sign bits.
DSdata = DSdata | $FF00
no_neg2:
DSdata = DSdata + 32 ' Complete the conversion.
DEBUG SDEC DSdata,".",CR ' Show signed temperature in F.
GOTO again ' Repeat forever.

Post Edited (proGodLik3) : 9/26/2008 12:17:08 PM GMT

SRLM
09-26-2008, 09:11 PM
One debug screen per COM port. As for merging the programs, that just takes time. There is not short and simple solution: you'll have to go through the whole thing and make it fit.

proGodLik3
09-26-2008, 10:08 PM
LOLx.. nvm thanks it can be done i have done it already.. and i also can display the values in VB =)