Microprocessors and Microcontrollers Lab
Microprocessors and Microcontrollers Lab
Lab Assesment-2
Question 1:
Get the Data from Port P1 and Send it to Port P2, Note: P1asinputPortand P2 as Output Port. Take
input as last 2 digits of your Reg. no
Code:
END
Output:
Question 2:
Write and assemble a program to toggle all the bits of P0, P1, and P2 continuously by
sending 55H and AAH to these ports.
Put a time delay between the "on" and "off" states. Then using the simulator, single-step
through the program and examine the ports. Do not single-step through the time delay
call.
Code:
HERE:
; Delay Subroutine
DELAY:
BACK:
MOV R2, #20H ; Load inner loop counter with 32 (hex 20H)
AGAIN:
Output:
Question 3:
A switch is connected to pin P1.7. Write a program to check the status of the switch and perform
the following: (a)If switch = 0, send letter ‘N’ to P2. (b)If switch = 1, send letter ‘Y’ to P2. • Use the
carry flag to check the switch status.
Code:
SETB P1.7 ; Make P1.7 an input (not strictly required for P1)
AGAIN: MOV C, P1.2 ; Read the switch at P1.2 into the Carry flag
OVER: MOV P2, #'Y' ; Switch is HIGH (1), send 'Y' to Port 2
Output:
Question 4:
Write an 8051 program to get the length (8-bit number) and breadth(8-bitnumber) of a rectangle
from port P0 and P1 respectively.
Calculate area and perimeter of the rectangle and send them through port P2 and P3respectively.
Note: assume values of the inputs are such that the outputs do not exceed 8-bits
• Do STEP Simulation
Code:
; Calculate Area (L * B)
MOV P2, A ; Send the low byte of the area to Port P2 (result <= 8 bits)
Output:
Question 5:
Create a square wave of 66% duty cycle on bit 3 of port 1. The 66% duty cycle means the “on” state
is twice the “off” state.
Code:
Output:
Question 6:
Write an 8051 assembly language program to get 8-bit number(x)from port P0. If x is odd number
compute y = x ^ 2 + 5 and if x is even number compute y = x / 2 + 2x Transfer the value y to port P1.
Note: The value of x is such that y does not exceed 8-bits.
Code:
MOV A, R0 ;A=x
RR A ;A=x/2
MOV R1, A ; R1 = x / 2
MOV A, R0 ;A=x
ADD A, R0 ; A = x + x = 2x
ADD A, R1 ; A = 2x + x/2
SJMP DONE
ODD_CASE:
MOV A, R0 ;A=x
MOV B, R0 ;B=x
MUL AB ;A=x*x
DONE:
END
Output: