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

Return code from FDSA call not OK

Hi,

I am using Compiler 51 v 8.09 and Atmel AT89c51RD2 chip.When I try to save data to internal flash the return value from routine is always not ok (0xF0), when I run the same code on Phlips P89c51RD2 processor the return code is OK. Here is routine that I use to save data to flash:

AUXR1 EQU 0xA2 ; Define AUXR1 Special Function Register

; FUNCTION _set_code (BEGIN)

SET_CODE SEGMENT CODE RSEG SET_CODE

PUBLIC _set_code

_set_code: ; set_code()

MOV DPL,R7 ; Set DPTR = cp MOV DPH,R6

MOV A,IE ; Save Interrupt Enable PUSH ACC

CLR A ; Disable All Interrupts MOV IE,A

MOV R0,#20 ; Set R0 = Oscillator Frequency MOV R1,#2 ; Set R1 = Program Data Byte Function Code MOV A,R5 ; Set ACC = Byte to Program

MOV AUXR1,#20H ; Set ENBOOT = Enable Boot Rom

LCALL 0xFFF0 ; Call PGM_MTP & Program Data Byte

MOV AUXR1,#0 ; Clear ENBOOT = Disable Boot Rom

MOV R7,A ; Set R7 = Return Value - 0=Ok FF=Fail

POP ACC ; Restore Interrupt Enable MOV IE,A

RET ; Return

END

; FUNCTION _set_code (END)

the parameters for function are address in flash (0xC000) and value to write.

Could somebody help me to understand what wrong with code or why the same code run on Philps and not on Atmel( I did recompile the code for each processor separetly)?

Parents
  • Sorry, Here is the code

    AUXR1      EQU     0xA2                    ; Define AUXR1 Special Function Register
    
    ; FUNCTION _set_code (BEGIN)
    
    SET_CODE        SEGMENT CODE
                            RSEG    SET_CODE
    
            PUBLIC  _set_code
    
    _set_code:                                      ; set_code()
    
            MOV             DPL,R7                  ; Set DPTR = cp
            MOV             DPH,R6
    
            MOV             A,IE                    ; Save Interrupt Enable
            PUSH    ACC
    
            CLR             A                               ; Disable All Interrupts
            MOV             IE,A
    
            MOV             R0,#20                  ; Set R0  = Oscillator Frequency
            MOV             R1,#2                   ; Set R1  = Program Data Byte Function Code
            MOV             A,R5                    ; Set ACC = Byte to Program
    
            MOV             AUXR1,#20H              ; Set ENBOOT = Enable Boot Rom
    
            LCALL   0xFFF0                  ; Call PGM_MTP & Program Data Byte
    
            MOV             AUXR1,#0                ; Clear ENBOOT = Disable Boot Rom
    
            MOV             R7,A                    ; Set R7 = Return Value - 0=Ok FF=Fail
    
            POP             ACC                             ; Restore Interrupt Enable
            MOV             IE,A
    
            RET                                             ; Return
    
            END
    
    ; FUNCTION _set_code (END)
    

    .

    I hope you will see the code better

Reply
  • Sorry, Here is the code

    AUXR1      EQU     0xA2                    ; Define AUXR1 Special Function Register
    
    ; FUNCTION _set_code (BEGIN)
    
    SET_CODE        SEGMENT CODE
                            RSEG    SET_CODE
    
            PUBLIC  _set_code
    
    _set_code:                                      ; set_code()
    
            MOV             DPL,R7                  ; Set DPTR = cp
            MOV             DPH,R6
    
            MOV             A,IE                    ; Save Interrupt Enable
            PUSH    ACC
    
            CLR             A                               ; Disable All Interrupts
            MOV             IE,A
    
            MOV             R0,#20                  ; Set R0  = Oscillator Frequency
            MOV             R1,#2                   ; Set R1  = Program Data Byte Function Code
            MOV             A,R5                    ; Set ACC = Byte to Program
    
            MOV             AUXR1,#20H              ; Set ENBOOT = Enable Boot Rom
    
            LCALL   0xFFF0                  ; Call PGM_MTP & Program Data Byte
    
            MOV             AUXR1,#0                ; Clear ENBOOT = Disable Boot Rom
    
            MOV             R7,A                    ; Set R7 = Return Value - 0=Ok FF=Fail
    
            POP             ACC                             ; Restore Interrupt Enable
            MOV             IE,A
    
            RET                                             ; Return
    
            END
    
    ; FUNCTION _set_code (END)
    

    .

    I hope you will see the code better

Children
No data