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

MIP Lab03

This document is a laboratory manual for an introduction to the AVR Atmega32 microcontroller. It provides learning objectives about using Atmel Studio 6 and Proteus 8 to perform assembly language I/O operations and simulations. It describes microcontrollers versus microprocessors, applications of microcontrollers, the AVR microcontroller family with a focus on the Atmega32 specifications and pin layout. It also covers basic concepts of C versus assembly languages, declaring ports as inputs and outputs, reading from and writing to ports with example code, and how to use Atmel Studio 6 to create projects, write assembly code, build and simulate projects to debug code.

Uploaded by

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

MIP Lab03

This document is a laboratory manual for an introduction to the AVR Atmega32 microcontroller. It provides learning objectives about using Atmel Studio 6 and Proteus 8 to perform assembly language I/O operations and simulations. It describes microcontrollers versus microprocessors, applications of microcontrollers, the AVR microcontroller family with a focus on the Atmega32 specifications and pin layout. It also covers basic concepts of C versus assembly languages, declaring ports as inputs and outputs, reading from and writing to ports with example code, and how to use Atmel Studio 6 to create projects, write assembly code, build and simulate projects to debug code.

Uploaded by

Usman jan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Microprocessor Interfacing &

Programming
EL-303
LABORATORY MANUAL
Fall 2017

LAB 03
Introduction to AVR Atmega32, Atmel Studio and Proteus 8 to Perform
Assembly Language I/O and operational Coding and Simulation

Student Name: _______________________________________

Roll Number: p __ - _________ Group: ________

Prepared by: Engr. Muhammad Usman Abbasi

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES (NUCES),


PESHAWAR
EL-303 Microprocessor Interfacing & Programming Lab

LAB #3

Lab Title: Introduction to AVR Atmega32, Atmel Studio and Proteus 8


to Perform Assembly Language I/O and operational Coding
and Simulation
Learning Introduction to:
Objectives:  Atmel Studio 6
 Proteus 8 as a Simulator and Assembler
Demonstration of:
 Basic assembly language
 Load/Store data into registers
 Parallel ports programming to read/write the data
 Addition, Subtraction, Increment and Decrement operations on registers

Hardware/ PC
Software Atmel Studio 6
Required: Proteus 8

Introduction:

Microcontroller vs. Microprocessor


Description Microprocessor Microcontroller

Examples Pentium (Intel) 8051, PIC, AVR


RAM, ROM and I/O Have no RAM, ROM or I/O. Limited RAM and ROM
pins Have to connect external RAM, ,Have built-in RAM, ROM, I/O
ROM and I/O Ports, Timer, Serial Port

Applications Can execute wide range of Used for specific embedded


programs applications

Architecture High processing speed and Simple 8-bit Architecture


Complex Architecture

A microcontroller (or MCU) is a computer-on-a-chip used to control electronic devices. It is a


type of microprocessor emphasizing self-sufficiency and cost-effectiveness, in contrast to a
general-purpose microprocessor (the kind used in a PC). A typical microcontroller contains all
the memory and interfaces needed for a simple application, whereas a general purpose
microprocessor requires additional chips to provide these functions.

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Applications of microcontroller

Different Embedded Systems

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Microcontroller Family:

Microcontroller
Family

Motorola PIC 8051 Hitachi ARM Others

Intel Philips Atmel Simemens Dallas

AT89 Series AVR Series Others

ATMEGA 32

Specifications of Atmega32 Microcontroller

Memory Code ROM Flash 32 KB

Data ROM EEPROM 1 KB

Data RAM SRAM 2 KB

Peripherals 4- IO Ports (PA, PB, PC, PD) Each 8-bit


Oscillator Internal
External 16 MHz max.
2
Serial Communication SPI, I C (TWI), USART
Interface
Miscellaneous ADC 10-bit ,8 input channels
Timers/Counters Two, 8-bit. One, 16 bit
PWM 4 channels

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Operating Voltage – 4.5V - 5.5V for ATmega32

Microcontroller AVR Atmega32: Pin Layout

C vs. Assembly

 High level language vs. low level language


 C is easier to read/write and debug. Assembly becomes too long
 Better synchronization in assembly as directly deal with hardware
 C consumes large memory of RAM as compared to assembly

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Introduction to AVR Atmega32 Instructions:

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Declaring port as input and output using DDRx Register:


Reading from Ports:
Set all the pins of DDRx of the specific port to 0 and then read the Pinx register connected to
the specific port.

Writing to Ports:
Set all the pins of DDRx of the specific port to 1 and then output the data to Portx register
connected to the specific port.

Example Code:

Atmel Studio 6 with assembly and C


 Start the Atmel Studio 6 program by clicking its icon on the Windows Desktop or
from the Start Menu.

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Creating New Project

 Atmel Studio 6 should launch and display a Start Page. To create a new AVR project,
click on the New Project... button, or navigate to File => New => Project...

 The dialogue box that appears should look similar to given Figure. Under Installed
Templates, make sure Assembler is selected.
 Select AVR Assembler Project as the project type.
 In the Name text box, type the name of the project, such as Lab3.
 Make sure that that the checkbox for Create directory for solution is checked.
 The location of the project can be changed by clicking on the Browse... button next to
the path name, and navigating to the desired location for the new project.
 Click OK to continue.

 The next dialogue requires a device selection. First, ensure that the dropdown menu
