Dr. Ivan's Blog Medicine Art and Design Programming Music

Recent posts:


Art (3)
Computer (24)
Education & Specialization (2)
Medicine (4)
Music (8)
This Site (2)

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.


9.08.10 | A binary calculator with an ATmega16L, 8 LEDs and 4 buttons
Filed under: Computer — Tags: , , , , , — Dr. Ivan @ 21:23 — Comments (2)

A quick one today: This was my second project done with ATmega microcontrollers (or any MCUs for that matter) – my first being of course the knight rider which is probably not worth a blog post (but you can find source for it here though). Here I am working with an ATmega16L and a rather nifty development board (STK16+). However, you can do with pretty much ANY microcontroller, 8 LEDs and some buttons.


This is by and large a programmatic challenge since our input and output methods are rather simplistic. Nonetheless being the first ATmega project of mine it gave a great insight into what could and could not be done on this platform. Below I will outline my goals and my approach. The source code, written in C, is rather poorly commented, but much of it should be self explanatory. You can get both it and the Makefile from the download section which I will be linking to.

Goals and challenges

The goal of the project was to make something at least half-way useful with just my development board and nothing more (well except for the connector cables of course, but they came bundled with the board itself). So no external components and no soldering.

The Plan

The idea behind this binary calculator was to give the user possibility to enter numbers by flipping bits of a byte symbolised by the 8 LEDs on the development board. The input itself would be conveyed by buttons on the very same board.

First the user would input one number, the operation and finally the last number after which he or she would be presented with the results represented in binary format.

This requires us to catch input from buttons and blink the cursor. I did not implement this project with interrupts, but I found that it would perhaps be a slight overkill for such simple task.

Material list

  • STK16+ – I am using just this development board (you can find a picture of it on my equipment page). However, you can of course use pretty much any other MCU (even other than ATmega), plus some LEDs, resistors and pushbuttons.
  • Connector cables – you will need female-female connector cables. These should have been supplied with the dev board.

Putting it all together

Again, just connect the jumper cables to the appropriate ports and flash the MCU with the code.

Conclusion and possible modifications

To conclude, this project gave me great insights into how the AVR platform could be manipulated. Having had very little experience with electronics in general this was also a quick introduction to its basic aspects.

I hope you can use some of the source code for learning. Feel free to comment and critique.

FacebookStumbleUponTwitterBlogger PostRedditGoogle BookmarksDZoneDeliciousDiggHotmailMySpaceCiteULikeYahoo BookmarksWebnewsTumblrSlashdotShare


  1. avatar

    plz send me programing code for simple calculater for avr atmega16 for lcd (16*2)display…..

    Comment by RAMDAS — 07/10/2011 @ 20:26

  2. avatar

    Well, no, RAMDAS. I can’t send you the entire code – first of all I don’t know what setup you are using. Secondly, even if I did – I am not doing your entire homework for you, sorry. Why don’t you ask a specific question – I will be glad to answer it as well as I can!

    Comment by Dr. Ivan — 07/10/2011 @ 23:16

RSS feed for comments on this post. TrackBack URL

Leave a comment