avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] how is PGM_P supposed to be used?


From: Martin Stejskal
Subject: Re: [avr-chat] how is PGM_P supposed to be used?
Date: Wed, 8 Jan 2014 09:04:34 +0100

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 <address@hidden>
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
address@hidden
https://lists.nongnu.org/mailman/listinfo/avr-chat


reply via email to

[Prev in Thread] Current Thread [Next in Thread]