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

FLASH PROGRAMMING IN p89v51RD2

HELLO

Please can anyone help me with the IAP of P89V51RD2 for programming multiplt locations in flash memory.

Thank you

Parents
  • sir,

    FCF EQU 0B1h
    ORG 0
    ljmp Reset
    ;---- interrupt vectors
    ;none here
    ;---- "main"
    Reset:
    ;if we try to rewrite an already programmed byte without previously erasing it, this will fail:
    MOV DPTR, #TestArea1
    MOV A, #55h
    CALL FLASH_PROGRAM_BYTE
    ;this is how a sector has to be erased prior bytes in it are being rewritten:
    MOV DPTR, #TestArea2
    CALL FLASH_ERASE_SECTOR
    MOV DPTR, #TestArea2
    MOV A, #0AAh
    CALL FLASH_PROGRAM_BYTE
    Stop: SJMP Stop
    ;---- data area, 128-byte sectors
    ;make sure that there is no code in the whole sector,
    ;as upon updating the data the whole sector gets erased
    ORG 0080h
    TestArea1:
    db 0, 0
    ORG 0100h
    TestArea2:
    db 0, 0
    ;end of TestArea2 at 017F
    ORG 0180h
    ;rest of code may go here
    ;---- FLASH API - must be located anywhere ABOVE 2000h
    ORG 03F00h
    ;programs a single byte in FLASH
    ;DPTR=addres, A=content of byte to be programmed
    ;the position to be programmed must be previously erased
    FLASH_PROGRAM_BYTE:
    PUSH IE ;DISABLE INTERRUPTS
    CLR EA
    MOV R1,#02 ;SETUP OPERATION CODE -- write byte
    ANL FCF,#0FCh ;enable boot sector - !!! this command MUST be located ABOVE 2000h!!!
    CALL 01FF0H ;call to ISP_API (modifies B register but no Rx)
    ORL FCF,#001h ;switch back to user FLASH
    POP IE
    RET
    ;erases a 128-byte sector in FLASH
    ;DPTR=address of first byte of sector to be erased
    FLASH_ERASE_SECTOR:
    PUSH IE ;DISABLE INTERRUPTS
    CLR EA
    MOV R1,#08 ;SETUP OPERATION CODE -- erase sector
    ANL FCF,#0FCh ;enable boot sector - !!! this command MUST be located ABOVE 2000h!!!
    CALL 01FF0H ;call to ISP_API (modifies B register but no Rx)
    ORL FCF,#001h ;switch back to user FLASH
    POP IE
    RET
    ;----- that's all, folks
    END

    this is what is my program

    now i m only using testarea1 and 2 to save my data how do i have multiple data in consecutive locations of the flash memory

    hope ths is clear

Reply
  • sir,

    FCF EQU 0B1h
    ORG 0
    ljmp Reset
    ;---- interrupt vectors
    ;none here
    ;---- "main"
    Reset:
    ;if we try to rewrite an already programmed byte without previously erasing it, this will fail:
    MOV DPTR, #TestArea1
    MOV A, #55h
    CALL FLASH_PROGRAM_BYTE
    ;this is how a sector has to be erased prior bytes in it are being rewritten:
    MOV DPTR, #TestArea2
    CALL FLASH_ERASE_SECTOR
    MOV DPTR, #TestArea2
    MOV A, #0AAh
    CALL FLASH_PROGRAM_BYTE
    Stop: SJMP Stop
    ;---- data area, 128-byte sectors
    ;make sure that there is no code in the whole sector,
    ;as upon updating the data the whole sector gets erased
    ORG 0080h
    TestArea1:
    db 0, 0
    ORG 0100h
    TestArea2:
    db 0, 0
    ;end of TestArea2 at 017F
    ORG 0180h
    ;rest of code may go here
    ;---- FLASH API - must be located anywhere ABOVE 2000h
    ORG 03F00h
    ;programs a single byte in FLASH
    ;DPTR=addres, A=content of byte to be programmed
    ;the position to be programmed must be previously erased
    FLASH_PROGRAM_BYTE:
    PUSH IE ;DISABLE INTERRUPTS
    CLR EA
    MOV R1,#02 ;SETUP OPERATION CODE -- write byte
    ANL FCF,#0FCh ;enable boot sector - !!! this command MUST be located ABOVE 2000h!!!
    CALL 01FF0H ;call to ISP_API (modifies B register but no Rx)
    ORL FCF,#001h ;switch back to user FLASH
    POP IE
    RET
    ;erases a 128-byte sector in FLASH
    ;DPTR=address of first byte of sector to be erased
    FLASH_ERASE_SECTOR:
    PUSH IE ;DISABLE INTERRUPTS
    CLR EA
    MOV R1,#08 ;SETUP OPERATION CODE -- erase sector
    ANL FCF,#0FCh ;enable boot sector - !!! this command MUST be located ABOVE 2000h!!!
    CALL 01FF0H ;call to ISP_API (modifies B register but no Rx)
    ORL FCF,#001h ;switch back to user FLASH
    POP IE
    RET
    ;----- that's all, folks
    END

    this is what is my program

    now i m only using testarea1 and 2 to save my data how do i have multiple data in consecutive locations of the flash memory

    hope ths is clear

