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

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

[avr-gcc-list] why does this not work?!?


From: Torsten Mohr
Subject: [avr-gcc-list] why does this not work?!?
Date: Wed, 8 Jun 2005 02:10:52 +0200
User-agent: KMail/1.8

Hi,

i use binutils-2.15, gcc-3.4.4 and avr-libc-1.2.3

I tracked down a certain problem to the attached example code.
There are two switches on PB2 and PB3 and there are two LEDs
on PB4 and PB5.
Sometimes the code after the simple for() is reached (what i expect, "it 
works"), sometimes not.  I see this on the patterns the LEDs show.

- If i use "i" as a global variable, the for() does not seem to exit.
- If i use "i" as the local variable, defined in main() it works.
- If i use "i" as a global variable and set the limit in the for() from 2 to 1
it works.  That way the exit condition for for() is met immediately.

This must be some really stupid bug i wrote, but i don't see it at the moment.

It would be great if anybody could give me some hints on this one.


Best regards,
Torsten.


I compile with these commands:

avr-gcc -I /opt/avr/avr/include/avr -mmcu=atmega128 -Wa,-ahnls=qwe.s -c \
qwe.c -O0 -oqwe.o
avr-gcc -I /opt/avr/avr/include/avr -o qwe.elf qwe.o
avr-objcopy -O srec qwe.elf qwe.hex


------------------- example code:
#include <io.h>
#include <wdt.h>
#include <interrupt.h>

#define L1 0x10
#define TMASK 0x0c
#define LMASK 0x30

volatile unsigned int i;


int main(void) {
  //volatile unsigned int i;

  cli();
  wdt_disable();

  DDRB = LMASK;
  PORTB = TMASK | L1;

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

  PORTB = TMASK | LMASK;

  do {
    i++;
  } while(1);

  return 0;
}




reply via email to

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