First steps with micro controllers (ATMega8)

micro controllers

Purpose of this article:

1) to learn how to connect the Micro controller in a simple circuit and how to power it
2) to see how to create a simple programmer (a device to connect the micro controller to a PC for uploading software)
3) to present a simple software program in C that controls a series of LEDS
4) to show everything in action.
Note: its my first time when I’m working with micro controllers. The info presented here might be inexact, but not incorrect, since I will stick to my findings and to the easy path for a beginner.
All that is presented below was the result of one day of reading, soldering, testing – a good score I would say.

micro controllers

Short Intro and Motivation

Since I’m a C++ developer for Embedded Devices, small processing units were always a strong point of interest for me. Furthermore, building a robot for my bachelor degree, a few years ago, required getting over serious hardware limitations related to power consumption and weight. So I’m still looking for a way to perfect my robot, and to extend its functionality, and the microcontrollers look like a very interesting approach, to say the least.
For a start, I had two micro controllers at hand: the popular ATMega8-16PU and the not-so-popular PIC24FJ64GA002. The first one I’ve bought on Ebay from a very good seller in Thailand:
or this article I will be targeting the ATMega8, since it gave me excellent results, thanks to available documentation. Can’t say the same about the PIC.
So let’s start:

Our first ATMega8 circuit

The ATMega8 is an excellent micro controller:

28 PINS (23 for Input/Output !!!)
8-Kbyte self-programming Flash Program Memory
1-Kbyte SRAM
512 Byte EEPROM
6 or 8 Channel 10-bit A/D-converter
Up to 16 MIPS throughput at 16 Mhz
2.7 – 5.5 Volt operation
Its datasheet is available hereI suggest you download the ATMega8 image to the left and print it, since you will need it often to consult the PIN layout when doing your circuit.

The Input/Output pins are important when it comes to how many devices you want to connect/control/use. To control a simple LED you will need to use 1 PIN (for output). To control a temperature sensor, you will need another PIN (for input).
To do a simple circuit and power the micro controller, first thing you need to know is that you need a stable 5V power source. The best way to achieve this is to use a regulator like the 7905/7805. This component has constant output regardless of the input current – in regards to some given boundaries, of course.
Here is the circuit. I suggest you use sockets for the ATMega8, to easily change the chip on your board.
First steps with micro controllers ATMega8 Schematic

Developing the Atmega software

Let’s try something simple – like controlling a LED on/off.
For this, we need to attach the led to any of the ATMega8’s available I/O pins.
I’ll use Pin 28 named PC5. This pin is part of the PORTC set of 7 pins PC0 – PC6. Notice there are other sets of pins like PORTB (PB0-PB7) and PORTD (PD0-PD7).

Next you’ll need a C compiler for the ATMega8 and a software programmer that will upload the compiled code to the micro controller.
For the compiler I’ve used AVR Studio from ATmel. Download the 3 files below and install them in the given order (the avr studio itself and 2 additional service packs):
1 AVR Studio, version 4.13, build 528 (73.8mb)
2 AVR Studio 4.13 SP1 (build 557) (37mb)
3 AVR Studio 4.13 SP2 (build 571) (45mb)

Read More: First steps with micro controllers (ATMega8)

Leave a Comment

Your email address will not be published. Required fields are marked *