Professional Documents
Culture Documents
Introduction To Avr Atmega32 Architecture: Plastic Case Chip
Introduction To Avr Atmega32 Architecture: Plastic Case Chip
Introduction to AVR
ATMega32 Architecture
Plastic
Chip case
Pins
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
Harvard architecture
Code Data
Memory Memory
Data bus
CPU Address bus
Control bus
• RISC vs. CISC is a topic quite popular on the Net. Every time Intel (CISC) or Apple (RISC) introduces a
new CPU, the topic pops up again.
• Most PC's use CPU based on CISC architecture. For instance Intel and AMD CPU's are based on CISC
architectures.
• Many claim that RICS is the architecture of the future.
• But even though RISC has been in the market since 1980, it hasn’t managed to kick CISC out of the
picture, some argue that if it is really the architecture of the future it should have been able to do
this by now.
20112012-I Module 2/8
AVR different groups
• 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
registers supply
Provides and
Port A
restart the
voltage to the Reference voltage
These
chip. Itpins
execution are
of be
should 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
0 high impedance Out 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
• Each location is 8 bit wide and can be used to store any data we
want.
...
LDI R20,
LDI
LDI
LDI R20, 0x9C
R20,
R16, 0x9C
0xA5
0x52 ;R16 = 0x38
0x38 Registers
R0 $001F IO Address
ALU LDI R21,
LDI
LDI
LDI R21, 0x64
R21,
R17, 0x9C
0x23
0x73 R1;R17 = 0x2F
0x2F $0020 TWBR $00
TWSR $01
R2 Standard
SUB R20,
SUB
ADD
ADD R20, R21
R20,
R16, R21
R21
R17 ;subtract
;subtract
;add
;add R21
R17 toR21
R21
to from
from
R20
R16 R20 IO
R20
...
...
…
Registers
SPH
SREG: I T H S V N Z C $3E
Solution:
Solution:
Solution:
$005F SREG $3F
CPU
Solution: R15
11 $0060
$520101
$9C
$A5 0010
1100 R16
10011100
1010 0101
$380011
$9C 1001 1000 General
- $730111 0011
R17 purpose
+-- +$64
$9C
$23 10010100
0010 1100
0011
...
$2F0010
0110 1111 RAM
PC$DF 1101 1111 R20 =
== $DF
…
$00
$82 0000
1000
$67 0000
0010
0110 R20
R20
0111 R16$00
$82
= 0x67
C = 1 because R21 is bigger than R20 R20
$100 1 0000 0000 = 00is a borrow from D8 bit.
(SRAM)
and there
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.
ZC == 00 because
Instruction because
decoder the
thereR20
is has
no a value
carry otherthe
beyond than
D7zero
bit. after the subtraction.
HZZ =
== 1
01 because
because there
because the R20
the R20 iscarry
is ahaszero after
a value
from the D3
other
the subtraction.
than 0 after
to the the subtraction.
D4 bit.
H = 1 because there is aR31 borrow
carry from
from D4D3
the totoD3.
the D4 bit.
H
ZH===100because
becausethe
because there
there
R20 is(the
is no
no borrow
borrow from
from D4
D4 to D3.
to D3.
Instruction Register
Z = 0 because the R16 (the result) has a value 0other
registers
result) has a value in it after
than 0the addition.
after the addition.
$FFFF