Module 2 Avr Atmega32 Architecture3
Module 2 Avr Atmega32 Architecture3
•ATMEGA 32
20102011-I 1
Processor Architecture & Organization
• Architecture
– attributes of a system visible to a programmer
– these attributes have a direct impact on the logical
execution of a program
• Classic AVR
• e.g. AT90S2313, AT90S4433
• Mega
• e.g. ATmega8, ATmega32, ATmega128
• Tiny
• e.g. ATtiny13, ATtiny25
• Special Purpose AVR
• e.g. AT90PWM216,AT90USB1287
Let’s get familiar with the AVR part numbers
ATmega128
Atmel group
Flash =128K
ATtiny44 AT90S4433
Atmel
Tiny Flash =4K Atmel Classic
Flash =4K
group group
ClearsPort
all theB Port A
registers supply
Provides and
restart
voltage to the
the chip. Reference voltage
These pins are
execution
It should of
be for ADC
Supply voltage for
used to connect
program
connected to +5 ADC and portA.
external crystal or
Connect it to VCC
RC oscillator
Port C
Port D
Mega32/Mega16
(XCK/T0) PB0 PA0 (ADC0)
(T1) PB1 PA1 (ADC1)
(INT2/AIN0) PB2 PA2 (ADC2)
(OC0/AIN1) PB3 PA3 (ADC3)
(SS) PB4 PA4 (ADC4)
(MOSI) PB5 PA5 (ADC5)
(MISO) PB6 PA6 (ADC6)
(SCK) PB7 PA7 (ADC7)
PINA
PORTB
DDRB
PINB
RESET DDRA AREF
PORTA
VCC AGND
PORTC
GND DDRC AVCC
PINC
XTAL2 PC7 (TOSC2)
XTAL1 PC6 (TOSC1)
(RXD) PD0 PC5 (TDI)
(TXD) PD1 PC4 (TDO)
(INT0) PD2 PC3 (TMS)
(INT1) PD3 PC2 (TCK)
(OC1B) PD4 PC1 (SDA)
(OC1A) PD5 PC0 (SCL)
(ICP) PD6 PD7 (OC2)
vcc
1 = Close
PORTx.n 0 = Open
pin n of
port x PINx.n
DDRx
DDRx.n 0 1
PORTx
PORTx.n high impedance Out 0
0
1 pull-up Out 1
PINx.n
2. 1KB EEPROM
– For persistent data storage
– Memory contents are retained
when power is off (non-volatile)
– Fast read; slow write
– Can write individual bytes
• The I/O memory is dedicated to specific Address Name Address Name Address Name
I/O Mem. I/O Mem. I/O Mem.
functions such as status register, timers, $00 $20 TWBR $16 $36 PINB $2B $4B OCR1AH
serial communication, I/O ports, ADC and $01 $21 TWSR $17 $37 DDRB $2C $4C TCNT1L
etc. $02 $22 TWAR $18 $38 PORTB $2D $4D TCNT1H
$03 $23 TWDR $19 $39 PINA $2E $4E TCCR1B
$04 $24 ADCL $1A $3A DDRA $2F $4F TCCR1A
• Function of each I/O memory location is $05 $25 ADCH $1B $3B PORTA $30 $50 SFIOR
fixed by the CPU designer at the time of $06 $26 ADCSRA $1C $3C EECR OCDR
$31 $51
design. (because it is used for control of $07 $27 ADMUX $1D $3D EEDR OSCCAL
$08 $28 ACSR $1E $3E EEARL
the microcontroller and peripherals) $32 $52 TCNT0
$09 $29 UBRRL $1F $3F EEARH $33 $53 TCCR0
$0A $2A UCSRB UBRRC
• AVR I/O memory is made of 8 bit $0B $2B UCSRA
$20 $40
$34 $54 MCUCSR
UBRRH $35 $55 MCUCR
registers. $0C $2C UDR $21 $41 WDTCR $36 $56 TWCR
$0D $2D SPCR $22 $42 ASSR $37 $57 SPMCR
• All of the AVRs have at least 64 bytes of $0E $2E SPSR $23 $43 OCR2 $38 $58 TIFR
I/O memory location. (This 64 bytes $0F $2F SPDR $24 $44 TCNT2 $39 $59 TIMSK
$10 $30 PIND $25 $45 TCCR2 $3A $5A GIFR
section is called standard I/O memory) $11 $31 DDRD $26 $46 ICR1L $3B $5B GICR
$12 $32 PORTD $27 $47 ICR1H $3C $5C OCR0
• In other microcontrollers, the I/O $13 $33 PINC $28 $48 OCR1BL $3D $5D SPL
registers are called SFRs (Special Function $14 $34 DDRC $29 $49 OCR1BH $3E $5E SPH
Registers) $15 $35 PORTC $2A $4A OCR1AL $3E $5E SREG
...
LDI LDI LDI 0x38
LDI
R16, R20, 0x9C
R20,
R20, 0x9C
0xA5
0x52
;R16 = 0x38 Registers
R0 $001F IO Address
ALU LDI LDI 0x2F
LDI
LDI
R17, R21,
R21,
R21, 0x9C
0x23
0x73
R1 0x64
;R17 = 0x2F
$0020 TWBR $00
TWSR $01
R2 StandardR21
IO from
ADD SUB R17R20,
SUB
ADD
R16, R20, R21
R20, R21;add R17;add
R21 ;subtract
;subtract
to R16R21 toR21 R20from R20
R20
...
...
…
Registers
SPH $3E
SREG: I T H S V N Z C
Solution:
Solution:
Solution: R15
$005F SREG $3F
Solution: 11
CPU $52
$9C
$A5
$38
$9C
- $23
$73
0101
R16 0010
1001
1010
0011
1001
0111
1100
0101
1000
1100
R17 0011
$0060
General
purpose
...
+-- +$64
$9C
$2F 10010100
0010
0110 1100
0011
1111 RAM
$DF 1101 1111 R20 = $DF
…
PC $00
$82 0000
1000
$67R211is0000 0000
0010
0110 0111 R20
R20 = $00
R16is==a00
$82
0x67
$100
C = 1 because bigger0000 R20
than R20 and there
(SRAM)
borrow from D8 bit.
C
CC===100because
becausethere
because R21 is
R21 is not
isnot bigger
bigger
a R30
carry than R20
than
beyond R20 andbit.
and
the D7 there is
there is no
no borrow
borrow from
from D8
D8 bit.
bit.
Z
C == 00 because
because the
thereR20
is has
no a value
carry otherthe
beyond than
D7zero after the subtraction.
Instruction
HZZ =
== 1 decoder
01 because
because there
because the R20
the R20 iscarry
is ahaszero after
a value
from the D3
other
the 0 bit.
subtraction.
than
to theafter the subtraction.
D4 bit.
H = 1 because there is a R31 borrow
carry from
from D4D3
the totoD3.
the D4 bit.
H
ZH===100 because
because
because
Instruction Register
there
there
the R20 is
is no
no
(the borrow
borrow
result) from
from
has a D4
D4 to
to
value D3.
D3.
0 in it after the addition.
Z = 0 because the R16 (the result) has a value other
registers than 0 after the addition.
$FFFF