WRITECODE or not????


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2006
    Location
    China
    Posts
    266

    Default WRITECODE or not????

    Hi,

    This might seem as a strange thing to do but I want to write to the program memory i.e as a Bootloader would do. I have located my code so it will not be overwritten but I get some weird results. So i decided to try this simple code that is put away far from my target write adresses. All variables are defined as Words.

    for i =0 to 31 step 2
    flash=i
    temp=$ABCD
    WRITECODE flash,temp
    next i
    HSEROUT ["DONE",10,13]
    pause 2000
    stop

    Every time I run it I get a small printout "DONE" . Then I readback the code into MPLAB using Programmer->READ and look in the Program Memory window. The thing is that I can write to ANY address and get the correct value stored EXCEPT if I write to adr $0000, $0002 and $0004. These adresses only accepts $0000 as value if they will store it right. If I use $ABCD as value it looks like this in the Program memory readback:

    0000: 2A04
    0002: AB40
    0004: A044
    0006: ABCD
    and the rest are ABCD as expected.

    Other values give similar results and sometimes adr $0004 reads back OK but never 0000 and 0002 if I don't write 0000 to them.

    Anyone? Any guess?
    The PIC is a 18F4620 and no code protection and Tablewrite fuses are OFF. Neither manual (PBP or 18F4620) mentions anything about this from what I can see.

    This is killing my project for the moment, I would be very happy if someone could come up with any ideas and answers.

    I also printed the values stright from the PIC using READCODE and they show the same as MPLAB, so it is not a MPLAB problem!

    best regards

    /me
    Last edited by Jumper; - 17th August 2006 at 10:38.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Jumper,

    Did you erase "block 0" first?

    Also the 4620 needs to write 64 bytes at a time, instead of 32.
    <br>
    DT

  3. #3
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Nah, I missed that part

    Hi,

    I forgot to erase the code first.

    It is allowed to write either 64 BYTES or 32 WORDS, I went for writig words


    /me

  4. #4
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default One more thing...

    When using ERASECODE don't forget this (a part from an e-mail from Melab support)
    The erase blocks of 64 bytes do, in fact, have specific start/end
    addresses that are arranged starting at address 0. The datasheet
    refers to these blocks as "rows".

    Each block (0-63, 64-127, etc.) will be erased in its entirety when
    you use ERASECODE at any address within the block.

    If you want to preserve part of the data in a block, use READCODE to
    save the information before you erase, then WRITECODE to restore the
    block with modified data afterward.

    The best way is to learn from other's misstakes :-)

    /me

Similar Threads

  1. Bootloader For 18F4520
    By isaac in forum mel PIC BASIC Pro
    Replies: 36
    Last Post: - 24th March 2010, 17:56
  2. WRITECODE, ERASECODE, and interrupts
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th March 2010, 02:46
  3. WRITECODE stores wrong 14-bit word values in FlashMEM
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 26th June 2009, 04:35
  4. Can anyone help me to use Writecode for pic18f458 ?
    By dip1 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th June 2006, 22:29

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