Davide Andrea
Davide Andrea

Reputation: 1413

Prevent compiler-generated code from clearing a location at initialization

We implemented a Real Time Clock in a PIC micro, which increments a count of seconds in RAM.

If there's a reset, the C code created by the compiler will clear the RAM, and the count is lost. (That is not a problem if we use assembly instead of C.)

Is there a way to tell the compiler not to clear a particular RAM location?

Is there a RAM area that is not cleared by the C code?

Should we appropriate some unused registers and use them instead of using RAM?

Upvotes: 0

Views: 123

Answers (1)

Ctx
Ctx

Reputation: 18410

Variables can be declared as __persistent:

__persistent int counter;

This should prevent the startup code from initializing it.

Upvotes: 1

Related Questions