Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 8453|回復: 4
打印 上一主題 下一主題

程式語法問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2011-4-29 12:00:41 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 mm521535 於 2011-4-29 12:26 編輯

不好意思 第一次發問 我們想知道以下的意思是什麼(可能的話盡量詳細一點,如: 單位 怎麼傳送 ...等)。
----------------------
Cnt2Mv CON $CE4C
GfCnv CON $3852
----------------------
DEBUG REP " "\dPad, DEC dValue----------------------
DEC跟DEC3...
----------------------
DEBUG CRSRXY, 6, 6
----------------------
Get_H48C:
  LOW CS
  SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, VRef\3] ' select vref register ,Dio=P15 Clk=P14
  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
----------------------
2#
發表於 2011-4-30 16:38:17 | 只看該作者
回復 1# mm521535


    藉著數據線讀取 Hitachi H48C 三軸加速度計 的值 .
3#
 樓主| 發表於 2011-5-2 18:45:07 | 只看該作者
回復 2# vegewell


   恩恩,我們是想知道以上的語法
4#
發表於 2011-5-3 13:49:50 | 只看該作者
看起來很像是pseudo code
有兩段的 serial bus 操作

細節...就查一下字典也可以猜出一些吧
shift, CS是做什麼用的你不知道嗎? 去看一下電路和計算機結構吧
5#
發表於 2011-5-3 21:38:42 | 只看該作者
本帖最後由 vegewell 於 2011-5-3 21:41 編輯



這是BStamp code .
我們可使用BASIC Stamp 的SHIFTOUT 和SHIFTIN 指令來
讀出H48C 的加速度值(從串列傳輸接收訊號)。
請參考與研究:
程式碼
'================================================================
' 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 BS2}
' {$PBASIC 2.5}
'================================================================

' -----[ 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
Copyright© Parallax Inc. ‧ Hitachi H48C 3-Axis Accelerometer Module (#28026) ‧
7/27/2007 Rev 1.2 Page 5 of 6
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
' -----[ Initialization ]--------------------------------------------------
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 "
' -----[ 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, 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),
Copyright© Parallax Inc. ‧ Hitachi H48C 3-Axis Accelerometer Module (#28026) ‧
7/27/2007 Rev 1.2 Page 6 of 6
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
' -----[ 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
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-11-21 19:18 , Processed in 0.133076 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表