///Kner 2009

///Übungen zu Speicherbereichen AVR-GCC

///Flash advanced

///====================================

  1. 1. 

  2. 2. 

  3. 3.#include <avr/pgmspace.h> 

  4. 4. 

  5. 5.void (*start_at7b) (void)=(void (*)(void))0x017b;  //jump to this location (crash !!!) 

  6. 6. 

  7. 7. 

  8. 8. 

  9. 9. 

  10. 10.// String in FLASH und RAM; der Pointer zeigt in das RAM 

  11. 11.const char* inFlashUndRam  PROGMEM  =  "String im Flash";   

  12. 12. 

  13. 13.// String und Variable im FLASH 

  14. 14.const char s1[] __attribute__((progmem)) = "StringImFlash1";  

  15. 15.const char s2[] PROGMEM = "StringImFlash2";  

  16. 16. 

  17. 17. 

  18. 18.///Daten in einem definierten Bereich im Speicher: das Segment benennen und im Linker die Location setzen 

  19. 19.const char nurimFlash[] __attribute__ ((section(".text"))) = "Hallo Welt!"; 

  20. 20.  

  21. 21. 

  22. 22. 

  23. 23.const int C1 = 34;         // SRAM!!! 

  24. 24.const int C2 PROGMEM = 23; // im FLASH 

  25. 25.const prog_int8_t C3 = 5;  // FLASH alternative Schreibweise 

  26. 26. 

  27. 27.void main(){ 

  28. 28.             

  29. 29.    //auf eine Adresse im Flash zeigen 

  30. 30.        PGM_P ps1 = s1;  

  31. 31.          

  32. 32.        char dest[5];  

  33. 33.        //copy from FLASH to c 

  34. 34.        memcpy_P(dest, ps1, 5); 

  35. 35. 

  36. 36.        //get a defined address in FLASH 

  37. 37.        char d;  

  38. 38.        PGM_P  ps2 = (PGM_P)0x29;  

  39. 39.        memcpy_P(&d, ps2, 1); 

  40. 40. 

  41. 41. 

  42. 42. 

  43. 43.    // Springe zu einer bestimmten Adresse (ICALL)  

  44. 44.        start_at7b(); 

  45. 45.        //oder  

  46. 46.        (*start_at7b)();  

  47. 47. 

  48. 48.}