AVR Microcontroller C Code

The AVR microcontroller is excellent with C code because it was designed with C in mind. Atmel have also made it easy to use C in AVR Studio, as WinAVR compiler can run from within AVRStudio just like the assembler.

Only a few years ago, using C compilers involved complicated commandline instructions and make files but WinAVR more or less takes care of this for you. WinAVR is based on the free GNU-GCC compiler but is much friendlier, especially for beginners.

When you create a project in AVRStudio, you just choose C project and write your code in the editor. Then you just click Make and WinAVR does the rest. There are a few settings to be aware of in the compiler that you should set.

Go to Project – Configuration Options menu, and on first screen check these points:

That’s it. Now you can paste in C code (or write it) and compile it. Emulators can step through C code in AVR Studio just like assembler code, which makes debugging much easier.

We have some C code example projects on our support pages.

Apart from WinAVR C compiler, there are professional compilers that produce smaller and faster code but they tend to be expensive. IAR do a free version of their compiler called Kick Start, which is limited to 4KB of output code. This is enough for most simple projects. Kanda Starter Kits include a book on getting going with embedded C programming.