NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Basic C Programming

October 07, 2010
by Proton
Proton's Avatar

Hi, I have the Nerdkit, and i am very interested to get going, but need some urgent help. I have installed WinAvr, but just want to start out by learning some basic C programming on my windows 7 box. Could someone please tell me how to compile and run a simple C program using WinAvr, Programmers's Notepad, and Makefile? Here is my program "hw.c", saved under C:WinAVR-20100110c_prog_source:

#include <stdio.h>
main ()
 printf("first c program");
 return (0);

Regards, Proton

October 07, 2010
by Rick_S
Rick_S's Avatar

The best way to go about this would probably be to go through your NK guide step by step. It will take you through the compile stage of some of the programs in the code folder (from the download section of the website). You can look over the sample code files from the download and see the basic structure for a C program on an avr microcontroller. After you go through the guide and it's samples, you'll have a much better understanding of the method for program creation, methods used, and how to compile and send the program to the chip.


October 07, 2010
by Ralphxyz
Ralphxyz's Avatar

WinAVR using the avr-gcc compiler will not make a .exe (pc executable) file.

You would need to install the regular gcc compiler or something like Visual Studio on windows and then make your executable. Like Rick said do the Nerdkit Guide and then look at the tutorials.


October 07, 2010
by Proton
Proton's Avatar

Hi, Thanks to all who replied to my query. Humberto responded and aided me further. We successfully installed cygwin and gcc and compiled our first program. Thank you for your help and advice. Upon further research, I discovered a very helpful tutorial for those in my boat. to compile a C program, I then used the following:

gcc hw.c -o hw.exe
October 14, 2010
by Hexorg
Hexorg's Avatar

Proton, there are many resources online about learning C language. Here is a good one. Punching "C programming" in a search engine will give you quite a good list :)

Also, in cygwin, gcc compiles programs for linux, not windows (cygwin then translates them for windows). If you want you can install MinGW, which gives you gcc for Windows, in which you can actually write programs that have GUI (Graphic User Interface) such as windows, buttons, and so on.

October 19, 2010
by tbohon
tbohon's Avatar

Pelles C is a great Windows environment - you can create both console and GUI programs and there is a lot of support in their forums.

Link: PellesC

February 06, 2011
by coastm
coastm's Avatar

This seems like a decent place to post a question I've had about the different compilers.

I've installed WinAVR and used it successfully, but like Proton, I wanted to learn basic C programming. I wrote a similar program (following the Howstuffworks url in the NK guide). It's not working like it should so I've considered downloading a different compiler.

question is, will this cause conflicts with WinAVR?

I'm using Vista.

I plan to do more nerdkit projects and don't want to create future headaches :)


February 06, 2011
by Rick_S
Rick_S's Avatar

It probably won't cause problems, but as with the addition of any software to your computer, there is always a chance.


February 06, 2011
by coastm
coastm's Avatar

Thanks, Rick. I appreciate your help....

fingers crossed.

February 06, 2011
by BobaMosfet
BobaMosfet's Avatar

If your code isn't doing what you want, that isn't the fault of the compiler, that's the fault of how you've written the code.

Try writing a 'flow-chart' for what your code is doing, not what you think it's doing. then you'll understand why it's not working as you want, and I'm sure you'll then know how to fix it. Flow-charts are you greatest tool in solving logic problems.



February 07, 2011
by Singlecoilx3
Singlecoilx3's Avatar

I would recommend some C programming tutorials on youtube, search for TheNewBoston. He has a ton of great easy-to-follow tutorials in C, Python and a ton of other stuff. Was very helpful for me.

February 08, 2011
by coastm
coastm's Avatar

thanks, all. I appreciate the suggestions.

February 25, 2011
by Pithikos
Pithikos's Avatar

If you are a bit familiar with other programming languages like Basic, Pascal etc. then I recommend you buy "C Programming Language" from Brian W. Kernighan and Dennis M. Ritchie. What makes this book so special is that it is written by the people who created the language C. There are quite some bad resources out there so learning from the right guys is important. This is not a book, it's a bible that you are going to use soon or later if you are about to stick with C.

Post a Reply

Please log in to post a reply.

Did you know that you can control multiple LEDs from one microcontroller output? Learn more...