Lab Task6,7,8,9,10
Lab Task6,7,8,9,10
______________________________________________________
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
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)