Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Microprocessor Lab3

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

Department of Electrical Engineering

Faculty Member: Dated: 23/2/2022

Course/Section: BEE-13B Semester: 4th

EE-222 Microprocessors Systems


Lab 3: Functions, Branches and Delays

PLO4 -CLO3 PLO5- PLO8-CLO5 PLO9-


CLO4 CLO6
Name Reg. No Viva / Analysis Modern Ethics and Individual
Quiz / of data Tool Safety and Team
Lab in Lab Usage Work
Perform Report
ance
5 Marks 5 Marks 5 Marks 5 Marks 5 Marks
Muhammad Sufiyan 368154
Sadiq

Abdul Hadi 374120


4 Lab Tasks
4.1 Controlling LED
4.1.1 Task A
Turn an LED on or off by sensing a switch connected to a pin as schematic suggests.
Logic low at pin should turn off the LED while logic high should immediately turn it on.

Code:

.ORG 0x00
start:
LDI R20, 0x01
OUT DDRB, R20 ;set the output pins

IN R16, PINB ;take intput from pinb to R16


andI R16, 0x10 ;select only the pin that we have connected
BRNE on ;if 1 then jump to on part of circle
rjmp off ;else jump to off part
on:
LDI R21, 0x01 ;load one to R21
OUT PORTB, R21 ;give to output
RJMP start ;repeat program

off:
LDI R22, 0x00 ;load 0 to R22
OUT PORTB, R22 ;output it to portB
RJMP start ;repeat program
Hardware:

4.2 Delay Function


4.2.1 Task B
Implement a delay function for 500 milliseconds delay. Write an assembly program that
utilizes this function to turn on an LED and wait 500ms and then turn it o_ and wait 500ms
repeatedly in a loop. Include your delay calculations in the report.

Code
.ORG 0x00
LDI R20, 200
LDI R21, 100
LDI R22, 0x01 ;constant that will xor output after every cycle
ldi R16, 0x00 ;will store our output
OUT DDRB, R22 ;for controlling one output LED
DELAY:
NOP
NOP
NOP
DEC R20 ;decrement the first counter and jump to the second
Brne loop2
rjmp end

;initialise2: LDI R21, 100


loop2:
NOP ;the second counter
NOP
NOP
NOP
NOP
NOP
NOP
DEC R21 ;decrement the second counter and jump to start of loop again
BRNE loop2
rjmp DELAY ;if this loop ends then jump back for next decrement of

end:
EOR R16, R22 ;XOR the output
OUT PORTB, R16 ;to output value from xor to the output
LDI R20, 200
LDI R21, 100
RJMP DELAY
4.3 Subroutines and Stack
4.3.1 Task C
The following program stores seven characters in memory. Write a subroutine named
CHECK PALINDROME that return 1 in R16 if this seven letter word is a palindrome
else return 0 in R16. Utilize the property of AVR stack in your function.
Replace these seven characters with "ROTATOR" and then with "JUMPOFF" to check

Code
.ORG 0x00
LDI R16, 'R'
STS 0x200, R16
LDI R16, 'A'
STS 0x201, R16
LDI R16, 'C'
STS 0x202, R16
LDI R16, 'E'
STS 0x203, R16
LDI R16, 'C'
STS 0x204, R16
LDI R16, 'A'
STS 0x205, R16
LDI R16, 'R'
STS 0x206, R16
CALL CheckPalindrome
rjmp Here

Here:
RJMP Here

.ORG 0x50
CheckPalindrome:
LDI R16, 0
LDI R20, 0
LDS R17, 0x200
LDS R18, 0x206
CP R17,R18
BRNE END
LDS R17, 0x201
LDS R18, 0x205
BRNE END
LDS R17, 0x202
LDS R18, 0x204
BRNE END
LDI R16, 1
RJMP Here
Ret
END:
RJMP Here
For Racecar

For Rotator

For JUMPOFF

You might also like