Hello,
I am so sorry, I should have tested the code I gave.
First, the adress to the subroutine was wrong it should of course be 0xfcbe and I also forgot to load H:X with the adress of the datablock. Well.. I guess you recognized this when you took a closer look.
Anyway it did still not work properly, it left the adress FFFF at 0xF7 (resetvector) for some reason.
The problem must be that the program returns to the erased flash.
Since I have problem with copying the program to RAM in the C-environment, I tried another aproach, to copy the OP-code for "bra *" into ram, let the stackpointer point to the adress of that.
I have now tested it an it works well.
I am so sorry if I caused you extra work with the incorrect code, but this should work.
Here in the main.c file:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
void Erase(void)
{
asm{
clr CONFIG2
mov #0x31,CONFIG1 //disable cop andLVI
ldhx #0xffff
sthx 0x62 //this tells the rom-routine to erase entire flash
mov #24,0x60 //crystal speed 24Mhz
ldhx #0x20fe //OP-code for bra * in RAM
sthx 0x70
lda #0x70
psha
clra
psha
ldhx #0x60
jmp 0xfcbe //jump to erase routine in ROM,
// OBS! not jsr !
}
}
void main(void) {
//EnableInterrupts; /* enable interrupts */
/* include your code here */
if(PTB_PTB0==0) Erase();//erase flash if PTBO is =0 (PTB0 is the monitor pin)
for(;

{
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
}
Message Edited by sungam on 2007-03-0410:05 PM