avr-libc-dev
[Top][All Lists]
Advanced

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

[avr-libc-dev] Strange behaviour of program-space


From: Florian Bantner
Subject: [avr-libc-dev] Strange behaviour of program-space
Date: Sun, 20 Feb 2005 00:57:48 +0100
User-agent: Mutt/1.3.28i

Hi List,

I don't know if this is the right list to ask this question, but the
other one (avr-chat) doesn't seem right either. Whatever...

My question is this: I'm trying out (as a first step) the example in
the FAQ for putting strings in program-space. My program looks like
this and doesn't work. It just outputs garbage:

-- snip: does not work ----------

#include "avr/pgmspace.h"

const char string1[] PROGMEM = "Test eins";
const char string2[] PROGMEM = "Test zwei";

PGM_P array[2] PROGMEM = { string1, string2 };

void delay();

int main(){

        uint8_t i;
        PGM_P c;

        lcdInit();

        for( ever ){

                lcdPut( '\n' );

                for( i=0; i<2; i++ ){

                        for( c = array[ i ]; pgm_read_byte_near( c ) != '\0'; 
c++ ){

                                lcdPut( (char) pgm_read_byte_near( c ) );
                        }
                }
                delay();
        }
}

-- snap: /does not work ----------

Removing the outer for-loop and expressing it direcly via array[ 0 ]
and array[ 1 ] it magically works.


-- snip: does work --------------

#include "avr/pgmspace.h"

const char string1[] PROGMEM = "Test eins";
const char string2[] PROGMEM = "Test zwei";

PGM_P array[2] PROGMEM = { string1, string2 };

void delay();

int main(){

        uint8_t i;
        PGM_P c;

        lcdInit();

        for( ever ){

                lcdPut( '\n' );
                for( c = array[ 0 ]; pgm_read_byte_near( c) != '\0'; c++){

                        lcdPut( (char) pgm_read_byte_near( c));
                }
                for( c = array[ 1 ]; pgm_read_byte_near( c) != '\0'; c++){ 

                        lcdPut( (char) pgm_read_byte_near( c) );
                }
                delay();
        }
}
-- snap: /does work --------------

Removing all pgm_*/PROGMEM stuff makes the programm work as well.

Is there some kind of c-magic which I'm missing? 


Best thanks,

Florian


PS: I'm not good enought in avr-asm to read from these sources whats going 
wrong. But if it would be helpfull I can post them as well.


-- 
--------------------------------------------------------
Florian Bantner                 fon +49 (0)941 599 854 4
AXON-E interaktive medien       fax +49 (0)941 599 854 1
technische Leitung              mail address@hidden
                                web http://www.axon-e.de
gpg public key    http://www.axon-e.de/gpg/f.bantner.key
hash  1191 0C87 D9DB 3217 ABBA  5223 6D74 AB19 5C9D FC49
--------------------------------------------------------




reply via email to

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