avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] about array in ram


From: Enrico Rossi
Subject: [avr-gcc-list] about array in ram
Date: Sat, 7 May 2005 13:42:46 +0200
User-agent: Mutt/1.5.9i

Hi everybody,

I feel myself lost in a glass of water, maybe someone could help :)
I'm trying to create an array of uint8_t with some element static 
const, and, in a cicle, output them to PORTB of an ATmega16 on STK500.

Below 2 version of the code, uncomment the apropriate lines.

#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#define F_CPU 1000000UL  // 1 MHz
#include <avr/delay.h>

int
main (void)
{
  //    version 1 uncomment the next line
  // static const prog_uint8_t pippo[]={8,16,32,64,128};

  //    version 2 uncomment the next line
  // static const uint8_t pippo[]={1,2,4,8,16,32,64,128};

  static uint8_t counter = 0;

  // PORTB output
  DDRB = 0xFF;

  for (;;)
    {
      if (counter < 8)
        {
        //      Version 1 uncomment the next line
        // PORTB = pgm_read_byte (&(pippo[counter]));

        //      Version 2 uncomment the next line
        // PORTB = pippo[counter];

        ++counter;
        }
      else
        counter = 0;

      _delay_ms (1000);
    };
    
return (0);
}

In case (1) I (hope) use the array stored in flash memory without
loosing RAM and access it contents with pgm_read_byte funcion.
The code work perfectly.

In case (2) I use only Ram and normal C code, compile OK, run OK under
simulAVR and gdb but once downloaded on the atmega16 it does output
0xFF.

I'm sure I miss something, what I misunderstood?
Thanks for help
Bye

-- 
Enrico Rossi <address@hidden>
Cell: +39 338 9064702 - ICQ: 14142419




reply via email to

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