Professional Documents
Culture Documents
PART A:
1.
Lock bits are set of bits to enable or disable some special security features of a microcontroller. For
example, in some cases you might want to disable the memory read functionality of the
microcontroller, so that the code you have written cannot be stolen by others.
(b) Draw the Power On Reset Circuit. What is the purpose of it?
A power-on reset (PoR) is a circuit that provides a predictable, regulated voltage to a microprocessor
or microcontroller with the initial application of power. The PoR system ensures that the
microprocessor or microcontroller will start in the same condition every time that it is powered up.
- the main purpose of the port register is, it is used as the input-output port.
- also some specific ports (port 0 and port 2) are used to access the external memory.
(d) What is the difference between CY and OV flags of PSW related to MCS-51?
In the MCS-51 microcontroller architecture, the PSW (Program Status Word) is a register that
contains various status flags. Among these flags, there are two specific flags called CY (Carry) and OV
(Overflow). Here's the difference between them:
Carry Flag (CY): The Carry flag, also known as the CY flag, is used to indicate a carry or borrow during
arithmetic or logical operations. It reflects the carry or borrows resulting from the most significant bit
(bit 7) of an operation.
Overflow Flag (OV): The Overflow flag, also known as the OV flag, is used to indicate signed
arithmetic overflow. It reflects an overflow of the signed result when performing arithmetic
operations.
(e) Which part of the internal RAM is related to PUSH and POP instructions?
Stack: The role of stack memory includes storage of temporary data when handling function calls
(normal stack PUSH and POP operations), storage for local variables, passing of parameters in
function calls, saving of registers during exception sequences, etc.
(f) What would be the content of DPH after execution of MOV DPTR, #1234H instruction?
The instruction, MOV DPTR, 1234H will load the value 1234H into the Data Pointer. DPH will
hold 12H and DPL will hold 34H.
(g) How many bytes of forward jump are possible for any DJNZ instruction?
Explanation: DJNZ is 2-byte instruction. This means jump can be of -128 to +127 locations with
respect to PC.
PART B:
2. (a) Explain the operation of LCALL instruction of MCS-51 with a suitable example.
LCALL (long call)
In this 3-byte instruction, the first byte is the opcode and the second and third bytes are used
for the address of the target subroutine. Therefore, LCALL can be used to call subroutines
located anywhere within the 64K-byte address space of the 8051. To make sure that after
execution of the called subroutine the 8051 knows where to come back to, the processor
automatically saves on the stack the address of the instruction immediately below the
LCALL. When a subroutine is called, control is transferred to that subroutine, and the
processor saves the PC (program counter) on the stack and begins to fetch instructions from
the new location. After finishing execution of the subroutine, the instruction RET (return)
transfers control back to the caller. Every subroutine needs RET as the last instruction.
(b) Write an Assembly language program with algorithm for MCS-51 to shift a block of 8 bytes of
data, presently located from 60H to 67H, 1-byte up, so that the data is available from 61H to 68H.
Algorithm:
SHIFT_LOOP:
DJNZ R0, SHIFT_LOOP ; Decrement loop counter and repeat if not zero
END:
Port 0 is one of the four I/O ports (Port 0, Port 1, Port 2, and Port 3) available in the MCS-51
microcontroller architecture. It is an 8-bit bidirectional I/O port, meaning it can be used for both
input and output operations. Port 0 is commonly used for various general-purpose I/O operations.
Here is a suitable diagram illustrating the working of Port 0 in the MCS-51 microcontroller:
_____________
P0.0 ----| |
P0.1 ----| |
P0.2 ----| |
P0.3 ----| |
P0.5 ----| |
P0.6 ----| |
P0.7 ----|___________|
In this diagram:
- P0.0 through P0.7 represent the individual pins of Port 0. These pins can be used for connecting
external devices or for internal I/O operations.
- Each pin can be configured as either an input or an output based on the software settings.
- When configured as an input, the pins can be used to read external signals or data.
- When configured as an output, the pins can be used to drive signals or data to external devices.
The working of Port 0 is controlled by the associated SFRs (Special Function Registers) in the MCS-51
architecture. Specifically, two SFRs are used to control Port 0:
1. P0 (Port 0): This SFR is used to read the current status of Port 0 pins when they are configured as
inputs. Writing to this SFR has no effect.
2. P0 (Port 0): This SFR is used to write data to Port 0 pins when they are configured as outputs. Each
bit of this SFR corresponds to a pin of Port 0. Writing a logic high (1) to a bit will set the
corresponding pin to a high level (Vcc), and writing a logic low (0) will set the corresponding pin to a
low level (GND).
To use Port 0 in an MCS-51 assembly language program, the programmer can read or write data to
Port 0 by accessing the appropriate SFRs. For example, to read the input data from Port 0, the
programmer can read the P0 SFR. To write data to Port 0, the programmer can write the desired
value to the P0 SFR.
It is important to note that Port 0 has an internal pull-up resistor feature. When a pin of Port 0 is
configured as an input and left unconnected or not driven externally, the internal pull-up resistor can
be enabled via software to ensure a defined logic level.
Overall, Port 0 in the MCS-51 microcontroller provides a flexible and versatile 8-bit I/O interface,
allowing communication with external devices and facilitating various I/O operations in embedded
systems and applications.
The SBUF register serves as a temporary storage location for data being transmitted or received via
the serial port. It plays a crucial role in facilitating serial communication protocols such as UART
(Universal Asynchronous Receiver-Transmitter).
1. Serial Data Transmission: When the microcontroller needs to transmit data serially, it writes the
data byte to be transmitted into the SBUF register. The data is then transmitted bit by bit, typically
using a specific protocol such as UART, over the serial port.
2. Serial Data Reception: When the microcontroller receives serial data, the data is received through
the serial port and stored in the SBUF register.
3. Buffering: The SBUF register acts as a buffer, allowing the microcontroller to handle data
transmission and reception asynchronously.
4. Interrupts: The SBUF register is often associated with interrupts to notify the microcontroller when
data transmission or reception is complete or requires attention.
5. Configuration and Control: In addition to data storage, the SBUF register may also have control or
configuration bits associated with it. These bits can be used to enable or disable specific features or
to set parameters for serial communication, such as baud rate or data format.
Overall, the SBUF register in the MCS-51 microcontroller architecture serves as a temporary storage
location for serial data transmission and reception. It facilitates asynchronous serial communication,
provides buffering capabilities, and allows the microcontroller to efficiently transmit and receive data
through its serial port.
6. (a) What are the different types of Unconditional jumps in MCS-51? Explain in brief with suitable
In the MCS-51 microcontroller architecture, there are three types of unconditional jump instructions
that can be used for altering the program flow: AJMP, LJMP, and SJMP. These instructions allow the
program to transfer control to a different memory location unconditionally, without any conditions or
flags affecting the jump.
The AJMP instruction is used for an absolute jump within the same 2K-byte page of memory. It
provides a jump range of ±2K bytes from the current program counter (PC).
Example:
ORG 0H
...
...
...
In this example, the AJMP instruction is used to perform an absolute jump from the `START` label to
the `LOOP` label. The program execution will continue from the memory location of the `LOOP` label.
Diagram:
______________
| |
----->| START |
| |
|______________|
___________________
| |
----->| LOOP |
| |
|___________________|
The LJMP instruction is used for a long jump to any address within the 64K-byte address space. It
allows the program to jump to any memory location without any limitations.
Example:
``` assembly
ORG 0H
...
LJMP TARGET ; Long jump to the memory address specified by 'TARGET'
...
ORG 100H
In this example, the LJMP instruction is used to perform a long jump from the `START` label to the
memory address specified by `TARGET`. The program execution will continue from the memory
location of the `TARGET` address.
Diagram:
______________
| |
-----> | START |
| |
|______________|
___________________
| |
----->| TARGET |
| |
|___________________|
The SJMP instruction is used for a short jump within the -128 to +127 bytes range from the current
program counter (PC). It allows for relative jumps within a limited range.
Example:
```assembly
ORG 0H
...
Diagram:
______________
| |
-----> | START |
| |
|______________|
___________________
| |
----->| NEXT |
| |
|___________________|
These unconditional jump instructions provide flexibility in altering the program flow within the
MCS-51 microcontroller. The choice of which instruction to use depends on the range and type of
jump required for a particular program scenario.
(b) What is an interrupt? Which SFRs are directly related to external interrupts of MCS-51? 7+3
An interrupt is a mechanism used in microcontrollers and other computer systems to suspend the
normal program execution temporarily and transfer control to a specific interrupt service routine
(ISR) when a particular event or condition occurs. Interrupts allow the microcontroller to respond
quickly to external events and handle time-critical tasks.
In the MCS-51 microcontroller architecture, there are two SFRs (Special Function Registers) directly
related to external interrupts:
1. IE (Interrupt Enable): The IE SFR is used to enable or disable interrupts in the MCS-51
microcontroller. It has individual bits that control the enable/disable state of different
interrupt sources. Specifically, bit 0 (EA) of the IE SFR is responsible for enabling or disabling
all interrupts globally. When EA is set to 1, interrupts are enabled, and when it is cleared to
0, interrupts are disabled.
2. IP (Interrupt Priority): The IP SFR is used to set the priority levels of interrupts in the MCS-51
microcontroller. It has individual bits for each interrupt source that determine the priority
level of that particular interrupt. The IP SFR allows the programmer to assign higher or lower
priority to different interrupt sources based on the application's requirements.
7. (a) Show with a simple circuit to interface a LED to port 1.0 of a MCS-51 and make it to blink
using
+5V
R1
+---[LED]--- P1.0
GND
In this circuit:
• The LED is connected in series with a current-limiting resistor (R1) between the +5V power
supply and ground (GND).
• The anode (longer leg) of the LED is connected to the microcontroller's Port 1.0 (P1.0) pin,
and the cathode (shorter leg) is connected to the resistor and ground.
Now, let's write an assembly language program to blink the LED connected to Port 1.0:
ORG 0H
MAIN:
DELAY:
LOOP:
END
The RET instruction pops the high-order and low-order bytes of the PC from the stack (and
decrements the stack pointer by 2). Program execution resumes from the resulting address which is
typically the instruction following an ACALL or LCALL instruction. No flags are affected by this
instruction.
8. (a) What is the difference between Timer and a Counter?
Timer Counter
The register is incremented for every The register is incremented considering 1 to 0 transition at
machine cycle. its corresponding to an external input pin (T0, T1).
The maximum count rate is 1/12 of The maximum count rate is 1/24 of the oscillator
the oscillator frequency. frequency.
A timer uses the frequency of the A counter uses an external signal to count pulses.
internal clock and generates delay.
(b) Explain with the help of simple hardware interfacing circuit with port 1.0 and P1.1 of MCS-51
connected to DC motor through a controlling module for direction control through software for a
DC motor. 2+8