Keil Logo

C51: Interface for IAP Functions on NXP Devices

Information in this article applies to:

  • C51 All Versions


I'm using a NXP (formerly Phillips) P89C51RD2 chip that provides In-system Application Programming (IAP). NXP provides an Assembler interface, however, I want to use these routines from C. What can I do?


The NXP IAP assembly interface is fully documented in the datasheet. In general, your program must make calls to address 0xFFF0.

This is easily accomplished by creating a small assembly routine that can be called from your C functions. For example:

sfr AUXR1        = 0xA2;

XTAL_MHZ        EQU     12            ; Chip runs at 12MHz
?PR?_ProgramDataByte?ISA  SEGMENT CODE
RSEG ?PR?_ProgramDataByte?ISA

PUBLIC _ProgramDataByte         ; Entry Point for C Compiler
; unsigned char ProgramDataByte (unsigned int addr, unsigned char v);
; The C51 compiler passes addr in R6/R7 and v in R5

_ProgramDataByte:       ORL   AUXR1,#20H     ; ENBOOT = 1 (required on some parts)

                        MOV   DPH,R6
                        MOV   DPL,R7
                        MOV   A,R5
                        MOV   R0,#XTAL_MHZ
                        MOV   R1,#02H        ; function code
                        CALL  0FFF0H         ; Call NXP firmware
                        MOV   R7,A           ; C51 expects return in R7

                        ANL   AUXR1,#NOT 20H ; ENBOOT = 0(required on some parts)


Note: Some devices require that you set the ENBOOT bit in the SFR AUXR1. You need to check with the device datasheet if this is required or not.

This routine may be called directly from your C functions as follows:

extern unsigned char ProgramDataByte (unsigned int addr, unsigned char v);
void main (void)  {
  ProgramDataByte (0x8000, 0x55);   // programs 0x55 at address 0x8000

You can implement the assembly interface to other routines just as easily. The same method works for many other parts like NXP P89C668.


  • NXP Device User's Manual


Last Reviewed: Thursday, February 25, 2021

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.