0% found this document useful (0 votes)
76 views11 pages

Lab Task6,7,8,9,10

This document contains 4 lab tasks from a microprocessor and interfacing lab. The tasks involve: 1. Making a circuit on a breadboard to check the waveform frequency of an 8051 microcontroller pin and drawing the 8051 diagram. 2. Writing assembly code to move values between registers on an 8051 microcontroller and simulating the code. 3. Writing more assembly code to increment register values and single-stepping the code in a simulator. 4. Running additional assembly code in a simulator and recording register values at each step.

Uploaded by

Rehmat Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views11 pages

Lab Task6,7,8,9,10

This document contains 4 lab tasks from a microprocessor and interfacing lab. The tasks involve: 1. Making a circuit on a breadboard to check the waveform frequency of an 8051 microcontroller pin and drawing the 8051 diagram. 2. Writing assembly code to move values between registers on an 8051 microcontroller and simulating the code. 3. Writing more assembly code to increment register values and single-stepping the code in a simulator. 4. Running additional assembly code in a simulator and recording register values at each step.

Uploaded by

Rehmat Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Ghulam Ishaq Khan Institute of

Engineering Sciences and Technology

Course Code: ES-314L


Micro-processor and interfacing
Lab task

Name Rehmat Ali


Reg no # 2018391
Submitted to : Engr. Zain
Lab task
Lab no. 6
Q #1
You are required to make this circuit on breadboard and check the waveform at pin
19 using oscilloscope. Verify that its frequency is equal to 12 MHz and show it to
your instructor. Draw the diagram of 8051 with minimum connections in space
provided below.
Q #2
This task is designed to get you familiar with ASEM-51 assembler. Write a simple
assembly language code in which you move a value in register A. Then from
register A, move this value to registers R0-R7. Save this file as .asm and generate
.hex file and simulate it.
ORG 00H
MOV A, # 0FFH
MOV R0,A
MOV R1,A
MOV R2,A
MOV R3,A
MOV R4,A
MOV R5,A
MOV R6,A
MOV R7,A
END

______________________________________________________

Q #3
Write an assembly language code in which a value is moved in register A. Then
from register A, 5H is added to this value and moved to register R0. Keep adding
5H and move the data from R1 to R7 registers. Now load the hex file of this code
in the simulator and use the simulator to single step the program. Examine and
write down the values of registers (PC, ACC, and R0-R9) on each step and show to
your instructor.
ORG 00H
MOV A, # 0FFH
ADD A, # 5H
MOV R0,A
ADD A, # 5H
MOV R1,A
ADD A, # 5H
MOV R2,A
ADD A, # 5H
MOV R3,A
ADD A, # 5H
MOV R4,A
ADD A, # 5H
MOV R5,A
ADD A, # 5H
MOV R6,A
ADD A, # 5H
MOV R7,A
END
______________________________________________________________

Q #4

Run the following code in the simulator and fill the blank spaces in which you are
required to write the values of register A, R0, R1, PC and SP at each step of the
code.
ORG 00H
MOV R0, #22H R0= 0X22H, R1= 0X00H, A= 0X00H, PC= 0X002
MOV R1, 00H R0=0X22 , R1= 0X22, A= 0X00, PC= 0X0004
MOV A, #13H R0= 0X22, R1= 0X22, A= 0X13, PC= 0X006
ADD A, R1 R0= 0X22, R1= 0X22, A= 0X35, PC= 0X007
MOV R1, A R0= 0X22, R1= 0X35, A= 0X35, PC= 0X0008
PUSH 1 R0= 0X22, R1= 0X35, SP= 0X08, PC= 0X000A
PUSH 0 R0= 0X22, R1= 0X35, SP= 0X09, PC= 0X000C
POP 1 R0= 0X22, R1= 0X22, SP= 0X08, PC= 0X000F
POP 0 R0= 0X35, R1= 0X22, SP= 0X07, PC= 0X0010

________________________________________________________________

