- •Features
- •1. Pin Configurations
- •1.1 Pin Descriptions
- •1.1.3 Port A (PA2..PA0)
- •1.1.4 Port B (PB7..PB0)
- •1.1.5 Port D (PD6..PD0)
- •1.1.6 RESET
- •1.1.7 XTAL1
- •1.1.8 XTAL2
- •2. Overview
- •2.1 Block Diagram
- •2.2 Comparison Between ATtiny2313A and ATtiny4313
- •3. About
- •3.1 Resources
- •3.2 Code Examples
- •3.3 Data Retention
- •4. CPU Core
- •4.1 Architectural Overview
- •4.2 ALU – Arithmetic Logic Unit
- •4.3 Status Register
- •4.4 General Purpose Register File
- •4.5 Stack Pointer
- •4.6 Instruction Execution Timing
- •4.7 Reset and Interrupt Handling
- •4.7.1 Interrupt Response Time
- •5. Memories
- •5.1 Program Memory (Flash)
- •5.2 Data Memory (SRAM) and Register Files
- •5.2.1 General Purpose Register File
- •5.2.2 I/O Register File
- •5.2.3 Data Memory (SRAM)
- •5.3 Data Memory (EEPROM)
- •5.3.1 Programming Methods
- •5.3.2 Read
- •5.3.3 Erase
- •5.3.4 Write
- •5.3.5 Preventing EEPROM Corruption
- •5.3.6 Program Examples
- •5.4 Register Description
- •5.4.1 EEAR – EEPROM Address Register
- •5.4.2 EEDR – EEPROM Data Register
- •5.4.3 EECR – EEPROM Control Register
- •5.4.4 GPIOR2 – General Purpose I/O Register 2
- •5.4.5 GPIOR1 – General Purpose I/O Register 1
- •5.4.6 GPIOR0 – General Purpose I/O Register 0
- •6. Clock System
- •6.1 Clock Subsystems
- •6.2 Clock Sources
- •6.2.1 Default Clock Source
- •6.2.2 External Clock
- •6.2.3 Calibrated Internal RC Oscillator
- •6.2.4 128 kHz Internal Oscillator
- •6.2.5 Crystal Oscillator
- •6.3 System Clock Prescaler
- •6.3.1 Switching Time
- •6.4 Clock Output Buffer
- •6.5 Register Description
- •6.5.1 OSCCAL – Oscillator Calibration Register
- •6.5.2 CLKPR – Clock Prescale Register
- •7. Power Management and Sleep Modes
- •7.1 Sleep Modes
- •7.1.1 Idle Mode
- •7.1.3 Standby Mode
- •7.2 Software BOD Disable
- •7.3 Power Reduction Register
- •7.4 Minimizing Power Consumption
- •7.4.1 Analog Comparator
- •7.4.2 Internal Voltage Reference
- •7.4.4 Watchdog Timer
- •7.4.5 Port Pins
- •7.5 Register Description
- •7.5.1 MCUCR – MCU Control Register
- •7.5.2 PRR – Power Reduction Register
- •8. System Control and Reset
- •8.1 Resetting the AVR
- •8.2 Reset Sources
- •8.2.2 External Reset
- •8.2.4 Watchdog Reset
- •8.3 Internal Voltage Reference
- •8.4 Watchdog Timer
- •8.4.1 Timed Sequences for Changing the Configuration of the Watchdog Timer
- •8.4.2 Code Example
- •8.5 Register Description
- •8.5.1 MCUSR – MCU Status Register
- •8.5.2 WDTCSR – Watchdog Timer Control and Status Register
- •9. Interrupts
- •9.1 Interrupt Vectors
- •9.2 External Interrupts
- •9.2.1 Low Level Interrupt
- •9.2.2 Pin Change Interrupt Timing
- •9.3 Register Description
- •9.3.1 MCUCR – MCU Control Register
- •9.3.2 GIMSK – General Interrupt Mask Register
- •9.3.3 GIFR – General Interrupt Flag Register
- •9.3.4 PCMSK2 – Pin Change Mask Register 2
- •9.3.5 PCMSK1 – Pin Change Mask Register 1
- •9.3.6 PCMSK0 – Pin Change Mask Register 0
- •10. I/O-Ports
- •10.1 Ports as General Digital I/O
- •10.1.1 Configuring the Pin
- •10.1.2 Toggling the Pin
- •10.1.3 Switching Between Input and Output
- •10.1.4 Reading the Pin Value
- •10.1.5 Digital Input Enable and Sleep Modes
- •10.1.6 Unconnected Pins
- •10.1.7 Program Examples
- •10.2 Alternate Port Functions
- •10.2.1 Alternate Functions of Port A
- •10.2.2 Alternate Functions of Port B
- •10.2.3 Alternate Functions of Port D
- •10.3 Register Description
- •10.3.1 MCUCR – MCU Control Register
- •10.3.2 PORTA – Port A Data Register
- •10.3.3 DDRA – Port A Data Direction Register
- •10.3.4 PINA – Port A Input Pins Address
- •10.3.5 PORTB – Port B Data Register
- •10.3.6 DDRB – Port B Data Direction Register
- •10.3.7 PINB – Port B Input Pins Address
- •10.3.8 PORTD – Port D Data Register
- •10.3.9 DDRD – Port D Data Direction Register
- •10.3.10 PIND – Port D Input Pins Address
- •11. 8-bit Timer/Counter0 with PWM
- •11.1 Features
- •11.2 Overview
- •11.2.1 Registers
- •11.2.2 Definitions
- •11.3 Clock Sources
- •11.4 Counter Unit
- •11.5 Output Compare Unit
- •11.5.1 Force Output Compare
- •11.5.2 Compare Match Blocking by TCNT0 Write
- •11.5.3 Using the Output Compare Unit
- •11.6 Compare Match Output Unit
- •11.6.1 Compare Output Mode and Waveform Generation
- •11.7 Modes of Operation
- •11.7.1 Normal Mode
- •11.7.2 Clear Timer on Compare Match (CTC) Mode
- •11.7.3 Fast PWM Mode
- •11.7.4 Phase Correct PWM Mode
- •11.8 Timer/Counter Timing Diagrams
- •11.9 Register Description
- •11.9.1 TCCR0A – Timer/Counter Control Register A
- •11.9.2 TCCR0B – Timer/Counter Control Register B
- •11.9.3 TCNT0 – Timer/Counter Register
- •11.9.4 OCR0A – Output Compare Register A
- •11.9.5 OCR0B – Output Compare Register B
- •11.9.6 TIMSK – Timer/Counter Interrupt Mask Register
- •11.9.7 TIFR – Timer/Counter Interrupt Flag Register
- •12. 16-bit Timer/Counter1
- •12.1 Features
- •12.2 Overview
- •12.2.1 Registers
- •12.2.2 Definitions
- •12.2.3 Compatibility
- •12.3 Timer/Counter Clock Sources
- •12.4 Counter Unit
- •12.5 Input Capture Unit
- •12.5.1 Input Capture Trigger Source
- •12.5.2 Noise Canceler
- •12.5.3 Using the Input Capture Unit
- •12.6 Output Compare Units
- •12.6.1 Force Output Compare
- •12.6.2 Compare Match Blocking by TCNT1 Write
- •12.6.3 Using the Output Compare Unit
- •12.7 Compare Match Output Unit
- •12.7.1 Compare Output Mode and Waveform Generation
- •12.8 Modes of Operation
- •12.8.1 Normal Mode
- •12.8.2 Clear Timer on Compare Match (CTC) Mode
- •12.8.3 Fast PWM Mode
- •12.8.4 Phase Correct PWM Mode
- •12.8.5 Phase and Frequency Correct PWM Mode
- •12.9 Timer/Counter Timing Diagrams
- •12.10 Accessing 16-bit Registers
- •12.10.1 Reusing the Temporary High Byte Register
- •12.11 Register Description
- •12.11.1 TCCR1A – Timer/Counter1 Control Register A
- •12.11.2 TCCR1B – Timer/Counter1 Control Register B
- •12.11.3 TCCR1C – Timer/Counter1 Control Register C
- •12.11.4 TCNT1H and TCNT1L – Timer/Counter1
- •12.11.5 OCR1AH and OCR1AL – Output Compare Register 1 A
- •12.11.6 OCR1BH and OCR1BL – Output Compare Register 1 B
- •12.11.7 ICR1H and ICR1L – Input Capture Register 1
- •12.11.8 TIMSK – Timer/Counter Interrupt Mask Register
- •12.11.9 TIFR – Timer/Counter Interrupt Flag Register
- •13. Timer/Counter0 and Timer/Counter1 Prescalers
- •13.1 Internal Clock Source
- •13.2 Prescaler Reset
- •13.3 External Clock Source
- •13.4 Register Description
- •13.4.1 GTCCR – General Timer/Counter Control Register
- •14. USART
- •14.1 Features
- •14.2 Overview
- •14.2.1 AVR USART vs. AVR UART – Compatibility
- •14.3 Clock Generation
- •14.3.1 Internal Clock Generation – The Baud Rate Generator
- •14.3.2 Double Speed Operation (U2X)
- •14.3.3 External Clock
- •14.3.4 Synchronous Clock Operation
- •14.4 Frame Formats
- •14.4.1 Parity Bit Calculation
- •14.5 USART Initialization
- •14.6 Data Transmission – The USART Transmitter
- •14.6.1 Sending Frames with 5 to 8 Data Bit
- •14.6.2 Sending Frames with 9 Data Bit
- •14.6.3 Transmitter Flags and Interrupts
- •14.6.4 Parity Generator
- •14.6.5 Disabling the Transmitter
- •14.7 Data Reception – The USART Receiver
- •14.7.1 Receiving Frames with 5 to 8 Data Bits
- •14.7.2 Receiving Frames with 9 Data Bits
- •14.7.3 Receive Compete Flag and Interrupt
- •14.7.4 Receiver Error Flags
- •14.7.5 Parity Checker
- •14.7.6 Disabling the Receiver
- •14.7.7 Flushing the Receive Buffer
- •14.8 Asynchronous Data Reception
- •14.8.1 Asynchronous Clock Recovery
- •14.8.2 Asynchronous Data Recovery
- •14.8.3 Asynchronous Operational Range
- •14.9.1 Using MPCM
- •14.10 Register Description
- •14.10.1 UDR – USART I/O Data Register
- •14.10.2 UCSRA – USART Control and Status Register A
- •14.10.3 UCSRB – USART Control and Status Register B
- •14.10.4 UCSRC – USART Control and Status Register C
- •14.10.5 UBRRL and UBRRH – USART Baud Rate Registers
- •14.11 Examples of Baud Rate Setting
- •15. USART in SPI Mode
- •15.1 Features
- •15.2 Overview
- •15.3 Clock Generation
- •15.4 SPI Data Modes and Timing
- •15.5 Frame Formats
- •15.5.1 USART MSPIM Initialization
- •15.6 Data Transfer
- •15.6.1 Transmitter and Receiver Flags and Interrupts
- •15.6.2 Disabling the Transmitter or Receiver
- •15.7 AVR USART MSPIM vs. AVR SPI
- •15.8 Register Description
- •15.8.1 UDR – USART MSPIM I/O Data Register
- •15.8.2 UCSRA – USART MSPIM Control and Status Register A
- •15.8.3 UCSRB – USART MSPIM Control and Status Register B
- •15.8.4 UCSRC – USART MSPIM Control and Status Register C
- •15.8.5 UBRRL and UBRRH – USART MSPIM Baud Rate Registers
- •16. USI – Universal Serial Interface
- •16.1 Features
- •16.2 Overview
- •16.3 Functional Descriptions
- •16.3.2 SPI Master Operation Example
- •16.3.3 SPI Slave Operation Example
- •16.3.5 Start Condition Detector
- •16.3.6 Clock speed considerations
- •16.4 Alternative USI Usage
- •16.4.4 Edge Triggered External Interrupt
- •16.4.5 Software Interrupt
- •16.5 Register Description
- •16.5.1 USICR – USI Control Register
- •16.5.2 USISR – USI Status Register
- •16.5.3 USIDR – USI Data Register
- •16.5.4 USIBR – USI Buffer Register
- •17. Analog Comparator
- •17.1 Register Description
- •17.1.1 ACSR – Analog Comparator Control and Status Register
- •17.1.2 DIDR – Digital Input Disable Register
- •18. debugWIRE On-chip Debug System
- •18.1 Features
- •18.2 Overview
- •18.3 Physical Interface
- •18.4 Software Break Points
- •18.5 Limitations of debugWIRE
- •18.6 Register Description
- •18.6.1 DWDR – debugWire Data Register
- •19. Self-Programming
- •19.1 Features
- •19.2 Overview
- •19.3 Lock Bits
- •19.4.2 Page Erase
- •19.4.3 Page Load
- •19.4.4 Page Write
- •19.4.5 SPMCSR Can Not Be Written When EEPROM is Programmed
- •19.5 Preventing Flash Corruption
- •19.6 Programming Time for Flash when Using SPM
- •19.7 Register Description
- •19.7.1 SPMCSR – Store Program Memory Control and Status Register
- •20. Lock Bits, Fuse Bits and Device Signature
- •20.1 Lock Bits
- •20.2 Fuse Bits
- •20.2.1 Latching of Fuses
- •20.3 Device Signature Imprint Table
- •20.3.1 Calibration Byte
- •20.3.2 Signature Bytes
- •20.4 Reading Lock Bits, Fuse Bits and Signature Data from Software
- •20.4.1 Lock Bit Read
- •20.4.2 Fuse Bit Read
- •20.4.3 Device Signature Imprint Table Read
- •21. External Programming
- •21.1 Memory Parametrics
- •21.2 Parallel Programming
- •21.2.1 Enter Programming Mode
- •21.2.2 Considerations for Efficient Programming
- •21.2.3 Chip Erase
- •21.2.4 Programming the Flash
- •21.2.5 Programming the EEPROM
- •21.2.6 Reading the Flash
- •21.2.7 Reading the EEPROM
- •21.2.8 Programming Low Fuse Bits
- •21.2.9 Programming High Fuse Bits
- •21.2.10 Programming Extended Fuse Bits
- •21.2.11 Programming the Lock Bits
- •21.2.12 Reading Fuse and Lock Bits
- •21.2.13 Reading Signature Bytes
- •21.2.14 Reading the Calibration Byte
- •21.3 Serial Programming
- •21.3.1 Pin Mapping
- •21.3.2 Programming Algorithm
- •21.3.3 Programming Instruction Set
- •21.4 Programming Time for Flash and EEPROM
- •22. Electrical Characteristics
- •22.1 Absolute Maximum Ratings*
- •22.2 DC Characteristics
- •22.3 Speed
- •22.4 Clock Characteristics
- •22.4.1 Calibrated Internal RC Oscillator Accuracy
- •22.4.2 External Clock Drive
- •22.5 System and Reset Characteristics
- •22.6 Analog Comparator Characteristics
- •22.7 Parallel Programming Characteristics
- •22.8 Serial Programming Characteristics
- •23. Typical Characteristics
- •23.1 Effect of Power Reduction
- •23.2 ATtiny2313A
- •23.2.1 Current Consumption in Active Mode
- •23.2.2 Current Consumption in Idle Mode
- •23.2.4 Current Consumption in Reset
- •23.2.5 Current Consumption of Peripheral Units
- •23.2.7 Output Driver Strength
- •23.2.8 Input Thresholds and Hysteresis (for I/O Ports)
- •23.2.9 BOD, Bandgap and Reset
- •23.2.10 Internal Oscillator Speed
- •23.3 ATtiny4313
- •23.3.1 Current Consumption in Active Mode
- •23.3.2 Current Consumption in Idle Mode
- •23.3.4 Current Consumption in Reset
- •23.3.5 Current Consumption of Peripheral Units
- •23.3.7 Output Driver Strength
- •23.3.8 Input Thresholds and Hysteresis (for I/O Ports)
- •23.3.9 BOD, Bandgap and Reset
- •23.3.10 Internal Oscillator Speed
- •24. Register Summary
- •25. Instruction Set Summary
- •26. Ordering Information
- •26.1 ATtiny2313A
- •26.2 ATtiny4313
- •27. Packaging Information
- •28. Errata
- •28.1 ATtiny2313A
- •28.2 ATtiny4313
- •29. Datasheet Revision History
- •Table of Contents
ATtiny2313A/4313
24. Register Summary
Address |
Name |
Bit 7 |
Bit 6 |
Bit 5 |
Bit 4 |
Bit 3 |
|
Bit 2 |
Bit 1 |
Bit 0 |
Page |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0x3F (0x5F) |
SREG |
I |
T |
H |
S |
V |
|
N |
Z |
C |
9 |
|
0x3E (0x5E) |
Reserved |
– |
– |
– |
– |
– |
|
– |
– |
– |
|
|
0x3D (0x5D) |
SPL |
SP7 |
SP6 |
SP5 |
SP4 |
SP3 |
|
SP2 |
SP1 |
SP0 |
12 |
|
0x3C (0x5C) |
OCR0B |
|
|
|
Timer/Counter0 – Compare Register B |
|
|
|
86 |
|||
0x3B (0x5B) |
GIMSK |
INT1 |
INT0 |
PCIE0 |
PCIE2 |
PCIE1 |
|
– |
– |
– |
52 |
|
0x3A (0x5A) |
GIFR |
INTF1 |
INTF0 |
PCIF0 |
PCIF2 |
PCIF1 |
|
– |
– |
– |
53 |
|
0x39 |
(0x59) |
TIMSK |
TOIE1 |
OCIE1A |
OCIE1B |
– |
ICIE1 |
|
OCIE0B |
TOIE0 |
OCIE0A |
87, 116 |
0x38 |
(0x58) |
TIFR |
TOV1 |
OCF1A |
OCF1B |
– |
ICF1 |
|
OCF0B |
TOV0 |
OCF0A |
87, 117 |
0x37 |
(0x57) |
SPMCSR |
– |
– |
RSIG |
CTPB |
RFLB |
|
PGWRT |
PGERS |
SPMEN |
176 |
0x36 |
(0x56) |
OCR0A |
|
|
|
Timer/Counter0 – Compare Register A |
|
|
|
86 |
||
0x35 |
(0x55) |
MCUCR |
PUD |
SM1 |
SE |
SM0 |
ISC11 |
|
ISC10 |
ISC01 |
ISC00 |
37, 51, 69 |
0x34 |
(0x54) |
MCUSR |
– |
– |
– |
– |
WDRF |
|
BORF |
EXTRF |
PORF |
45 |
0x33 |
(0x53) |
TCCR0B |
FOC0A |
FOC0B |
– |
– |
WGM02 |
|
CS02 |
CS01 |
CS00 |
85 |
0x32 |
(0x52) |
TCNT0 |
|
|
|
Timer/Counter0 (8-bit) |
|
|
|
86 |
||
0x31 |
(0x51) |
OSCCAL |
– |
CAL6 |
CAL5 |
CAL4 |
CAL3 |
|
CAL2 |
CAL1 |
CAL0 |
32 |
0x30 |
(0x50) |
TCCR0A |
COM0A1 |
COM0A0 |
COM0B1 |
COM0B0 |
– |
|
– |
WGM01 |
WGM00 |
82 |
0x2F |
(0x4F) |
TCCR1A |
COM1A1 |
COM1A0 |
COM1B1 |
COM1B0 |
– |
|
– |
WGM11 |
WGM10 |
111 |
0x2E |
(0x4E) |
TCCR1B |
ICNC1 |
ICES1 |
– |
WGM13 |
WGM12 |
|
CS12 |
CS11 |
CS10 |
113 |
0x2D |
(0x4D) |
TCNT1H |
|
|
Timer/Counter1 – Counter Register High Byte |
|
|
115 |
||||
0x2C |
(0x4C) |
TCNT1L |
|
|
Timer/Counter1 – Counter Register Low Byte |
|
|
115 |
||||
0x2B |
(0x4B) |
OCR1AH |
|
|
Timer/Counter1 – Compare Register A High Byte |
|
|
115 |
||||
0x2A |
(0x4A) |
OCR1AL |
|
|
Timer/Counter1 – Compare Register A Low Byte |
|
|
115 |
||||
0x29 |
(0x49) |
OCR1BH |
|
|
Timer/Counter1 – Compare Register B High Byte |
|
|
115 |
||||
0x28 |
(0x48) |
OCR1BL |
|
|
Timer/Counter1 – Compare Register B Low Byte |
|
|
115 |
||||
0x27 |
(0x47) |
Reserved |
– |
– |
– |
– |
– |
|
– |
– |
– |
|
0x26 |
(0x46) |
CLKPR |
CLKPCE |
– |
– |
– |
CLKPS3 |
|
CLKPS2 |
CLKPS1 |
CLKPS0 |
32 |
0x25 |
(0x45) |
ICR1H |
|
|
Timer/Counter1 - Input Capture Register High Byte |
|
|
116 |
||||
0x24 |
(0x44) |
ICR1L |
|
|
Timer/Counter1 - Input Capture Register Low Byte |
|
|
116 |
||||
0x23 |
(0x43) |
GTCCR |
– |
– |
– |
– |
– |
|
– |
– |
PSR10 |
119 |
0x22 |
(ox42) |
TCCR1C |
FOC1A |
FOC1B |
– |
– |
– |
|
– |
– |
– |
114 |
0x21 |
(0x41) |
WDTCSR |
WDIF |
WDIE |
WDP3 |
WDCE |
WDE |
|
WDP2 |
WDP1 |
WDP0 |
45 |
0x20 |
(0x40) |
PCMSK0 |
PCINT7 |
PCINT6 |
PCINT5 |
PCINT4 |
PCINT3 |
|
PCINT2 |
PCINT1 |
PCINT0 |
54 |
0x1F |
(0x3F) |
Reserved |
– |
– |
– |
– |
– |
|
– |
– |
– |
|
0x1E |
(0x3E) |
EEAR |
– |
|
|
EEPROM Address Register |
|
|
24 |
|||
0x1D |
(0x3D) |
EEDR |
|
|
|
EEPROM Data Register |
|
|
|
23 |
||
0x1C |
(0x3C) |
EECR |
– |
– |
EEPM1 |
EEPM0 |
EERIE |
|
EEMPE |
EEPE |
EERE |
24 |
0x1B |
(0x3B) |
PORTA |
– |
– |
– |
– |
– |
|
PORTA2 |
PORTA1 |
PORTA0 |
69 |
0x1A |
(0x3A) |
DDRA |
– |
– |
– |
– |
– |
|
DDA2 |
DDA1 |
DDA0 |
69 |
0x19 |
(0x39) |
PINA |
– |
– |
– |
– |
– |
|
PINA2 |
PINA1 |
PINA0 |
70 |
0x18 |
(0x38) |
PORTB |
PORTB7 |
PORTB6 |
PORTB5 |
PORTB4 |
PORTB3 |
|
PORTB2 |
PORTB1 |
PORTB0 |
70 |
0x17 |
(0x37) |
DDRB |
DDB7 |
DDB6 |
DDB5 |
DDB4 |
DDB3 |
|
DDB2 |
DDB1 |
DDB0 |
70 |
0x16 |
(0x36) |
PINB |
PINB7 |
PINB6 |
PINB5 |
PINB4 |
PINB3 |
|
PINB2 |
PINB1 |
PINB0 |
70 |
0x15 |
(0x35) |
GPIOR2 |
|
|
|
General Purpose I/O Register 2 |
|
|
|
25 |
||
0x14 |
(0x34) |
GPIOR1 |
|
|
|
General Purpose I/O Register 1 |
|
|
|
25 |
||
0x13 |
(0x33) |
GPIOR0 |
|
|
|
General Purpose I/O Register 0 |
|
|
|
25 |
||
0x12 |
(0x32) |
PORTD |
– |
PORTD6 |
PORTD5 |
PORTD4 |
PORTD3 |
|
PORTD2 |
PORTD1 |
PORTD0 |
70 |
0x11 |
(0x31) |
DDRD |
– |
DDD6 |
DDD5 |
DDD4 |
DDD3 |
|
DDD2 |
DDD1 |
DDD0 |
70 |
0x10 |
(0x30) |
PIND |
– |
PIND6 |
PIND5 |
PIND4 |
PIND3 |
|
PIND2 |
PIND1 |
PIND0 |
70 |
0x0F (0x2F) |
USIDR |
|
|
|
USI Data Register |
|
|
|
166 |
|||
0x0E (0x2E) |
USISR |
USISIF |
USIOIF |
USIPF |
USIDC |
USICNT3 |
|
USICNT2 |
USICNT1 |
USICNT0 |
165 |
|
0x0D (0x2D) |
USICR |
USISIE |
USIOIE |
USIWM1 |
USIWM0 |
USICS1 |
|
USICS0 |
USICLK |
USITC |
163 |
|
0x0C (0x2C) |
UDR |
|
|
|
UART Data Register (8-bit) |
|
|
|
137 |
|||
0x0B (0x2B) |
UCSRA |
RXC |
TXC |
UDRE |
FE |
DOR |
|
UPE |
U2X |
MPCM |
138 |
|
0x0A (0x2A) |
UCSRB |
RXCIE |
TXCIE |
UDRIE |
RXEN |
TXEN |
|
UCSZ2 |
RXB8 |
TXB8 |
139 |
|
0x09 |
(0x29) |
UBRRL |
|
|
|
UBRRH[7:0] |
|
|
|
141 |
||
0x08 |
(0x28) |
ACSR |
ACD |
ACBG |
ACO |
ACI |
ACIE |
|
ACIC |
ACIS1 |
ACIS0 |
168 |
0x07 |
(0x27) |
BODCR |
– |
– |
– |
– |
– |
|
– |
BODS |
BODSE |
38 |
0x06 |
(0x26) |
PRR |
– |
– |
– |
– |
PRTIM1 |
|
PRTIM0 |
PRUSI |
PRUSART |
37 |
0x05 |
(0x25) |
PCMSK2 |
– |
PCINT17 |
PCINT16 |
PCINT15 |
PCINT14 |
|
PCINT13 |
PCINT12 |
PCINT11 |
53 |
0x04 |
(0x24) |
PCMSK1 |
– |
– |
– |
– |
– |
|
PCINT10 |
PCINT9 |
PCINT8 |
54 |
0x03 |
(0x23) |
UCSRC |
UMSEL1 |
UMSEL0 |
UPM1 |
UPM0 |
USBS |
|
UCSZ1 |
UCSZ0 |
UCPOL |
140 |
0x02 |
(0x22) |
UBRRH |
– |
– |
– |
– |
|
|
UBRRH[11:8] |
|
141 |
|
0x01 |
(0x21) |
DIDR |
– |
– |
– |
– |
– |
|
– |
AIN1D |
AIN0D |
169 |
0x00 |
(0x20) |
USIBR |
|
|
|
USI Buffer Register |
|
|
|
167 |
255
8246B–AVR–09/11
Notes: 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory addresses should never be written.
2.I/O Registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions.
3.Some of the status flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only operate on the specified bit, and can therefore be used on registers containing such status flags. The CBI and SBI instructions work with registers 0x00 to 0x1F only.
4.When using the I/O specific commands IN and OUT, the I/O addresses 0x00 - 0x3F must be used. When addressing I/O Registers as data space using LD and ST instructions, 0x20 must be added to these addresses.
256 ATtiny2313A/4313
8246B–AVR–09/11
ATtiny2313A/4313
25. Instruction Set Summary
Mnemonics |
Operands |
|
Description |
Operation |
Flags |
#Clocks |
ARITHMETIC AND LOGIC INSTRUCTIONS |
|
|
|
|
||
ADD |
Rd, Rr |
|
Add two Registers |
Rd ← Rd + Rr |
Z,C,N,V,H |
1 |
ADC |
Rd, Rr |
|
Add with Carry two Registers |
Rd ← Rd + Rr + C |
Z,C,N,V,H |
1 |
ADIW |
Rdl,K |
|
Add Immediate to Word |
Rdh:Rdl ← Rdh:Rdl + K |
Z,C,N,V,S |
2 |
SUB |
Rd, Rr |
|
Subtract two Registers |
Rd ← Rd - Rr |
Z,C,N,V,H |
1 |
SUBI |
Rd, K |
|
Subtract Constant from Register |
Rd ← Rd - K |
Z,C,N,V,H |
1 |
SBC |
Rd, Rr |
|
Subtract with Carry two Registers |
Rd ← Rd - Rr - C |
Z,C,N,V,H |
1 |
SBCI |
Rd, K |
|
Subtract with Carry Constant from Reg. |
Rd ← Rd - K - C |
Z,C,N,V,H |
1 |
SBIW |
Rdl,K |
|
Subtract Immediate from Word |
Rdh:Rdl ← Rdh:Rdl - K |
Z,C,N,V,S |
2 |
AND |
Rd, Rr |
|
Logical AND Registers |
Rd ← Rd • Rr |
Z,N,V |
1 |
ANDI |
Rd, K |
|
Logical AND Register and Constant |
Rd ← Rd • K |
Z,N,V |
1 |
OR |
Rd, Rr |
|
Logical OR Registers |
Rd ← Rd v Rr |
Z,N,V |
1 |
ORI |
Rd, K |
|
Logical OR Register and Constant |
Rd ← Rd v K |
Z,N,V |
1 |
EOR |
Rd, Rr |
|
Exclusive OR Registers |
Rd ← Rd Rr |
Z,N,V |
1 |
COM |
Rd |
|
One’s Complement |
Rd ← 0xFF − Rd |
Z,C,N,V |
1 |
NEG |
Rd |
|
Two’s Complement |
Rd ← 0x00 − Rd |
Z,C,N,V,H |
1 |
SBR |
Rd,K |
|
Set Bit(s) in Register |
Rd ← Rd v K |
Z,N,V |
1 |
CBR |
Rd,K |
|
Clear Bit(s) in Register |
Rd ← Rd • (0xFF - K) |
Z,N,V |
1 |
INC |
Rd |
|
Increment |
Rd ← Rd + 1 |
Z,N,V |
1 |
DEC |
Rd |
|
Decrement |
Rd ← Rd − 1 |
Z,N,V |
1 |
TST |
Rd |
|
Test for Zero or Minus |
Rd ← Rd • Rd |
Z,N,V |
1 |
CLR |
Rd |
|
Clear Register |
Rd ← Rd Rd |
Z,N,V |
1 |
SER |
Rd |
|
Set Register |
Rd ← 0xFF |
None |
1 |
BRANCH INSTRUCTIONS |
|
|
|
|
||
RJMP |
k |
|
Relative Jump |
PC ← PC + k + 1 |
None |
2 |
IJMP |
|
|
Indirect Jump to (Z) |
PC ← Z |
None |
2 |
RCALL |
k |
|
Relative Subroutine Call |
PC ← PC + k + 1 |
None |
3 |
ICALL |
|
|
Indirect Call to (Z) |
PC ← Z |
None |
3 |
RET |
|
|
Subroutine Return |
PC ← STACK |
None |
4 |
RETI |
|
|
Interrupt Return |
PC ← STACK |
I |
4 |
CPSE |
Rd,Rr |
|
Compare, Skip if Equal |
if (Rd = Rr) PC ← PC + 2 or 3 |
None |
1/2/3 |
CP |
Rd,Rr |
|
Compare |
Rd − Rr |
Z, N,V,C,H |
1 |
CPC |
Rd,Rr |
|
Compare with Carry |
Rd − Rr − C |
Z, N,V,C,H |
1 |
CPI |
Rd,K |
|
Compare Register with Immediate |
Rd − K |
Z, N,V,C,H |
1 |
SBRC |
Rr, b |
|
Skip if Bit in Register Cleared |
if (Rr(b)=0) PC ← PC + 2 or 3 |
None |
1/2/3 |
SBRS |
Rr, b |
|
Skip if Bit in Register is Set |
if (Rr(b)=1) PC ← PC + 2 or 3 |
None |
1/2/3 |
SBIC |
P, b |
|
Skip if Bit in I/O Register Cleared |
if (P(b)=0) PC ← PC + 2 or 3 |
None |
1/2/3 |
SBIS |
P, b |
|
Skip if Bit in I/O Register is Set |
if (P(b)=1) PC ← PC + 2 or 3 |
None |
1/2/3 |
BRBS |
s, k |
|
Branch if Status Flag Set |
if (SREG(s) = 1) then PC←PC+k + 1 |
None |
1/2 |
BRBC |
s, k |
|
Branch if Status Flag Cleared |
if (SREG(s) = 0) then PC←PC+k + 1 |
None |
1/2 |
BREQ |
k |
|
Branch if Equal |
if (Z = 1) then PC ← PC + k + 1 |
None |
1/2 |
BRNE |
k |
|
Branch if Not Equal |
if (Z = 0) then PC ← PC + k + 1 |
None |
1/2 |
BRCS |
k |
|
Branch if Carry Set |
if (C = 1) then PC ← PC + k + 1 |
None |
1/2 |
BRCC |
k |
|
Branch if Carry Cleared |
if (C = 0) then PC ← PC + k + 1 |
None |
1/2 |
BRSH |
k |
|
Branch if Same or Higher |
if (C = 0) then PC ← PC + k + 1 |
None |
1/2 |
BRLO |
k |
|
Branch if Lower |
if (C = 1) then PC ← PC + k + 1 |
None |
1/2 |
BRMI |
k |
|
Branch if Minus |
if (N = 1) then PC ← PC + k + 1 |
None |
1/2 |
BRPL |
k |
|
Branch if Plus |
if (N = 0) then PC ← PC + k + 1 |
None |
1/2 |
BRGE |
k |
|
Branch if Greater or Equal, Signed |
if (N V= 0) then PC ← PC + k + 1 |
None |
1/2 |
BRLT |
k |
|
Branch if Less Than Zero, Signed |
if (N V= 1) then PC ← PC + k + 1 |
None |
1/2 |
BRHS |
k |
|
Branch if Half Carry Flag Set |
if (H = 1) then PC ← PC + k + 1 |
None |
1/2 |
BRHC |
k |
|
Branch if Half Carry Flag Cleared |
if (H = 0) then PC ← PC + k + 1 |
None |
1/2 |
BRTS |
k |
|
Branch if T Flag Set |
if (T = 1) then PC ← PC + k + 1 |
None |
1/2 |
BRTC |
k |
|
Branch if T Flag Cleared |
if (T = 0) then PC ← PC + k + 1 |
None |
1/2 |
BRVS |
k |
|
Branch if Overflow Flag is Set |
if (V = 1) then PC ← PC + k + 1 |
None |
1/2 |
BRVC |
k |
|
Branch if Overflow Flag is Cleared |
if (V = 0) then PC ← PC + k + 1 |
None |
1/2 |
BRIE |
k |
|
Branch if Interrupt Enabled |
if ( I = 1) then PC ← PC + k + 1 |
None |
1/2 |
BRID |
k |
|
Branch if Interrupt Disabled |
if ( I = 0) then PC ← PC + k + 1 |
None |
1/2 |
BIT AND BIT-TEST INSTRUCTIONS |
|
|
|
|
||
SBI |
P,b |
|
Set Bit in I/O Register |
I/O(P,b) ← 1 |
None |
2 |
CBI |
P,b |
|
Clear Bit in I/O Register |
I/O(P,b) ← 0 |
None |
2 |
LSL |
Rd |
|
Logical Shift Left |
Rd(n+1) ← Rd(n), Rd(0) ← 0 |
Z,C,N,V |
1 |
LSR |
Rd |
|
Logical Shift Right |
Rd(n) ← Rd(n+1), Rd(7) ← 0 |
Z,C,N,V |
1 |
ROL |
Rd |
|
Rotate Left Through Carry |
Rd(0)←C,Rd(n+1)← Rd(n),C←Rd(7) |
Z,C,N,V |
1 |
257
8246B–AVR–09/11
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mnemonics |
Operands |
Description |
|
Operation |
Flags |
#Clocks |
|
|||
|
|
|
|
|
|
|
|
|
|
|
ROR |
Rd |
Rotate Right Through Carry |
Rd(7)←C,Rd(n)← Rd(n+1),C←Rd(0) |
Z,C,N,V |
1 |
|
||||
ASR |
Rd |
Arithmetic Shift Right |
Rd(n) ← Rd(n+1), n=0..6 |
Z,C,N,V |
1 |
|
||||
SWAP |
Rd |
Swap Nibbles |
Rd(3..0)←Rd(7..4),Rd(7..4)←Rd(3..0) |
None |
1 |
|
||||
BSET |
s |
Flag Set |
SREG(s) ← 1 |
SREG(s) |
1 |
|
||||
BCLR |
s |
Flag Clear |
SREG(s) ← 0 |
SREG(s) |
1 |
|
||||
BST |
Rr, b |
Bit Store from Register to T |
T ← Rr(b) |
T |
1 |
|
||||
BLD |
Rd, b |
Bit load from T to Register |
Rd(b) ← T |
None |
1 |
|
||||
SEC |
|
Set Carry |
C ← 1 |
C |
1 |
|
||||
CLC |
|
Clear Carry |
C ← 0 |
C |
1 |
|
||||
SEN |
|
Set Negative Flag |
N ← 1 |
N |
1 |
|
||||
CLN |
|
Clear Negative Flag |
N ← 0 |
N |
1 |
|
||||
SEZ |
|
Set Zero Flag |
Z ← 1 |
Z |
1 |
|
||||
CLZ |
|
Clear Zero Flag |
Z ← 0 |
Z |
1 |
|
||||
SEI |
|
Global Interrupt Enable |
I ← 1 |
I |
1 |
|
||||
CLI |
|
Global Interrupt Disable |
I ← 0 |
I |
1 |
|
||||
SES |
|
Set Signed Test Flag |
S ← 1 |
S |
1 |
|
||||
CLS |
|
Clear Signed Test Flag |
S ← 0 |
S |
1 |
|
||||
SEV |
|
Set Twos Complement Overflow. |
V ← 1 |
V |
1 |
|
||||
CLV |
|
Clear Twos Complement Overflow |
V ← 0 |
V |
1 |
|
||||
SET |
|
Set T in SREG |
T ← 1 |
T |
1 |
|
||||
CLT |
|
Clear T in SREG |
T ← 0 |
T |
1 |
|
||||
SEH |
|
Set Half Carry Flag in SREG |
H ← 1 |
H |
1 |
|
||||
CLH |
|
Clear Half Carry Flag in SREG |
H ← 0 |
H |
1 |
|
||||
DATA TRANSFER INSTRUCTIONS |
|
|
|
|
|
|
|
|
|
|
MOV |
Rd, Rr |
Move Between Registers |
Rd ← Rr |
None |
1 |
|
||||
MOVW |
Rd, Rr |
Copy Register Word |
Rd+1:Rd ← Rr+1:Rr |
None |
1 |
|
||||
LDI |
Rd, K |
Load Immediate |
Rd ← K |
None |
1 |
|
||||
LD |
Rd, X |
Load Indirect |
Rd ← (X) |
None |
2 |
|
||||
LD |
Rd, X+ |
Load Indirect and Post-Inc. |
Rd ← (X), X ← X + 1 |
None |
2 |
|
||||
LD |
Rd, - X |
Load Indirect and Pre-Dec. |
X ← X - 1, Rd ← (X) |
None |
2 |
|
||||
LD |
Rd, Y |
Load Indirect |
Rd ← (Y) |
None |
2 |
|
||||
LD |
Rd, Y+ |
Load Indirect and Post-Inc. |
Rd ← (Y), Y ← Y + 1 |
None |
2 |
|
||||
LD |
Rd, - Y |
Load Indirect and Pre-Dec. |
Y ← Y - 1, Rd ← (Y) |
None |
2 |
|
||||
LDD |
Rd,Y+q |
Load Indirect with Displacement |
Rd ← (Y + q) |
None |
2 |
|
||||
LD |
Rd, Z |
Load Indirect |
Rd ← (Z) |
None |
2 |
|
||||
LD |
Rd, Z+ |
Load Indirect and Post-Inc. |
Rd ← (Z), Z ← Z+1 |
None |
2 |
|
||||
LD |
Rd, -Z |
Load Indirect and Pre-Dec. |
Z ← Z - 1, Rd ← (Z) |
None |
2 |
|
||||
LDD |
Rd, Z+q |
Load Indirect with Displacement |
Rd ← (Z + q) |
None |
2 |
|
||||
LDS |
Rd, k |
Load Direct from SRAM |
Rd ← (k) |
None |
2 |
|
||||
ST |
X, Rr |
Store Indirect |
(X) ← Rr |
None |
2 |
|
||||
ST |
X+, Rr |
Store Indirect and Post-Inc. |
(X) ← Rr, X ← X + 1 |
None |
2 |
|
||||
ST |
- X, Rr |
Store Indirect and Pre-Dec. |
X ← X - 1, (X) ← Rr |
None |
2 |
|
||||
ST |
Y, Rr |
Store Indirect |
(Y) ← Rr |
None |
2 |
|
||||
ST |
Y+, Rr |
Store Indirect and Post-Inc. |
(Y) ← Rr, Y ← Y + 1 |
None |
2 |
|
||||
ST |
- Y, Rr |
Store Indirect and Pre-Dec. |
Y ← Y - 1, (Y) ← Rr |
None |
2 |
|
||||
STD |
Y+q,Rr |
Store Indirect with Displacement |
(Y + q) ← Rr |
None |
2 |
|
||||
ST |
Z, Rr |
Store Indirect |
(Z) ← Rr |
None |
2 |
|
||||
ST |
Z+, Rr |
Store Indirect and Post-Inc. |
(Z) ← Rr, Z ← Z + 1 |
None |
2 |
|
||||
ST |
-Z, Rr |
Store Indirect and Pre-Dec. |
Z ← Z - 1, (Z) ← Rr |
None |
2 |
|
||||
STD |
Z+q,Rr |
Store Indirect with Displacement |
(Z + q) ← Rr |
None |
2 |
|
||||
STS |
k, Rr |
Store Direct to SRAM |
(k) ← Rr |
None |
2 |
|
||||
LPM |
|
Load Program Memory |
R0 ← (Z) |
None |
3 |
|
||||
LPM |
Rd, Z |
Load Program Memory |
Rd ← (Z) |
None |
3 |
|
||||
LPM |
Rd, Z+ |
Load Program Memory and Post-Inc |
Rd ← (Z), Z ← Z+1 |
None |
3 |
|
||||
SPM |
|
Store Program Memory |
(Z) ← R1:R0 |
None |
- |
|
||||
IN |
Rd, P |
In Port |
Rd ← P |
None |
1 |
|
||||
OUT |
P, Rr |
Out Port |
P ← Rr |
None |
1 |
|
||||
PUSH |
Rr |
Push Register on Stack |
STACK ← Rr |
None |
2 |
|
||||
POP |
Rd |
Pop Register from Stack |
Rd ← STACK |
None |
2 |
|
||||
MCU CONTROL INSTRUCTIONS |
|
|
|
|
|
|
|
|
|
|
NOP |
|
No Operation |
|
|
None |
1 |
|
|||
SLEEP |
|
Sleep |
(see specific descr. for Sleep function) |
None |
1 |
|
||||
WDR |
|
Watchdog Reset |
(see specific descr. for WDR/timer) |
None |
1 |
|
||||
BREAK |
|
Break |
For On-chip Debug Only |
None |
N/A |
|
258 ATtiny2313A/4313
8246B–AVR–09/11