I'm evaluating an Xmega Xplained board whose code examples are in AVRGCC. They work fine, but I'm more familiar with ICCAVR, so I'm trying to get them to work with that compiler.
In the snippet below, counter is declared as a volatile unsigned int, and x as an unsigned char initialized to 0 (I've omitted the rest of the code the snippet comes from as I think it's irrelevant and would just make for a longer and more confusing extract).
The nop() is in the AVRGCC code but is unrecognized by ICCAVR, so I commented it out and replaced it with x++ hoping to achieve a similar effect. However, while x gets incremented as expected, counter only goes from 0 to 2 before resetting (both in simulation and emulation). If I compile the code as shown with AVRGCC, counter increments as it should, but AVR Studio won't let me set a breakpoint on the x++ line or let me run-to-cursor on that line, saying it's not a valid source line.
I'm mostly interested in learning what's causing the first issue, though I'm curious about the second, as well. Regarding the latter, my guess would be that, unlike ICCAVR, AVRGCC realizes x isn't used anywhere and omits it from the object code, so there's nothing to break on, but maybe something else is going on.
Thanks from a newb.
while (1) { LEDPORT.OUTTGL = 0xff; // Delay for ( counter=0; counter<10000; counter++) { // nop(); x++; } }