Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 3683|回復: 1

BS2PX如何讓SRF02動作

[複製鏈接]
發表於 2010-9-9 11:48:12 | 顯示全部樓層 |閱讀模式
我有找到SRF08的程式,要如何改為SRF02

'{$STAMP BS2px}
' {$PBASIC 2.5}
'***********************************************************
'**                                                       **
'**         I2C Routines for the Basic Stamp BS2p         **
'**          Controlling SP03 Speech Synthesizer          **
'**                                                       **
'**             Copyright 2002 - Devantech Ltd            **
'**     Commercial use of this software is prohibited     **
'**     Private and educational use only is permitted     **
'**                                                       **
'**        Written by Gerald Coe - August 2002            **
'**                                                       **
'***********************************************************

SCL   CON 10 ' I2C clock
SDA   CON 9 ' I2C data
NOP   CON 0 ' No Operation command
status VAR  Byte
Main:
' The following shows how easy it is to use the BS2p with the Speech Module,
' a single line command is all that is required to speak any of the 30
' pre-loaded phrases. The example below shows how to speak phrase number 21.

      GOSUB wait4shutup                ' wait for last phrase to finish speaking
      I2COUT SDA, $C4, 0, [21]       ' speak phrase number 21 and flush internal buffer

' You can also send your own Text to Speech messages to the module to be spoken.
' The first data byte is the command, in this case a NOP, since we just need to
' load the buffer. The 2nd value is Volume (0-7) which works backwards - 0 is
' loudest and 7 is quiet. The 3rd value is Pitch (0-7) which it is best to just
' try it and see. The 4th value is Speed (0-3) with 3 being fastest.
' You then place the text you wish spoken in inverted comma's and finally
' the 0 (NULL).

                 GOSUB wait4shutup                                                                       ' wait for last phrase to finish speaking
                 I2COUT SDA, $C4, 0, [NOP, 0,5,3, "Hello Gerry, How are u today", 0]

' The above loads the modules internal buffer. You then need to send a command to
' speak the phrase you just loaded.
  I2COUT SDA, $C4, 0, [$40] ' The speak command also flushes the buffer
' You can also load the buffer in smaller, multiple fragments if you wish to.
' Up to 85 bytes can be stored in the SP03's internal buffer, that's 81 characters
' plus the Volume, Pitch, Speed and terminating NULL.

            GOSUB wait4shutup                                                                            ' wait for last phrase to finish speaking
            I2COUT SDA, $C4, 0, [NOP, 0,5,3, "This is a test on how"]
            I2COUT SDA, $C4, 0, [NOP, " to send a message as"]
            I2COUT SDA, $C4, 0, [NOP, " a number of smaller pieces", 0]
            I2COUT SDA, $C4, 0, [$40] ' Speak the phrase.

' And thats it.
' The following completes the program so that you can run it.

forever:'GOTO forever

wait4shutup:
  I2CIN SDA, $C4, 0, [status]
  'DEBUG "Status:",DEC status,CR
  IF status>0 THEN wait4shutup
  RETURN
playrobot 該用戶已被刪除
發表於 2010-9-15 06:48:43 | 顯示全部樓層
對, 使用BS2PX只要用 一行指令 I2Cout 或是 I2Cin 就可以對任何I2C裝置收發資料。
要注意: $C4是指I2C裝置的位置 (每個裝置都要事先指定不同的位置) !
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2022-1-18 23:55 , Processed in 0.150956 second(s), 9 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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