1. Description of ATmega 128 microcontroller
ATmega 128 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture (see figure 1). By executing powerful instructions in a single clock cycle, the ATmega 128 achieves throughputs approaching 1 MIPS per 1 MHz for the maximum frequency 16MHz that means 16 MIPS.
Having 133 instructions and most of them executed in one clock cycle, the processor can control until 53 input/output lines, 4 kBytes SRAM memory that include 32 x 8 bits registers, 4 kBytes EEPROM memory and 128 kBytes program flash memory.
A lot of peripheral devices are included on chip, such as: 2 timers at 8 bit each with prescalers and other 2 timer/counters 16 bits each that accept a large variety of programming modes. An analogue to digital converter is implemented on chip with 8 inputs that are multiplexed.
The microcontroller includes two USART (Universal Synchronous and Asynchronous Receive Transmit) units, one SPI (Serial Peripheral Interface) unit and the other TWI (Two Wire Interface), unit that allows implementation of a wide kind of possibilities for serial communication between the microcontroller and external systems.
A lot of possibilities are allowed to preset the system clock, such as: internal clock based on RC calibrated oscillator, external RC oscillator, and external crystal stabilized oscillator. The clock signal can be divided by software in a wide range of modes.
A large variety of power saving modes could be programmed in order to choose the optimal saving mode.
The direction of signal can be set for all the input/output lines (input / output 20mA /each line). If the port is programmed as a special peripheral unit (USART, timer, etc) this programming has priority.
Interrupt sources are defined for all the peripheral devices that are treated separately using interrupt vectors.
Programming language includes instructions that implement the transfer of data from/to internal and external memory, transfer of data from/to input and output ports, using direct/indirect-addressing modes, decision instructions.
This allows to redirect the running of the program (logical and mathematical), functions of a bit or byte value, repeating instructions (loops without or with test applied in advance or at the end of loop) and arithmetical operations: addition, subtract, multiply and division. By using data transfer instructions the user can configure all the ports in a wide variety of modes, including also the internal memory and the mapping of registers in it.

Figure 1. Structure of ATmega 128 microcontroller