Hallo Rufus,
wo finde ich eigentlich etwas kurzes darüber,
was denn da zum guten Stil gehört ?
Marc Mk schrieb:
> Zur besseren Übersicht möchte ich Konstanten in eine .h Datei auslagern.
>
> In der .c Datei vor main() funktioniert das:
> volatile uint8_t Werte[] PROGMEM = {1,2,3,4,5};
>
> Wie kann ich das in eine .h Datei auslagern ?
Hallo Marc,
wie Rufus schon schrieb:
-> Weshalb "volatile" bei Konstanten ?
-> "volatile" ist doch hauptsächlich für globale Variablen und IRQ
(Der erzeugte Assembler-Code verwendete LDS - aus RAM !)
-> für meine Projekte nutze ich "static const ... PROGMEM ..."
(Der erzeugte Assembler-Code verwendet dann auch LPM aus FLASH !)
Egal, ob es nun so gehört oder nicht - es funktioniert zumindest.
(Winavr & Avr-Simulator)
main.c:1 | #include <avr/io.h>
|
2 | #include <avr/pgmspace.h>
|
3 | #include "progmemconst.h"
|
4 |
|
5 | int main()
|
6 | {
|
7 |
|
8 | unsigned char counter;
|
9 |
|
10 | while(1)
|
11 | {
|
12 | for (counter = 0; counter < 6; counter++)
|
13 | {
|
14 | PORTA = pgm_read_byte(&Werte[counter]);
|
15 | }
|
16 |
|
17 | }
|
18 |
|
19 |
|
20 | }
|
progmemconst.h:
1 | #ifndef _PROGMEMCONST_H_
|
2 | #define _PROGMEMCONST_H_
|
3 |
|
4 | #include <avr/pgmspace.h>
|
5 |
|
6 | static const uint8_t Werte[] PROGMEM = {1,2,3,4,5};
|
7 |
|
8 | #endif
|