Need help with write function


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default Need help with write function

    Yes, I have RTFD and still don't quite understand how to do it. In the PBP manual, it says that you can do something like:

    Write 0, Brakes
    Write 1, Lights

    Then, you can read them by doing this:

    Read 0, Brakes
    Read 1, Lights

    But according to the 16F688 datasheet, it says that the memory register is different and has to be accesed through the EECON1, EECON2........and I am not sure how to set up the code to write.

    Can someone help me with the write function please?

    Thanks,

    Chris

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    DATA, READ and WRITE are the correct commands for the internal EEPROM in the 16F688 chip. Make sure your version of PICBasic supports this chip, and you have any patches installed. Check on MeLabs website.

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Just to add ... PBP takes care of all the EECON1 and EECON2 stuff so you do not have to - you just need DATA, READ, and WRITE.

    See example code on melabs website
    http://www.melabs.com/resources/samples/pbp/ee.bas

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  4. #4
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help. I am still a bit unclear, so I want to know if I can do something like this (I would do it myself with the PIC but I won't be able to until tomorrow):

    Beep var byte
    flash var byte


    Gosub EEPROM


    Start:

    if portb.4=1 then
    beep=beep+1
    gosub EEPROM

    if beep=1 then
    high portb.0
    endif

    if portb.3=1 then
    flash=flash+1
    gosub EEPROM

    if flash=2 then
    high portb.1
    endif

    goto start


    EEPROM:

    write 0, beep
    write 1, flash
    return

    I know this isn't a very complex code but the reason I need to write to the EEPROM is because I need to change functions on an alarm system after the PIC is already programmed. Some questions.... if for example I just say "flash var byte," does the PIC automatically recognize flash as a zero? Lets say the PIC has been running for a while and flash=7. Now, I power off the PIC and it holds the 7 in memory. If I goto power up the PIC and I have it go directly to the write command, will it simply just write over flash but still make it 7? Also, do I need the read command or can I just say "If beep=1 then......?"

    Thanks,

    Chris

  5. #5
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi Chris,
    Maybe one of the pros will add some more answers, but for now...

    if for example I just say "flash var byte," does the PIC automatically recognize flash as a zero?
    PBP does not initialize RAM variables to any value, and on power up the RAM variables will contain an unknown value. You can use the CLEAR command to clear all RAM variables to 0, or just set each variable to 0 manually: flash=0

    After any power up, you'll need to READ your saved settings from EEPROM to restore your user selections.

    Keep in mind the EEPROM has a limited number of write/erase cycles (check data sheet for details).

    Arch
    Last edited by Archilochus; - 2nd June 2006 at 23:21.

  6. #6
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    OK, so I understand when you have used the PIC for a while you just simply read the EEPROM and everything is OK. What I don't understand is the very first time you power up the PIC, how do you deal with the memory? I mean, if you go to read it, it's an unknown value.

Similar Threads

  1. WRITE: One more PBP 2.60 Surprise ...
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 26th August 2009, 09:10
  2. Replies: 5
    Last Post: - 29th May 2008, 18:03
  3. Need the code to write to a memory
    By Hamlet in forum General
    Replies: 0
    Last Post: - 20th August 2007, 00:22
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Storing Strings using the Write command
    By BobP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st November 2005, 11:31

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