Using eeprom for the first time- Help please


+ Reply to Thread
Results 1 to 4 of 4
  1. #1

    Exclamation Using eeprom for the first time- Help please

    Hi
    I am using PIC 16F690 and here is a fraction of my code. I have written this code so it stores my phone number and only enters once under this label "first:". Code does not seem to enter this label to being with - Is there somthing wrong with my code?
    first:
    read 230,a : read 231,b : read 232,c
    if a<>"6" and b<>"8" and c<>"4"then
    for c=0 to 255
    write c,0
    next c
    write 230,"6"
    write 231,"8"
    write 232,"4"
    pause 5000
    for c=0 to 12
    read c,ph[c]
    next c

    write 200,"+" : write 201,"4" : write 202,"4" : write 203,"7" : write 204,"8" : write 205,"3" : write 206,"2" : write 207,"2" : write 208,"2" : write 209,"5" : write 210,"1" : write 211,"7" : write 212,"4" ' this is all in one line
    for c=200 to 212
    read c,my[c-200]
    next c
    endif

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi financecatalyst,
    Wow, that's one heck of an If/Then loop, I never had any success trying to cram that much into one. If it were me I would build a subroutine for all that stuff and return after. Not really experienced with Write too much and of course I am not at my bench to try it out, but might add a short pause, say 10 or 15 ms after each write.
    Code:
    read c,my[c-200]
    So you have a 255 byte array ?
    Not sure I understand this otherwise . . .
    and it works with c-200 ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Your code:

    Code:
    write 200,"+" : write 201,"4" : write 202,"4" : write 203,"7" : write 204,"8" : write 205,"3" : write 206,"2" : write 207,"2" : write 208,"2" : write 209,"5" : write 210,"1" : write 211,"7" : write 212,"4" ' this is all in one line
    for c=200 to 212
    read c,my[c-200]
    next c
    You can write eeprom only once when you program your pic with this instruction at the begining of your program:

    Code:
    EEPROM 200,[43,52,52,55,56,51,50,50,50,53,49,55,52]
    
    'In your code when you need to load the number then
    
    for c=200 to 212
    read c,my[c-200]
    next c

    But you should avoid to use this peace of code (In red) otherwise you will erase your phone #

    Code:
    read 230,a : read 231,b : read 232,c
    if a<>"6" and b<>"8" and c<>"4"then
    for c=0 to 255
    write c,0
    next c
    ...........
    ...........

    You should use this instead, so you will save your number.

    Code:
    read 230,a : read 231,b : read 232,c
    if a<>"6" and b<>"8" and c<>"4"then
    for c=0 to 199
    write c,0
    next c
    ..........
    ..........

    In order to avoid holes in the eeprom you can change location to your phone # like this:

    Code:
    EEPROM 243,[43,52,52,55,56,51,50,50,50,53,49,55,52]
    
    'In your code when you need to load the number then
    
    for c=243 to 255
    read c,my[c-243]
    next c

    In this case you could erase up to location 242 and still save you phone #.

    Code:
    read 230,a : read 231,b : read 232,c
    if a<>"6" and b<>"8" and c<>"4"then
    for c=0 to 242
    write c,0
    next c
    ..........
    ..........
    Al.
    Last edited by aratti; - 11th October 2009 at 11:54.
    All progress began with an idea

  4. #4


    Did you find this post helpful? Yes | No

    Post

    Hi
    Thanks for the input.
    I wanted to fill the whole eeprom with "0" for the first time before loading any numbers to it, and choose 3 locations which are away from phone arrays and can mark if the code should enter there (first time) or not (anytime after the first time).

    I have managed to make it work. I am having problem with receiving string for my sms controller for which I have started another thread. Your input there will be appreciated.
    Thanks Again
    ___________________
    WHY things get boring when they work just fine?

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. Data EEPROM gets clobbered during programming
    By BrianT in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th July 2008, 02:46
  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

Posting Permissions

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