AVR® - High Performance and Low Power RISC Architecture
•
118 Powerful Instructions - Most Single Clock Cycle Execution
•
2K bytes of In-System Reprogrammable Flash
– SPI Serial Interface for Program Downloading
– Endurance: 1,000 Write/Erase Cycles
•
128 bytes EEPROM
– Endurance: 100,000 Write/Erase Cycles
•
128 bytes Internal RAM
•
32 x 8 General Purpose Working Registers
•
15 Programmable I/O Lines
•
VCC: 2.7 - 6.0V
•
Fully Static Operation
– 0 - 10 MHz, 4.0 - 6.0V
– 0 - 4 MHz, 2.7 - 6.0V
•
Up to 10 MIPS Throughput at 10 MHz
•
One 8-Bit Timer/Counter with Separate Prescaler
•
One 16-Bit Timer/Counter with Separate Prescaler
and Compare and Capture Modes
•
Full Duplex UART
•
Selectable 8, 9 or 10 bit PWM
•
External and Internal Interrupt Sources
•
Programmable Watchdog Timer with On-Chip Oscillator
•
On-Chip Analog Comparator
•
Low Power Idle and Power Down Modes
•
Programming Lock for Software Security
•
20-Pin Device
8-Bit
Microcontr oller
with 2K bytes
In-System
Programmable
Flash
AT90S2313
Description
The AT90S2313 is a low-power CMOS 8-bit microcontroller based on the AVR
enhanced RISC architecture . By exe cuting powe rful instruc tions in a single clock
cycle, the AT90S2313 achieves throughpu ts approaching 1 MIPS per MHz allowing
the system designer to optimize power consumption versus processing speed.
The AVR core combines a rich instr uction set with 32 gene ral purpose working registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU),
allowing two indep endent r egisters to be acce ssed in one singl e instr uction execute d
in one clock cycle. Th e resulting arc hitecture is mor e code efficie nt while achievin g
throughputs up to ten times faster than conventional CISC microcontrollers.
(continued)
Pin Configuration
Rev. 0839DS–07/98
Note: This is a summary document. For the complete 68 page
datasheet, please visit our web site at
literature@atmel.com
mail at
and request literature #0839D.
www.atmel.com
or e-
1
Page 2
Block Diagram
Figure 1.
The AT90S2313 Block Diagram
The AT90S2313 provides the following features: 2K bytes
of In-System Programmable Flash, 128 bytes EEPROM,
128 bytes SRAM, 15 gen eral purpo se I/O li nes, 3 2 general
purpose working registers, flexible timer/counters with
compare modes, internal and external interrupts, a programmable serial UART, programmable Watchdog Timer
with internal oscillato r, an SPI serial port for Flash Memory
downloading and two software selectable power saving
modes. The Idle Mode stops the CPU while allowing the
SRAM, timer/counters, SPI port and interrupt system to
continue functioning. The power down mode saves the register contents but freezes the oscillator, disabling all other
chip functions until the next interrupt or hardware reset.
The device is manufac tured using Atmel’ s high density
non-volatile memory technology. The on-chip In-System
2
AT90S2313
Programmable Flash allows the program memory to be
reprogrammed in-sys tem th ro ugh an S PI se rial i nterface or
by a conventional n onvolatile memo ry programmer. By
combining an enhanced RISC 8-bit CPU wit h In-System
Programmable Flash on a monolithic chip, the Atmel
AT90S2313 is a powerful microcontroller that provides a
highly flexible and co st effect ive solution to many em bedded control applications.
The AT90S2313 AVR is supported with a full s uite of program and system development tools including: C compilers, macro assemblers, program debugger/si mulators, incircuit emulators, and evaluati on kits.
Page 3
AT90S2313
Pin Descriptions
VCC
Supply voltage pin.
GND
Ground pin.
Port B (PB7..PB0)
Port B is an 8-bit bi-directional I/O port. Port pins can provide internal pul l-up resist ors (se lected for ea ch bit). PB 0
and PB1 also se rve as the po sitive inpu t (AIN0) an d the
negative input ( AIN1), resp ectively , of the on-chi p analog
comparator. The Port B output buffers can sink 20mA and
can drive LED displays directly. When pins PB0 to PB7 are
used as inputs and are externally pulled low, they will
source current if the internal pull-up resistors are activated.
Port B also serves the fu nction s of vario us speci al feat ures
of the AT90S2313 as listed on page 38.
Port D (PD6..PD0)
Port D has seven bi-directional I/O pins with internal pull-up
resistors, PD6..PD0. The Port D o utput buffers can s ink 20
mA. As inputs, Port D pins that are externally pulled low will
source current if the pull-up resistors are activated.
Port D also serves th e fu nc tion s of v ario us sp ec ial fea tur es
of the AT90S2313 as listed on page 43.
RESET
Reset input. A low on th is pi n for two machi ne cy cles wh ile
the oscillator is running resets the device.
XTAL1
Input to the inverting os cillator amplifi er and input to th e
internal clock operating circuit.
XTAL2
Output from the inverting oscillator amplifier
Figure 2.
Figure 3.
Oscillator Connec tio ns
External Clock Drive Configuration
Crystal Oscillator
XTAL1 and XTAL2 are input and output, respectively, of an
inverting amplifier which can be configured for use as an
on-chip osci llator, as s hown in Figu re 2. Either a quartz
crystal or a ceramic resonator may be used. To drive the
device from an external clock source, XTAL2 should be left
unconnected while XTAL1 is driven as shown in Figure 3.
3
Page 4
AT90S2313 Architectural Overview
The fast-access register file concept contains 32 x 8-bit
general purpose worki ng regi ster s with a sin gle cl ock c ycle
access time. This means that during one single clock cycle,
one ALU (Arithmetic Logic Unit) operation is executed. Two
operands are output from the register file, the operation is
executed, and the result is stored back in the register file in one clock cycle.
Six of the 32 registers can be used as three 16-bits indirect
address register pointers for Data Space addressing enabling efficient addr ess calculations . One of the thre e
address pointers is also used as the address pointer for the
constant table look up function. These added function registers are the 16-bits X-register, Y-register and Z-register.
The ALU supports arithmetic and logic functions between
registers or be tween a const ant and a r egist er. Si ngle re gister operations are also executed in the ALU. Figure 4
shows the AT90S231 3 AVR Enhan ced RISC mi crocontro ller architecture .
In addition to the register operation, the conventional memory addressing mode s can be used on the re gister file as
well. This is e nabled by th e fact that t he register f ile is
assigned the 32 lowermost Data Space addresses ($00 $1F), allowing them to be accessed as though they were
ordinary memory locations.
The I/O memory space contains 64 addresses for CPU
peripheral functions as Control Registers, Timer/Counters,
A/D-converte rs, and ot her I/O fun ctions. T he I/O mem ory
can be accessed dir ectly, or as the Da ta Space loca tions
following those of the register file, $20 - $5F.
The AVR has Harvard architecture - with separate memories and buses for program and data. The program memory
is accessed with a two stage pipeline. While one instruction
is being executed, the next instructio n is pre-fetched from
the program memory. This concept enables instructions to
be executed in every clock cycle. The program memory is
In-system Programmable Flash memory.
With the relat ive jump an d call i nstructi ons, the w hole 1K
AVR
address space i s directl y access ed. Most
have a single 16-bit word format. Every program memory
address contains a 16- or 32-bit instruction.
During interrupts and su broutine calls, t he retur n addre ss
program counter (PC) is stor ed on the stack. The stack is
effectively allo cated i n the gene ral dat a SRAM, and cons equently the stack size is only limited by the total SRAM size
and the usage of the SR AM. All user programs mu st ini tialize the SP in the reset routine (before sub routin es or in terrupts are executed). The 8-bit stack pointer SP is read/write
accessible in the I/O space.
The 128 bytes data SRAM + register file and I/O registers
can be easily accessed through the five different addressing modes supported in the AVR architecture.
The memory spaces in the AVR architecture are all l inear
and regular memory maps.
ADDRd, RrAdd two Registe r s
ADCRd, RrAdd with Carry two Registers
ADIWRdl,KAdd Immediate to Word
SUBRd, RrSubtract two Registers
SUBIRd, KSubtract Constant from Register
SBIWRdl,KSubtract Immediate from Word
SBCRd, RrSubtract with Carry two Registers
SBCIRd, KSubtract with Carry Constant from Reg.
ANDRd, RrLogical AND Registers
ANDIRd, KLogical AND Register and Constant
ORRd, RrLogical OR Registers
ORIRd, KLogical OR Register and Constant
EORRd, RrExclusive OR Registers
COMRdOne’s Complement
NEGRdTwo’s Complement
SBRRd,KSet Bit(s) in Register
CBRRd,KClear Bit(s) in Register
INCRdIncrement
DECRdDecrement
TSTRdTest for Zero or Minus
CLRRdClear Register
SERRdSet Register
BRANCH INSTRUCTIONS
RJMPkRelative Jump
IJMPIndirect Jump to (Z)
RCALLkRelative Subroutine Call
ICALLIndirect Call to (Z)
RETSubroutine Return
RETIInterrupt Return
CPSERd,RrCompare, Skip if Equal
CPRd,RrCompareRd
CPCRd,RrCompare with CarryRd
CPIRd,KCompare Register with ImmediateRd
SBRCRr, bSkip if Bit in Register Cleared
SBRSRr, bSkip if Bit in Register is Set
SBICP, bSkip if Bit in I/O Register Cleared
SBISP, bSkip if Bit in I/O Register is Set
BRBSs, kBranch if Status Flag Set
BRBCs, kBranch if Status Flag Cleared
BREQ kBranch if Equal
BRNE kBranch if Not Equal
BRCS kBranch if Carry Set
BRCC kBranch if Carry Cleared
BRSH kBranch if Same or Higher
BRLO kBranch if Lower
BRMI kBranch if Minus
BRPL kBranch if Plus
BRGE kBranch if Greater or Equal, Signed
BRLT kBranch if Less Than Zero, Signed
BRHS kBranch if Half Carry Flag Set
BRHC kBranch if Half Carry Flag Cleared
BRTS kBranch if T Flag Set
BRTC kBranch if T Flag Cleared
BRVS kBranch if Overflow Flag is Set
BRVC kBranch if Overflow Flag is Cleared
BRIE kBranch if Interrupt Enabled
BRID kBranch if Interrupt Disabled
Rd ← Rd + Rr
Rd ← Rd + Rr + C
Rdh:Rdl ← Rdh:Rdl + K
Rd ← Rd − Rr
Rd ← Rd − K
Rdh:Rdl ← Rdh:Rdl − K
Rd ← Rd − Rr − C
Rd ← Rd − K − C
Rd ← Rd • Rr
Rd ← Rd • K
Rd ← Rd v Rr
Rd ← Rd v K
Rd ← Rd ⊕ Rr
Rd ← $FF − Rd
Rd ← $00 − Rd
Rd ← Rd v K
Rd ← Rd • ($FF − K)
Rd ← Rd + 1
Rd ← Rd − 1
Rd ← Rd • Rd
Rd ← Rd ⊕ Rd
Rd ← $FF
PC ← PC + k + 1
PC ← Z
PC ← PC + k + 1
PC ← Z
PC ← STACK
PC ← STACK
if (Rd = Rr) PC ← PC + 2 or 3
− RrZ, N,V,C,H1
− Rr − CZ, N,V,C,H1
− KZ, N,V,C,H1
if (Rr(b)=0) PC ← PC + 2 or 3
if (Rr(b)=1) PC ← PC + 2 or 3
if (P(b)=0) PC ← PC + 2 or 3
if (R(b)=1) PC ← PC + 2 or 3
if (SREG(s) = 1) then PC←PC + k + 1
if (SREG(s) = 0) then PC←PC + k + 1
if (Z = 1) then PC ← PC + k + 1
if (Z = 0) then PC ← PC + k + 1
if (C = 1) then PC ← PC + k + 1
if (C = 0) then PC ← PC + k + 1
if (C = 0) then PC ← PC + k + 1
if (C = 1) then PC ← PC + k + 1
if (N = 1) then PC ← PC + k + 1
if (N = 0) then PC ← PC + k + 1
if (N ⊕ V= 0) then PC ← PC + k + 1
if (N ⊕ V= 1) then PC ← PC + k + 1
if (H = 1) then PC ← PC + k + 1
if (H = 0) then PC ← PC + k + 1
if (T = 1) then PC ← PC + k + 1
if (T = 0) then PC ← PC + k + 1
if (V = 1) then PC ← PC + k + 1
if (V = 0) then PC ← PC + k + 1
if (I = 1) then PC ← PC + k + 1
if (I = 0) then PC ← PC + k + 1
MOVRd, RrMove Between RegistersRd
LDIRd, KLoad ImmediateRd
LDRd, XLoad IndirectRd
LDRd, X+Load Indirect and Post-Inc.Rd
LDRd, - XLoad Indirect and Pre-Dec.X
LDRd, YLoad IndirectRd
LDRd, Y+Load Indirect and Post-Inc.Rd
LDRd, - YLoad Indirect and Pre-Dec.Y
LDDRd,Y+qLoad Indirect with DisplacementRd
LDRd, ZLoad Indirect Rd
LDRd, Z+Load Indirect and Post-Inc.Rd
LDRd, -ZLoad Indirect and Pre-Dec.Z
LDDRd, Z+qLoad Indirect with DisplacementRd
LDSRd, kLoad Direct from SRAMRd
STX, RrStore Indirect(X)
STX+, RrStore Indirect and Post-Inc.(X)
ST- X, RrStore Indirect and Pre-Dec.X
STY, RrStore Indirect(Y)
STY+, RrStore Indirect and Post-Inc.(Y)
ST- Y, RrStore Indirect and Pre-Dec.Y
STDY+q,RrStore Indirect with Displacement(Y + q)
STZ, RrStore Indirect(Z)
STZ+, RrStore Indirect and Post-Inc.(Z)
ST-Z, RrStore Indirect and Pre-Dec.Z
STDZ+q,RrStore Indirect with Displacement(Z + q)
STSk, RrStore Direct to SRAM(k)
LPMLoad Program MemoryR0
INRd, PIn PortRd
OUTP, RrOut PortP
PUSHRrPush Register on StackSTACK
POPRdPop Register from StackRd
BIT AND BIT-TEST INSTRUCTIONS
SBIP,bSet Bit in I/O RegisterI/O(P,b)
CBIP,bClear Bit in I/O RegisterI/O(P,b)
LSLRdLogical Shift LeftRd(n+1)
LSRRdLogical Shift RightRd(n)
ROLRdRotate Left Through CarryRd(0)
RORRdRotate Right Through CarryRd(7)
ASRRdArithmetic Shift RightRd(n)
SWAPRdSwap NibblesRd(3..0)
BSETsFlag SetSREG(s)
BCLRsFlag ClearSREG(s)
BSTRr, bBit Store from Register to TT
BLDRd, bBit load from T to RegisterRd(b)
SECSet CarryC
CLCCle ar CarryC
SENSet Negative FlagN
CLNClear Negative FlagN
SEZSet Zero FlagZ
CLZClear Zero FlagZ
SEIGlobal Interrupt EnableI
CLIGlobal Interrupt DisableI
SESSet Signed Test FlagS
CLSClear Signed Test FlagS
SEVSet Twos Complement OverflowV
CLVClear Twos Complement OverflowV
SETSet T in SREGT
CLTClear T in SREGT
SEHSet Half Carry Flag in SREGH
CLHClear Half Carry Flag in SREGH
NOPNo OperationNone1
SLEEPSleep(see specific descr. for Sleep function)None3
WDRWatchdog Reset(see specific descr. for WDR/timer)None1