Introduction to AVR assembler programming for beginners

Ports in the AVR are gates from the central processing unit to internal and external
hard- and software components. The CPU communicates with these components, reads from
them or writes to them, e.g. to the timers or the parallel ports. The most used port
is the flag register, where results of previous operations are written to and branch
conditions are read from.

There are 64 different ports, which are not physically available in all different AVR
types. Depending on the storage space and other internal hardware the different ports
are either available and accessable or not. Which of these ports can be used is listed
in the data sheets for the processor type.

and the registers of the 8515 are all defined then and easily accessable.

Ports usually are organised as 8-bit numbers, but can also hold up to 8 single bits
that don't have much to do with each other. If these single bits have a meaning they
have their own name associated in the include file, e.g. to enable manipulation of a
single bit. Due to that name convention you don't have to remember these bit positions.
These names are defined in the data sheets and are given in the include file, too. They
are provided here in the port tables.

The Out command brings the content of my preferred register, a Sleep-Enable-Bit called
SE, to the port MCUCR and sets the AVR immediately to sleep, if there is a SLEEP
instruction executed. As all the other bits of MCUCR are also set by the above instructions
and the Sleep Mode bit SM was set to zero, a mode called half-sleep will result: no
further command execution will be performed but the chip still reacts to timer and
other hardware interrupts. These external events interrupt the big sleep of the CPU
if they feel they should notify the CPU.

reads the bits in port MCUCR to the register. As many ports have undefined and unused
bits in certain ports, these bits always read back as zeros.

More often than reading all 8 bits of a port one must react to a certain status of a
port. In that case we don't need to read the whole port and isolate the relevant bit.
Certain commands provide an opportunity to execute commands depending on the level
of a certain bit (see the JUMP section). Setting or clearing
certain bits of a port is also possible without reading and writing the other bits in
the port. The two commands are SBI (Set Bit I/o) and CBI (Clear Bit I/o). Execution
is like this:

.EQU ActiveBit=0 ; The bit that is to be changed SBI PortB, ActiveBit ; The bit will be set to one CBI PortB, Activebit ; The bit will be cleared to zero

These two instructions have a limitation: only ports with an adress smaller than 0x20
can be handled, ports above cannot be accessed that way.

By far the mostly used port is the status register with its 8 bits. Usually access to
this port is only by automatic setting and clearing bits by the CPU or accumulator,
some access is by reading or branching on certain bits in that port, in a few
cases it is possible to manipulate these bits directly (using the assembler command
SEx or CLx, where x is the bit abbreviation). Most of these bits are set or cleared
by the accumulator through bit-test, compare- or calculation-operations. The
following list has all assembler commands that set or clear status bits depending
on the result of the execution.