PDA

View Full Version : I need help with writecode



Marten
- 27th February 2005, 22:35
Hi

I have been trying to use writecode on my 18F252 for a while, but i seem to fail whatever i do

I need a simple code example to get me going, i have looked at Melanies posts about the subject, but i need more concrete advice.

I'm trying to copy the contents from one adress in codespace to another.

if someone could write a few lines and show me how it's supposed to be done, with readcode,erasecode,eecon and all of it, please ?


I have PicBasic Pro 2.42,have not used PBP for long, i 'm migrating from AtomBasic > PBP, so far so good, but my adventures with writecode makes my head spin.

i know i'm supposed to do a block write in the 18F, and that's my problem, i dont know how it's performed, str ?



Marten

Marten
- 28th February 2005, 11:47
What i mean, what i am trying to do, is to copy parts of code from one adress in codespace to another, in the same way that you use read and write with eeprom, i'm going to use this function to update code in a 18F252 from an smartcard later on, i simply have to learn how it all works first.

what i have tried to do is the following:

'Lcd Defines removed from code snip'

define osc 20

snip1 var word
snip2 var word


erasecode $7FF

readcode $000,snip1
pause 50
writecode $7FF,snip1
pause 50
readcode $7FF,snip2

LCDOUT $FE,1,"Orig: ",hex snip1
LCDOUT $FE,$C0, "Copy: ",hex snip2


This, does not work, snip1 and 2 does not have the same value,and it is many things that may be wrong, and i do not know what at the moment, the data sheet says that i must perform a block write with 8 bytes, something i dont understand how, without a array variable 'str var\8' or something like it, that is whats bugging me .

Could you or anyone tell me how to proceed, is there any configuration bit that i cant see ?, i have checked all the bits in 18F252.inc and P18F252 and everything that sounds like write protection is disabled.


Marten

Marten
- 2nd March 2005, 23:15
this actually works:

( Thanks Bruce ! [piclist.org])

This code snippet copies a bunch of bytes to a different location in codespace.

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@

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

Y=$0000 'Location to copy data from
A=$04F0 ' Location to copy data to

main
For x = 0 to 9
Lcdout $fe,1,"Copying Data ! "
For I = 0 To 14 ' Loop 14 times
Readcode Y,D ' Read Data and copy it to new location
Writecode A,D ' Send value in D to code space location A
A = A + 1 ' Increment Address
y = Y + 1
pause 10
Next I
Pause 1
Next x

goto showme

showme:

A= $04F0

For I = 0 To 72 ' Loop 72 times
Readcode A,D ' Get data in location A
Lcdout $fe,1,"Data:",hex A,":",hex D ' Display the location and data
Pause 1000
A = A + 1 ' Increment Address
Next

End

goto main