![]() |
|
Registrazione | Blogs | FAQ | Lista utenti | Gruppi | Calendario | Cerca | Messaggi odierni | Segna i forum come letti |
BasicX I BasicX sono microcontrollori programmabili in Basic. Il linguaggio e' pressoche' identico al Visual Basic, risultano quindi molto semplici da utilizzare e molto potenti. |
![]() |
|
Strumenti della discussione | Modalità di visualizzazione |
#1
|
||||
|
||||
![]()
Per gentile contributo del Prof. Massimo Negrotti.
Questo programma e' un esempio di utilizzo del modulo vocale SP03 della Devantech, con il microcontrollore BasicX BX24. E' utilizzato il protocollo I2C. '***************SP03 with I2C ************************************************** * '* by MaxNegro, 2006 * '* * '* massimo.negrotti(at)libero.it * '* * '************************************************* ******************************* Const SCL As Byte = 5 ' SP03 clock Const SDA As Byte = 6 ' I2C data Const CmdReg As Byte = 0 ' SP03 command register Const SP03 As Byte = 196 ' SP03 module address Dim I2cAck As Boolean ' Acknowledge flag Dim Phrase as String * 64 Dim I as byte Dim P as integer Dim Ve(1 to 64) As Byte Dim N as byte Dim II as byte Sub Main() '----------------------------------------------------------------------- 'text should be lowercase Phrase = "now we should start to salt lake city" For P = 1 to len(Phrase) 'phrase parsing N = N + 1 Ve(N)= asc(Mid(Phrase,P,1)) Next Ve(N) = 0 'NULL N = 0 Call I2cStart() 'Start of SP03 protocol Call I2cByteWrite(SP03, CmdReg, 0) 'SP03 address, Command Register, NOP Call I2cByteWrite(7, 5, 1) 'Volume - Pitch - Speed Call I2cOutBy() 'Send the Phrase Call I2cStop() Call I2cStart() Call I2cByteWrite(SP03, CmdReg, 64) Call I2cStop() 'end of SP03 protocol End Sub '-------------------------------------------------------------------------- '----------------------------------------------------------------------------------- ' I2C subroutines adapted to fit SP03 Buffer control '----------------------------------------------------------------------------------- ' writes I2cData to I2cReg at I2cAddr Sub I2cByteWrite(ByVal I2cAddr As Byte, ByVal I2cReg As Byte, ByVal I2cData As Byte) Call I2cOutByte(I2cAddr) ' send device address Call I2cOutByte(I2cReg) ' send register address Call I2cOutByte(I2cData) ' send the data End Sub Sub I2cOutByte(I2cData As Byte) Call ShiftOut(SDA, SCL, 8, I2cData) ' shift data out Call PutPin(SDA, bxInputTristate) ' turn SDA around Call PutPin(SCL, bxOutputHigh) ' and clock in the ack' bit Call PutPin(SCL, bxOutputLow) End Sub Sub I2cOutBy() For II = 1 to 64 I = Ve(II) Call PH(I) Next End Sub Sub PH(ByVal I as byte) ' puts characters into the buffer (63 Chars max). The last one must be '0' (NULL) Call ShiftOut(SDA, SCL, 8, I) ' shift data out Call PutPin(SDA, bxInputTristate) ' turn SDA around Call PutPin(SCL, bxOutputHigh) ' and clock in the ack' bit Call PutPin(SCL, bxOutputLow) End Sub Function I2cInByte() As Byte I2cInByte = ShiftIn(SDA, SCL, 8) If I2cAck=True Then Call PutPin(SDA, bxOutputLow) Else Call PutPin(SDA, bxOutputHigh) End If Call PutPin(SCL, bxOutputHigh) ' clock out the ack' bit Call PutPin(SCL, bxOutputLow) End Function Sub I2cStart() ' I2C start bit sequence Call PutPin(SDA, bxOutputHigh) Call PutPin(SCL, bxOutputHigh) Call PutPin(SDA, bxOutputLow) Call PutPin(SCL, bxOutputLow) End Sub Sub I2cStop() ' I2C stop bit sequence Call PutPin(SDA, bxOutputLow) Call PutPin(SCL, bxOutputHigh) Call PutPin(SDA, bxOutputHigh) End Sub Ultima modifica di Robotadmin; 04-22-2006 a 08:49 AM |
![]() |
Segnalibri |
Strumenti della discussione | |
Modalità di visualizzazione | |
|
|