The ATmega328P is an 8-bit AVR microcontroller widely used in embedded systems, electronics projects, and Arduino-based applications. It is the main microcontroller used on the popular Arduino Uno board. It combines a CPU, program memory, data memory, input/output ports, timers, communication interfaces, and analog peripherals in a single chip. Understanding the ATmega328P block diagram helps students learn how these internal components communicate and work together. It is also an important topic for ECE and EEE students studying microcontrollers, embedded C programming, and embedded system design. In this article, we will explore the ATmega328P internal block diagram, its architecture, memory organization, pin diagram, peripheral functions, working principle, and commonly used ATmega328P assembly instructions.
ATmega328P is an 8-bit microcontroller developed by Atmel, now part of Microchip Technology. It is based on the AVR enhanced RISC architecture and uses a Harvard architecture, which separates program memory and data memory.
The microcontroller can execute instructions, process sensor inputs, control electronic devices and communicate with external components through its built-in peripherals.
| Specification | Details |
| Microcontroller family | AVR |
| Architecture | 8-bit RISC |
| Operating voltage | 1.8V–5.5V |
| Maximum CPU clock frequency | 20 MHz |
| Flash memory | 32 KB |
| SRAM | 2 KB |
| EEPROM | 1 KB |
| General-purpose I/O | 23 programmable lines |
| Timers/Counters | Two 8-bit and one 16-bit |
| ADC | 10-bit |
| Communication interfaces | USART, SPI, TWI (I2C-compatible) |
| Watchdog timer | Yes |
| Package options | 28-pin and 32-pin variants |
These specifications make ATmega328P suitable for small embedded applications that require processing, timing, analog measurement and communication capabilities.
The ATmega328P block diagram represents the internal functional units of the microcontroller and explains how they are connected through internal buses.
The major blocks include:
The diagram can be understood by dividing the microcontroller into five main sections: processing unit, memory, input/output, communication peripherals, and timing and control circuits.
The CPU is the central processing unit of the ATmega328P. It controls the execution of instructions stored in program memory and manages communication between the memory and peripheral devices.
The AVR CPU contains:
The CPU fetches instructions, decodes them and executes the required operations.
For example, when a program reads a sensor value and compares it with a predefined threshold, the CPU performs the necessary operations and controls the output accordingly.
Flash memory stores the program or instructions that the microcontroller executes.
ATmega328P contains 32 KB of in-system programmable Flash memory. It is non-volatile, which means the stored program remains available even when the power supply is disconnected.
The microcontroller retrieves instructions from Flash memory during program execution.
For example, an Arduino program uploaded to an Arduino Uno is stored in the ATmega328P’s Flash memory.
SRAM is the temporary working memory of the microcontroller. It stores variables, temporary data and the stack while a program is running.
ATmega328P contains 2 KB of SRAM. Unlike Flash memory, SRAM is volatile. Its contents are lost when the power supply is turned off.
For example, when a program reads a temperature sensor value, the measured value can be temporarily stored in SRAM for further processing.
EEPROM is non-volatile memory used to store data that must remain available even after the microcontroller is powered off.
ATmega328P contains 1 KB of EEPROM. It is useful for storing:
For example, an electronic device can store its last selected operating mode in EEPROM and retrieve it after restarting.
The ALU performs arithmetic and logical operations required by the CPU.
Its operations include:
The ALU works with the general-purpose registers to process data.
For example, if a program needs to compare two sensor readings, the ALU performs the required comparison operation and updates the status flags.
ATmega328P has 32 general-purpose 8-bit working registers, named R0 to R31. These registers are directly connected to the ALU and are used to store operands and intermediate results during program execution.
For example, an assembly instruction can load a constant into a register:
LDI R16, 25
This instruction loads the value 25 into register R16. The general-purpose registers help the CPU perform operations efficiently without repeatedly accessing SRAM.
The ATmega328P provides 23 programmable general-purpose I/O lines divided into three ports:
These ports allow the microcontroller to interact with external electronic components. They can be configured as inputs or outputs depending on application requirements.
Examples include:
Each port has associated registers for controlling its direction, output value and input reading.
Timers and counters are used to measure time intervals, generate delays, count external events and produce PWM signals.
ATmega328P contains three timer/counter units:
| Timer | Resolution | Common Applications |
| Timer 0 | 8-bit | Timing and PWM generation |
| Timer 1 | 16-bit | Accurate timing, input capture and PWM |
| Timer 2 | 8-bit | Timing and PWM generation |
Timers can operate using the internal clock or supported external clock sources.
For example, a timer can generate a periodic interrupt to perform an operation at regular intervals without continuously checking the time in the main program.
The ADC converts analog input signals into digital values that the CPU can process.
ATmega328P has a 10-bit ADC. In the common 28-pin DIP package, it provides six ADC input channels. The 32-pin TQFP and QFN/MLF packages provide eight ADC channels. A 10-bit ADC produces digital values from 0 to 1023.
For example, a temperature sensor may produce an analog voltage. The ADC converts that voltage into a digital value, which the CPU can use to calculate or display the temperature.
USART stands for Universal Synchronous and Asynchronous Serial Receiver and Transmitter. It enables serial communication between the ATmega328P and external devices.
Common applications include:
The USART uses the RXD and TXD pins for receiving and transmitting data in asynchronous mode.
SPI stands for Serial Peripheral Interface. It is a synchronous serial communication protocol used to exchange data between a microcontroller and peripheral devices.
The main SPI signals are:
SPI is commonly used to interface with memory devices, displays, sensors and other SPI-compatible peripherals.
TWI stands for Two-Wire Interface. It is compatible with the I2C communication protocol.
It uses two main signal lines:
TWI allows the microcontroller to communicate with multiple compatible devices using a shared two-wire bus.
For example, an ATmega328P can communicate with an I2C-based LCD module or sensor using the SDA and SCL lines.
An interrupt is a signal that temporarily changes the normal program execution flow so that the CPU can respond to an event. ATmega328P supports external and internal interrupt sources.
Examples include:
When an enabled interrupt occurs, the CPU executes the corresponding Interrupt Service Routine (ISR) and then returns to the previous program flow.
Interrupts are useful when an application must respond quickly to an event without continuously polling the device.
The watchdog timer is a safety mechanism that helps recover from certain software failures.
The program periodically resets the watchdog timer. If the program becomes stuck and fails to reset it within the configured time, the watchdog can generate a system reset.
This feature is useful in embedded products that need reliable operation with minimal human intervention.
The clock circuit provides the timing reference required for CPU and peripheral operation. ATmega328P supports internal clock sources and external clock arrangements, depending on configuration.
The RESET pin is used to restart the microcontroller. The reset circuitry initializes the device and begins program execution from the reset vector.
The clock and reset circuits are essential for correct and controlled microcontroller operation.
The ATmega328P microcontroller architecture is based on an 8-bit AVR RISC processor and follows the Harvard architecture.
In Harvard architecture, program memory and data memory are separated. This allows the CPU to fetch instructions from Flash memory while accessing data through the data memory system.
The AVR architecture also uses instruction pipelining. While one instruction is being executed, the next instruction can be fetched. This helps improve instruction throughput.
The basic working process can be understood through the following steps:
Consider a simple application in which an LED is connected to digital pin PB5. The microcontroller can perform the following operations:
This example demonstrates how the CPU, Flash memory, I/O ports, clock circuit and program instructions work together in a practical embedded application.
The ATmega328P pin diagram shows the physical pins available for power, ground, clock, reset, analog inputs, digital inputs and outputs, and communication interfaces.
The microcontroller is available in different package options. The following pin details refer to the commonly used 28-pin DIP package.
| Pin Number | Pin Name | Function |
| 1 | PC6 / RESET | Reset input |
| 2 | PD0 / RXD | USART receive |
| 3 | PD1 / TXD | USART transmit |
| 4 | PD2 / INT0 | External interrupt 0 |
| 5 | PD3 / INT1 | External interrupt 1, PWM |
| 6 | PD4 | Digital I/O |
| 7 | VCC | Digital power supply |
| 8 | GND | Ground |
| 9 | PB6 / XTAL1 | Crystal oscillator input |
| 10 | PB7 / XTAL2 | Crystal oscillator output |
| 11 | PD5 | Digital I/O, PWM |
| 12 | PD6 | Digital I/O, PWM |
| 13 | PD7 | Digital I/O |
| 14 | PB0 | Digital I/O |
| 15 | PB1 | Digital I/O, PWM |
| 16 | PB2 / SS | SPI slave select |
| 17 | PB3 / MOSI | SPI data output |
| 18 | PB4 / MISO | SPI data input |
| 19 | PB5 / SCK | SPI clock |
| 20 | AVCC | Analog supply voltage |
| 21 | AREF | ADC reference input |
| 22 | GND | Ground |
| 23 | PC0 / ADC0 | Analog input 0 |
| 24 | PC1 / ADC1 | Analog input 1 |
| 25 | PC2 / ADC2 | Analog input 2 |
| 26 | PC3 / ADC3 | Analog input 3 |
| 27 | PC4 / ADC4 / SDA | Analog input 4, TWI data |
| 28 | PC5 / ADC5 / SCL | Analog input 5, TWI clock |
Important: The 32-pin TQFP and QFN/MLF package versions include additional ADC6 and ADC7 inputs. These are not available as general-purpose digital I/O pins. Always check the pinout for the exact package before designing a circuit.
Memory organization is an important part of ATmega328P microcontroller architecture. The microcontroller uses three main types of memory.
| Memory Type | Capacity | Purpose |
| Flash | 32 KB | Stores program instructions |
| SRAM | 2 KB | Stores temporary variables and runtime data |
| EEPROM | 1 KB | Stores non-volatile application data |
Flash memory stores the application program. It is non-volatile and can be programmed through supported programming methods.
SRAM is used during program execution. It stores variables, temporary data and the stack.
EEPROM is useful when data must be retained even after power is removed. It is commonly used for configuration values and calibration information.
Understanding the difference between these three memory types is important when writing embedded C programs and designing memory-efficient applications.
ATmega328P uses the AVR instruction set, which contains instructions for data transfer, arithmetic, logical operations, branching and bit manipulation.
Assembly language allows programmers to control the microcontroller at a lower level compared with high-level languages such as C. The following are commonly used ATmega328P assembly instructions.
These instructions move data between registers, memory and I/O locations.
| Instruction | Function |
| MOV | Copies data from one register to another |
| LDI | Loads an immediate value into a register |
| LDS | Loads data directly from data memory |
| STS | Stores data directly into data memory |
| LD | Loads data indirectly using a pointer register |
| ST | Stores data indirectly using a pointer register |
| PUSH | Pushes a register value onto the stack |
| POP | Retrieves a value from the stack |
Example: LDI R16, 10 — this instruction loads the value 10 into register R16.
Arithmetic instructions perform mathematical operations.
| Instruction | Function |
| ADD | Addition |
| ADC | Addition with carry |
| SUB | Subtraction |
| SBC | Subtraction with carry |
| INC | Increment by one |
| DEC | Decrement by one |
| MUL | Multiplication |
| NEG | Two’s complement negation |
Example: ADD R16, R17 — this instruction adds the contents of R17 to R16 and stores the result in R16.
Logical instructions perform bitwise operations on register data.
| Instruction | Function |
| AND | Bitwise AND |
| OR | Bitwise OR |
| EOR | Exclusive OR |
| COM | One’s complement |
| CLR | Clears a register |
| TST | Tests a register |
| LSL | Logical shift left |
| LSR | Logical shift right |
Example: AND R16, R17 — this instruction performs a bitwise AND operation between R16 and R17.
These instructions change the normal program execution sequence.
| Instruction | Function |
| RJMP | Relative jump |
| JMP | Absolute jump |
| RCALL | Relative subroutine call |
| CALL | Absolute subroutine call |
| RET | Returns from a subroutine |
| RETI | Returns from an interrupt routine |
| BRNE | Branch if not equal |
| BREQ | Branch if equal |
Example: RJMP LOOP — this instruction transfers program execution to the label LOOP.
Bit manipulation is important when controlling individual hardware pins and peripheral registers.
| Instruction | Function |
| SBI | Sets a bit in an I/O register |
| CBI | Clears a bit in an I/O register |
| SBIS | Skips the next instruction if a bit is set |
| SBIC | Skips the next instruction if a bit is clear |
| BST | Stores a bit in the T flag |
| BLD | Loads a bit from the T flag |
Example: SBI PORTB, 5 — this instruction sets bit 5 of PORTB, making PB5 HIGH when configured as an output.
The following AVR assembly example configures PB5 as an output and turns it ON.
LDI R16, 0x20 OUT DDRB, R16 SBI PORTB, 5 LOOP: RJMP LOOP
Explanation:
LDI R16, 0x20 loads the bit pattern for bit 5 into R16.OUT DDRB, R16 configures PB5 as an output.SBI PORTB, 5 sets PB5 HIGH.RJMP LOOP keeps the program running in a continuous loop.A suitable current-limiting resistor must be connected in series with the LED. The example demonstrates basic AVR register control; it does not include a blinking delay.
ATmega328P is used in several educational, prototyping and embedded control applications.
Some common applications include:
The ATmega328P block diagram provides a clear understanding of how the CPU, memory, I/O ports, timers, ADC, communication interfaces and control circuits work together inside an 8-bit microcontroller.
Learning its internal architecture, pin configuration, memory organization and assembly instructions gives students a strong foundation in microcontroller programming and embedded system development.
For students who want to move beyond theoretical concepts, practical experience with microcontrollers, embedded C, peripheral interfacing and real-time hardware projects is essential. At the Indian Institute of Embedded Systems (IIES), Bangalore, students can develop these skills through practical embedded systems training and hands-on microcontroller projects.
Explore the Embedded Systems Course with Placement to build a strong foundation in microcontrollers, Embedded C and real-time project development.
ATmega328P is an 8-bit AVR RISC-based microcontroller that uses Harvard architecture, with separate program and data memory spaces.
ATmega328P has 32 KB of Flash program memory.
It has 2 KB of SRAM and 1 KB of EEPROM.
ATmega328P provides 23 programmable general-purpose I/O lines across PORTB, PORTC, and PORTD.
The ADC has a 10-bit resolution and produces values from 0 to 1023.
Indian Institute of Embedded Systems – IIES