Well If you want use program memory as constant variable, you should do it
this way:
const char my_array_of_bytes[] PROGMEM = {0x11, 0x64, '@', 'H', 'e', 'l',
'l', 'o', '\n'};
Now array compiler should throw to flash memory.
However reading is little bit complicated. You must know if you want read
byte by byte, or word by word and so on. So there is example to 8bit
variable:
char loaded_char;  // Variable in SRAM
loaded_char = pgm_read_byte(&(my_array_of_bytes[0]));  // Load one byte
from flash to SRAM
You can use pointer to flash memory if you want, but I just give an example
with direct addressing.
 Regards Martin


2014/1/8 Britton Kerin <[email protected]>

> This works for me:
>
>      printf_P (PSTR("hello\n"));
>
> But this doesn't (prints garbage):
>
>      PGM_P hello_string = "hello\n";
>      printf_P (hello_string);
>
> Nor does this (complains about invalid initializer at printf_P line):
>
>      PGM_P hello_string = "hello\n";
>      printf_P (PSTR (hello_string));
>
> How is PGM_P supposed to be used?
>
> Is it perhaps defined incorrectly?  Doxygen says its:
>
>   #define       PGM_P   const char *
>
> Which doesn't mention PROGMEM at all?
>
> Thanks,
> Britton
>
> _______________________________________________
> AVR-chat mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/avr-chat
>
_______________________________________________
AVR-chat mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/avr-chat

Reply via email to