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

about start.a51 files

i trying to understand startup files, here an example
start_mx.a51

;----------------------------------------------------;  START_MX.A51:  This code is executed after processor reset.
;  You may add this file to a uVision2 project.


according to this defintion, always after reset this codes will execute

here is an another part:

PDATASTART      EQU     0H      ; the absolute start-address of PDATA memory
PDATALEN        EQU     0H      ; the length of PDATA memory in bytes.


for example if i determine program data memory 100H PDATALEN EQU 100H ;

IF PDATALEN <> 0
                MOV     R0,#PDATASTART
                MOV     R7,#LOW (PDATALEN)
                CLR     A
PDATALOOP:      MOVX    @R0,A
                INC     R0
                DJNZ    R7,PDATALOOP
ENDIF


according to this code all the program memory will clear after reset. why this codes necessary? why the programmers wants clear their program memory, if i clears program memory , program dosent work. is it true?

Parents
  • for example i have got a global variable , and i want to locate it an absolute adress.

    extern xdata unsigned char my_global;
    xdata unsigned char my_global _at_ 0x0A00 ;
    main(){//etc..}
    


    how can i initilize my_golbal to 0. but i want to do this only one time, when program is loads. therefore in startup file i dont add 0x0A00 to clearing lines. becouse i dont want to clear this variable all of after resets.

Reply
  • for example i have got a global variable , and i want to locate it an absolute adress.

    extern xdata unsigned char my_global;
    xdata unsigned char my_global _at_ 0x0A00 ;
    main(){//etc..}
    


    how can i initilize my_golbal to 0. but i want to do this only one time, when program is loads. therefore in startup file i dont add 0x0A00 to clearing lines. becouse i dont want to clear this variable all of after resets.

Children
  • " want to do this only one time, when program is loads."

    Do you mean that you want the variable to retain its value even after the system has been turned off, then turned back on?

    In that case, you need some sort of Non-Volatile memory...

  • yes. i means, variable stars with zero and it can change in program flow, but it must be keep this changes all the turn off, turn on and resets. for this i think i can use batery backup sram. but i dont be success about initilize this variable to zero.

  • This is a special case, and you really should have explained it in the first place.

    Yes, you obviously need to exclude any non-volatile memories from the startup initialisation.

    But you also need to consider what will happen in a "virgin" system the very first time it is started.
    You need to provide some means to reset everyting to a known starting condition - or at least mark everything as "undefined"

    You might include this as part of your manufacturing pocess...

  • thank you very much for your helps, may be i can use similar this;

    main(){
    xdata unsigned char initilize_flag _at_ 0x0AFF /*also located at nvram*/
    
    if (initilize_flag != 253){
    initilize_nvram_variables();
    initilize_flag = 253;
    }
    
    //others parts..
    }
    


    it is only a little possible that there is 253 value in nvram(0x0AFF) at the beginning