English
Language : 

ATTINY40_14 Datasheet, PDF (16/204 Pages) ATMEL Corporation – 8-bit Atmel tinyAVR Microcontroller
To read a location the user must first write the RAM address into RAMAR and then read the data from RAMDR.
Reading the data from RAMDR triggers the read operation and the data from RAM address given by RAMAR is
fetched and written to the destination register within the same instruction cycle.
Assembly Code Example
RAM_write:
; Set up address (r17) in address register
out RAMAR, r17
; Write data (r16) to data register
out RAMDR, r16
ret
RAM_read:
; Set up address (r17) in address register
out RAMAR, r17
; Read data (r16) from data register
in r16, RAMDR
ret
C Code Example
void RAM_write(unsigned char ucAddress, unsigned char ucData)
{
/* Set up address register */
RAMAR = ucAddress;
/* Write data into RAMDR */
RAMDR = ucData;
}
void RAM_read(unsigned char ucAddress, unsigned char ucData)
{
/* Set up address register */
RAMAR = ucAddress;
/* Read data from RAMDR */
ucData = RAMDR;
}
5.3 I/O Memory
The I/O space definition of the ATtiny40 is shown in “Register Summary” on page 189.
All ATtiny40 I/Os and peripherals are placed in the I/O space. All I/O locations may be accessed using the LD and
ST instructions, enabling data transfer between the 16 general purpose working registers and the I/O space. 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. See document
“AVR Instruction Set” and section “Instruction Set Summary” on page 191 for more details. When using the I/O
specific commands IN and OUT, the I/O addresses 0x00 - 0x3F must be used.
For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory
addresses should never be written.
ATtiny40 [DATASHEET]
16
8263B–AVR–01/2013