labeled Device Family: selects either All or megaAVR, 8-bit.

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

 In the ‘Device Selection’ dialog that appears, search for ATmega32 and
then click button OK.

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

 A project file will be created and Atmel Studio displays an initial file Lab3.asm (see
Figure).

Writing the Assemble Code:

Type a simple program in Lab3.asm file as shown in the figure given below.

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Building Project:

Press F7 to assemble, or choose Build Solution from the Build menu.

The results of assembling the


program are shown in the Output window.

Project Simulation

Once a project has been created, and you have written an assembly program, it will need to be
tested. This is accomplished by running the program on a simulated microcontroller built into
Atmel Studio 6. Atmel Studio 6 has the capability to simulate almost every AVR
microcontroller offered by Atmel. For the purposes of this tutorial, the ATmega32 will be the

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

microcontroller that will be simulated. This microcontroller was selected earlier during the
project creation phase. (To change the microcontroller, right-click on your project name in the
Solution Explorer and select Properties. This will open a tab that allows you to configure
various properties of your project. Make sure the Build tab is selected, and then click the
Change Device... button and select a different microcontroller.)

1. Before the program can be simulated, the program must first be compiled. There are three
ways to do this.
(a) In the main Atmel Studio 6 menu, navigate to Build => Build Solution.
(b) Click on the Build Solution icon on the main toolbar.
(c) Press the F7 key.
2. If the code was successfully compiled, a message in the Output window at the bottom
should read “Build succeeded”. If it does not say this, then there were some errors in the
code. Clicking on the errors in the Error
List will highlight the line of code causing the error in the editor window.

Project Debugging:
Once the code has been successfully compiled, simulation can begin. There are two ways to
simulate the chip: debugging mode, which allows a line-by-line simulation, and run mode,
which continuously runs the program.
(a) There are a few ways to run in debug mode
i. Follow the menu Debug => Start Debugging and Break.
ii. Click on the Start Debugging and Break icon.
iii. Press Alt+F5.
(b) To debug the program step by step, Use Step into to go to next instruction, or Step Over
to go to previous instruction.

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

To stop the simulation at any point:


i. Follow the menu Debug => Stop Debugging.
ii. Click on the Stop Debugging Icon.
iii. Press Ctrl+Shift+F5.
This is how to simulate a program.

Processor and I/O View


Atmel Studio lets you examine the contents of CPU registers and IO ports during Debugging.
To enable these views, select menu Debug | Windows and then Processor View or I/O View.

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

 A yellow arrow will appear in the code window; it indicates the Assembly instruction
to be executed next.
 While debugging the Assembly program, you can change the contents of a register. For
example, to change Port B Input Pins register (PINB), click on the value column of 8
PINB and enter a new value. This change will take effect immediately. As PORTB is
being treated as input, so, you have to change the value of DDRB=0xFF as shown in
figure.

Debugging Steps:
1- Before debugging you can see values of Program counter, all four ports and registers
from 0-31.

2- After executing the first line you can see that register R17 has value 0x00.

3- After next step DDRA will have the value of register R17 i.e, 0x00.

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

4-After execution of next line register R18 will have value of 0xff.

5-Now DDRB register will have value stored in register R18 i.e, 0xff

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

6-In this step pinb value will be stored in register R19 as in this case it is 0x12.

7- In the next step value of debugging value of register R19 will be displayed on
portb.

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Status Register:
 Status Register has various flag bits which are set or cleared by the processor on
execution of arithmetic operation
 These bits indicate the status of the operation
 Carry/Borrow has occurred
 Overflow has occurred
 Result is zero
 These bits are used to implement conditional instructions

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

STS Command:
To visualize data stored in a specific memory location, use Memory (EEPROM) as shown in
the figure.

Adding two numbers:

Simulation on Proteus

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Loading Hex File in Proteus Atmega32


When the project is build, the Hex file is generated in Atmel Studio. You can check the path
of hex file as shown in the figure.

Open the Proteus Simulation.

Double Click on AVR Atmega32 MCU. Edit Component Window will be opened.

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Choose the specific Hex file, and Click Open and then Press OK.

Run Proteus Simulation, It will perform the required functionality.

Lab 3 Performance:

Department of Electrical Engineering FAST NU, Peshawar


EL-303 Microprocessor Interfacing & Programming Lab

Task 3.1
Write Assembly language program for Atmega32 microcontroller to write 0xAA in Register
R23, and Copy register R23 value into register R24. Display the results on Atmel Studio
Processor view.
Task 3.2
Write Assembly language program for Atmega32 microcontroller which takes input from
PORTA and PORTB. Add and subtract both Numbers and display result on PORTC and
PORTD respectively. Show the results on Atmel Studio I/O view.
Generate Hex file from Atmel Studio and Implement simulation in Proteus 8.
Task 3.3
Write code to design an Up Counter that counts from 0xF0 to 0xFF. Debug the code and Check
the Status register bits and Counter Current value in Processor View at each count.
Task 3.4
Write code to design a Down Counter that counts from 0xFF to 0xF0. Debug the code and
Check the Status register bits and Counter Current value in Processor View at each count.
Task 3.5
Write code to take input from PORTA, store the input value on 0x200 memory location
(EEPROM). Then transfer the data from 0x200 to 0x300 location.

Department of Electrical Engineering FAST NU, Peshawar

You might also like