PIC18 (452) DATA or EEPROM Command


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614

    Unhappy PIC18 (452) DATA or EEPROM Command

    Hi everybody,

    A small surprise this afternoon with a 18F452 :

    Clearing ( With 0s ) locations in the EEPROM gives such results ...

    DATA (0), 0 (10) ... writes 10 Times 0 from location 0 to 09 ... quite normal !!!

    but

    DATA (1), 0 (10) ... writes 11 Times 0 from location 1 to location ...0B or 12 !!!


    EEPROM equivalent Command gives exactly the same result ...

    Not THE big bug ... , but take care when presetting EEPROM values ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    It's not actually a bug. The block write size to EEPROM is done in blocks of two bytes,
    so when you have an odd number of bytes, the most significant byte written will be 0.

    If you change DATA (1), 0 (10) to DATA (1), 1 (10) you'll see how the msb is 0, and you
    have only 10 1's actually being written.
    Regards,

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

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Unhappy

    Hi, Bruce

    Thanks for the reply ...

    If I undestood it , in your example there's Always 11 Writes: 10 "1"'s and 1 x "0" ... The original "FF" @ Loc. 12 is then overwritten by a "0"

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Hi Alain,

    With DATA (1), 0 (10). Skip location 0 then write 10 0's. The total is 11. 1 byte skipped, and
    10 bytes to be written.

    PBP produces asm that looks like this;

    ORG EEPROM_START + 00000h
    DW 0000000FFh ' locations 0 and 1. Note FF is the skipped location 0.
    DW 000000000h ' locations 2 and 3
    DW 000000000h ' location 4 and 5
    DW 000000000h ' locations 6 and 7
    DW 000000000h ' locations 8 and 9
    DW 000000000h ' locations 10 and 11

    Which looks like this in EEPROM;

    0000- ff 00 00 00 00 00 00 00
    0008- 00 00 00 00

    DW defines a data word, so each word is made up of two bytes. If you write an odd number
    of bytes, the most significant byte will be cleared because DW forms everything as a word
    value. On the 18F series, program memory (where EEPROM is) is all word aligned.

    It's a bit easier to see if you do something like this;

    DATA 1,2,3,4,5,6,7,8,9

    Which produces;

    ORG EEPROM_START + 00000h
    DW 000000201h
    DW 000000403h
    DW 000000605h
    DW 000000807h
    DW 000000009h

    And in EEPROM it looks like this;

    0000- 01 02 03 04 05 06 07 08
    0008- 09 00 <-- note the msb here is 0

    You just have to remember that there will always be an even number of bytes written to
    EEPROM. The 18F reference manual shows how this works.
    Regards,

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

Similar Threads

  1. Data EEPROM gets clobbered during programming
    By BrianT in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th July 2008, 02:46
  2. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21
  3. LCD + bar graph
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th October 2005, 14:50
  4. Internal EEPROM Read/write Addressing Errors with 18F PIC's
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 18
    Last Post: - 12th July 2005, 19:42
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 28th November 2004, 23:56

Members who have read this thread : 2

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