Storing a variable in EEPROM


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default Storing a variable in EEPROM

    I'm trying to store a numeric variable into a PIC18F2550 EEPROM.

    I would like to store the variable and then call it later on.

    This is what i use to store the variable
    Code:
    DelayIn VAR WORD
    Delayin = 120           ' This is in Seconds
    
    Write 5, Delayin.Byte0
    Write 6, Delayin.Byte1
    And to Read
    Code:
    Procedure:
        Read 5, DelayOut.byte0
        Read 6, DelayOut.Byte1
        Pause DelayOut * 1000 ' Multiply DelayIn by 1000 to give seconds
        For Loop = 1 to 5
            Red = 1
            Pause 100
            Red = 0
            Pause 100
        Next Loop
    Return
    If the variable was set at 120, i would expect the pause around 120seconds (2mins) before the LED flashed, but its only around 53 seconds. Therefore i am guessing i am not storing the variable correctly.

    I've checked the manual and this is the example it gives.

    Is there a better way of completing this type of task?

    Thanks

  2. #2
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Why not store your delay time as a single byte in eeprom? As long as you don't plan on exceeding 255 that should work fine.

    DelayIn VAR byte
    Delayin = 120 ' This is in Seconds

    Write 5, Delayin

    Procedure:
    Read 5, DelayOut
    Pause DelayOut * 1000 ' Multiply DelayIn by 1000 to give seconds
    For Loop = 1 to 5
    Red = 1
    Pause 100
    Red = 0
    Pause 100
    Next Loop
    Return

  3. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Tried that, it is still only pausing for around 54-55seconds and not 120 as expected.

    I've tried with both the DelayIn and DelayOut VAR BYTE and WORD.

    Still no luck.

    Any other suggestion?

    Regards,

    Steve

  4. #4
    Join Date
    Oct 2005
    Posts
    28


    Did you find this post helpful? Yes | No

    Default

    PAUSE is limited to 65535 milliseconds (65.534) seconds

  5. #5
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Default

    Do you have an LCD or RS232 connection? If you have either one of these I would suggest sending out the value you are retrieving from the EEprom using the DIG command to display it as it's individual digits.

    Example:
    Code:
    Read eeadr,data
    For x = 2 To 0 Step -1
    Hserout[data DIG x]
    Next x
    This will give you a way to confirm the value you are getting out of the EEPROM, and help you troubleshoot the problem by elimination.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    PAUSE works with up to a 16-bit period. If you use an expression that attempts to load anything greater than 65535 into the registers used for the delay period, they will overflow.

    65535 + 54465 = 120,000. You're probably getting a delay of 1mS * 54465 due to the overflow. That would explain the ~54 S delay period.

    Put together a loop like the one you're using for the LED. You could get several hours (or more) if needed.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Default code correction

    My previous example for viewing your eeprom data for verification was a bit abbreviated, and wouldn't work as stated. So here it is in a more usable form.
    Code:
    DEFINE HSER_TXSTA 20h   ' enable RS232 transmission
    DEFINE HSER_BAUD 19200  ' set to required baud rate on your system
    
    eeadr con 100       ' set to eeprom address for data of interest
    eedata var byte     ' eeprom data storage
    
    getdata
        Read eeadr,eedata               ' retrieve data byte from eeprom
        For x = 2 To 0 Step -1          ' extract 3 digits for display
        eedata = (eedata DIG x) + $30   ' convert to "decimalized" ascii number
        Hserout[eedata]                 ' send ascii out RS232
        Next x                          ' do it for all 3 digits of byte
    With this code added to your program, you can send out, and verify the value of any byte stored in your internal eeprom as a decimalized 3 digit number (readable on any RS232 terminal program).

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. 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
  3. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 03:17
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. 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

Members who have read this thread : 1

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