[Top][All Lists]

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

RE: [avr-gcc-list] Program Space String Utility - winavr20030312

From: Todd Lucas
Subject: RE: [avr-gcc-list] Program Space String Utility - winavr20030312
Date: Thu, 10 Apr 2003 10:40:54 -0700

I'll assume that

        static uint8_t PROGMEM array[] ... 

is really

        static uint8_t PROGMEM leds[] ... 

If the assumption is correct, strlen_P will not return the correct length
since it's not technically a null-terminated string. At a minimum, you'd
need to append a 0x0 at the end of the array for it to work. Are you saying
that there's a PROGMEM-related issue beyond that?

As a side note, you probably already know this, but sizeof(leds) will cause
a failure if you expand the size of the type of the array. I find it better
as a practice to always declare such iterative constructs as

-----Original Message-----
From: Loc Mai [mailto:address@hidden
Sent: Thursday, April 10, 2003 8:45 AM
To: address@hidden
Subject: [avr-gcc-list] Program Space String Utility - winavr20030312

Why  does sizeof(leds) work, but not strlen(leds) in for loop
1.  for (l=0; l<sizeof(leds); l++) {    //works fine

2.  // for (l=0; l< strlen_P(leds); l++) { does not work properly, never get
0xFF from array.

Anyone knows where I can get examples how I can use Program Space String
Utility - winavr20030312.
In the AVR-libc reference does not show how the can be applied.  It is not
easy to understand for newbie like me.

Here is program:
#include <inttypes.h> //-------
#include <avr/io.h>
#include <avr/pgmspace.h>

static uint8_t PROGMEM array[]={0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80,
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff};

int main(void)
   uint8_t i, j, k, l, n=0;
//   uint8_t i, j, k, l;

    outp(0xff,DDRB);                /* use all pins on PortB for output */
   for (;;) {
        for (l=0; l<sizeof(leds); l++) {    //works fine
//        for (l=0; l< strlen_P(leds); l++) {
            outp(PRG_RDB(&leds[l]), PORTB);

//delay ....cut here ................

avr-gcc-list mailing list

reply via email to

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