Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

MT-359L Microcontroller and Embedded Systems

MT-359L Microcontroller and Embedded System


Lab Manual

Name

Registration Number

Class

Instructor’s Name

Session

Air University, Islamabad Page 1


MT-359L Microcontroller and Embedded Systems

Introduction
This is the Lab Manual for MT 359L Microcontroller and Embedded System. During
the labs you will work in groups (no more than three students per group) as well as
individual. You are required to complete the ‘Pre-Lab’ tasks assigned before coming
to the lab. You will be graded for this and the ‘In-Lab’ tasks during the in-lab viva.
You will complete the ‘Post-Lab’ section of each lab before coming to the next week’s
lab.

You are not allowed to wander in the lab or consult other groups when performing
experiments. Similarly, the lab reports must contain original efforts. Air University
has a zero tolerance anti-plagiarism policy.

Apart from these weekly labs you will complete mini projects as well as final project.
The grading policy is already discussed in the Course Description File.

Acknowledgement
The labs for MT-359L Microcontroller and Embedded System were designed by Engr.
Umer Farooq. The manuals were prepared by Engr. Haroon Khan and Engr.
Zargham Raza. The first version was completed in Session Fall Sept, 2018.

History of Revision
Version and
Team Comments
Date of Issue

This is the first editable draft of MT-


Engr. Umar Farooq
359L Microcontroller and Embedded
Version 1. Sept
Engr. Haroon Khan System lab manual. For comments and
2018
suggestions please contact:
Engr. Zargham Raza
umer.farooq@mail.edu.pk

Air University, Islamabad Page 2


MT-359L Microcontroller and Embedded Systems

Safety Precautions
 Be calm and relaxed, while working in lab.

 First check your measuring equipment.

 When working with voltages over 40 V or current over 10 A , there must be at least two

people in the lab at all time.

 Keep the work area neat and clean.

 Be sure about the locations of fire extinguishers and first aid kit.

 No loose wires or metals pieces should be lying on the table or neat the circuit.

 Avoid using long wires, that may get in your way while making adjustments or changing

leads.

 Be aware of bracelets, rings, and metal watch bands (if you are wearing any of them). Do

not wear them near an energized circuit.

 When working with energize circuit use only one hand while keeping rest of your body

away from conducting surfaces.

 Always check your circuit connections before power it ON.

 Always connect connection from load to power supply.

 Never use any faulty or damage equipment and tools.

 If an individual comes in contact with a live electrical conductor.

o Do not touch the equipment, the cord, the person.

o Disconnect the power source from the circuit breaker and pull out the plug using

insulated material.

Air University, Islamabad Page 3


MT-359L Microcontroller and Embedded Systems

Lab # 01 Introduction to Development Tools and Lab


Software
Objectives

 Learn to use software development tools such as Arduino IDE, AVR Studio, and
Simulator (Proteus) for the AVR Atmega16 microcontroller.
 Learn to develop code in C and Assembly language for Atmega16
Software Used

 AVR Studio (Version 7/4)


 Proteus ISIS (Version 8.4)
 Audrino IDE
Pre Lab
Get the following software AVR studio Version 7 and Proteus install in your laptops. The same
software will be installed the Lab PCs.

Software’s Introduction:
AVR Studio

AVR Studio is an Integrated Development Environment (IDE) used to develop projects (software
part) for AVR microcontrollers. This IDE consists of a Code Navigator, a Debugger and a
Hardware (MCU registers) Simulator. With AVR Studio, you can develop code in C as well as
Assembly Language. Both approaches are different from each other. Each has its own merits as
you will learn during the coursework.

Proteus

Proteus PCD design is used to design PCB and Proteus VSM is a virtual circuit simulator. Main
ability of Proteus VSM is that it cannot only simulate electric/electronic circuits but it can also
simulate microcontroller based circuits. It can simulate a number of microcontrollers available in
the market.

In-Lab Task 1: AVR Studio 7.0 Learning Tutorial (Creating project in Assembly Language)
To learn how to load a program to an Arduino UNO board using Atmel Studio instead of the
Arduino IDE. This is useful when you need to develop a program using more advance features or
in another language, in this case we are going to use Assembly language.

Step 1: Configuring Atmel Studio

Air University, Islamabad Page 4


MT-359L Microcontroller and Embedded Systems

Air University, Islamabad Page 5


MT-359L Microcontroller and Embedded Systems

Air University, Islamabad Page 6


MT-359L Microcontroller and Embedded Systems

Now plug your Arduino UNO board into your computer and wait while the drivers installs. When
is done take note of the COM port it is using. You can check it in the device administrator if you
missed it. In my case is "COM4" but yours may be different, so pay attention to this.

Open Atmel Studio click in the menu "tools/external tools" You will see a dialog box asking for
some parameters. So let's fill the required information.

In title: "Send to Arduino UNO" or the name you want. In command: "C:\Program Files
(x86)\Arduino\hardware\tools\avr\bin\avrdude.exe" this may vary according to the installation
directory of the Arduino IDE. Check for avrdude.exe directory in your install.

In arguments:

"-C "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf" -p


atmega328p -c arduino -P COM4 -b 115200 -U
flash:w:"$(ProjectDir)Debug\$(TargetName).hex":i" again this can vary according to the
installation directory of the Arduino IDE. You need to replace the COM4 with the actual COM
port your board is using as we see in the device administrator. Check "Use output window" box.
Click OK. We are done, you will see the new option "Send to Arduino UNO" in the tools menu.
Air University, Islamabad Page 7
MT-359L Microcontroller and Embedded Systems

