
AN INTRODUCTION INTENDED FOR PEOPLE WITH NO PRIOR AVR KNOWLEDGE - AVRFREAKS.NET
11
;My Very First AVR Project
Lines beginning with " ; " (semicolon) are comments.
Comments can be added to any line of code. If comments
are written to span multiple lines, each of these lines much
begin with a semicolon
Different AVR devices have e.g. PORTB placed on different
location in IO memory. These .inc files maps MNEMONICS
codes to physical addresses. This allows you for example
to use the label PORTB instead of remembering the
physical location in IO memory (0x18 for AT90S8515)
The .def (Define) allow you to create easy to remember
labels (e.g. Temp) instead of using the default register
Name (e.g. R16). This is especially useful in projects
where you are working with a lot of variables stored in the
general purpose Registers (The Datasheet gives a good
explanation on the General Purpose Registers!)
This is a directive to the assembler that instructs it to place
the following code at location 0x0000 in Flash memory. We
want to do this so that the following RJMP instruction is
placed in location 0 (first location of FLASH). The reason is
that this location is the Reset Vector, the location from
where the program execution starts after a reset, power-
on or Watchdog reset event. There are a also other
interrupt vectors here, but our application does not use
interrupts, so we can use this space for regular code!
Since the previous command was the .org 0x0000, this
Relative Jump (RJMP) instruction is placed at location 0 in
Flash memory, and is the first instruction to be executed.
If you look at the Instruction Set Summary in the
Datasheet, you will see that the AT90S8515 do not have a
JMP instruction. It only has the RJMP instruction! The
reason is that we do not need the full JMP instruction. If
you compare the JMP and the RJMP you will see that the
JMP instruction has longer range, but requires an
additional instruction word, making it slower and bigger.
RJMP can reach the entire Flash array of the AT90S8515,
so the JMP instruction is not needed, thus not
implemented.
This is a label. You can place these where you want in the
code, and use the different branch instructions to jump to
this location. This is quite neat, since the assembler itself
will calculate the correct address where the label is.
Ah.. finally a decent instruction to look at: Load Immediate
(LDI). This instruction loads an Immediate value, and
writes it to the Register given. Since we have defined the
R16 register to be called "Temp", this instruction will write
the hex value 0xff (255 decimal) to register R16.
Why aren't we just writing "ldi DDRB, Temp"? A good
question, and one that require that we take a look in the
Instruction Set Manual. Look up the "LDI" and "OUT"
instructions. You will find that LDI has syntax : "LDI Rd, K"
which means that it can only be used with General Purpose
Registers R16 to R31. Looking at "OUT" instruction we see
that the syntax is "OUT A, Rr" Which means that the
content that is going to be written by the OUT instruction
Comentários a estes Manuais