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?
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