Note: for Atmel Studio 6 users you will need to click in Tools\Select Profile and then set it to
Advance before doing this steps. Thanks to "cysix" for the information.Step 2: Make a test

Air University, Islamabad Page 8


MT-359L Microcontroller and Embedded Systems

We are ready to go, all we need to do is make a little test. So click file/new/project and select
"AVR assembler project under "Assembler" option. Click OK and select ATMEGA328P and click
OK again. Now in the text editor copy and paste the following code:

Air University, Islamabad Page 9


MT-359L Microcontroller and Embedded Systems

Assembly Code:

.ORG 0x0000 // Tells the next instruction to be written

RJMP main // State that the program begins at the main label

main:

LDI r16, 0xFF // Load the immedate value 0xFF (all bits 1) into register 16

OUT DDRB, r16 // Set Data Direction Register B to output for all pins

loop:

SBI PortB, 5 // Set the 5th bit in PortB. (i.e. turn on the LED)

RCALL delay_05

CBI PortB, 5 // Clear the 5th bit in PortB. (i.e. turn off the LED)

RCALL delay_05

RJMP loop // Loop again

// Everything beneath is part of the delay loop

delay_05:

LDI r16, 8

outer_loop:

LDI r24, low(3037)

LDI r25, high(3037)

delay_loop:

ADIW r24, 1

BRNE delay_loop

DEC r16

BRNE outer_loop

RET

To create project in C/C++ select “New Project” then select “C/C++” and “GCC C Executable
Project” then click on “OK”
C-Code:
#define F_CPU 16000000UL

Air University, Islamabad Page 10


MT-359L Microcontroller and Embedded Systems

#include <avr/io.h>

#include <util/delay.h>

int main(void)

DDRB |= (1<<DDB5); //Set the 6th bit on PORTB(PB5) to 1 => output

while(1)

PORTB |= (1<<PORTB5); //Turn 6th bit on PORTB (PB5) to 1 => on

_delay_ms(1000); //Delay for 1000ms => 1 sec

PORTB &= ~(1<<PORTB5); //Turn 6th bit on PORTB(PB5) to 0 => off

_delay_ms(1000); //Delay for 1000ms => 1 sec

Part II- Proteus Introductory Learning Tutorial

To learn basics about Proteus, we will simulate a microcontroller based circuit in Proteus. We will
use the same program for microcontroller which we simulated in AVR Tutorial.

1. Launch Proteus from start menu or by desktop icon. Proteus component library is equipped
with lots of components and ICs including microcontrollers. To pick necessary components
required for circuit, click on small P in device window.

Air University, Islamabad Page 11


MT-359L Microcontroller and Embedded Systems

2. After Clicking Pick devices menu as in figure 1.6 will appear on the screen. There is a
keyword prompt which can refine your search. Write ATmega16 in keyword prompt and
result window will display components having keyword of ATmega16. Double click
ATmega16 component in result window to add it to device list.

3. As described in step 2 add following components needed for this tutorial


i. ATmega16 Microcontroller
ii. Animated LED
iii. 470 ohms resistor

Air University, Islamabad Page 12


MT-359L Microcontroller and Embedded Systems

4. To add any component on root sheet, simply select that component from device window
and click anywhere in the root sheet to place that component. To draw wire connection
between two pins of any components, simply move mouse cursor to the tip of the pin and
click and then click on tip of the other pin you want connect. Draw a circuit shown in figure
1.7 on Proteus root sheet by using components indicated above.

Figure 1.7: Circuit Diagram for In-Lab Task 2

5. On the left side of Proteus layout, different modes can be selected. To add ground terminal
to the circuit, click terminal mode from buttons on left side of screen and then select ground
terminal. You can change characteristic properties of any component. To change, simply
double the required component. An edit component menu will appear for that particular
component where you can change the characteristic properties of that component.
6. You also need to load your required program into the microcontroller as shown in figure
1.8. Program is loaded into microcontroller through hex file. Double click microcontroller,
edit menu will have prompt for load program. Select the hex file generated from AVR
Studio tutorial. This hex (Lab1.hex) file can be found in the Lab1 directory you created on
desktop for the AVR Studio tutorial.

Air University, Islamabad Page 13


MT-359L Microcontroller and Embedded Systems

Figure 1.8: Edit component menu


7. Now Run the Simulation form the bottom of Root Sheet and show result to your lab
instructor (figure 1.9).

Figure 1.9: Start Simulation in Proteus

Air University, Islamabad Page 14


MT-359L Microcontroller and Embedded Systems

Part III - Arduino IDE Introductory Learning Tutorial


In-lab Task 3
Download latest version of Arduino IDE from https://www.arduino.cc/en/main/software. Install
it to your computer. When you open Arduino IDE you will have following window.

1. Make sure to check select correct board from Tools > Board > (Select your Arduino
Board)
2. Select the right port on which Arduino board is connected from Tools > Port > (Select the
port)

In lab Activity: Go to File > Example > Basic > Blink then select the upload button.

After uploading Arduino Board, you will see that the LED of Pin 13 will start blinking.

Air University, Islamabad Page 15

You might also like