The ATmega32 microcontroller has the following architecture:
The CPU components are shaded blue.
The memory components are shaded green.
The clock components are shaded in orange.
The I/O components are shaded in purple.
Native data size is 8 bits (1 byte).
Uses 16-bit data addressing allowing it to address 216 = 65536 unique addresses.
Has three separate on-chip memories
2KiB SRAM
8 bits wide
used to store data
1KiB EEPROM
32KiB Flash
I/O ports A-D
Digital input/output
Analog input
Serial/Parallel
Pulse accumulator
Before we get into the details, let's look at the programmers model to help motivate our desire to better understand the internals of the ATmega32 microcontroller.
Using high-level languages like C, C++, and Java require little, if any, knowledge of the CPU's internal configuration.
Assembly language requires knowledge of the internals of the CPU since we are operating at a lower level.
Machine language is the native language of the CPU
Consists only of 1's and 0's.
Is what we actually download to the controller's program memory.
Is stored in the .hex file generated by AVR studio.
Program hierarchy:
High-level language gets converted into assembly language by a compiler.
Assembly language gets converted into machine language by an assembler.
AVR Studio acts as our assembler for this course.
For CE2800, we will be writing programs in assembly language.
In CE2810 we will write programs/functions in C and use a GNU compiler to compile those programs/functions into assembly.
Program Counter fetches program instruction from memory
The PC stores a program memory address that contains the location of the next instruction.
The PC is initialized to 0x0 on reset/power up.
When the program begins, the PC must contain the address of the first instruction in the program.
Program instructions are stored in consecutive program memory locations.
The PC is automatically incremented after each instruction.
Note: There are jump instructions that can modify the PC (e.g., the PC must change when calling or returning from some other routine).
Places instruction in Instruction Register.
Instruction Decoder determines what the instruction is.
Arithmetic Logic Unit executes the instruction.
The CPU clock determines the timing of when instructions are fetched and executed:
There are 32 8 bit general purpose registers, R0-R31.
X, Y, and Z are 16 bit registers that overlap R26-R31.
Used as address pointers.
Or to contain values larger than 8 bits (i.e., >255).
Only register Z may be used for access to program memory.
Certain operations cannot be performed on the first 16 registers, R0-R15
CLR Rx does work on all registers.
Stack pointer (SP)
Status Register (SREG)
The address bus is 16 bits wide.
The data bus is 8 bits wide.
Program memory is stored on Flash from 0x0000 to 0x3FFF (F_END).
SRAM is used for:
32 General Purpose registers from 0x00 to 0x1F.
64 I/O ports from 0x20 to 0x5F.
User data from 0x60 to 0x85F (RAMEND).
Note: the bootloader uses the last 32 bytes of data memory, we will consider RAMEND-0x20 as the end of data RAM.
ROM for user data is stored on EEPROM.