Lab no. 7
Q #1
Write a code for 8 bit up counter. Increment should be occur after 1 second delay.
Show your result on LEDs connected to Port 1.
ORG 00H
MOV P1, #00000000B
MOV A, #01H
Main : MOV P1, A
ACALL delay
CLR P1
ACALL delay
SJMP Main
; DELAY SUB – ROUTINE
delay : MOV R5, #1000
JNZ R5
ret
END

__________________________________________________________________

Q #2
Write a code which toggle all bits of P1 with 500ms delay. Show the result on
LEDs connected to Port 1.
ORG 00H
Toggle : MOV P1, #01H
CALL delay
MOV A, P1
CPL A
MOV P1, A
CALL delay
sjmp Toggle

; DELAY SUB – ROUTINE


delay : MOV R5, #500
DJNZ R5
ret
END
Lab no. 8
TASK1
Write a code which generates a square wave of central frequency 5 KHz and duty cycle of
70%. Use timer mode 1. Explain mathematical calculations for timer setting and show the
output wave on oscilloscope.

MOV TMOD, #01 ; Timer 0, mode 1


HERE : MOV TL0, #3EH ;Timer value = B83EH
MOV TH0, #0B8H
SETB P2.3
SETB TR0
ACALL DELAY
AGAIN :JNB TF0, AGAIN
CLR TR0
CLR TF0
CLR P2.3

TASK2
Timers in 8051 can also be used as event counter for events happening outside
microcontroller. When C/T bit of TMOD register is set, timer acts as counter. In this case the
counter counts up as the pulses are fed from pins P3.4 and P3.5 for timer 0 and timer 1
respectively. Write a program to count pulses fed to pin 3.4 and move the result on port 1.
MOV TMOD, #01100000
MOV TH1, #0
SETB P3.5
AGAIN : SETB TR1
BACK : MOV A, TL1
MOVE P2, A
JNB TF1, BACK
CLR TR1
CLR TF1
SJMP AGAIN

TASK 3
Write an assembly language code that counts the pulse applied at P3.4 for 4 second and
move the result on port 2. Use timer 1 to create a delay of 4 second after which the count is
checked and reset. Verify your program by applying signals of different frequency and check
their count.
MOV TMOD, #01100000
MOV TH1, #0
SETB P3.5
AGAIN : SETB TR1
BACK : MOV A, TL1
MOVE P2, A
JNB TF1, BACK
CLR TR1
CLR TF1
SJMP AGAIN
Delay subroutine
Mov R4, #10
Mov R5 , # 200
Mov R6, #300
DJNZ R4
DJNZ R5
DJNZ R6
END

Lab no. 9
TASK 2
Write a code which generates a square wave of central frequency 10 KHz using timer 0 in
interrupt mode. Upon Receiving Interrupt, blink LED connected to P1.3 with 2 seconds delay.
Use timer 1 to generate the delay.
ORG 0
LJMP MAIN
ORG 000BH
T0ISR : CPL P1.3
RET
ORG 0030H
MAIN : MOV TMOD , #02H
MOV THO, #-50
SETB TRO
MOV IE, #82H
SJMP$
END

TASK1
Write a code to turn on all LEDs using port 2 for 3 seconds on receiving an external interrupt
0. Use timer in interrupt mode to generate 3 second delay.
ORG 000H
LJMP
ORG 0013H
SETB P2
MOV R0, 3000
WAIT : DJNZ R0, WAIT
CLR P1.1
RET I
ORG 30H
MAIN : SETB IT1
MOV IE, $10000100B
WAIT2 : SJPM WAIT2
END

Lab no. 10
TASK1
Write a program to blink LED using Python.
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function from the time module
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin and set initial
value to low (off)
while True: # Run forever
GPIO.output(8, GPIO.HIGH) # Turn on
sleep(1) # Sleep for 1 second
GPIO.output(8, GPIO.LOW) # Turn off
sleep(1) # Sleep for 1 second

TASK2
Write a program to Turn LED on and off using button.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(13,GPIO.IN) #button
GPIO.setup(21,GPIO.OUT) #led
while True:
if (GPIO.input(13)):
print("on")
GPIO.output(21, GPIO.HIGH)
while False:
if (GPIO.input(13)):

GPIO.output(21, GPIO.LOW)

You might also like