Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Swordfish External EEPROM Example

Status
Not open for further replies.

gramo

New Member
If anyone's interested, I just finished converting my External EEPROM example for Swordfish (from Proton)

**broken link removed**
Pin 4 on 24LC256 = Vss (Earth)
Pin 8 on 24LC256 = Vdd (5V)
**broken link removed**

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                                                   //
 
Last edited:
hi gramo,

I expect you are also posting this work on the swordfish forum???

Regards
 
Hi,
I think David would be well pleased.

Why don't you offer to be a Beta tester for him?
 
Don't think I have what it takes just yet - plenty to learn...

When my futurlec & digikey orders gets in, I'll be adding around 10ish new examples to my site, all with Swordfish (DTMF, SD Cards, IR, Accelerometers, GLCD's, GSM, GPS etc..)

I'm finding that programming with SF is simply bliss, hows your times with SF going?
 
Made a small edit to the program;

Code:
// 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)

Now the user can simply define the Family and Address of the I2C EEPROM separately (as defined in its datasheet), and the program will do the rest
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top