Let’s make a line follower robot part:: 5


 This is core programming part of your robot. first Install the AVR GCC in your computer and then come to the point. We will learn here the registers and the pin configurations of AVR micro-controllers. I assumed that you all have the basic knowledge of C programming.

  • AVR Registers:

A register is a special storage space in which the state of the bits in the register have some special meaning to the AVR micro-controller. Most of the registers are 8-bits wide (there are a few exceptions).

Each register has a name and individual bits may also have unique names. All of the register and bit names are described in ATmega48/88/168/328 datasheet. The AVR Libc library will define identifiers for the register names and bit names so that they can be easily accessed in C.

Manipulating the bits in the various registers of the AVR is the basis for AVR programming. Everything from configuring the AVR device’s built-in peripherals to using the AVR’s pins for digital I/O is done by manipulating bits in these registers.

  • AVR Bits and Bytes:

                                           bit represents one of two possible states: 1 or 0 (aka: on/off, set/clear, high/low). Several bits together represent numerical values in binary, where each bit is one binary digit. An AVR microcontroller groups 8 bits together to form one byte wtih the Least Significant Bit (LSB) on the right. Each bit is numbered, starting from 0, at the LSB.

Consider the decimal number 15 for example. 15 represented in 8-bit binary is 00001111. The 4 least significant bits 0, 1, 2, and 3, are setavrbits.

Another example, the decimal number 40 is represented in binary as 00101000. Bits 3 and 5 are set.

Bits in a byte containing decimal value 40
Figure 3.2 – The decimal number 40 represented in 8 bits

Numerical values in a C program for an AVR microcontroller may be defined using a decimal, hexadecimal, or binary notation depending on the context and the programmer’s preference. A hexadecmial number is defined using the 0x prefix and a binary number is defined using the 0b prefix.

The following C code shows 3 ways in which a variable might be initialized to the decimal value of 15.

uint8_t a = 15;         /* decimal */
uint8_t b = 0x0F;       /* hexidecimal */
uint8_t c = 0b00001111; /* binary */


The uint8_t data type is one of the fixed width integer types from the C99 standard. It defines an 8-bit unsigned integer. The C99 style data types will be used throughout this tutorial series.

That’s all for this episode.

Happy Robotics: 😛 😛 😛

By the way I have my own blog now. I am going to start it with some tricks and hacks of programming and technology. If you wish to visit there please click here. Or visit blog.techiehunter.org


About Author


I am a free learner like to fly in the whole cyber world to gather knowledge. And I know I have only a little to share but I will try my best to give you what I have. :) Thank you :)

Comments are closed.