Hey thanks alot peg,
But i think i need to trouble you again sorry . I have read AN2874 and also used the code for debugging but it encountered the same message too. I am currently using Motrola Modular evaluation system(MMEVS) for dubugging.
Is it that when u debug and check the memory where it is intended to be erased, it will read all ff??
During this period i tried using the method without rom routines but it encountered the same problem.
I think it is due to my carelessness or limited knowledge haha .Below is my code thanks!
*******************************************************************************************************
#include <hidef.h> /* for EnableInterrupts macro */
#include <MC68HC908JK3.h> /* include peripheral declarations */
void initMCU(void);
void initTimer(void);
unsigned char *address_flag;
unsigned int startadd;
unsigned char *addresserase_flag;
unsigned int add;
unsigned char cycle;
unsigned char READ;
/**********************/
#pragma CODE_SEG ToCopyToRAM
void flash_erase(void) {
FLBPR= 0XFF;
FLCR=0x02; //set erase bit
READ = FLBPR;
// FLCR=0x02; //clear mass bit
addresserase_flag=(unsigned char*)0xFBDF ;
*addresserase_flag = 0;
asm{
ldx #7
loop1:
dbnzx loop1 //(10us)
}
FLCR=0x0A; //set hven bit
asm {
ldx #16400
tloop :
dbnzx tloop //(4ms)
}
FLCR=0x08; //clear erase
asm{
ldx #4
loop2:
dbnzx loop2 ; //(5us)
}
FLCR=0; //clear hven bit
asm{
ldx #1
loop3:
dbnzx loop3; //(1us)
}
}
#pragma CODE_SEG DEFAULT
extern char __SEG_START_ToCopyToRAM[];
extern char __SEG_SIZE_ToCopyToRAM[];
void flash_erase(void) ;
#define Start_Copy_In_RAM __SEG_START_ToCopyToRAM
#define Size_Copy_In_RAM __SEG_SIZE_ToCopyToRAM
void CopyInRAM(void)
{
char *srcPtr, *dstPtr;
int count2;
srcPtr = (char*)Start_Copy_In_RAM;
dstPtr = (char*)&flash_erase;
for (count2 = 0; count2< (int) Size_Copy_In_RAM;
count2++, dstPtr++, srcPtr++) {
*dstPtr = *srcPtr;
}
}
//**********************************************************************************************
//Timer Initialisation
//**********************************************************************************************
/*void initTimer(void)
{
TSC = 0x20;
TMODH = 0x00;
TMODL = 0x10; //ms
} */
//**********************************************************************************************
//Main Function
//**********************************************************************************************
void main(void)
{
initMCU();
//initTimer();
// INTSCR|=0x06; //BR: Clear the IRQ latch; Disable IRQ INT
EnableInterrupts;
__RESET_WATCHDOG(); //Note as of now the COP module is disabled
TSC_TSTOP = 0; //active timer
TSC_TOIE = 1;
DisableInterrupts;
CopyInRAM();
flash_erase();
EnableInterrupts;
for(;
;
}
//**********************************************************************************************
//Initialisation
//**********************************************************************************************
void initMCU(void) {
DisableInterrupts; //Disable interrupts
CONFIG1=0x11;//Disabled Power to LVI module, COP enabled
// 0x09 LVI enabled, 5V LVI;// 0x01 LVI enabled + COP disabled, 3V LVI; // 0x39 LVI disabled + COP disabled
// 0x00, LVI 3V, COP enabled
//BR: COP disabled first, LVI is enabled (mazm) bit7: 0011 1001 bit1
// Out of stop mode bit7 - COPRS: COP rate select bit; 1: (8176) BUSCLKX4 cycle to time out; 0
262128 BUSCLKX4)
// bit7 - COPRS:In stop mode, Autowakeup period selection ; 1: 2^9 * INTRCOSC ; 0: 2^14 * INTRCOSC
// bit6 LVISTOP - LVI enable in stop mode ; 0 - Disable ; 1 - Enable;
// bit5 LVIRSTD -LVI Reset disable bit; 0 - Enable 1- Disable
// bit4 - LVIPWRD - LVI Power Disable bit ; 1- Disable ; 0 - Enable
// bit3 - LVI5OR3 - LVI 5V or 3V Operating mode ; 1 - LVI 5 v; 0 - LVI 3V
// bit2 - SSREC: Short Stop RECovery bit;
// bit1 - STOP: Stop instruction enable bit; 1: Enable; 0: Disable
// bit0 - COPD: COP Disable bit; 1: COP Disable; 0: COP Enable
// Reset value: 0x00
CONFIG2=0x00;
// Internal oscillator ; IRQ pin disabled ; Reset pin disabled ;
// Bit 7 6 5 4 3 2 1 0
// IRQPUD IRQEN R OSCOPT1 OSCOPT0 R R RSTEN
// 0-PA2 pullup 1-IRQ in pin 00- internal osc 1- reset in pin
// 1-NO Pullup 01- external osc 0- rst not active in pin
FLBPR=0xFF;
//I/O port Intialization Port A
PTA = 0x00;
PTB = 0x00;
PTD = 0x00;
DDRA = 0x01;
DDRB = 0x01;
DDRD = 0x01;
PTAPUE=0x40;
__RESET_WATCHDOG();
}
THANKS FOR ANY HELP