AVR Datasheet

Thread Starter

maxx5612

Joined Apr 6, 2020
19
As I'm a new microcontrollers student, I read in a book that in ATmega168 the hardware register for Port B is at byte number five of the memory. And I downloaded the datasheet and kept searching for this in the "pin configuration" section, but I could not figure out where to find this specific information
 

MrChips

Joined Oct 2, 2009
30,706
The information can be found in the Register Summary on page 417 of this document.

http://ww1.microchip.com/downloads/...Microcontroller-ATmega48-88-168_Datasheet.pdf

Note that you have to be careful which address is being used for which type of instruction.
Atmel AVR hardware addresses are located within the general RAM addressing space.
Hardware port addresses begin at address 0x20.
PORTB is at address 0x25.
Use this address when the instructions are referencing RAM space, i.e. load and store instructions.

Use address 0x05 when using output instruction OUT.

Use PINB at address 0x03 when attempting to read the I/O pin.
 

Papabravo

Joined Feb 24, 2006
21,157
How is this related to byte number five?
If you use an instruction that refers to "data memory", the I/O registers begin at address 0x0020, to reference the PORTB Data Register you use address 0x0025.
The I/O instructions IN and OUT reference a subset of the data memory beginning a address 0x0020, to reference the PORTB Data register you only use the offset from 0x0020 or 0x0005
Got it?
 

Papabravo

Joined Feb 24, 2006
21,157
you mean offset from 0x0020 (in hex) or 32 (in deciaml)
All numbers prefixed with a "0x" are hexadeimal numbers. Numbers without that prefix are decimal.

64 locations of I/O space in the AVR data memory map begin at Data Memory Address 0x0020
PORTB Data Register is at Data Memory Address 0x0025
PORTB Data Register is at I/O Space Address 0x0005 which is physically the identical piece of silicon as Data Memory Address 0x0025

You use the Data Memory Address when you use an instruction with Data Memory Addressing
You use the I/O space Address when you use an instruction wit I/O Space Addressing

If you study the instruction set encoding you will come to understand why this is the case.
 

Thread Starter

maxx5612

Joined Apr 6, 2020
19
All numbers prefixed with a "0x" are hexadeimal numbers. Numbers without that prefix are decimal.

64 locations of I/O space in the AVR data memory map begin at Data Memory Address 0x0020
PORTB Data Register is at Data Memory Address 0x0025
PORTB Data Register is at I/O Space Address 0x0005 which is physically the identical piece of silicon as Data Memory Address 0x0025

You use the Data Memory Address when you use an instruction with Data Memory Addressing
You use the I/O space Address when you use an instruction wit I/O Space Addressing

If you study the instruction set encoding you will come to understand why this is the case.
Now I perfectly understand. Can you post a reference for this, please?
 

Papabravo

Joined Feb 24, 2006
21,157
Now I perfectly understand. Can you post a reference for this, please?
Look at Figure 5-2 in the datasheet on page 16.

There is a small typo in the figure. The amount of RAM should be 512/1024/2048 as you can tell from the listed addresses to the right of the block diagram.
 
Top