0% found this document useful (0 votes)
25 views

Lab 05 MIP

Uploaded by

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

Lab 05 MIP

Uploaded by

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

Microprocessor Interfacing &

Programming
EL-3002
LABORATORY MANUAL
Fall 2023

LAB 05
ATmega32 delay operations and Implementation of AVR Kit using
Atmega32 Microcontroller and testing of Kit (I/O Ports) by loading hex
files using SUPER PRO Programmer
Engr. Maryam Zafar

2162,1429,
Asma,Aiman Hamna,Nabiha 2196,1429 A
________________________________________ __________ __
STUDENT NAME ROLL NO SEC

______________________________________
LAB ENGINEER SIGNATURE & DATE

MARKS AWARDED: /10


________________________________________________________________
NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES (NUCES),
ISLAMABAD

Prepared by: Engr. Aneela Sabir Version: 1.01


Microprocessor Interfacing & Programming LAB: 05
Last Edited by: Engr. Maryam Zafar Date: 11 September, 2024
Verified by: Dr. Niaz Ahmed Date: 13 September, 2024

ATmega32 delay operations and Implementation of AVR Kit using


LAB: 05 Atmega32 Microcontroller and testing of Kit (I/O Ports) by loading
hex files using SUPER PRO Programmer

Learning Objectives:
a. Introduction to
 BRSH Conditional branch
 Stack Operations
 Delay calculations
 Atmega32 simulation on Proteus.
 Hardware implementation
 Super Pro software to load hex file into Microcontroller
b. Implementation of
 AVR Kit

Equipment Required:
Software Required
a. Atmel Studio 6
b. Proteus 8.5
c. Super Pro Device Programmer
Hardware Required
a. AVR Atmega32 MCU
b. Bread board
c. 5V DC Power Supply
d. Resistors
e. Jumper Wires
f. Push button
g. PC
h. LEDs
i. Programmer

Introduction:
BRSH (Branch same or higher branch if C = 0):
Tests the Carry flag (C) and branches relatively to PC if C is cleared. If the instruction is executed
immediately after execution of any of the instructions CP, CPI, SUB or SUBI the branch will occur
if and only if the unsigned binary number represented in Rd was greater than or equal to the
unsigned binary number represented in Rr.

Example:

MIP Lab 4 NUCES, ISLAMABAD Page 2 of 7


Microprocessor Interfacing & Programming LAB: 05

Stack Operations:
Debug the following code line by line and note the value of stack pointer, R15, R16 and R17 after
every line, stack pointer is available in processor view.

start:
ldi r16,0x009
ldi r17,0xf6
out sph,r16
out spl,r17
push r17
push r16
pop r15
pop r4
push r15
push r16
push r4
rjmp start
Delay Calculations:
10 MHz Processor Instruction Cycles
.DEF COUNT = R20 0
DELAY: LDI COUNT, 0xFF 1
AGAIN: NOP 1
NOP 1
DEC COUNT 1
BRNE AGAIN 2/1
RET 4

Time delay = [1+ ((1+ 1+ 1+ 2) x 255) +4] x 0.1 μs


Time delay = 128.0 μs = 127.9 s
BRNE instruction takes 1 m/c in last execution
Calling subroutines:
. INCLUDE "M32DEF. INC"
.ORG 0
MAIN: CALL SUBROUTINE 1
CALL Delay
HERE: RJMP HERE
; ----end of MAIN

MIP Lab 4 NUCES, ISLAMABAD Page 3 of 7


Microprocessor Interfacing & Programming LAB: 05

For delay functions you need to initialize SP through this code:


.INCLUDE "M32DEF.INC"
LDI R16, HIGH(RAMEND)
OUT SPH, R16
LDI R16, LOW(RAMEND)
OUT SPL, Rl6 ;initialize stack pointer
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.
Serial Communication SPI, I2C (TWI), USART
Interface
Miscellaneous ADC 10-bit ,8 input channels
Timers/Counters Two, 8-bit. One, 16 bit
PWM 4 channels
Operating Voltage – 4.5V - 5.5V for ATmega32
Table 1. ATmega32 Microcontroller Specifications

