///Kner 2009
///Übungen zu Speicherbereichen AVR-GCC
///Flash advanced
///====================================
1.
2.
3.#include <avr/pgmspace.h>
4.
5.void (*start_at7b) (void)=(void (*)(void))0x017b; //jump to this location (crash !!!)
6.
7.
8.
9.
10.// String in FLASH und RAM; der Pointer zeigt in das RAM
11.const char* inFlashUndRam PROGMEM = "String im Flash";
12.
13.// String und Variable im FLASH
14.const char s1[] __attribute__((progmem)) = "StringImFlash1";
15.const char s2[] PROGMEM = "StringImFlash2";
16.
17.
18.///Daten in einem definierten Bereich im Speicher: das Segment benennen und im Linker die Location setzen
19.const char nurimFlash[] __attribute__ ((section(".text"))) = "Hallo Welt!";
20.
21.
22.
23.const int C1 = 34; // SRAM!!!
24.const int C2 PROGMEM = 23; // im FLASH
25.const prog_int8_t C3 = 5; // FLASH alternative Schreibweise
26.
27.void main(){
28.
29. //auf eine Adresse im Flash zeigen
30. PGM_P ps1 = s1;
31.
32. char dest[5];
33. //copy from FLASH to c
34. memcpy_P(dest, ps1, 5);
35.
36. //get a defined address in FLASH
37. char d;
38. PGM_P ps2 = (PGM_P)0x29;
39. memcpy_P(&d, ps2, 1);
40.
41.
42.
43. // Springe zu einer bestimmten Adresse (ICALL)
44. start_at7b();
45. //oder
46. (*start_at7b)();
47.
48.}