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.
Another example, the decimal number
40 is represented in binary as
00101000. Bits 3 and 5 are set.
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
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 */
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: 😛 😛 😛