Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
36 views

Lab Handout#02 Solved

The document provides information about an embedded systems lab experiment on AVR I/O port assembly programming and simulation in Proteus. It includes objectives, outcomes, required tools, basics of AVR I/O port programming, an example program to turn on an LED, and steps to simulate the program in Proteus including designing the circuit and loading the program file.

Uploaded by

hk2359140
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Lab Handout#02 Solved

The document provides information about an embedded systems lab experiment on AVR I/O port assembly programming and simulation in Proteus. It includes objectives, outcomes, required tools, basics of AVR I/O port programming, an example program to turn on an LED, and steps to simulate the program in Proteus including designing the circuit and loading the program file.

Uploaded by

hk2359140
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

MEHRAN UNIVERSITY OF ENGINEERING AND TECHNOLOGY, JAMSHORO

DEPARTMENT OF ELECTRONIC ENGINEERING

INTRODUCTION TO EMBEDDED SYSTEMS (ES-314)


Batch: 21ES (5th Semester)

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

REQUIRED TOOLS AND SOFTWARES:


 WinAVR (GCC Compiler)
 AVR Studio 4 or any latest version - (for Programming)
 Proteus 8 or any latest version - (for Simulation)

AVR I/O Port Assembly Programming Basics:

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

Getting / Writing Data on Ports:


PINx // to get data from PORT (Input)
PORTx // to write on PORT (Output)
x is the Port name i.e. A, B, C etc.
 For example, we want to set the output direction on PIN#03 of PORTB i.e PB3, then we
can set it as
DDRB= 0b00001000 OR DDRB= (1<<3) OR DDRB= 0x04
 For example, we want to write High on PB3, then we can write as
PORTB= 0b00001000 OR PORTB= (1<<3) OR PORTB= 0x04
 As the data cannot directly be loaded into SFRs so it must be loaded through allowed
GPR’s (i.e.R16 ≤ R ≤ R31). This is further explained in Program Example # 01.

Example Program # 01:


An Assembly language program that turns on LED connected to PB2 of Port B.
Program:
.include "M16DEF.INC"
.org 0000
LDI R16, (1<<2)
OUT DDRB,R16 ; making pin#02 (PB2) of PORT B as output
LDI R17, (1<<2) ; sending data High to PB2
OUT PORTB,R17
AGAIN: JMP AGAIN

Simulate the Program in Proteus


Now, for the execution of the program, we are going to use simulator- Proteus 8. A simulator is
software that is used to test the program written for another machine before loading it. It is good
to simulate the program first because a bad program can damage the whole system. The point is
that you are allowed to make mistakes without the risk of damaging your system. Proteus 8 is
one such software. For simulation of the program in Proteus, follow these steps given below:

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.

Figure 6: New Project Wizard: Summary

Step 7: Now click on Finish. The page appears should be something like this as shown in figure
7.
Figure 7: Proteus Workplace

Designing of the Required Circuit in Proteus


Now, this is your workplace in Proteus. We are going to design a circuit on this page only. We
can simulate the circuit as well. For designing the circuit, we must add components which can
be done by:
 In the left corner, there should be a label named device. Click on P button and under the
Keywords block, type LED, click any color LED you want to add Double click on it as
shown in figure 8. It should be added in your device list as you can see in figure 9.

Figure 8: Pick Device and Components


Figure 9: Required Schematic Diagram

 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.

Simulation of the program in Proteus


Now our work is almost done here. Our circuit is for simulation is complete but for simulation of
the program in Proteus, we must add the program in this microcontroller. For that follow the
steps given below-

Browse Hex file


from PC

Figure 10: Selection of Program file and clock frequency


 Double click on Atmega 16/32. There should be a window appears as shown in figure 10.
 There in the option-program files, click on folder icon button and go to the folder of your
project. In the folder, there should be another folder named Debug. In Debug, double-
click on your “.hex” file. Drop down the CKSEL Fuses option and click on the frequency
1 MHz and click on OK.

 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.

Run the Simulation

Figure 11: Run the Simulation

 Observe the output, as shown in the figure below 12.

. Figure 12: Output Simulation Result


Example Program # 02: Get Data from Port C (Switches) and Put it on Port B (LEDs)

.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.

You might also like