AVR assembly language

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

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top