1. Intoduction to AVR Microcontrollers and ATmega328P
1. Intoduction to AVR Microcontrollers and ATmega328P
1
Introduction
• A microcontroller or MCU (micro controller unit) is a computer in chip, i.e., all the
different parts of a computer (CPU, RAM, ROM and I/O ports) are put in a single
chip
• A microcontroller is used to create an embedded system (e.g., a garage door
opener), where the software application and hardware are embedded together
and designed to do a specific task
• Some microcontrollers are: 8-bit – 8051 (Intel), AVR (formerly Atmel, now
Microchip), PIC16 and PIC18 (Microchip) and 64HCS08 (NXP); 16-bit – PIC24 and
dsPIC (Microchip), HCS12 (NXP/Freescale) and MSP430 (TI); 32-bit – ARM,
AVR32,ColdFire (Freescale), MIPS32, PIC32 and etc.
• A microcontroller is chosen based on: (i) chip characteristics: speed, packaging
(for space on PCB), power consumption, amount of RAM and ROM on chip,
peripherals, number of I/O pins and timers on the chip, ease of upgrade, price (ii)
ease of development: how easy it is to develop products around it, and (iii)
availability: ready availability in needed quantities both now and in future
2
Overview of the AVR Family
• The AVR stands for Advanced Virtual RISC
• Except for AVR32, AVRs are all 8-bit microcontrollers, i.e., they can work only on
8-bits of data at a time (data longer than 8 bits must be broken down into 8-bit
pieces)
• The AVR is a RISC microcontroller with Harvard architecture (i.e., separate
program/code memory from data memory)
• The AVR comes with on-chip program/code ROM, data RAM, data EEPROM,
timers, I/O ports and so on, as shown in Figure 1
• Most AVRs have some additional features (other peripherals) like ADC, PWM and
different kinds of serial interfaces like USART, SPI, I2C (TWI), CAN, USB and so on
• AVRs are classified into five groups: Mega, Xmega, Tiny, Special Purpose and
Classic
• In this subject, we will deal with the Mega family, specifically the ATMega328P,
since it is widely available, has dual inline package (DIP) and has a low-cost trainer
board (Arduino UNO)
3
RAM EEPROM Timers
CPU
PROGRAM BUS
Interrupt Other
OSC Ports
Unit Peripherals
I/O PINS
Figure 1. View of AVR Microcontroller 4
Program ROM
• Program ROM is used to store program or code, hence, program ROM
• The AVR has a maximum of 8M bytes of program (code) ROM, but not all family
members come with that much ROM
• The ATmega328P has 32K (1K = 1024) of code ROM space
• The AVR uses flash program memory – erasable in seconds and reprogrammable
for fast development
I/O Pins
• The AVR can have 3 to 86 pins for input/output (I/O)
• The 28-pin ATmega328P has 23 pins for I/O
Peripherals
• Most AVRs come with an ADC (analogue-to-digital converter), timers, USART
(Universal Asynchronous Receiver Transmitter) as standard peripherals
• The ATmega328P has a 6 channel 10-bit ADC (DIP), 3 timers, internal and external
interrupts, one USART, a byte-oriented 2-wire Serial Interface (I2C) and an SPI
serial port
6