If anyone's interested, I just finished converting my External EEPROM example for Swordfish (from Proton)
Pin 4 on 24LC256 = Vss (Earth)
Pin 8 on 24LC256 = Vdd (5V)
Note the PIC's power supply/oscillator are not shown
Code:Device = 18F452 Clock = 20 // import libraries... Include "I2C.bas" Include "usart.bas" Include "convert.bas" // local variables... Dim TempByte As Byte // User must define the EEPROM family and address bits... // See the EEPROM's datasheet for more information Const EEPROM_Family = %1010, EEPROM_Address = %001, EEPROM_Control = (EEPROM_Family << 4) Or (EEPROM_Address << 1) Sub EEPROM_Write(Data As Byte, Memory_Address As Word) I2C.Start // Write data to the external EEPROM I2C.WriteByte(EEPROM_Control) // I2C.WriteByte(Memory_Address.Byte1) // I2C.WriteByte(Memory_Address.Byte0) // I2C.WriteByte(Data) // I2C.Stop // DelayMS(10) // Small deley required between writes End Sub Function EEPROM_Read(Memory_Address As Word) As Byte I2C.Start // Read data from the external EEPROM I2C.WriteByte(EEPROM_Control) // I2C.WriteByte(Memory_Address.Byte1) // I2C.WriteByte(Memory_Address.Byte0) // I2C.Restart // I2C.WriteByte(EEPROM_Control + 1) // Result = I2C.ReadByte(I2C_NOT_ACKNOWLEDGE) // I2C.Stop // End Function // program start... TempByte = 0 I2C.Initialize USART.SetBaudrate(br19200) For TempByte = 1 To 10 // Make a loop EEPROM_Write((TempByte + 100), TempByte) // Write to the EEPROM Next For TempByte = 1 To 10 // Read from the EEPROM and send it to the virtual terminal USART.Write("Memory Address = ", DecToStr(TempByte, 2), ", ") USART.Write("Data = ", DecToStr(EEPROM_Read(TempByte), 3), 13, 10) Next While True // Infinate Loop Wend //


Reply With Quote