Thanks Coding Badly.
What @gardner posted is not a work-around. It is correct.
I can't find any other examples on the net that require one to use pgm_read_word() before using pgm_read_byte().
I had read that documentation that you refer to (http://www.nongnu.org/avr-libc/user-manual/pgmspace.html
) several times prior to posting this thread.
The documentation does not suggest that I use both routines to extract bytes. In relation to reading strings it states:
"You probably don't want to pull the string out of Program Space, byte by byte, using the pgm_read_byte() macro."
It so happens that I do, so the pgm_read_byte() macro is for me. It does not state that I also need to use the pgm_read_word() first.
The caveat at the bottom of the AVR-Libc documentation states that there is extra overhead incurred by these routines. So it would be best to run just one instead of two. Of course if this is the only way to do it, then one has to live with the overhead. But if it isn't, then i'd rather not.
The fact that the pgm_read_byte() runs fine with the static values seems to prove that one does not have to use the pgm_read_word() prior to using the pgm_read_byte().
No. It's a bug in your code.
Please would you point out specifically where the bug is in my code?
I've played around a bit more and have the following alternative code working fine (which shows that you don't have to use pgm_read_word() prior to using the pgm_read_byte()) but it still doesn't explain why the original code does not work.
PROGMEM const char BitMap1 = "abcdefgh";
PROGMEM const char BitMap2 = "ijklmnop";
PROGMEM const char* const progbytes =
for (int j = 0; j < 2; j++)
for (int i = 0; i < 8; i++)
byte var = pgm_read_byte(&progbytes[j][i]);
while (true); // loop forever
Now I'm just comparing it to my code in my first post in this thread to see why this one works and the other one doesn't.
Still can't see it, can you?