3

I'm not sure how to pose this question, but here it goes:

  1. When programming on my Atmel MCU's in c++ I tend to mix the 'program'-variables and the 'user'-variables in the same datamemory. Which in time is a hassle because I want to make a few presets that can be loaded or saved. And I do not want the 'program'-variables saved because the program will generate the correct values based on the 'user'-values. Is it common practice to split that in memoryplaces? Eg. timercounter in PGM-Memory, thresholdByUser in DATA-memory?

  2. In my program i've made several different functions which all have their own set of uservariables. Eg: settings has 5 uservariables, generator has 6 uservariables etc... Would you make 1 big array and then make #define settingsgeneratorSpeed 1, #define settingsBacklight 2 as places, so you could call them as such: Array[generatorSpeed], Array[settingsBacklight] or would you still split it up and collect them by using a struct orso?

Working on atmelstudio 4.0 with a ATMEGA644 on STK500.

Thanks for all the help you can give!

4

2 回答 2

1

假设您使用的是 AT(X)Mega,当提到 Atmel MCU 时:IIRC 这取决于您使用的编译器套件。使用 gcc,如果您有类似静态 int 的东西,它将转到 PGM 并在程序运行时复制到 RAM。因此,如果您希望变量不在 PGM 内存中,则必须将它们设置为堆栈或堆变量。常量和静态将始终存在于两者中。如果您不想只拥有 PGM 常量,您可以指定它,但这需要特殊的读取操作。

于 2013-08-28T09:54:13.127 回答
0

对于问题 2,我会使用const int& settingX = array[Xoffset]而不是定义。但这假设有一些需要遍历数组,否则我只需定义单独的变量。

于 2013-08-28T12:04:46.527 回答