AVR
AVR
AVR
Microcontroller Basics
Contents
8-Bit and 16-bit Microcontroller Internal Block Diagram
CPU, ALU
Address bus, data bus, control signals
Working Registers, SFRs
Clock and Reset circuits
Stack and use of Stack Pointer, Program Counter
I/O Ports
Memory structure, Data Memory, Program Memory, and
Execution of Program
Power saving modes and its operation
Timing Diagram: Timing diagram for execution cycle
Different Addressing Modes
Interrupts priority, interrupt handling
Housekeeping during power on and power situations
Self check and recoveries
Reference
AVR ATmega32 Datasheet
The AVR Microcontroller and embedded
system, M. A. Mazidi, S. Naimi
Introduction to Atmel AVR
The AVR architecture was conceived by two students Alf-Egil Bogen
and Vegard Wollan at the Norwegian Institute of Technology (NTH).
The AVR was one of the first microcontroller families to use on-chip
flash memory for program storage, as opposed to one-time
programmable ROM, EPROM, or EEPROM used by other
microcontrollers at the time.
The AVR is a modified Harvard architecture machine where
program and data is stored in separate physical memory systems
that appear in different address spaces, but having the ability to
read data items from program memory using special instructions.
Emphasis on software
Application-specific AVR
megaAVRs with special features not found on the other
members of the AVR family, such as LCD
controller, USB controller, advanced PWM, CAN, etc.
ATmega128
Atmel group
Flash
=128K
ATtiny44 AT90S4433
Atmel
Tiny Flash =4K Atmel Classi
Flash =4K
group c
group
Port B Port A
Port C
Port D
Digital IO is the most fundamental mode of connecting a MCU to
external world. The interface is done using a PORT.
A port is the point where internal data from MCU chip comes out
or external data goes in.
They are present is form of PINs of the IC. Most of the PINs are
dedicated to this function and other pins are used for power supply,
clock source etc .
ATMega32 ports are named PORTA, PORTB, PORTC, and PORTD.
General Purpose IO Ports
Four 8 Bit IO Ports
Port A, B, Port C & Port D
Pins identified as PAx, PBx, PCx or PDx (x=0..7)
vcc
1 = Close
PORTx.n 0 = Open
pin n of
port x PINx.n
DDRx
0 1
PORTx
1 pull-up Out 1
The PINx register gets the reading from the input pins of the
MCU
Programming
Assign value 0x55 and 0xAA (alternatively after
specific delay) to the pin no. 33 to 40 of
Atmega32 (PDIP).
Instruction Format
e. g: Buzzer System
ATMega32 Architecture
Block Diagram of the AVR MCU Architecture
In order to maximize performance and parallelism, the
AVR uses a Harvard architecture with separate
memories and buses for program and data.
The AVR Stack Pointer is implemented as two 8-bit registers in the I/O
space.The number of bits actually used is implementation dependent.
The first 96 locations address the Register File and I/O Memory,
and the next 2048 locations address the internal data SRAM.
EEPROM Data Memory
The ATmega32 contains 1024 bytes of data EEPROM memory.
EEPROM does not lose its data when power is OFF, whereas
SRAM does.
So, the EEPROM is used for storing data that should rarely be
changed and should not be lost when the power is OFF ;
whereas the SRAM is used for storing data and parameters
that are changed frequently.
Programming (Instructions)
LDI Rd, K ; (LDI : Load Data Immediate)
Rd represents any general purpose register between R16 to
R31.
K represents immediate 8 bit value.
LDI instruction is not valid for R0 to R15.
ADD Rd, Rr ;
Answer :
IN Vs. LDS
Advantages
Disadvantage
AVR Status Register
eg.1
;
;
eg.2
;
;
Stack and Stack Pointer
The CPU needs Stack storage area because there are only
limited no. of registers.
Stack Pointer
PUSH Rr;
Rr can be any general purpose registers (R0 - R31)
PUSH R10;
Store R10 onto the stack and decrement SP.
Popping from the Stack
Popping the contents of the stack back into the given
register is the opposite process of pushing.
POP Rr;
Rr can be any general purpose registers (R0 - R31)
eg : POP R16;
Increment SP, and then load top of the stack to R16
eg : 0x 08 ; After Execution :
;
0x 5F ;
;
;
;
;
;
;
;
;
;
;
CALL instruction and the role of Stack
When the subroutine is called, the processor first
saves the address of the instruction just below the
CALL instruction on the stack (contains of PC), and
then transfers control to that subroutine.
;
;
;
;
;
;
;
;
;
;
Ans:
;
;
AVR Time Delay
Instruction cycle Time for the AVR
CPU takes certain amount of time to execute instruction, this
time is referred to as Machine cycle.
TCCR0 Register
The internal structure of ATmega32 Timer
TIFR (Timer/ Counter Interrupt Flag Register)
TOV0 (Timer0 Overflow)
The flag is set when the counter overflows, going from
0xFF to 0x00.
When the timer rolls over from 0xFF to 0x00, the TOV0
flag is set to 1 and remains set until the software clears
it.