In SX Microcontrollers, SX/B Compiler and SX-Key Tool, wickedbeernut wrote: Am I close? ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- SlaveID CON $A0 Ack CON 0 Nak CON 1 '-------------------------------------------------------------------------- ' Subroutines Code ' ------------------------------------------------------------------------- ' Use: MEMOUT addrLo, addrHi, aVal ' -- writes 'aVal' to 24LC16 at location addrHi/addrLo MEMOUT: temp1 = __PARAM1 temp2 = __PARAM2 temp3 = __PARAM3 I2CSTART SDA temp4 = SlaveID ' create control byte (with no chip select) ' temp4.0 = 0 ' set RW bit for write I2CSEND SDA, temp4 ' send slave ID I2CSEND SDA, temp2 ' send word address I2CSEND SDA, temp1 ' send word address I2CSEND SDA, temp3 ' send data byte I2CSTOP SDA ' finish RETURN ' Use: MEMIN addrLo, addrHi, @aVal ' -- reads 'aVal' from 24LCXX with XXK x 8 bits at location addrHi/addrLo MEMIN: temp1 = __PARAM1 temp2 = __PARAM2 temp3 = __PARAM3 I2CSTART SDA temp4 = SlaveID ' create control byte (with no chip select) ' temp4.0 = 0 ' set RW bit for write I2CSEND SDA, temp4 ' send slave ID I2CSEND SDA, temp2 ' send address high byte I2CSEND SDA, temp1 ' send address low byte I2CSTART SDA temp4.0 = 1 ' set RW bit for read I2CSEND SDA, temp4 ' resend slave ID I2CRECV SDA, temp4, Nak ' get one byte I2CSTOP SDA __RAM(temp3) = temp4 ' move to target RAM RETURN ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=82905#m82908 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)