Lets start by writing an application to flash the LED on the
Xplained Mini board. We will use a delay loop with a NOP instruction inside a large
counter and pulse the LED with about a 1% duty cycle. The code for low_power_101 is
shown
here.
#include <avr/io.h>
void delay (uint16_t length)
{
for (uint16_t i=0; i<length; i++) {
for (uint8_t j=0; j<255; j++) {
asm volatile("nop");
}
}
}
int main(void)
{
DDRB = (1 << 5);
while (1) {
PORTB = (1 << 5);
delay(50);
PORTB = 0x00;
delay(5000);
}
}
Important: For this example set
the optimisation level to None (-O0) in the project options under Toolchain →
AVR/GNU C Compiler → Optimization.
Todo: Build
the project/solution (F7).
Todo: Program the
application into the target by selecting Start Without Debugging
(Ctrl+Alt+F5).

LED0 on the mEDBG kit should now start to blink.
Info: In
this example we are going to make use of programming mode only. In most systems
running code through a debugger will not yield accurate current measurements. This
is because the target device's debug module (OCD) requires a clock source which
cannot be disabled while debugging.
Important: Remember to
disable on-board power on the Xplained Mini.