EEPROM Memory


Closed Thread
Results 1 to 4 of 4

Thread: EEPROM Memory

  1. #1
    Join Date
    Jun 2008
    Posts
    24

    Default EEPROM Memory

    I am toying around with a Lab X1 board, trying to make a program that turns on one of two LEDs, (toggled by a switch), then remembers which LED is on when I reset the power. Right now, it always turns on the opposite of the light the was on before I turned it off. Though this does satisfy my goal of using stored memory after power is turned off, I would like it to turn on the correct light, instead of the opposite on, and for the life of me, I can't figure out why. I am sure it is something simple that I am just missing.

    If anyone could take a quick look at my code, it would be phenomenal.

    Thanks,
    Matt

    EEPROM 1,[%00000001] 'set initial EEPROM Value

    TRISB=%11110000 'set imputs and outputs
    PORTB=%11111110
    OPTION_REG.7=0
    setting Var BYTE 'declare setting as a variable
    READ 1,setting 'read EEPROM value to setting
    PAUSE 100

    LOOP:
    IF setting=%00000001 THEN 'determines which LED to turn on
    HIGH PORTD.0
    LOW PORTD.1
    ENDIF
    IF setting=%00000010 THEN
    LOW PORTD.0
    HIGH PORTD.1
    ENDIF
    IF PORTB.4=1 THEN 'goto subroutine on button press
    GOSUB SWITCH
    ENDIF
    GOTO LOOP

    SWITCH:
    IF setting=1 THEN 'if setting is 1, write 2 to EEPROM
    WRITE 1,%00000010
    ENDIF
    IF setting=2 THEN 'if setting is 2, write 1 to EEPROM
    WRITE 1,%00000001
    ENDIF
    READ 1,setting 'read EEPROM value to setting
    WHILE PORTB.4=1 'wait for button release
    PAUSEus 10
    WEND
    RETURN 'go back to main loop

    END

  2. #2
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86


    Did you find this post helpful? Yes | No

    Default

    I've been looking over your code for about 10 minutes and nothing is jumping out at me. My only thought is something flaky is going on during the power down stage where PORTB.4 goes high momentarily. You could try adding a debounce or a small pause at the beginning of the SWITCH routine and see if there is any change.

    David

  3. #3
    Join Date
    Jun 2008
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Just tried that, didn't seem to make much difference...It toggled a bit smoother though.

    My guess is somehow the program is causing the EEPROM value to switch at startup or shutdown. No clue how though.

    Thank you,
    Matt

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


    Did you find this post helpful? Yes | No

    Default

    Have you tried switching this;
    Code:
    SWITCH:
    IF setting=1 THEN 'if setting is 1, write 2 to EEPROM
    WRITE 1,%00000010
    ENDIF
    IF setting=2 THEN 'if setting is 2, write 1 to EEPROM
    WRITE 1,%00000001
    ENDIF
    To this;
    Code:
    SWITCH:
    IF setting=1 THEN 'if setting is 1, write 1 to EEPROM
    WRITE 1,%00000001
    ENDIF
    IF setting=2 THEN 'if setting is 2, write 2 to EEPROM
    WRITE 1,%00000010
    ENDIF
    Regards,

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

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. Replies: 4
    Last Post: - 2nd March 2007, 06:12
  4. 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
  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