Several members of the Vancouver Robotics Club have expressed an interest in learning to program in C.
To that end, I have started to collect some resources to help us along this
Since many of the platforms that are common at the club, like the AVR, many
of the Motorola processors, the ARM processor, are all based around GCC,
we'll use a PC version of GCC to ease ourselves into C programming.
The PC toolchain that we'll use, comes from the
MinGW - Minimalist GNU for Windows project.
If you happen to like using cygwin, then the gcc
compiler that comes with cygwin will work just as well. If you don't know what
cygwin is, then use the MinGW compiler.
(15 Mb). If you don't have a high-speed internet account, let me know, and
I'll bring in a CD with the appropriate files on it.
Once you've downloaded the executable, run it, and it will come up with a
series of dialogs. I chose the defaults for everything, which will put the
program in c:\MinGW.
The next step is to add c:\MinGW\bin to your PATH.
- Windows 95/98
add the following line to c:\AUTOEXEC.BAT (using Notepad)
You'll need to reboot for this to take effect.
- Windows NT/2000/XP
You can edit your PATH using the Control
Panel. Open up 'System' and on the Advanced tab, click on Environment Variables.
Put c:\MinGW\bin; in front of what's currently there. You can edit either
the User or System entry (no need to do both). There is no need to reboot, just start
a new command prompt.
Here's a link
with slightly more detailed instructions.
Next, you'll need a text editor. If you're already using one that you're
comfortable with, by all means, continue to use it.
Crimson Editor is a nice little
free editor that does syntax highlighting, and will allow us to run the
compiler from within the editor.
Here's an MS-DOS Tutorial
for those of you who are unfamiliar with DOS (or maybe you've just forgotten).
For this series of tutorials, we'll put all of our files inside a working
directory. So go ahead and create C:\VRC, and inside that, create a directory
called "Hello-World". Download (right click and choose "Save As...")
Hello-World.c and build.bat
into the Hello-World directory.
Start a new MS-DOS prompt. You can use the Run command from the Start menu. Under
Windows 95/98 use 'command' (without the quotes), and under Windows NT/2000/XP
use 'cmd'. In the listings below, the blue text is what you type, everything
else is what you see.
C:\vrc\Hello-World>mingw32-gcc -o Hello-World Hello-World.c
If you do a 'dir' command, you should see:
Volume in drive C has no label.
Volume Serial Number is 903E-1803
Directory of C:\vrc\Hello-World
08/12/2004 06:48 AM <DIR> .
08/12/2004 06:48 AM <DIR> ..
08/12/2004 06:42 AM 39 build.bat
08/12/2004 06:33 AM 303 Hello-World.c
08/12/2004 06:48 AM 14,627 Hello-World.exe
3 File(s) 14,994 bytes
2 Dir(s) 1,397,178,368 bytes free
Finally, if you run Hello-World
You can configure Crimson Editor to run the build.bat to compile your current
source file. Lauch Crimson Editor. In the Tools menu, select 'Conf. User Tools..."
and fill it in like this:
You should now be able to open a source file, press Control-1 (press the control
key and the number one) and it should try to
build an executable. You'll see the error messages in the window at the bottom
of the editor. Note that this particular batch file only works with programs
which are entirely in a single file.
So now you can compile a simple program, and you want to learn more. Here's
a really good course
on learning to program in C. During the upcoming meetings we'll go over this
material, so if you want to speed ahead, read away.
Another really good introduction to C can be found on this page titled Essential C.
If you're looking for an introduction to C programming using WinAVR, then be
sure to check out Smiley Micros.
If you need some material to put you to sleep at night, here's a copy of the
Here's a list of the files that are available for downloading: