Shop OBEX P1 Docs P2 Docs Learn Events
Hitachi Trix Axis Source Codes to Integrate LCD Display — Parallax Forums

Hitachi Trix Axis Source Codes to Integrate LCD Display

Pablo  MartosPablo Martos Posts: 14
edited 2009-05-06 20:59 in BASIC Stamp
I have a parallax 2x16 LCD display, BS2 and an Hitachi Tri-Axis accelemoter. I am using this sourc code and i am wondering if anybody knows a source code to dislpay this output on the LCD display??· Does anybody have any other source·codes available to play around whith??·




[noparse][[/noparse] I/O Definitions ]

Dio PIN 15 ' data to/from module
Clk PIN 14 ' clock output
CS PIN 13 ' active-low chip select
'
[noparse][[/noparse] 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 **
'
[noparse][[/noparse] 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

Reset:
HIGH CS ' deselect module
DEBUG CLS, ' paint display
"=========================", CR,
"H48C 3-Axis Accelerometer", CR,
"=========================", CR,
CR,
" Count Volts G ", CR,
"


", CR,
"VRef ", CR,
" X ", CR,
" Y ", CR,
" Z "
Main:
FOR axis = XAxis TO ZAxis ' loop through each axis
GOSUB Get_H48C ' read vRef & axis counts
dValue = rvCount ' display vRef count
DEBUG CRSRXY, 6, 6
GOSUB RJ_Print
dValue = axCount ' display axis count
DEBUG CRSRXY, 6, (7 + axis)
GOSUB RJ_Print
mVolts = rvCount ** Cnt2Mv ' convert vref to mv
DEBUG CRSRXY, 13, 6, ' display
DEC (mVolts / 1000), ".",
DEC3 mVolts
mVolts = axCount ** Cnt2Mv ' convert axis to mv

DEBUG CRSRXY, 13, (7 + 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, 20, (7 + axis), ' display g-force
" " + (gForce.BIT15 * 13),
DEC1 (ABS(gForce) / 100), ".",
DEC2 ABS(gForce)
NEXT
PAUSE 200

GOTO Main

' 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, [noparse][[/noparse]%11\2, VRef\3] ' select vref register
SHIFTIN Dio, Clk, MSBPOST, [noparse][[/noparse]rvCount\13] ' read ref voltage counts
HIGH CS
PAUSE 1
LOW CS
SHIFTOUT Dio, Clk, MSBFIRST, [noparse][[/noparse]%11\2, axis\3] ' select axis
SHIFTIN Dio, Clk, MSBPOST, [noparse][[/noparse]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, >=[noparse][[/noparse]10000, 1000, 100, 10, 0], dPad
DEBUG REP " "\dPad, DEC dValue

RETURN

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-05-06 20:59
    If you go to the product pages for the items you are interested in there is usually source code and examples for that product.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.