What is an AVR ?
First of all AVR stands for: Advanced Virtual RISC, the founders are Alf Egil Bogen Vegard Wollan RISC (also forms AVR). An AVR is a small microcontroller (chip, IC) which is switching digitally (controller) by means of so called i/o’s (input/output pins) The i/o’s do all the digital switching. The AVR’s used on this website are 8-bit AVR’s, meaning 1 byte (1 byte = 8 bits) width working registers, a register is a place in the AVR where you can store and manipulate bits, you can do this with the 118+ so called instructions. The AVR is based on the Harvard RISC architecture which means that one instruction only takes about one clock-cyle, which again means if you put an X-tal of 4 MHz to the AVR, the processing speed is 4 MIPS (million instructions per second) Most instructions are only one clock-cycle (1/ck -> 1/4.000.000 sec), some are two clock-cycles (2/ck) The instructions are abbreviations of names, i.e ldi means: Load Immidiate, what means; load a value directly to a register, i.e.:
ldi temp, 0x0A
In this example, you load (put) the value 0x0A (hexadecimal value) into the register ‘temp’. 0x0A means A (= 10 decimal). What does this mean? You know the registers are 8 bit width, so if you really want to see how the value 0x0A sits in the register, you must convert is to binairy (the processor only operates with 1’s and 0’s), then you will see this: 00001010. So you already know the maximum value per register is 11111111 (255), with AVR assembly you write values like this: binairy = 0b00001010, decimal = 10, hexadecimal = 0x0A.
So how can I make a LED go on and off ?
An AVR has one or more so called PORTs, this is a register which is controlling the pins of the AVR, you can make a pin an input or an output, this is done with the Data Direction Registers DDRn (n is A, B, C or D, depends on which AVR using), suppose you want to make pin 11 of PORTD an output, do this:
sbi DDRD, led
If ‘led’ was 6 (PD6), pin 11 would become an output (because you did Set the 6th bit in the DDRD register) Now you made this i/o as an output. The next thing to do is, make the pin high and low with a certain speed, by connecting a LED + serie resistor (330 ohm) on the pin, you can see what really happens. Connect like this:
For more detail: AVR assembly language
This free embedded project also found using:
- atmega328p assembly language