
AN INTRODUCTION INTENDED FOR PEOPLE WITH NO PRIOR AVR KNOWLEDGE - AVRFREAKS.NET
12
has to be fetched from one of the 32 (R0 to R31) General
Purpose Registers. Anyway, this instruction sets the Data
Direction Register PORTB (DDRB) register to all high. By
setting this register to 0xFF, all IO pins on PORTB are
configured as outputs.
We Now write the value 0xFF to PORTB, which would give
us 5V (Vcc) on all PORTB IO pins if we where to measure it
on a real device. Since the IO ports is perhaps the most
used feature of the AVR it would be a good idea to open
the Datasheet on the PORTB. Notice that PORTB has 3
registers PORTB, PINB and DDRB. In the PORTB register
we write what we want written to the physical IO pin. In
the PINB register we can read the logic level that is
currently present on the Physical IO pin, and the DDRB
register determines if the IO pin should be configured as
input or output. (The reason for 3 registers are the "Read-
Modify-Write" issue associated with the common 2 register
approach, but this is a topic for the Advanced class.)
This Decrement (DEC) instruction decrements the Temp
(R16) register. After this instruction is executed, the
contents of Temp is 0xFE. This is an Arithmetic instruction,
and the AVR has a wide range of Arithmetic instructions.
For a complete listing of available instruction: Look in the
Instruction Set Summary in the Datasheet!
Here we make a jump back to the Loop lable. The program
will thus continue to write the Temp variable to PORTB
decrementing it by one for each loop.
I guess you have figured out what our masterpiece is doing. We have made a
counter counting down from 255 to 0, but what happens when we reach zero?
To find out this, we will simulate the behaviour in AVR Studio 4.
Comentários a estes Manuais