Professional Documents
Culture Documents
Lab Manual: MT-359L Microcontroller and Embedded System
Lab Manual: MT-359L Microcontroller and Embedded System
Name
Registration Number
Class
Instructor’s Name
Session
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
Safety Precautions
Be calm and relaxed, while working in lab.
When working with voltages over 40 V or current over 10 A , there must be at least two
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
When working with energize circuit use only one hand while keeping rest of your body
o Disconnect the power source from the circuit breaker and pull out the plug using
insulated material.
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
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.
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:
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
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:
Assembly Code:
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
delay_05:
LDI r16, 8
outer_loop:
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
#include <avr/io.h>
#include <util/delay.h>
int main(void)
while(1)
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.
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.
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.
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.
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.