We write programs for AVR microcontrollers in Code :: Blocks 10.5 environment

    Hello, Habr!

    This small topic will show how to use the popular IDE Code :: Blocks 10.5 to write programs for the ATMEL microcontrollers of the AVEL family.





    And so, it all starts with downloading the free GCC - C compiler for AVR, which under Windows is respectively called WinAVR.

    Now the newest version is the version of WinAVR-20100110.
    Download this file from SourceForge.

    Install WinAVR



    The package is simply installed wherever convenient, but, of course, Russian letters should not be in the way. After installation, the path to the compiler must be added to PATH so that all programs know that we are now proud owners of WinAVR.
    That's all.

    Code :: Blocks



    Code :: Blocks is installed,
    Run, create a new project, select AVR Project.



    As you can see, there are many target platforms, and this is a positive feature of Code :: Blocks.
    We select the type of processor that interests us, set the clock frequency,
    check off the file types that we need for debugging.



    Writing a simple program



    We blink beautifully with the LEDs connected to the PORTD.


    #include
    #include
    int main (void)
    {
    int i=0;
    // set PORTD for output
    DDRD = 0xFF;

    while(1){
    for(i = 1; i <= 128; i = i*2)
    {
    PORTD = i;
    _delay_loop_2(30000);
    }

    for(i = 128; i > 1; i -= i/2)
    { PORTD = i;
    _delay_loop_2(30000);
    }
    }
    return 1;
    }




    click build - no errors, 2 warnings.

    In the working directory of the project in the BIN folder we find the hex-file, this is the program for our microcontroller, which can be loaded into it and launched.

    To work with the compiler from the console, you need a special makefile file that contains information about the type of processor, clock speed and other important things.

    When working with Code :: Blocks, there is no need to manually fill in the makefile. Because everything can be configured in the compilation settings window.
    It also edits optimization and more.



    Code :: Blocks is a very flexible environment that will suit many.
    She came up to me, now I constantly write code for AVR in it, it’s convenient.

    Hope the information was helpful.

    Also popular now: