WRITECODE on F819


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2008
    Posts
    8

    Default WRITECODE on F819

    i am having difficulty getting the WRITECODE command to do anything at all. i have PBP 2.50a and a EPIC programmer. when i run the following code (found while trying to resolve this issue) i find all memory locations other than my code stuffed with 3FFF.

    ***************

    'use the following when using the MP assembler
    @ DEVICE PIC16F819, hs_osc, wdt_off, pwrt_on, mclr_on, bod_off, cpd_off, protect_off, lvp_off, WRT_3FOURTHS

    'use the following when using the MPASM assembler
    '@ __CONFIG _HS_OSC & _WDT_OFF & _CP_OFF & _CPD_OFF & _WRT_ENABLE_512 & _PWRTE_OFF & _MCLR_ON & _BODEN_OFF & _LVP_OFF

    DEFINE OSC 10
    clear

    I var byte ' Loop count
    D var word ' Data
    A var word ' Address

    A=$04F0
    d=$1234

    erasecode A
    For I = 0 TO 63 STEP 2
    Writecode A + I, D
    Next I

    stop
    end

    ***************

    i've tried both PM and MPASM and while both compile just fine with no errors neither one produces the results i'm expecting to see (32 words valued $1234 starting at memory location $04F0) when i read the memory.

    i've tried two different chips just to make sure i obtain the same results on both. i do.

    any ideas on this one?

    thanks in advance

    -=drew

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Are you sure the program is even running once programmed into the PIC itself? (think blinky LED)...

  3. #3
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    i test the results by reading the code space using my programmer software. i don't see any $1234 in memory.

    -=drew

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dhickman View Post
    i test the results by reading the code space using my programmer software. i don't see any $1234 in memory.

    -=drew
    Exactly. If the program doesn't run, how do you know that it reprogrammed the memory or not?

  5. #5
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    here's the code now with two LEDs. portb.0 flashes on startup and portb.1 flashes after attempted write operations.

    **************

    'use the following when using the MP assembler
    '@ DEVICE PIC16F819, hs_osc, wdt_off, pwrt_on, mclr_on, bod_off, cpd_off, protect_off, lvp_off, WRT_3FOURTHS

    'use the following when using the MPASM assembler
    @ __CONFIG _HS_OSC & _WDT_ON & _CP_OFF & _CPD_OFF & _WRT_ENABLE_512 & _PWRTE_OFF & _MCLR_ON & _BODEN_OFF _LVP_OFF

    DEFINE OSC 10
    clear

    I var byte ' Loop count
    D var word ' Data
    A var word ' Address

    A=$04F0
    d=$1234

    TRISB=0 'set portb pins to all output
    PORTB=0 'turn off all portb pins

    portb=0
    for i=0 to 3
    toggle portb.0
    pause 200
    next i

    erasecode A
    For I = 0 TO 63 STEP 2
    Writecode A + I, D
    Next I

    portb=0
    for i=0 to 3
    toggle portb.1
    pause 200
    next i

    stop
    end

    *******************

    if i read the code space after the portb.1 LED blinks i get the same results as before.

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


    Did you find this post helpful? Yes | No

    Exclamation

    The 819 erases Flash in blocks of 32 WORDS.
    Those blocks are restricted to physical boundaries, not just 32 words from where you said to erase.

    With $04F0, the beginning of the block it will erase is at $04E0.
    Make the lowest 5-bits 0 to find the beginning.

    Then when writing, you have to write in blocks of 4 WORDS. These blocks also have physical boundaries.

    After erasing from $4E0, the first write block is from $4E0 to $4E3.
    Anything written to those locations will be transferred to flash memory only AFTER the 4th location is written too.

    But your FOR loop is only writing every other word, so it would write to the 1st and 3rd locations, and the data will never be transferred to Flash.

    Plus the loop should only go to 31 instead of 63. You're writing WORD's not BYTE's.
    DT

  7. #7
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    success!

    i don't have to use the ERASECODE command in order for this to work (on this PIC).

    now for the one piece of information that will allow me to fish for myself: where are the pieces of information about block size, the number of bytes/words to write before they are actually written, and if a block first needs to be erased located in a typical datasheet?

    thanks for the assistance! i appreciate your work, Darrel. i'm currently trying to get USART interrupts working using your instant interrupts system. just need to figure out how to grab the byte from the buffer so i can store it. the SPWM code you offer works great!

    thanks again!

    -=drew

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dhickman View Post
    i don't have to use the ERASECODE command in order for this to work (on this PIC).
    Not the first time, because you'll be writing to areas that were erased when it was programmed.

    If you ever want to write over then same locations again, then you have to erase it first.
    now for the one piece of information that will allow me to fish for myself: where are the pieces of information about block size, the number of bytes/words to write before they are actually written, and if a block first needs to be erased located in a typical datasheet?
    Section 3.6 in the 819's datasheet.

    i'm currently trying to get USART interrupts working using your instant interrupts system. just need to figure out how to grab the byte from the buffer so i can store it.
    Take a look at this ...
    http://www.picbasic.co.uk/forum/show...?p=28336#28336
    <br>
    DT

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