• AVR Freaks

Hot!Variables reset to data values after reset instruction?

Author
acharnley
Super Member
  • Total Posts : 369
  • Reward points : 0
  • Joined: 2016/05/01 06:51:28
  • Location: 0
  • Status: offline
2019/09/22 10:18:42 (permalink)
0

Variables reset to data values after reset instruction?

If I have:


#include "variables.h"
uint16_t acAtBlip = 33;


I assume the compiler writes the value 33 into data/flash and reserves a segment of memory to hold the dynamic value.

My question is whether the value is copied back into memory on reset or should I do it inside of main()?

In other words when does RAM get set with flash values?

Cheers,

Andrew
#1

4 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 17847
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Variables reset to data values after reset instruction? 2019/09/22 10:32:36 (permalink)
    +1 (1)
    After a reset it will equal 33.
    When it is set depends on where it is in code.
    Since it appears to be a global, then it will be set in the C startup code.
    #2
    ric
    Super Member
    • Total Posts : 23893
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Variables reset to data values after reset instruction? 2019/09/22 13:15:28 (permalink)
    +1 (1)
    What is the relevance of the '#include "variables.h" ' line?
    You don't mention what's in that header file.
    Any variables declared in the header file are treated exactly the same as variables declared after it, but convention dictates that you should NOT assign initial values inside a header file, as that converts "declarations" into "definitions".

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    acharnley
    Super Member
    • Total Posts : 369
    • Reward points : 0
    • Joined: 2016/05/01 06:51:28
    • Location: 0
    • Status: offline
    Re: Variables reset to data values after reset instruction? 2019/09/22 14:09:52 (permalink)
    0
    I'm not, my headers are only for #defines and prototypes.

    The "C Startup code" was what I was after. It's as I expected but I thought I'd double check.

    Thanks all.
    post edited by acharnley - 2019/09/22 14:10:54
    #4
    1and0
    Access is Denied
    • Total Posts : 9771
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Variables reset to data values after reset instruction? 2019/09/22 16:12:30 (permalink)
    +1 (1)
    acharnley
    The "C Startup code" was what I was after. It's as I expected but I thought I'd double check.

    Just look at the disassembly listing or listing file.
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5