問題:
有人可以告訴我兩塊Easy藍牙模組的通訊程式
還有怎麼跟手機溝通嗎?
謝謝作者: playrobot 時間: 2010-12-20 11:06 回復 1#cthunter9434
範例:
' {$STAMP BS2}
' {$PBASIC 2.5}
'
'File: EasySEND.bs2
'
'Purpose: Load on the transmitting unit in the AppNote Easy Bluetooth to Easy Bluetooth Communcation.
' The example connects to the remote Bluetooth module via serial connection. An address is given to the
' remote module that the transmitting unit uses to establish connection. 5 seconds after the connection
' is attempted then a counter variable is sent and incremented by 1 in a repeat loop and then will DEBUG
' the counter value.
'
'Author: Parallax Technical Support
' ' '' ' '' ' ' Declarations ' ' '' ' '' ' '' ' ''
RX PIN 2
TX PIN 0
counter VAR Byte
'Place the values for each part of the address in the constants below; whereas the first part of the address will be placed in
'addy1 and the second in addy2; for example the address A1:B2:C3:D4:E5:F6 would be edited to look like the following:
' addy1 CON $A1 <--- A1 from A1:B2:C3:D4:E5:F6 goes here
' addy2 CON $B2 <--- B2 from A1:B2:C3:D4:E5:F6 goes here
' addy3 CON $C3 <--- C3 from A1:B2:C3:D4:E5:F6 goes here
' addy4 CON $D4 <--- D4 from A1:B2:C3:D4:E5:F6 goes here
' addy5 CON $E5 <--- E5 from A1:B2:C3:D4:E5:F6 goes here
' addy6 CON $F6 <--- F6 from A1:B2:C3:D4:E5:F6 goes here
' Place the address for the receiving Easy Bluetooth modules below
'( the address for the Easy Bluetooth module used in the example is 00:17:A0:01:56:65 )
addy1 CON $00
addy2 CON $17
addy3 CON $A0
addy4 CON $01
addy5 CON $56
addy6 CON $65
#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
Baud CON 84
#CASE BS2SX, BS2P
Baud CON 240
#CASE BS2PX
Baud CON 396
#ENDSELECT
' ' '' ' '' ' ' Program ' ' '' ' '' ' '' ' ''
Program_Start:
DEBUG CLS
PAUSE 3000
DEBUG CR,"Establishing SPP connection..."
SEROUT TX, Baud, [$02,$52,$0A,$08,$00,$64,$01,addy6,addy5,addy4,addy3,addy2,addy1,$01,$03]
PAUSE 5000
DEBUG CR,"Entering Transparent mode...",CR
'Entering Transparent mode
SEROUT TX, Baud, [$02,$52,$11,$01,$00,$64,$01,$03]
PAUSE 3000
'Transmitting counter variable to remote Bluetooth device and to the DEBUG terminal
DO
SEROUT TX, Baud, [counter]
counter = counter + 1
PAUSE 500
DEBUG ? counter
LOOP