Provided you are familiar with C, I recommend to
- start with the AVR Libc reference
- inspect iom328p.h for your processor specific definitions (located under
...\Atmel Toolchain\AVR8 GCC\Native\[#.#.####]\avr8-gnu-toolchain\avr\include\avr
)
- optionally, in Atmel Studio create a new ASF board project selecting device ATmega328p and inspect the sources loaded into your project folder from the "user_board" template (which anyway is a generic nearly empty set of
*.h
's providing space for things you may/may not need)
- have the complete processor manual close to you at all times - register and bitnames found there match with the definitions in AVR libraries
Be aware that the libraries coming with Atmel Studio and the toolchain support the m328P, but the UNO board per se is not supported by the ASF. However, for basic programming you will be fine.
adding ... on PORTB
PORTB
is defined in your processor's specific ...io.h
(1st bullet above) which is automatically included by including <io.h>
and choosing the correct processor in AVR Studio. In the library of your processor you find
#define PORTB _SFR_IO8(0x05)
Looking up the processor guide (4th bullet above) page 615 you see that PORTB is at I/O address 0x05
(q.e.d.). _SFR_IO8(..)
by itself is a macro defined in <avr/sfr_defs.h>
to convert from I/O to memory address (yes the lower registers are double mapped as I/O and Memory, whereby Memory address is by 0x20 higher because the lowest Memory addresses are occupied by R0 to R31).
By including <io.h>
you get from the AVR library
#include <avr/io.h>
// included by io.h
// #include <avr/sfr_defs.h>
// #include <avr/portpins.h>
// #include <avr/common.h>
// #include <avr/version.h>
// #include <avr/io(your_processor).h> via processor declaration ... fuses
// #include <avr/(maybe some more).h>
All these ...h
's (and some more) finally let you program in C using the register/port/pin names you find in the processor manual.
There are some more usefull libs like
#include <stdint.h> // Type definitions, e.g. uint8_t
// #include "stdint-gcc.h"
#include <avr/power.h> // clock prescaler macro
#include <avr/interrupt.h> // interrupt macros
you will find libs to support reading/writing from/to program and flash memory etc. etc.