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.
>why not just use FlashMagic. He's trying to collect and store data in the flash at run time. How would you propose to use FlashMagic for this?
Here is a small code that I am using to try save data to a memory position: void main(void) { unsigned char man_id=45, status=50, teste=55; config_timer1(); config_serialIO(); set_baudrate (4800); //iap_init(11); // initialize IAP Library by specifying //com_initialize (); /* initialize interrupt driven serial I/O */ crystal frequency (rounded down to // nearest integer) teste = 120; // read manufacturer id man_id = iap_read_manufacturer_id(); com_putchar(man_id); //status = iap_read_status_byte(); // read and print status byte // com_putchar(status); iap_erase_block(BLOCK_0x2000_0x3FFF); // erase flash memory from 2000H to 3FFFH iap_erase_block(BLOCK_0x4000_0x7FFF); // erase flash memory from 2000H to 3FFFH iap_erase_block(BLOCK_0x8000_0xBFFF); // erase flash memory from 2000H to 3FFFH iap_erase_block(BLOCK_0xC000_0xFFFF); // erase flash memory from 2000H to 3FFFH printf("memoria limpa!"); while(1){ // escrever numeros seguidos para posicoes contiguas de memoria. putchar("Programming memory...\n"); teste++; if (iap_program_data_byte(teste++, 0x2000)!=0) if (teste >= 0xFF) teste = 0; com_putchar(teste); com_putchar('\n'); } }