We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'm a relative newbie at embedded programming and I've come accross something that maybe could help some other newbies. I had a (for me) reasonable size project, and quite glad when it was finished and run through the simulator. When however I run the program on my target board it would not run at all. Took me days to troubleshoot but at last, I found it. I hope I'm not lying here, otherwise someone will surly rectify me. In the simulator all variables (if not initialised with a value) are allways set to "0" so you can take for granted that everything will start at "0". On the target board this is completely random, unless you initialise the variable with a value, you will not know the initial state. In my application after setting all the variables to a startup state, all was well. Hope this will help someone sometime. Regards John
The code that clears down RAM to all zeros is in STARTUP.A51 and the constants in STARTUP.A51 may need to be modified to match your hardware. When the start-up code jumps to ?C_START, the compiler generated code initialises all the variables that have been given specific initialisation values. Personally, I make it a habit to make sure that all of RAM is cleared to zero and to specify initialisation values for all variables. There may be reasons why you might not want to do one (or even both) of these things. Both operations take time which lengthen the period between reset and the first instruction of main(). Also, C51 seems to build some sort of table of initialisation values for global and local static variables, and this table will take up code space. Natuarally, non-initialisation should be treated with great care. Presumably, the simulator starts out with memory that is all zeros, so these problems will not necessarily show up in simulation. I think some LINT programs will warn you about variables that are used without first being initialised.