This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

P89V51RD2 Code starting location

I am using P89V51RD2, and I am coding in C.
I want my code to begin at address 0x2001. How can I do that with the help of C code?

Parents Reply Children
  • I suspect that you are trying to protect the IAP code. This calling sequence will allow you to have your program anywhere and still call the on chip API.

    ChipAPI Equ     01FF0H          ; Declare on chip API address
    FCF     Data    0B1H            ; Flash Control Flag
    
    ;
    ;       Physical call to API ... must be at or above 0x2000
    
            Public  _IChipAPI
            CSEG    AT 2000H
    _IChipAPI:                      ; Indirect call to on chip API
            Push    IE
            Clr     EA
            Anl     FCF,#0FCH       ; Set IAP block active
            LCall   ChipAPI
            Orl     FCF,#1          ; Clear IAP block active
            Pop     IE
            Ret
    

  • Yes Bob you are right, I want to use IAP. But my problem is I just don't want my original code overwritten by IAP, which can program the chip from 0x0000 to 0x1fff. I want to write some data with IAP while the controller is accessing the user code and then use this data further in my program. Please don't get confused between data and RAM. I just want to write a few bytes to the controller flash with IAP making sure that my original flash memory code remains the same.

  • The IAP is located in a parallel memory page to your application. That memory page has a size of 8K bytes and shares the address space 0x0000 - 0x1fff. By setting the flash bank select and calling into the IAP you are permitting the IAP (running in its memory page) to perform any operation you request on any memory within your microprocessor.

    The key is making sure that you are not calling from an address that is in the parallel page address range. If your call is located in the overlaping address range, when you switch the flash bank bit, the next instruction executed will be from the IAP memory ... not your program.