Lab 05 MIP
Lab 05 MIP
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
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:
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
A high on this pin for two machine cycles while the oscillator is running resets 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.
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.
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.
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.
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.)