EEE/ECE 365
Microprocessor
Lecture #2
AVR microcontroller : ATmega32
and Proteus & CodeVisionAVR
Slide Courtesy of Imtiaz Ahmed, Lecturer, Dept. of EEE
Brac University
Introduction to Atmel AVR
• Atmel Corporation is a manufacturer of semiconductors, founded in
1984.
• Atmel introduced the first 8-bit flash microcontroller in 1993, based on
the 8051 core.
• In 1996, a design office was started in Trondheim, Norway, to work on
the AVR series of products.
• Its products include microcontrollers (including 8051 derivatives and
AT91SAM and AT91CAP ARM-based micros), and its own Atmel AVR and
AVR32 architectures.
2
AVR features
• They come with some standard features
– Program (code) ROM
– Data RAM
– Data EEPROM
– Timers
– I/O ports
• Most AVRs have some additional features like
– ADC, PWM
– Different Serial Interface such as USART, SPI, I2C (TWI)
– CAN, USB, etc.
3
Layout of a General AVR uC
• The figure below gives the basic layout of a general AVR
microcontroller.
4
Microcontroller Components/ Peripherals
• Processor - The processor refers to the
– Central Processing Unit (CPU) of the microcontroller.
– It contains the Arithmetic Logic Unit (ALU),
– Control Unit,
– Instruction Decoder and
– Some Special Registers (Stack Pointer, Status Register, Program
Counter, etc.).
• Volatile Memory - This is memory used by the microcontroller for
– temporary data storage,
– system setup and peripherals configurations.
– Memory in this category includes SRAM and DRAM.
– AVR microcontrollers utilize SRAM.
5
Microcontroller Components/ Peripherals
(contd.)
• Non-Volatile Memory - is used by the microcontroller
– to store programs.
– sometime to store data in this memory, the access time is much slower
than that of RAM.
– category includes ROM, PROM, EPROM, EEPROM and FLASH.
– AVR microcontrollers utilize Flash for program storage,
– some AVR controllers contains a bit of EEPROM as well.
• Timer Module - Timer/Counter modules are used
– to perform timing or
– for counting operations in the controller.
– for time stamping,
– for measuring intervals,
– for counting events, etc.
6
Microcontroller Components/ Peripherals
(contd.)
• Interrupt Module - Interrupts enable the microcontroller
– to monitor certain events in the background while executing
application program and
– to react to the event if necessary pausing the original program.
– all are coordinated by the interrupt module.
• Digital I/O Module - This module allows
– digital/logic communication with the microcontroller and the
external world.
– Communication signals are that of TTL or CMOS logic.
7
Microcontroller Components/ Peripherals
(contd.)
• Analog I/O Modules - These modules are used
– to input/output analog information from/to the external world.
– Analog modules include
• Analog Comparators and
• Analog-to-Digital Converters.
• Serial Modules - These modules are used
– for serial communication with the external world.
– An example is the USART peripheral which utilizes the RS232
standard.
8
ATMega32 Programmer Model: Memory
1. 2KB SRAM
– For temporary data storage
– Memory is lost when power is shut off (volatile)
– Fast read and write
2. 1KB EEPROM
– For persistent data storage
– Memory contents retain when power is off (non-volatile)
– Fast read; slow write
– Can write individual byte
3. 32KB Flash Program Memory
– Used to store program code
– Memory contents retain when power is off (non-volatile)
– Fast to read; slow to write
– Can only write entire “blocks” of memory at a time
– Organized in 16-bit words (16KWords)
9
ATMega32 Programmer Model: Data Memory
EEPROM
• ATmega32 contains 1024 bytes of data EEPROM memory.
• It is organized as a separate data space, in which single bytes can be
read and written.
• The EEPROM has an endurance of at least 100,000 write/erase cycles.
• Different chip have different size of EEPROM memory
Chip Bytes Chip Bytes Chip Bytes
ATmega8 512 ATmega16 512 ATmega32 1024
ATmega64 2048 ATmega128 4096 ATmega256RZ 4096
ATmega640 4096 ATmega1280 4096 ATmega2560 4096
10
ATMega32 Programmer Model: Data Memory
The data memory is composed of three parts:
• GPRs (general
purpose registers),
• Special Function
Registers (SFRs), and
• Internal data SRAM.
11
ATMega32 Programmer Model: I/O
Registers (SFRs)
• The I/O memory is dedicated to specific functions such as status register,
timers, serial communication, I/O ports, ADC etc.
• Function of each I/O memory location is fixed by the CPU designer at the
time of design. (because it is used for control of the microcontroller and
peripherals)
• AVR I/O memory is made of 8 bit registers.
• All of the AVRs have at least 64 bytes of I/O memory location. (This
section is called standard I/O memory)
• In other microcontrollers, the I/O registers are called SFRs (Special
Function Registers)
12
ATMega32 Programmer Model: I/O Registers
(SFRs)
13
ATMega32 Pin out & Descriptions
Clears all
the registers
and restart
the
Port A
Port B
execution of Reference
program voltage for
Provides supply ADC
voltage to the Supply voltage for
chip. It should be ADC and port A.
connected to +5 Connect it to VCC
Port C
Port D
These pins are
used to connect
external crystal
or RC oscillator 14
Use of CodeVisionAVR
Step 1: Start the Software
15
Use of CodeVisionAVR (continued)
• Step 2: Choose File, then New and finally Project
🞆 Step 3: Choose “No” on the following prompt
16
Use of CodeVisionAVR (continued)
o Step 4: You will be asked to enter a
file number
🞆 Step 5: When you choose a file
name in your chosen directory,
you will be asked to choose the
chip you are going to use. The
screen will look like as shown
in the picture
17
Use of CodeVisionAVR (continued)
• Step 6: Choose ATmega32
from the list since we will
be using ATmega32 chip
in this course. Once you
press “OK” button, the
following screen will
appear.
18
Use of CodeVisionAVR (continued)
• Step 7: When you press “”OK” button in the previous step, the
following page will appear.
19
Use of CodeVisionAVR (continued)
#include <mega32.h>
#include <delay.h>
void main(void)
{
DDRC=0xFF;
Step 8: Type the following in PORTC=0x00;
the code area while (1)
{
PORTC=~PORTC;
delay_ms(1000);
}
} 20
Use of CodeVisionAVR (continued)
• Step 9: Choose the build the project from the short cut menu as
shown below:
Choose the middle
one among
apparently similar
three symbols
🞆 Step 10: If your code is error free, it will say so and if it is not, error
will be shown in the bottom window. In that case correct them and
build the project and finally make it error free.
21
The generated .hex file
• Note that in the folder where you saved your “*.c” file, there will
be a folder called “Debug”
• If you click “Debug” folder there will “Exe” folder and in that folder
you will find an Intel hex file with the same name as the C file.
• Note down the path, it will be necessary for your Proteus design
file and for your Extreme Burner software.
22
Thanks
23