Using Flash to save the code and data.How to?

I am using the P89C51RD+ from Philips. I intend to use the flash as follows:
0x000- 0x1FFF to save the program code.This prohram acquires data from a GPS, processes it and saves it.
0x2000- 0xFFFF : the processed data ust be saved in this space in the Flash memory.
Is it possible? How should I do it?
I have tried to use the IAP to save the data to the flsh but I dont have a mean to prove that it works.
Here are the routines in assembly:

NAME IAPMODE
;
PUBLIC _COPIA_P_FLASH, _APAGAR_FLASH, _LE_D_FLASH

IAP_ROUTINES SEGMENT CODE ;Declaração de Variáveis

AUXR1 DATA 000A2H
PGM_MPT EQU 0FFF0H ;Philips FirmWare

RSEG IAP_ROUTINES


/*****************************************************************************/
/* +Funcao : carregar(long,u16) */
/* +Descrição : rotina que invoca uma rotina, 'In Aplication Program (IAP) */
/* do micro para a escrita de um byte */
/* */
/*****************************************************************************/
_COPIA_P_FLASH:
MOV AUXR1,#20H ;Carregamento de dados na Flash
MOV R0,#11 ;frequencia do micro
MOV R1,#02H
MOV A,R3
MOV DPH,R7 ;parte alta
MOV DPL,R5 ;parte baixa
CALL PGM_MPT
RET
/* FIM de _LOAD */


/*****************************************************************************/
/* +Funcao : apagar(char) */
/* +Descrição : rotina que invoca uma In Aplication Program (IAP) do micro */
/* para apagar blocos na memoria */
/* */
/*****************************************************************************/

_APAGAR_FLASH:
MOV AUXR1,#20H ;Apaga blocos da Flash
CLR A
MOV DPL,A
MOV R0, #32
MOV R1, #01
MOV DPH,R7
CALL PGM_MPT
RET
/* FIM de _APAGAR */


/*****************************************************************************/
/* +Funcao : ler(char, char) */
/* +Descrição : rotina que invoca uma In Aplication Program (IAP) do micro */
/* para apagar blocos na memoria */
/* */
/*****************************************************************************/

_LE_D_FLASH:
MOV AUXR1, #20H ;ENBOOT = 1 (required on some parts)
MOV R1, #01H ;codigo da operacao de leitura
MOV DPH, R6
MOV DPL, R7 ;o endereço e de 16bits,fica em R6&R7
CALL PGM_MPT
MOV R7,A ; C51 expects return in R7
RET

END


I call those routines using C routines:
extern byte apagar_flash(unsigned char);
extern byte copia_p_flash(char,char, char);
extern byte le_d_flash(u16 addr);

I am using the keil Uvision v2.33
Am I doind the right way?
I cant put the program to work when I save the code in the micro!
Is there any way to download the program and test it directly from the Uvision2? I ask this beacuse there's a tab that permits to download but I ca't get access to that.

Thanks.

Parents
  • It is difficult to read your non-english comments and routine names; however http://www.esacademy.com has all kinds of routines for the RD2 (skip the RD+, it is discontinued) to achieve what you want.

    It seems to me (again, "reading" non-english)that you do not understand the difference between Flash and RAM, you can not just write to flash, you must erasse before write.

    Also it seems (again, "reading" non-english)that you try to do IAP yourself, why not just use FlashMagic.

    Erik

Reply
  • It is difficult to read your non-english comments and routine names; however http://www.esacademy.com has all kinds of routines for the RD2 (skip the RD+, it is discontinued) to achieve what you want.

    It seems to me (again, "reading" non-english)that you do not understand the difference between Flash and RAM, you can not just write to flash, you must erasse before write.

    Also it seems (again, "reading" non-english)that you try to do IAP yourself, why not just use FlashMagic.

    Erik

Children
More questions in this forum