Microcontroller Programming

Microcontroller programming can seem a bit tricky because there are many confusing choices to make. I remember how I felt in the beginning. With all the available compilers, IDE’s, programmers and programming methods – no wonder you get confused!

So, let’s break it down.

Microcontroller Board ATmega32u4 from Sparkfun

I struggled a lot when I was learning the microcontroller basics. I followed different tutorials and ended up with lots of different software on my computer, which made it confusing. And I had to use an external board for programming the chip.

All of this made it hard to understand what I actually needed to make it work.

So to make microcontroller programming as simple as possible for you – here is an overview of what you need to do.

The Basics Of Microcontroller Programming

A microcontroller does not know what to do by itself. It’s your job to tell it what you want it to do.

So, you need to:

  • write program code on your computer
  • compile the code with a compiler for the microcontroller you are using
  • upload the compiled version of your program to your microcontroller

Arduino programming is a bit easier if you want to start really simple.

Write your program code

The first step is to write your program code. This is usually done is C. But some compilers support other languages as well. Find out what other people who are using the same microcontroller are doing.

Microcontroller programming code

It doesn’t matter what software you use to write code. You can even use Notepad for this step. I like to use a really simple editor. But one that supports syntax highlighting makes the coding a bit easier. For Windows, my favorite is Notepad++

Compile your code for your microcontroller

Before you can upload your program to your microcontroller, you need to compile it. This means converting the code from human-readable code to machine-readable code.

Use a compiler that supports your microcontroller and compile your code into machine-code for your chip. A popular compiler for Atmel AVR microcontrollers is avr-gcc.

After compilation, you will have one or more files containing machine code. Then you need to upload these files to your microcontroller.

Upload the compiled file(s) to you microcontroller

Usually, it’s one program file and a file for EEPROM and/or flash that you need to upload.

You need a physical connection from your computer to your microcontroller. Either you can use a dedicated programmer (such as the AVRISP for AVR microcontrollers), or if you have a USB programmable chip you can program it with a USB cable (my preferred method).

And you need a program for uploading the file(s). For AVR chips, you can use AVRDUDE.

Next Step

With the main steps of microcontroller programming fresh in mind, it’s time to start building. If you are starting out, I would recommend starting with a microcontroller board. Arduino is the simplest, but there are many more available.

I’ve aslo written a very popular 5-part Microcontroller tutorial that takes you through the steps of building your own USB-programmable microcontroller board from scratch.

More Microcontrollers Tutorials