Lab 03
Introduction to Programming in Assembly for AVR
Microcontrollers and Basic Input/Output Operations
using Assembly
Prepared by
Abdul Samad
Objectives:
To familiarize with PCB designing and etching process.
To get started with assembly language programming for
microcontrollers.
Tools:
For PCB designing: Cooper sheet, Ferric Chloride ,Printer & Drill
machine.
AVR Studio, Proteus ISIS
ISIS.
COMSATS Institute of Information Technology, Islamabad
AVR Assembler:
We will be using AVR assembler in this lab. This assembler is automatically
installed when AVR Studio is installed.
The Assembler translates assembly source code into object code. The
generated object code can be used as input to a simulator or an emulator such
as the Atmel AVR In-Circuit Emulator. The Assembler also generates a
PROMable code and an optional EEPROM file which can be programmed
directly into the program memory and EEPROM memory of an AVR
microcontroller.
3-Select AVR Assembler as project type. Specify the project location and give
your project a suitable name and click next to get the following window:
4-Select AVR Simulator in debug platform and ATMEGA16 in Device list. Then
clicking on finish will complete the project setup.
Now we can use MyPreferredRegister instead of R16 and use it to access R16
wherever needed.
Semicolon ; is always succeeded by comments in other words you can insert
comments after semicolon in assembly. Consider an Example
LDI temp, 150 ; will load 150 to R16 where LDI is Load Immediate
Registers R26 to R31 are used as two-byte pointers by more advanced
commands. Similarly R0 to R15 also have some restrictions for usage.
Therefore we usually stick with R16-R25 for our use.
Some examples for assembly instructions:
ANDI Rx,K; Bit-And of register Rx with a constant value K
ORI Rx,K; Bit-OR of register Rx with a constant value K
CPI Rx,K; Compare the content of the register Rx with a constant value K
SBR Rx,M; Set all bits in register Rx to one, that are one in the constant
mask M
CBR Rx,0b00110000; Clear bits 4 & 5 (Clear bits that are set in constant mask)
SER Rx; Set all bits in register Rx to one (equal to LDI Rx,255)
SUBI Rx,K; Subtract the constant K from the content of register Rx and
store the result in register Rx
In lab task 1:
Interface a led seven segment display to the ATMEGA16 microcontroller
and display numbers from 0 t0 9 one after the other. There should be a
delay of 1 second between each digit. The display should restart from 0
after displaying 9.
The proteus circuit is shown below.