OnlineCourse/BlinkingLEDs

Now that you did the previous steps on OnlineCourse, you succeeded to compile and upload the application to the GenBoard it's time to write your first addition. The "Hello World" application for microcontrollers is blinking LEDs.

On GenBoard/VerTwo you can use the small SMD LED on PORTA3 (this is inverted! lights up on output=0) or the NPN driven LEDs on PORTA4..7 pins.

The best place to stick your code is megasquirt.c, main() function, right after ioinit(). ioinit() set these ports to output with the DDRA=... instruction. The simplest way to do the delay is with a busyloop (untested code, but should work):

uint16_t inner;

uint8_t outer;

  1. define MASK (0xF8)
for(outer=0xff; outer; outer--)

for(inner=0xffff; inner; inner--)

PORTA = (PORTA & ~MASK) | (outer & MASK);

You could say it's unnecessary to write the same value 65536*8 times to the PORTA bits (bits that are high in the MASK). But this makes sure that GCC does not optimize the cycles away (which it could if we put in a nop() inside). After this is executed, (in a few seconds for 16MHz clock), the MS-AVR application will start.

Go back to OnlineCourse