Children
  • Are you reading datasheets as carefully as you read the posting instructions for this site?

    Didn't you notice the notes directly above the message text box, giving information how to post source code?

    Or maybe you did write every line starting from the left column and never with more than one space in a row for indent or separation?

  • FCF EQU 0B1h
    
    ORG 0
    
    ljmp Reset
    
    ;---- interrupt vectors
    ;none here
    ;---- "main"
    
    Reset:
    
    ;if we try to rewrite an already programmed byte without previously erasing it, this will fail:
    
    MOV DPTR, #TestArea1
    MOV A, #55h
    CALL FLASH_PROGRAM_BYTE
    
    ;this is how a sector has to be erased prior bytes in it are being rewritten:
    
    MOV DPTR, #TestArea2
    CALL FLASH_ERASE_SECTOR
    MOV DPTR, #TestArea2
    MOV A, #0AAh
    CALL FLASH_PROGRAM_BYTE
    Stop: SJMP Stop
    
    ;---- data area, 128-byte sectors
    ;make sure that there is no code in the whole sector,
    ;as upon updating the data the whole sector gets erased
    
    ORG 0080h
    TestArea1:
    db 0, 0
    
    ORG 0100h
    TestArea2:
    db 0, 0
    
    ;end of TestArea2 at 017F
    ORG 0180h
    
    ;rest of code may go here
    ;---- FLASH API - must be located anywhere ABOVE 2000h
    ORG 03F00h
    
    ;programs a single byte in FLASH
    ;DPTR=addres, A=content of byte to be programmed
    ;the position to be programmed must be previously erased
    
    FLASH_PROGRAM_BYTE:
    PUSH IE ;DISABLE INTERRUPTS
    CLR EA
    MOV R1,#02 ;SETUP OPERATION CODE -- write byte
    ANL FCF,#0FCh ;enable boot sector - !!! this command MUST be located ABOVE 2000h!!!
    CALL 01FF0H ;call to ISP_API (modifies B register but no Rx)
    ORL FCF,#001h ;switch back to user FLASH
    POP IE
    RET
    
    ;erases a 128-byte sector in FLASH
    ;DPTR=address of first byte of sector to be erased
    
    FLASH_ERASE_SECTOR:
    PUSH IE ;DISABLE INTERRUPTS
    CLR EA
    MOV R1,#08 ;SETUP OPERATION CODE -- erase sector
    ANL FCF,#0FCh ;enable boot sector - !!! this command MUST be located ABOVE 2000h!!!
    CALL 01FF0H ;call to ISP_API (modifies B register but no Rx)
    ORL FCF,#001h ;switch back to user FLASH
    POP IE
    RET
    
    ;----- that's all, folks
    END
    
    hope now this is fine
    
    
    

  • For the NXP P89V51RD2 IAP,
    please check the following documents and example code:

    www.efton.sk/.../p89v51rd2 iap.pdf
    www.efton.sk/.../iap.zip
    www.efton.sk/.../index.htm

    Jan has done a great work!