+ Reply to Thread
Results 1 to 7 of 7

Thread: Swordfish External EEPROM Example

  1. #1
    gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    1,207
    Blog Entries
    3

    Default Swordfish External EEPROM Example

    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                                                   //
    
    Last edited by gramo; 9th May 2007 at 10:05 AM.


  2. #2
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,807
    Blog Entries
    13

    Default

    hi gramo,

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

    Regards
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

  3. #3
    gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    1,207
    Blog Entries
    3

    Default

    You think I should?

  4. #4
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,807
    Blog Entries
    13

    Default

    Hi,
    I think David would be well pleased.

    Why don't you offer to be a Beta tester for him?
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

  5. #5
    gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    1,207
    Blog Entries
    3

    Default

    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?

  6. #6
    gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    1,207
    Blog Entries
    3

    Default

    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

  7. #7
    gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    1,207
    Blog Entries
    3

    Default

    I added a little more content for the library, and made examples for single/multiple eeproms, more can be found here if anyone is interested: Swordfish Tutorial/Library - External EEPROM

    Couple of video sims in there too

+ Reply to Thread

Similar Threads

  1. magnetic reader 16f84 with external eeprom 24c256
    By jordan in forum Micro Controllers
    Replies: 2
    Latest: 13th February 2007, 11:46 PM
  2. Problem with 16f876 and external eeprom (i2c)
    By dibe84 in forum Micro Controllers
    Replies: 3
    Latest: 10th June 2006, 08:50 PM
  3. PIC16F628 and EXTERNAL eeprom
    By dibe84 in forum Micro Controllers
    Replies: 3
    Latest: 10th December 2005, 09:22 PM
  4. upgrading external eeprom
    By AndyWatson in forum Micro Controllers
    Replies: 1
    Latest: 9th November 2004, 04:53 AM
  5. Need help with external eeprom
    By low_byte in forum Micro Controllers
    Replies: 0
    Latest: 14th December 2003, 05:33 PM

Tags for this Thread