Writing To Eeprom


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78

    Default Writing To Eeprom

    Hello Everyone, I have a quick question I wanted to address. I have searched for keywords in the search menu but did not get the results I wanted for my question. I also looked in the PBP manual but only got a partial answer to it.

    My question is about the READ and WRITE FUNCTIONs. I am using a PIC 18F series that has ON-BOARD EEPROM. Will the WRITE and READ command work for the 18F series microcontrollers?

    I have 1024 byte of EEPROM space available for the 18F device. And how do I konw what address the PIC micro is writing or reading to when I include these commands into my CODE?
    How do I konw where the Addressing starts in my PIC micro?


    thanks in advance for answering these questions.

    srig

  2. #2
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Forgot something else

    Oops I forgot .. I will be using 20Mhz quartz crystal oscillator. Not sure if I need to define the OSC on top of my CODE

    OSC 20 into my code

  3. #3
    thelightbrain's Avatar
    thelightbrain Guest


    Did you find this post helpful? Yes | No

    Default

    You need to download the datasheet for your processor from Microchip. Then you need to read the section on EEPROM data memory.
    This will explain how the 1K of memory is addressed.

    The write command should work fine but probably can only access the first 256 bytes.

    I use assembly subroutines to allow access to the full 1K memory. The datasheet shows exactly how to do this in assembly. I am using the PIC18F2525.

    -Jim

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hi srig,

    Actualy you don't need to know at wich address you write to internal EEPROM, PBP handle it.

    You must define OSC 20... always


    The following will write and read on internal EEPROM. And display on LCD.

    Code:
    
        ' Code to Read/Write to Internal EEPROM
        ' =====================================
        '
        ' File name : InternalEEPROM.bas
        ' Company : Mister E 
        ' Programmer : Steve Monfette
        ' Date : 22-12-2004
        ' Device : PIC18f452-I/P
        '
        '
        '
        '        Device programming mode and hardware definition 
        '        ===============================================
                 '
                 '
                 '
        @ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H
        ' Oscillator switch OFF
        ' Use HS oscillator (20MHZ here)
        '
        @ __CONFIG _CONFIG2L, _BOR_ON_2L & _PWRT_ON_2L & _BORV_45_2L
        ' Brown out reset ON @ 4.5Volts
        ' Power-up timer ON
        '
        @ __CONFIG _CONFIG2H, _WDT_ON_2H 
        ' Watch dog timer ON
        '
        @ __CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
        ' Stack over/underflow ON
        ' Low Voltage programming OFF
        ' Background debugger OFF
        '
        define OSC 20 'Use of 20 MHZ crystal 
        '        Lcd defines
        '        ===========
                 ' BO-B3 : Data port (pin 33-36) 
                 ' B4 : Rs Bit    (pin 37)          
                 ' B5 : E Bit     (pin 38)          
                 '
                 '
                 '
        define LCD_DREG PORTB     ' Set data pin of LCD to
        define LCD_DBIT 0         ' PORTB.0-PORTB.3
        define LCD_RSREG PORTB    ' Set RS bit of LCD to
        define LCD_RSBIT 4        ' PORTB.4
        define LCD_EREG PORTB     ' Set E bit of LCD to
        define LCD_EBIT 5         ' PORTB.5
        DEFINE LCD_LINES 4        ' 4 Lines LCD
        define LCD_COMMANDUS 2000 ' Command delay time in uSec
        DEFINE LCD_DATAUS 50      ' Data delay time in uSec
                 '
                 '
                 '
        '        Variable definition 
        '        ===================
                 '
                 '
                 '
        Addr            var     Byte
        ToStore         var     byte
        ToRead          var     byte
                 '
                 '
        ' Let's begin
        ' ===========
        '
        PAUSE 500  ' waiting for LCD Start up
        
        ' Writing to internal EEPROM
        ' ==========================
        '
        For addr=0 to 10     
            Tostore = 10+addr
            write Addr, tostore
        next
        '
        ' Reading from internal EEPROM
        ' ============================
        '
        For addr=0 to 10
            read addr,Toread
            lcdout $FE,1,"Address : ",dec addr,_
                   $FE,$C0,"Data : ",dec ToRead
            Pause 1000 ' wait 1 sec between each display
        next
        Here:goto here
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    But for full access 1024 bytes... i cannot test it for now... i don't have any of those PIC. Probably define Addr as WORD could work... let me know.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Talking

    It's also working for 1024 BYTES too following code is working
    Code:
    'Use of PIC18F2525
    @ __CONFIG    _CONFIG1H, _OSC_HS_1H & _FCMEN_ON_1H & _IESO_OFF_1H
      ' Use HS oscillator (20MHZ)
      ' Fail Safe Clock Monitor ON
      ' Internal/External switch over mode OFF
      '
    @ __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOREN_ON_2L & _BORV_45_2L
      ' Power-up timer ON
      ' Brown out detect ON
      ' brown out detect voltage 4.5 Volts
      '
    @ __CONFIG    _CONFIG2H, _WDT_ON_2H
      ' Watch dog timer ON
      '
    @ __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _PBADEN_OFF_3H
      ' MCLR pin enable
      ' PORTB<4:0> digital on RESET
      '
      
      
      
    @ __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L & _ENHCPU_OFF_4L
      ' stack overflow ON
      ' Low Voltage programming OFF
      ' Debug OFF
      ' extended CPU OFF
    ToStore   var   byte
    Addr      var   word
    
    start:
          for addr=0 to 1024
              tostore=addr.lowbyte
              write addr,tostore
          next
    here: goto here
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  2. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 03:17
  3. How to write/read strings EEPROM/LCD
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 11th February 2007, 06:26
  4. I2CWRITE writing Strings to EEPROM
    By NavMicroSystems in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th March 2005, 19:45
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 19:59

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts