Skip to main content

Microcontrollers SEM 2 UNIT 3

 Unit 3: 8051 Interfacing and Programming



Question 1 (6 Marks): Explain the concept of the stack in the 8051 microcontroller and PUSH & POP.

Answer:
A stack is a linear data structure in which the insertion of a new element and removal of an existing element takes place at the same end represented as the top of the stack.

Stack is a section of RAM used by the CPU to store the information temporarily

The register used to access the stack is called the SP (stack pointer) register.

The ‘PUSH’ is used for taking the values from any register and storing in the starting address of the stack pointer.

POP is used for placing the values from the stack pointer’s maximum address to any other register’s address

To implement the stack, it is required to maintain the pointer to the top of the stack, which is the last element to be inserted because we can access the elements only on the top of the stack.

LIFO (Last In First Out):
This strategy states that the element that is inserted last will come out first. You can take a pile of plates kept on top of each other as a real-life example. The plate which we put last is on the top and since we remove the plate that is at the top, we can say that the plate that was put last comes out first.




Question 2 (6 Marks): Describe subroutine. State its advantages and explain any 2 subroutine instructions in detail. 

Answer:

Subroutine is a group of instructions Written separately from the main program to perform a function that occurs repeatedly in the main program.
When you call a subroutine implementation of the current program is stopped, the program counter PC is loaded with the memory location of the subroutine, running up to the RET instruction (end of subroutine), where produce a return to the main program resumes running.

Advantages:
  1. Minimize the content of the sentences in the main program.
  2. Dividing a large programming task among various programmers, or various stages of a project.
  3. Improving Traceability.
  4. Make the program easier and it takes up less space in the ROM.

Calling the Subroutine (ACALL and LCALL):

  • These instructions are like invitations to the subroutine.
  • ACALL (Absolute Call): This is a shorter instruction (2 bytes) used when the subroutine is located within a limited address range (256 bytes) from the calling instruction. You directly specify the memory address of the subroutine's first instruction after the ACALL keyword.
    • Example: ACALL 0x100 (Calls the subroutine located at memory address 0x100)
  • LCALL (Long Call): This is a longer instruction (3 bytes) used for subroutines located anywhere in the 64kb memory space of the 8051. You provide the full 16-bit address of the subroutine after the LCALL keyword.
    • Example: LCALL 0x3F2A (Calls the subroutine located at memory address 0x3F2A)

Returning from the Subroutine (RET):

  • Once the subroutine finishes its task, it needs to return control back to the main program.
  • The RET instruction acts like a "come back" signal within the subroutine.
  • When RET is encountered, the 8051 automatically retrieves the return address (the location where the main program was paused) from the stack and resumes execution from that point.

RETI (Optional for Interrupt Handling):

  • This instruction is similar to RET but additionally clears the interrupt flag.
  • It's used in specific situations related to handling interrupts (external events that temporarily pause the program execution). 




Question 3: What is the role of control transfer instructions in assembly language?  

Answer:
Control transfer instructions, unlike sequential program execution, alter the program's flow by directing it to a specific location in memory. These instructions fall into two categories:

Conditional Jumps: Execution hinges on a certain condition being true (e.g., JZ, JNZ, JNC, JC, JB, JNB).
Unconditional Jumps: Execution jumps to a predetermined location regardless of conditions (e.g., SJMP, LJMP).




Question 4: Describe different conditional jump instructions in the 8051.

Answer:
The 8051 offers various conditional jump instructions based on different conditions:
  1. JZ (Jump if Zero): Jumps if the Accumulator (A register) content is zero.
  2. JNZ (Jump if Not Zero): Jumps if the Accumulator content is NOT zero.
  3. JNC (Jump if No Carry): Jumps if the Carry Flag (CY bit in PSW register) is cleared (CY = 0).
  4. JC (Jump if Carry): Jumps if the Carry Flag is set (CY = 1).
  5. JB (Jump if Bit is High): Jumps if a specific bit in a register or memory location is set to 1.
  6. JNB (Jump if Bit is Low): Jumps if a specific bit is cleared (0).




Question 5: Explain the concept of looping in the 8051 microcontroller. Discuss the limitation of the DJNZ instruction for looping.

Answer:

Looping allows a sequence of instructions to be repeated a specific number of times. The 8051 uses the DJNZ reg, label instruction for looping.

DJNZ (Decrement and Jump if Not Zero):

o    This instruction decrements a register (reg) by 1.

o    If the register value is not zero (i.e., greater than 0), the program jumps to the instruction labeled by label.

o    Registers R0-R7 can be used as loop counters.

o    The loop continues until the register reaches zero.

The DJNZ instruction has a limitation in the number of loop iterations it can handle:

  • It uses an 8-bit register, which can only hold a maximum value of 255.
  • Therefore, the maximum number of loop iterations using DJNZ is limited to 256.

 


Comments

Popular posts from this blog

Microcontrollers SEM 2 UNIT 1

Unit 1: 8051 Microcontroller (General Questions and Answers) Question 1 (6 Marks): Differentiate between a microprocessor and a microcontroller. Question 2 (6 Marks): Briefly describe the 8051 microcontroller architecture with the help of a block diagram. Answer: The 8051 microcontroller follows the Harvard architecture, separating program memory from data memory. Key components include: Central Processing Unit (CPU): Processes instructions, performs calculations, and controls program flow. It consists of: Arithmetic Logic Unit (ALU) for arithmetic and logical operations. Control Unit (CU) for fetching, decoding, and executing instructions. Registers for temporary data storage and program control. Question 3 (6 Marks): Explain the functionalities of any three 8051 microcontroller pins with the help of a pin diagram. Answer: Port 0 (P0.0 - P0.7): 8-bit bidirectional I/O port. Each pin can be configured as input or output for connecting with external devices (sensors, LEDs, etc.). ALE (A...

Free hand sketch quality images for Engineering drawing UNIT 6

 Below are easy to draw sketches, better picture quality images for UNIT 6 SEM I Exam Types of gears Fastener Categories Nut types Types of keys (a) Compression spring; (b) Tension spring; (c) Torsion spring; (d) Scroll spring ...

Microcontrollers SEM 2 UNIT 6

 Unit 6: Introduction to Arduino Question  1. Explain the steps involved in installing the Arduino development environment. (6 Marks) The Arduino development environment, also known as the Arduino IDE (Integrated Development Environment), allows you to write and upload code to Arduino boards. Here's how to install it: Steps: Download Arduino IDE Software:  Visit the official Arduino website ( https://www.arduino.cc/en/software ) and download the software installer for your operating system (Windows, macOS, Linux). Run the installer:  Double-click the downloaded installer file and follow the on-screen instructions. This will install the Arduino IDE software on your computer. (Optional) Install additional boards support:  If you're using a non-standard Arduino board, you may need to install additional board definitions. This can be done through the "Boards Manager" within the Arduino IDE. Question...