PDA

View Full Version : WRITECODE on F819



dhickman
- 14th February 2008, 21:05
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

skimask
- 14th February 2008, 21:21
Are you sure the program is even running once programmed into the PIC itself? (think blinky LED)...

dhickman
- 14th February 2008, 21:46
i test the results by reading the code space using my programmer software. i don't see any $1234 in memory.

-=drew

skimask
- 14th February 2008, 21:46
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?

dhickman
- 14th February 2008, 22:19
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.

Darrel Taylor
- 14th February 2008, 23:30
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.

dhickman
- 15th February 2008, 01:05
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

Darrel Taylor
- 15th February 2008, 01:19
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/showthread.php?p=28336#28336
<br>