I need to make this possibly. I am using keil IDE and the AT89c51RD2 MCU.

At initialization, a function will be called to derive about 1500bytes. I want to write this byte to code memory (byte by byte), because it will never change through the entire program. This I know might take about 2 pages of Flash memory.

How can I possibly do this?



I fould this where it appears it can be done. http://www.keil.com/forum/3483/

  • \$\begingroup\$ Correct me if I am wrong but Flash of 89C51 is only used to store programs and it is not available for Application. \$\endgroup\$ – Swanand Apr 2 '13 at 10:34
  • \$\begingroup\$ @Swanand You're perfectly right! But there is a way of writing to a page(s) of the Flash memory, even at run time. I have heard of that...so that is why I am asking. \$\endgroup\$ – Paul A. Apr 2 '13 at 10:43
  • \$\begingroup\$ I doubt... Can you add Datasheet reference or something where it says so! \$\endgroup\$ – Swanand Apr 2 '13 at 10:52
  • \$\begingroup\$ @Swanand See my edit! There is a link, but no one clarely gave an answer. \$\endgroup\$ – Paul A. Apr 2 '13 at 11:00

It is possible. I've done it. But 8051 variants really don't like doing this. If you're interested in why they don't like doing this, read up on Harvard Architecture.

The first reply in the thread you linked actually told you the two different ways this can be achieved. The first, mapping XDATA over your code memory and then using the XDATA assembly instructions to write into that space is more trouble than it's worth. I say this because your micro does contain those "magic instructions" that the poster references.

You need to link in a library that you can get from the Atmel website and then you can make calls to these magic instructions and write to the flash via In-System Programming (ISP) also called In-Application Programming (IAP) in the literature.

Have a look at the datasheet. You should probably read all of Section 24. But the important part is Section 24.10.

24.10 API Call Description

The IAP allows to reprogram a microcontroller on-chip Flash memory without removing it from the system and while the embedded application is running.

The user application can call some Application Programming Interface (API) routines allowing IAP. These API are executed by the bootloader.

To call the corresponding API, the user must use a set of Flash_api routines which can be linked with the application.

Example of Flash_api routines are available on the Atmel web site on the software application


C Flash Drivers for the AT89C51RD2/ED2

The API calls description and arguments are shown in Table 24-10.

24.10.1 Process

The application selects an API by setting R1, ACC, DPTR0 and DPTR1 registers.

All calls are made through a common interface “USER_CALL” at the address FFF0h.

The jump at the USER_CALL must be done by LCALL instruction to be able to comeback in the application.

Before jump at the USER_CALL, the bit ENBOOT in AUXR1 register must be set.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.