MIP Lab 4 NUCES, ISLAMABAD Page 4 of 7


Microprocessor Interfacing & Programming LAB: 05

Microcontroller AVR Atmega32: Pin Layout

Figure 1. ATmega32 Pins Description


Reset Circuit
RST (Pin 9)

 Active Low Microcontroller Reset

 A high on this pin for two machine cycles while the oscillator is running resets the
device

MIP Lab 4 NUCES, ISLAMABAD Page 5 of 7


Microprocessor Interfacing & Programming LAB: 05

Figure 2. Reset Circuit

Proteus Simulation and Hardware Implementation:


In previous labs, only simulation part is done, and the circuit diagram for simulation is shown in
figure below:

Figure 3. ATmega32 basic circuit for simulation

To design the AVR Kit follow the given steps:

Step 1: Place Atmega32 Microcontroller IC header on breadboard.


Step 2: Design a reset circuit on PIN 9 of MCU.
Step 3: Connect 5V VCC to pin number 10, 30 and 32.
Step 4: Connect GND to pin number 11 and 31.
Steo 5: Connect Crystal Frequency to pin 12 and 13.

MIP Lab 4 NUCES, ISLAMABAD Page 6 of 7


Microprocessor Interfacing & Programming LAB: 05

Connecting LEDs on hardware for Output:


LED's have a positive side and a negative side, and will only light up when wired correctly. Most
LED's have one longer lead to indicate the polarity, but not all.

Figure 4. LED and its internal structure

Loading Program to MCU using Super PRO:


Actual Dumping of the Code in Microcontroller’s On-chip Memory using Super Pro.
Step 1: Open the Super Pro software
Step 2: Select device i.e. ATmega32 and set following configurations in ConfigWord:

MIP Lab 4 NUCES, ISLAMABAD Page 7 of 7


Microprocessor Interfacing & Programming LAB: 05

Step 3: Erase and blank check device


Step 4: Load the .hex file
Step 5: Program the device

Lab Tasks:

1. Find the sum of the values 0x3A, 0x8F, and 0xC7.Put the sum into R18 (low byte) and R19
(high byte). Use BRSH instruction to write the code.

MIP Lab 4 NUCES, ISLAMABAD Page 8 of 7


Microprocessor Interfacing & Programming LAB: 05

2. Generate table of 5 using addition and push every result after addition to a stack with stack
pointer initialized at 05A3 location. Now pop the results and store in R9. Debug the
program to check the registers status. Display the result on 7 segment display (BCD) on
Proteous.

MIP Lab 4 NUCES, ISLAMABAD Page 9 of 7


Microprocessor Interfacing & Programming LAB: 05

3. Write code in Atmel Studio to toggle all bits of all ports with a delay of 0.5 seconds
continuously. Write a delay function and call it in the main program. Simulate your
program on Proteus. Connect LED banks on all ports to display the output.

MIP Lab 4 NUCES, ISLAMABAD Page 10 of 7


Microprocessor Interfacing & Programming LAB: 05
4. Write a code to blink PORTA pins with a time delay of 0.5 sec. Assume the crystal
frequency of 8 Hz. Simulate your program on Proteous and hardware. \

5. Write a program to toggle all the bits of I/O register PORTB after every 1 sec. Assume that
the crystal frequency is 8 MHz. Initially, your PORTB value is 0xAA. Simulate your
program on Proteous and implement it on hardware.

MIP Lab 4 NUCES, ISLAMABAD Page 11 of 7


Microprocessor Interfacing & Programming LAB: 05

6. Take an input from Port A must be less than 6. Read the value and display the result on
PORTB. (Implement a subroutine to find the factorial of a number stored in a register from
PORTA. Test your subroutine with a sample values and verify the result.)

MIP Lab 4 NUCES, ISLAMABAD Page 12 of 7


Microprocessor Interfacing & Programming LAB: 05

MIP Lab 4 NUCES, ISLAMABAD Page 13 of 7

You might also like