'*********************************************************** '** ** '** I2C Routines for the Dios to demonstrate ** '** the use of the SP03 text to speech synthesizer ** '** ** '** It speaks preloaded phrase number 2 followed ** '** by the SP03 software Revision number ** '** ** '** Written by Gerald Coe - August 2003 ** '** ** '*********************************************************** gconst SP03 $C4 ' SP03 I2C bus address gconst Cmd_reg 0 ' Command register gconst Ver_reg 1 ' Software Version address gconst LDBUF 0 ' Load SP03 buffer command gconst SPKBUF $40 ' Speak buffer command gconst VOLUME 0 ' See SP03 documentation for these valuse gconst PITCH 5 gconst SPEED 2 global Text(60) as string ' Text buffer holds phrase to be spoken func main() const sda 0 const scl 1 dim Ver loop: I2cout(sda,scl,SP03,Cmd_reg, 2) ' speak phrase number 2 wait4shutup(sda, scl) Ver = I2cin(sda,scl,SP03, Ver_reg) strout @Text, "You're using revision ", dec Ver, " software on the SP03", 0 speakstring(sda, scl, @Text) goto loop endfunc ' speakstring sends the Volume, Pitch, Speed and Text to the ' SP03 in a single I2C transaction, using the low level I2C functions ' built into the Dios \lib\DiosI2c.lib. func speakstring(sda, scl, addr) dim dat I2c_start(sda,scl) I2c_sendbyte(sda,scl,SP03) ' Sp03 I2C address I2c_getack(sda,scl) I2c_sendbyte(sda,scl,Cmd_reg) I2c_getack(sda,scl) I2c_sendbyte(sda,scl,LDBUF) I2c_getack(sda,scl) I2c_sendbyte(sda,scl,VOLUME) I2c_getack(sda,scl) I2c_sendbyte(sda,scl,PITCH) I2c_getack(sda,scl) I2c_sendbyte(sda,scl,SPEED) I2c_getack(sda,scl) loop: getstringbyte addr,dat,done I2c_sendbyte(sda,scl, dat) ' Send supplied string to SP03 internal buffer I2c_getack(sda,scl) goto loop done: I2c_stop(sda,scl) I2cout(sda,scl,SP03,Cmd_reg, SPKBUF) ' Speak the SP03 internal buffer wait4shutup() ' wait until talking finished endfunc func wait4shutup(sda, scl) dim stat Wait: stat = I2cin(sda,scl,SP03, Cmd_reg) ' Read status register if stat>0 then goto Wait ' and wait until its zero endif endfunc include \lib\DiosI2c.lib