Lab Handout#02 Solved
Lab Handout#02 Solved
Lab Experiment#2
AVR I/O PORT Assembly Programming and Simulation of the Program in Proteus
Name Hitesh Kumar Roll # 21ES048
Signature of Lab Tutor Date
RUBRICS:
DATA ANALYSIS
Performance Metric
PARTICIPATION
OBSERVATION/
ENGINEERING
CALCULATION
EXPERIMENT
AND CODING
CONDUCTING
TEAMWORK
Total Score
PROGRAM
MODERN
RESULTS
USE OF
TOOLS
0.5 0.5 1 1 1 1 05
Obtained
OBJECTIVE(S)
The purpose of this lab is to:
# Topic # Of Lectures CLO Taxonomy level
Understand the basics of Assembly Programming
1
of AVR I/O Port. 3 4,5 P3, A2
2 Become familiar with lab Tool –Proteus
OUTCOME(S)
a. An ability to use the techniques, skills, and modern PLO5: Modern Tool Usage
engineering tools necessary for engineering practice.
b. An ability to function on multi-disciplinary teams PLO9: Individual and Teamwork
Digital input output (I/O) is the basic feature supported by AVR micro controller. To facilitate
digital input output, three registers are associated with each port of the micro controller.
Data Direction Register– This register determines which of the pins will act as an output
port, and which of them as input.
Data Output Register-This register holds the Data output to the port.
Data Input Register– Reads data from the port
Initialize ports as Input / Output:
Following registers should be loaded with the described data to initialize ports as Input
/ Output:
DDRx = 0xFF; // Initialize PORT as an Output
and in binary we can write as: DDRx= 0b11111111
DDRx = 0x00; // Initialize PORT as an Input
And in binary we can write as : DDRx= 0b00000000
Step 1: Write the above program#01 in AVR Studio Assembler and build the Program. Note the
Hex file creation and its path.
Step 2: Open Proteus. At the home page, click on New Project as shown in figure 1.
Figure 1: Home page of Proteus Design Suite 8.0
Step 3: In the name section type the name you want to give to your project and then click on
Next (figure 2).
Figure 2: New Project Wizard: Start Figure 3: New Project Wizard: Schematic Design
Step 4: Click on a circle that says create a schematic from a selected template, and then select
DEFAULT and click on Next (figure 3).
Step 5: Click on a circle that says do not create a PCB layout and click on Next (figure 4).
Figure 4: New Project Wizard: PCB layout Figure 5: New Project Wizard: Firmware
Step 6: Click on firmware project, select the family-AVR, Controller- ATmega16/ ATmega32
and Compiler-AVRASM(Proteus) as shown in figure 5 and click on Next. It will show you a
summary of your project as shown in figure 6.
Step 7: Now click on Finish. The page appears should be something like this as shown in figure
7.
Figure 7: Proteus Workplace
Click on LED and place anywhere you want to. For ground, there is an option on the left
side called terminal mode. Select ground and place anywhere you want to. Draw the
schematic as shown above figure 9.
Now you have loaded this program into the microcontroller Atmega16/Atmega32. To
simulate the program Click on the play button in the bottom shown in figure 11, left
corner of the page and if everything works fine, your LED should glow.
.INCLUDE "M16DEF.INC"
.ORG 0000
LDI R16,0x00
OUT DDRC, R16 ; making PORT C as input
LDI R17,0xFF
OUT DDRB,R17 ; making PORT B as output
AGAIN: IN R0,PINC ; Read continuously from PORT C
OUT PORTB,R0 ; & send it to PORT B
JMP AGAIN
Proteus Output Simulation result
Lab Tasks:
Simulate on Proteus and execute the following programs on AVR chip. Attach the Assembly
program files and simulation results snapshots along with the handouts.
1. Write an Assembly language program that gets data from switches connected at Port
C and display the complimented output data to Port B.
2. Write an Assembly program that gets data from the lower nibble of Port C and put it
to upper nibble of port B.
3. Write an Assembly program that that count numbers from 0 to 255 on Port B.
Solution:
4. Write an Assembly program that toggle an LED connected PA2 with a small delay.