0% found this document useful (0 votes)
25 views28 pages

Embedded QuestionBank1,2

The document is a question bank for the Embedded Systems and IoT course, focusing on the 8051 microcontroller architecture, instruction set, and programming. It covers various topics including the features of the 8051, its RAM size, port configurations, addressing modes, special function registers, and pin configurations. Additionally, it includes questions on serial communication, interrupts, and programming examples related to the 8051 microcontroller.

Uploaded by

rohitk15102004
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)
25 views28 pages

Embedded QuestionBank1,2

The document is a question bank for the Embedded Systems and IoT course, focusing on the 8051 microcontroller architecture, instruction set, and programming. It covers various topics including the features of the 8051, its RAM size, port configurations, addressing modes, special function registers, and pin configurations. Additionally, it includes questions on serial communication, interrupts, and programming examples related to the 8051 microcontroller.

Uploaded by

rohitk15102004
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/ 28

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

QUESTIONBANK

Subject Name EMBEDDED SYSTEMS AND IOT Subject Code CS3691


Department CSE Year/Sem III/VI
Faculty M.JANAKI
UNIT I

8-BIT MICROCONTROLLER – ARCHITECTURE – INSTRUCTION SET AND


PROGRAMMING – PROGRAMMING PARALLELPORTS – TIMERS AND SERIAL PORT –
INTERRUPT HANDLING.

1. Discuss the salient features of 8051 family of controllers?(May/June 12)

The Key features of the 8051 Microcontroller –


4 KB on-chip ROM (Program memory).
128 bytes on-chip RAM (Data memory).
The 8-bit data bus (bidirectional).
16-bit address bus (unidirectional).
Two 16-bit timers.
Instruction cycle of 1 microsecond with 12 MHz crystal.
Four 8-bit input/output ports.
128 user-defined flags.

2. What is the size of RAM in 8051?

128 bytes
As is illustrated in this map, the 8051 has a bank of 128 bytes of Internal RAM. This
Internal RAM is found on-chip on the 8051 so it is the fastest RAM available, and it is also
the most flexible in terms of reading, writing, and modifying its contents.

3. How many ports are available in 8051 microcontroller?

8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as
input or output. Hence, total 32 input/output pins allow the microcontroller to be connected
with the peripheral devices. Pin configuration, i.e. the pin can be configured as 1 for input
and 0 for output as per the logic state.

4. How to select the register bank of Intel 8051.(May2015)

Register bank 0 is the default when the 8051 is powered up. We can switch to the
other banks using PSW register. D4 and D3 bits of the PSW are used to select the desired
register bank, since they can be accessed by the bit addressable instructions SETB and
CLR.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

5. List the flags of 8051 and give their usage.

The flag format of the 8051 microcontroller consists of five flags: Carry (CY),
Auxiliary Carry (AC), Overflow (OV), Parity (P), and Sign (S). These flags are used to
indicate various conditions and results during arithmetic and logical operations.

6. Explain the various flags in PSW register.

7. What is the function of DPTR register?

The Data PointerThe Accumulator, R0–R7 registers and B register are 1-byte value
registers. DPTR is meant for pointing to data. It is used by the 8051 to access external
memory using the address indicated by DPTR. DPTR is the only 16-bit register available
and is often used to store 2-byte values.

8. What is the significance of EA line of 8051 microcontroller?

Pin 31 (EA/ VPP) – EA stands for External Access input. It is used to enable/disable
external memory interfacing. In 8051, EA is connected to Vcc as it comes with on-chip
ROM to store programs. For other family members such as 8031 and 8032 in which there is
no on-chip ROM, the EA pin is connected to the GND.

9. What is the difference between MOVX and MOV?

MP4 are typically more compressed and smaller in size, while MOV files are often
higher in quality and larger in size.

10. What are the different ways of operand addressing in 8051?

Addressing modes of 8051


 Immediate addressing mode.
 Register addressing mode.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

 Direct addressing mode.


 Indirect addressing mode.
 Indexed addressing mode.

11. Mention some of the 8051 special function register.

Categories of 8051 Microcontroller Special Function Registers.


 A or Accumulator (ACC)
 B (Register B)
 Data Pointer (DPTR – DPL and DPH)
 Stack Pointer (SP)
 PCON (Power Control)
 SCON (Serial Control)
 TCON (Timer Control)

12. What is the function of XTAL1 and XTAL2 pins?

Pin 18 and Pin 19 (XTAL2 And XTAL1) – These pins are connected to an external
oscillator which is generally a quartz crystal oscillator. They are used to provide an external
clock frequency of 4MHz to 30MHz.

13. How is RAM memory space allocated in 8051?

RAM Memory Space Allocation in 8051 80 bytes from 30H to 7FH locations are used
for read and writes storage; it is called as scratch pad. These 80 locations RAM are widely
used for the purpose of storing data and parameters by 8051 programmers.

14. What is the purpose of overflow flag.

In computer processors, the overflow flag (sometimes called the V flag) is usually a
single bit in a system status register used to indicate when an arithmetic overflow has
occurred in an operation, indicating that the signed two's-complement result would not fit in
the number of bits used for the result.

15. What is the operation of the given 8051 microcontroller instruction XRLA?

XRL performs the bitwise logical Exclusive-OR operation between the indicated
variables, storing the results in the destination.

16. Write a program to perform multiplication of 2 numbers using 8051?

MOV A, 40h ; Copy the content of 40h into accumulator


MOV 0F0h, 41h ; Copy content of 41h into register B
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
MUL AB ; Multiply contents of Accumulator and B register
MOV 42H, A ; Copy the lower byte of result from accumulator to 42h
MOV 43H, 0F0h ; Copy the higher byte of result from B register to 43h
STOP: AJMP STOP ; Stop

17. Which port used as multifunction port? List the signals

Port 3 is multifunction part it can be used as a simple input/output port. Port 3 as


simple input port: When port 3 is used as an input port '1' must be written to the
corresponding port 3 latch bit this cause the FET to turn off pin & input to pin buffer are
pulled to logic high by internal pull up load.

18. What are the difference between a microcontroller and microprocessor?

19. Name any two 16-bit microcontrollers.(May/June 2007)

MCS 896 family of 16-bit microcontroller includes


 8096
 8097
 8098

20. What does the mnemonics “LCALL” and “ACALL” stands for? (Nov/Dec 12)

ACALL is a 2-byte instruction, in contrast to LCALL which is 3 bytes. The target


address of the subroutine must be within 2k bytes because only 11 bits of the 2 bytes are used
for the address.

21. What is meant by Program Counter?


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
The function of the program counter is to point to the memory address of the next
instruction to be executed. When an opcode is being fetched, the program counter is
incremented by one to point to the next memory location.

22. What is meant by serial communication?

In serial communication, data is first converted to serial bits by using parallel in-serial out
shift register.
23. What are the SFRs associated with the Timer Operations of 8051 microcontroller?

TCON (Timer Control): Timer Control or TCON Register is used to start or stop the
Timers of the 8051 Microcontroller. It also contains bits to indicate if the Timers have
overflowed. The TCON SFR also consists of Interrupt related bits.
The TMOD (Timer Mode) register is a control register in microcontrollers and
microprocessors that is used to set the different modes of operation for the timers and
counters. The timer and counter modes include timer modes 0, 1, 2 and counter modes 0, 1.
24. What is nested interrupts?

In a nested interrupt system, an interrupt is allowed to anytime and anywhere even an


ISR is being executed. But, only the highest priority ISR will be executed immediately. The
second highest priority ISR will be executed after the highest one is completed.
25. Write the vector address and priority sequence of 8051 interrupts.

PART – B

1. Draw and explain the pin configuration of 8051 in detail.

8051 microcontroller is a 40 pin Dual Inline Package (DIP). These 40 pins serve different
functions like read, write, I/O operations, interrupts etc. 8051 has four I/O ports wherein each port
has 8 pins which can be configured as input or output depending upon the logic state of the pins.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

Description of the Pins :


 Pin 1 to Pin 8 (Port 1) – Pin 1 to Pin 8 are assigned to Port 1 for simple I/O operations. They
can be configured as input or output pins depending on the logic control i.e. if logic zero (0)
is applied to the I/O port it will act as an output pin and if logic one (1) is applied the pin will
act as an input pin. These pins are also referred to as P1.0 to P1.7 (where P1 indicates that it
is a pin in port 1 and the number after ‘.’ tells the pin number i.e. 0 indicates first pin of the
port. So, P1.0 means first pin of port 1, P1.1 means second pin of the port 1 and so on). These
pins are bidirectional pins.
 Pin 9 (RST) – Reset pin. It is an active-high, input pin. Therefore if the RST pin is high for a
minimum of 2 machine cycles, the microcontroller will reset i.e. it will close and terminate all
activities. It is often referred as “power-on-reset” pin because it is used to reset the
microcontroller to it’s initial values when power is on (high).
 Pin 10 to Pin 17 (Port 3) – Pin 10 to pin 17 are port 3 pins which are also referred to as P3.0
to P3.7. These pins are similar to port 1 and can be used as universal input or output pins.
These pins are bidirectional pins. These pins also have some additional functions which are as
follows:
 P3.0 (RXD) : 10th pin is RXD (serial data receive pin) which is for serial input.
Through this input signal microcontroller receives data for serial communication.
 P3.1 (TXD) : 11th pin is TXD (serial data transmit pin) which is serial output pin.
Through this output signal microcontroller transmits data for serial
communication.
 P3.2 and P3.3 (INT0′, INT1′ ) : 12th and 13th pins are for External Hardware
Interrupt 0 and Interrupt 1 respectively. When this interrupt is activated(i.e. when it
is low), 8051 gets interrupted in whatever it is doing and jumps to the vector value
of the interrupt (0003H for INT0 and 0013H for INT1) and starts performing
Interrupt Service Routine (ISR) from that vector location.
 P3.4 and P3.5 (T0 and T1) : 14th and 15th pin are for Timer 0 and Timer 1
external input. They can be connected with 16 bit timer/counter.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
 P3.6 (WR’) : 16th pin is for external memory write i.e. writing data to the external
memory.
 P3.7 (RD’) : 17th pin is for external memory read i.e. reading data from external
memory
 Pin 18 and Pin 19 (XTAL2 And XTAL1) – These pins are connected to an external
oscillator which is generally a quartz crystal oscillator. They are used to provide an external
clock frequency of 4MHz to 30MHz.
 Pin 20 (GND) – This pin is connected to the ground. It has to be provided with 0V power
supply. Hence it is connected to the negative terminal of the power supply.
 Pin 21 to Pin 28 (Port 2) – Pin 21 to pin 28 are port 2 pins also referred to as P2.0 to P2.7.
When additional external memory is interfaced with the 8051 microcontroller, pins of port 2
act as higher-order address bytes. These pins are bidirectional.
 Pin 29 (PSEN) – PSEN stands for Program Store Enable. It is output, active-low pin. This is
used to read external memory. In 8031 based system where external ROM holds the program
code, this pin is connected to the OE pin of the ROM.
 Pin 30 (ALE/ PROG) – ALE stands for Address Latch Enable. It is input, active-high pin.
This pin is used to distinguish between memory chips when multiple memory chips are used.
It is also used to de-multiplex the multiplexed address and data signals available at port 0.
During flash programming i.e. Programming of EPROM, this pin acts as program pulse input
(PROG).
 Pin 31 (EA/ VPP) – EA stands for External Access input. It is used to enable/disable external
memory interfacing. In 8051, EA is connected to Vcc as it comes with on-chip ROM to store
programs. For other family members such as 8031 and 8032 in which there is no on-chip
ROM, the EA pin is connected to the GND.
 Pin 32 to Pin 39 (Port 0) – Pin 32 to pin 39 are port 0 pins also referred to as P0.0 to P0.7.
They are bidirectional input/output pins. They don’t have any internal pull-ups. Hence, 10 K?
pull-up registers are used as external pull-ups. Port 0 is also designated as AD0-AD7 because
8051 multiplexes address and data through port 0 to save pins.
 Pin 40 (VCC) – This pin provides power supply voltage i.e. +5 Volts to the circuit.
The pin diagram of the 8051 microcontroller is as follows:
1. VCC: This pin is connected to the power supply and provides a voltage of +5V to the
microcontroller.
2. GND: This pin is connected to the ground and serves as the reference voltage for the
microcontroller.
3. XTAL1 and XTAL2: These pins are used for connecting an external crystal oscillator that
provides the clock signal for the microcontroller.
4. Reset: This pin is used for resetting the microcontroller. A high pulse on this pin resets the
microcontroller to its initial state.
5. Port 1: This is an 8-bit bidirectional input/output port that can be used for interfacing with
external devices.
6. Port 2: This is an 8-bit bidirectional input/output port that can be used for interfacing with
external devices.
7. Port 3: This is an 8-bit bidirectional input/output port that can be used for interfacing with
external devices.
8. Port 4: This is an 8-bit bidirectional input/output port that can be used for interfacing with
external devices.
9. INT0: This is an external interrupt 0 input pin.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
10. INT1: This is an external interrupt 1 input pin.
11. T0: This is an external timer 0 input pin.
12. T1: This is an external timer 1 input pin.
13. WR: This is the write signal for external memory.
14. RD: This is the read signal for external memory.
15. ALE: This is the address latch enable signal that is used to latch the address for external
memory.
16. PSEN: This is the program store enable signal that is used for accessing the program
memory.
17. 17-24. Address bus: These pins are used for transmitting the address information to the
external memory.
18. 25-32. Data bus: These pins are used for transmitting the data between the microcontroller
and external memory.
19. RST: This is the output signal that indicates the microcontroller is being reset.
20. EA: This is the external access enable signal that is used for selecting the program memory.
21. VPP: This pin is used for programming the microcontroller.
22. 36-39. XTAL: These pins are used for connecting an external crystal oscillator.
23. P1.0 (AD0) – P1.7 (AD7): These pins are used for interfacing with external analog devices.
Uses of pin diagram of the 8051 microcontroller :
The pin diagram of the 8051 microcontroller is used for various purposes in embedded systems.
Some of the main uses of the pin diagram are:
1. Interfacing with external devices: The 8051 microcontroller has several input/output pins
that can be used for interfacing with external devices such as sensors, actuators, displays, and
communication modules. The pin diagram provides the information about the location of
these pins, their functionalities, and their electrical characteristics.
2. Programming the microcontroller: The 8051 microcontroller can be programmed using
various programming languages such as Assembly, C, and BASIC. The pin diagram provides
the information about the pins that are used for programming the microcontroller, such as the
PSEN pin and the ALE pin.
3. Debugging and testing: The pin diagram provides access to the internal signals of the
microcontroller, such as the address and data buses, which can be used for debugging and
testing the microcontroller. Special hardware tools such as logic analyzers and oscilloscopes
can be connected to the pins to monitor the signals and diagnose any issues in the system.
4. Expansion and customization: The pin diagram provides the flexibility to expand and
customize the functionality of the microcontroller by connecting external devices and
peripherals. For example, additional memory can be added by connecting external RAM or
ROM chips to the address and data buses.

2. Explain in detail the different addressing modes supported by8051.

Different addressing modes of the 8051 microcontrollers. In 8051 there are 1-byte, 2-byte
instructions and very few 3-byte instructions are present. The opcodes are 8-bit long. As the opcodes
are 8-bit data, there are 256 possibilities. Among 256, 255 opcodes are implemented.
The clock frequency is12MHz, so 64 instruction types are executed in just 1 µs, and rest are just 2
µs. The Multiplication and Division operations take 4 µsto to execute.
In 8051 there are six types of addressing modes.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
 Immediate Addressing Mode
 Register Addressing Mode
 Direct Addressing Mode
 Register Indirect Addressing Mode
 Indexed Addressing Mode
 Implied Addressing Mode
Immediate addressing mode
In this Immediate Addressing Mode, the data is provided in the instruction itself. The data is
provided immediately after the opcode. These are some examples of Immediate Addressing Mode.
MOVA, #0AFH;
MOVR3, #45H;
MOVDPTR, #FE00H;
In these instructions, the # symbol is used for immediate data. In the last instruction, there is
DPTR. The DPTR stands for Data Pointer. Using this, it points the external data memory location.
In the first instruction, the immediate data is AFH, but one 0 is added at the beginning. So when the
data is starting with A to F, the data should be preceded by 0.
Register addressing mode
In the register addressing mode the source or destination data should be present in a register
(R0 to R7). These are some examples of RegisterAddressing Mode.
MOVA, R5;
MOVR2, #45H;
MOVR0, A;
In 8051, there is no instruction like MOVR5, R7. But we can get the same result by using
this instruction MOV R5, 07H, or by using MOV 05H, R7. But this two instruction will work when
the selected register bank is RB0. To use another register bank and to get the same effect, we have
to add the starting address of that register bank with the register number. For an example, if the RB2
is selected, and we want to access R5, then the address will be (10H + 05H = 15H), so the instruction
will look like this MOV 15H, R7. Here 10H is the starting address of Register Bank 2.

Direct Addressing Mode


In the Direct Addressing Mode, the source or destination address is specified by using 8-bit
data in the instruction. Only the internal data memory can be used in this mode. Here some of the
examples of direct Addressing Mode.
MOV80H, R6;
MOVR2, 45H;
MOVR0, 05H;
The first instruction will send the content of registerR6 to port P0 (Address of Port 0 is 80H).
The second one is forgetting content from 45H to R2. The third one is used to get data from Register
R5 (When register bank RB0 is selected) to register R5.
Register indirect addressing Mode
In this mode, the source or destination address is given in the register. By using register
indirect addressing mode, the internal or external addresses can be accessed. The R0 and R1 are used
for 8-bit addresses, and DPTR is used for 16-bit addresses, no other registers can be used for
addressing purposes. Let us see some examples of this mode.
MOV0E5H, @R0;
MOV@R1, 80H
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
In the instructions, the @ symbol is used for register indirect addressing. In the first
instruction, it is showing that theR0 register is used. If the content of R0 is 40H, then that instruction
will take the data which is located at location 40H of the internal RAM. In the second one, if the
content of R1 is 30H, then it indicates that the content of port P0 will be stored at location 30H in
the internal RAM.

MOVXA, @R1;
MOV@DPTR, A;
In these two instructions, the X in MOVX indicates the external data memory. The external data
memory can only be accessed in register indirect mode. In the first instruction if the R0 is holding
40H, then A will get the content of external RAM location40H. And in the second one, the content
of A is overwritten in the location pointed by DPTR.
Indexed addressing mode
In the indexed addressing mode, the source memory can only be accessed from program memory
only. The destination operand is always the register A. These are some examples of Indexed
addressing mode.
MOVCA, @A+PC;
MOVCA, @A+DPTR;
The C in MOVC instruction refers to code byte. For the first instruction, let us consider A
holds 30H. And the PC value is1125H. The contents of program memory location 1155H (30H +
1125H) are moved to register A.
Implied Addressing Mode
In the implied addressing mode, there will be a single operand. These types of instruction can
work on specific registers only. These types of instructions are also known as register specific
instruction. Here are some examples of Implied Addressing Mode.
RLA;
SWAPA;
These are 1- byte instruction. The first one is used to rotate the A register content to the Left. The
second one is used to swap the nibbles in A.

3. Explain the instruction set of 8051?


The instructions of 8051 Microcontroller can be classified into five different groups. These
groups are like below
 Data Transfer Group
 Arithmetic Group
 Logical Group
 Program Branch Group
 Bit Processing Group
This Bit-Processing group is also known as Boolean Variable Manipulation.
Like 8085, some instruction has two operands. The first operand is the Destination, and the
second operator is Source.
In the following examples, you will get some notations. The notations are like −
Rn = Any register from R0to R7
Ri = Either R0 or R1
d8 = Any 8-bit immediate data (00H to FFH)
d16 = 16-bit immediate data
a8 = 8-bit address
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
bit = 8-bit address of bit which is bit addressable
rel = 8-bit signed displacement. The range is -128 to 127. It is relative to the first byte of the
instruction.

Arithmetic instructions
Arithmetic instructions perform several basic operations such as addition, subtraction, division,
multiplication etc. After execution, the result is stored in the first operand. For example:
ADD A,R1 - The result of addition (A+R1) will be stored in the accumulator.

Branch Instructions
There are two kinds of branch instructions:
Unconditional jump instructions: upon their execution a jump to a new location from where the
program continues execution is executed.
Conditional jump instructions: a jump to a new program location is executed only if a specified
condition is met. Otherwise, the program normally proceeds with the next instruction
Data Transfer Instructions
Data transfer instructions move the content of one register to another. The register the content of
which is moved remains unchanged. If they have the suffix “X” (MOVX), the data is exchanged
with external memory.
Logic Instructions
Logic instructions perform logic operations upon corresponding bits of two registers. After
execution, the result is stored in the first operand.
Bit-oriented Instructions
Similar to logic instructions, bit-oriented instructions perform logic operations. The difference is
that these are performed upon single bits.

ARITHMETIC INSTRUCTIONS

ADD A,Rn Adds the register to the accumulator


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
ADD A,direct Adds the direct byte to the accumulator

ADD A,@Ri Adds the indirect RAM to the accumulator

ADD A,#data Adds the immediate data to the accumulator

ADDC A,Rn Adds the register to the accumulator with a carry flag

ADDC A,direct Adds the direct byte to the accumulator with a carry flag

ADDC A,@Ri Adds the indirect RAM to the accumulator with a carry flag

ADDC A,#data Adds the immediate data to the accumulator with a carry flag

SUBB A,Rn Subtracts the register from the accumulator with a borrow

SUBB A,direct Subtracts the direct byte from the accumulator with a borrow

SUBB A,@Ri Subtracts the indirect RAM from the accumulator with a borrow

SUBB A,#data Subtracts the immediate data from the accumulator with a borrow

INC A Increments the accumulator by 1

INC Rn Increments the register by 1

INC Rx Increments the direct byte by 1

INC @Ri Increments the indirect RAM by 1

DEC A Decrements the accumulator by 1

DEC Rn Decrements the register by 1

DEC Rx Decrements the direct byte by 1

DEC @Ri Decrements the indirect RAM by 1

INC DPTR Increments the Data Pointer by 1

MUL AB Multiplies A and B

DIV AB Divides A by B

DA A Decimal adjustment of the accumulator according to BCD code


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

BRANCH INSTRUCTIONS

ACALL addr11 Absolute subroutine call

LCALL addr16 Long subroutine call

RET Returns from subroutine

RETI Returns from interrupt subroutine

AJMP addr11 Absolute jump

LJMP addr16 Long jump

SJMP rel Short jump (from –128 to +127 locations relative to the following instruction)

JC rel Jump if carry flag is set. Short jump.

JNC rel Jump if carry flag is not set. Short jump.

JB bit,rel Jump if direct bit is set. Short jump.

JBC bit,rel Jump if direct bit is set and clears bit. Short jump.

JMP @A+DPTR Jump indirect relative to the DPTR

JZ rel Jump if the accumulator is zero. Short jump.

JNZ rel Jump if the accumulator is not zero. Short jump.

CJNE A,direct,rel Compares direct byte to the accumulator and jumps if not equal. Short jump.

CJNE A,#data,rel Compares immediate data to the accumulator and jumps if not equal. Short
jump.

CJNE Rn,#data,rel Compares immediate data to the register and jumps if not equal. Short jump.

CJNE @Ri,#data,rel Compares immediate data to indirect register and jumps if not equal. Short
jump.

DJNZ Rn,rel Decrements register and jumps if not 0. Short jump.

DJNZ Rx,rel Decrements direct byte and jump if not 0. Short jump.

NOP No operation
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

DATA TRANSFER INSTRUCTIONS

MOV A,Rn Moves the register to the accumulator

MOV A,direct Moves the direct byte to the accumulator

MOV A,@Ri Moves the indirect RAM to the accumulator

MOV A,#data Moves the immediate data to the accumulator

MOV Rn,A Moves the accumulator to the register

MOV Rn,direct Moves the direct byte to the register

MOV Rn,#data Moves the immediate data to the register

MOV direct,A Moves the accumulator to the direct byte

MOV direct,Rn Moves the register to the direct byte

MOV direct,direct Moves the direct byte to the direct byte

MOV direct,@Ri Moves the indirect RAM to the direct byte

MOV direct,#data Moves the immediate data to the direct byte

MOV @Ri,A Moves the accumulator to the indirect RAM

MOV @Ri,direct Moves the direct byte to the indirect RAM

MOV @Ri,#data Moves the immediate data to the indirect RAM

MOV DPTR,#data Moves a 16-bit data to the data pointer

MOVC A,@A+DPTR Moves the code byte relative to the DPTR to the accumulator
(address=A+DPTR)

MOVC A,@A+PC Moves the code byte relative to the PC to the accumulator (address=A+PC)

MOVX A,@Ri Moves the external RAM (8-bit address) to the accumulator

MOVX A,@DPTR Moves the external RAM (16-bit address) to the accumulator

MOVX @Ri,A Moves the accumulator to the external RAM (8-bit address

MOVX @DPTR,A Moves the accumulator to the external RAM (16-bit address)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

PUSH direct Pushes the direct byte onto the stack

POP direct Pops the direct byte from the stack

XCH A,Rn Exchanges the register with the accumulator

XCH A,direct Exchanges the direct byte with the accumulator

XCH A,@Ri Exchanges the indirect RAM with the accumulator

XCHD A,@Ri Exchanges the low-order nibble indirect RAM with the accumulator

RETI Returns from interrupt subroutine

LOGIC INSTRUCTIONS

ANL A,Rn AND register to accumulator

ANL A,direct AND direct byte to accumulator

ANL A,@Ri AND indirect RAM to accumulator

ANL A,#data AND immediate data to accumulator

ANL direct,A AND accumulator to direct byte

ANL direct,#data AND immediate data to direct register

ORL A,Rn OR register to accumulator

ORL A,direct OR direct byte to accumulator

ORL A,@Ri OR indirect RAM to accumulator

ORL direct,A OR accumulator to direct byte

ORL direct,#data OR immediate data to direct byte

XRL A,Rn Exclusive OR register to accumulator

XRL A,direct Exclusive OR direct byte to accumulator

XRL A,@Ri Exclusive OR indirect RAM to accumulator

XRL A,#data Exclusive OR immediate data to accumulator


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
XRL direct,A Exclusive OR accumulator to direct byte

XORL direct,#data Exclusive OR immediate data to direct byte

CLR A Clears the accumulator

CPL A Complements the accumulator (1=0, 0=1)

SWAP A Swaps nibbles within the accumulator

RL A Rotates bits in the accumulator left

RLC A Rotates bits in the accumulator left through carry

RR A Rotates bits in the accumulator right

RRC A Rotates bits in the accumulator right through carry

CJNE @Ri,#data,rel Compares immediate data to indirect register and jumps if not equal. Short
jump.

BIT-ORIENTED INSTRUCTIONS

CLR C Clears the carry flag

CLR bit Clears the direct bit

SETB C Sets the carry flag

SETB bit Sets the direct bit

CPL C Complements the carry flag

CPL bit Complements the direct bit

ANL C,bit AND direct bit to the carry flag

ANL C,/bit AND complements of direct bit to the carry flag

ORL C,bit OR direct bit to the carry flag

ORL C,/bit OR complements of direct bit to the carry flag

MOV C,bit Moves the direct bit to the carry flag

MOV bit,C Moves the carry flag to the direct bit


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

Description of all 8051 instructions


Here is a list of the operands and their meanings:

 A - accumulator;
Rn - is one of working registers (R0-R7) in the currently active RAM memory bank;
 Direct - is any 8-bit address register of RAM. It can be any general-purpose register or a
SFR (I/O port, control register etc.);
 @Ri - is indirect internal or external RAM location addressed by register R0 or R1;
 #data - is an 8-bit constant included in instruction (0-255);
 #data16 - is a 16-bit constant included as bytes 2 and 3 in instruction (0-65535);
 addr16 - is a 16-bit address. May be anywhere within 64KB of program memory;
 addr11 - is an 11-bit address. May be within the same 2KB page of program memory as
the first byte of the following instruction;
 rel - is the address of a close memory location (from -128 to +127 relative to the first byte
of the following instruction). On the basis of it, assembler computes the value to add or
subtract from the number currently stored in the program counter;
 bit - is any bit-addressable I/O pin, control or status bit; and
 C - is carry flag of the status register (register PSW).

4. Explain in detail about the 8051 register bank and stack.

The collection of general purpose registers (R0-R7) is called as register banks, which accept one
byte of data. The bank register is a part of the RAM memory in the embedded microcontrollers, and
it is used to store the program instructions. Each microcontroller consists of various memory banks,
and each bank register consists of a unique address for recognizing the storage location.

Register Banks in 8051

Register Banks in 8051


The 8051 microcontroller consists of four register banks, such as Bank0, Bank1, Bank2, Bank3
which are selected by the PSW (Program Status Word) register. These register banks are present in
the internal RAM memory of the 8051 microcontroller, and are used to process the data when the
microcontroller is programmed.
Switching of Register Banks
By default, the 8051 microcontroller is powered up with register bank 0; and, by using the
Program Status Word (PSW), we can switch to other banks. The two bits of PSW are used for
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
switching between the register banks. These two bits are accessed by the bit-addressable
instructions SETB and CLR.
Based on the possible combinations of RS1 and RS0 of PSW, the register bank is changed
accordingly, i.e., if RS1 and RS0 are 0, then the Bank 0 is selected. Similarly, Bank1, 2&3 are
selected as per the values of RS1 and RS0.
Stack Memory Allocation in 8051 Microcontroller
The stack is an area of random access memory (RAM) allocated to hold temporarily all the
parameters of the variables. The stack is also responsible for reminding the order in which a
function is called so that it can be returned correctly. Whenever the function is called, the
parameters and local variables associated with it are added to the stack (PUSH). When the function
returns, the parameters and the variables are removed (“POP”) from the stack. This is why a
program’s stack size changes continuously while the program is running.
The register used to access the stack is called stack pointer register. The stack pointer is a small
register used to point at the stack. When we push something into the stack memory, the stack
pointer increases.

Stack Memory Allocation in 8051 Microcontroller


Example
When an 8051 microcontroller power up, the stack pointer contained value is 07, by default, as
shown in the above figure. If we perform ‘PUSH’ operation, then the stack pointer address will
be increased and shifted to another register. To avoid this problem, before starting the program,
we have to assign a different address location to the stack pointer.
PUSH operation
The ‘PUSH’ is used for taking the values from any register and storing in the starting address of
the stack pointer, i.e., 00h by using ‘PUSH’ operation. And, for the next ‘PUSH’, it increments
+1, and stores the value in the next address of the stack pointer, i.e., 01h.

PUSH operation of Stack


PUSH operation means (First in First out)
Example: WAP in assembly language for PUSH operation
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
0000h
MOV 08h, #21h
MOV 09h, #56h
PUSH 00h
PUSH 01h
END
POP Operation
It is used for placing the values from the stack pointer’s maximum address to any other
register’s address. If we use this ‘POP’ again, then it decrements by 1, and the value stored
in any register is given as ‘POP’.

POP Operation in Stack


POP operation means ‘Last in First out’.
000H
MOV 00H, #12H
MOV 01H, #32H
POP 1FH
POP 0EH
END
Registers of 8051 Microcontroller
If we perform any operation whether addition or subtraction, then these operations are
unable to be performed directly in the memory, and therefore, are performed by using the
registers. There are different types of registers in 8051 microcontroller.
These registers are classified into two types based on their operations:
• General Purpose Registers
• Special Function Registers
General Purpose Registers
There are four different bank registers with each bank having 8 addressable 8-bit registers,
and only one bank register can be accessed at a time. But, by changing the bank register’s
number in the flag register, we can access other bank registers, which have been discussed
earlier on this paper along with interrupt concept in 8051.
Special Function Registers
The special function registers including the Accumulator, Register B, Data pointer, PCON,
PSW, etc., are designed for a predetermined purpose during manufacturing with the address
80H to FFH, and this area cannot be used for the data or program storage purpose. These
registers can be implemented by bit address and byte address registers.

5. Describe in detail about architecture of 8051 microcontrollers.


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

The figure below represents the architectural block diagram of 8051 microcontroller:
As we can see that several units are present in the above architecture. And every unit is
embedded to execute the desired operation. Let us now discuss the operation of each unit present
in the architecture.
Central processing unit (CPU): 8051 uses the 8-bit processor. This unit carries out the operation
on 8-bit data. A processor is the heart of microcontroller. As the execution of the program
stored in the memory is performed by the processor.
The unit performs arithmetic and logical operations on 8-bit data as it has ALU, with internal
registers and program counters.
Several logical operations are performed by the ALU according to the program stored in the
memory.
The processor of 8051 microcontrollers possesses a special feature by which it can process single
bit or 8-bit data. This simply means that it has the ability to access each single bit data either to
clear, set or move etc. for any logical computation.
Memory: Basically 8051 microcontroller consists of on-chip program memory i.e., ROM
and on-chip data memory i.e., RAM.
ROM
8051 microcontroller has 4 KB ROM with 0000H to 0FFFH as the addressable space. It
is completely a program or code memory that means used by the programmer to store the
programs that are to be executed by the microcontroller.
The operations that are executed by the device in which the microcontroller is present
are stored in the ROM of the memory at the time of fabrication. Hence cannot be
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

changed or modified.

RAM
8051 holds a 128 bytes RAM. Basically, RAM is used to store data or operands for only a
small time duration. It can be altered anytime according to the need of the user. It is
also known as the data memory as it stores the data temporarily.
Out of the 128-byte RAM, first, 32 bytes is held by the working registers. Basically, these are
4 banks which separately has 8 registers. These registers are accessed either by its name or
address. It is to be noted here that at a particular time only a single register bank can be used.
As in 8051, the data and program memory i.e., RAM and ROM hold a definite memory
space. However, for some applications there exist the need for external memory to enhance
the memory space, thus external RAM, ROM/EPROM is used by the 8051 microcontrollers.
Input/ Output port: 8051 consists of 4 parallel ports of 8 bit each thereby providing 32 input-
output pins. All the 4 ports function bidirectional i.e., either input or output according to the
software control.
Timer and Control Unit: Timers are used to create a time gap or delay between 2 events.
8051 microcontroller consists of 2 timers of 16 bit each by which the system can produce two
delays simultaneously in order to generate the appropriate delay.
8051 Flag Bits and PSW Register
The program status word (PSW) register is an 8-bit register, also known as flag register. It is of
8-bit wide but only 6-bit of it is used. The two unused bits are user-defined flags.
The Data Pointer (DPTR) is the 8051's only user-accessible 16-bit (2-byte) register. The
Accumulator, R0–R7 registers and B register are 1-byte value registers. DPTR is meant for
pointing to data. It is used by the 8051 to access external memory using the address indicated by
DPTR.
Basically, microcontrollers use hardware delays in which a physical device is used by the
processor to produce the respective delay. And this physical device is known as a timer.
The timer produces the delay according to the demand of the processor and sends the signal to
the processor once the respective delay gets produced.

6. Write an Example Program for LED blinking using with 8051 microcontrollers?

The microcontroller programming differs for each type of operating system. There are many
operating systems such as Linux, Windows, RTOS and so on. However, RTOS has several
advantages for embedded system development. Some of the Assembly levels programming
examples are given below.

Number Displaying on 7-segment display using 8051 microcontroller


Timer/Counter calculations and program using 8051 microcontroller
Serial Communication calculations and program using 8051 microcontroller

LED programs with 8051 Microcontrller


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK
1. WAP to toggle the PORT1 LEDs
ORG 0000H
TOGLE: MOV P1, #01 //move 00000001 to the p1 register//
CALL DELAY //execute the delay//
MOV A, P1 //move p1 value to the accumulator//
CPL A //complement A value //
MOV P1, A //move 11111110 to the port1 register//
CALL DELAY //execute the delay//
SJMP TOGLE
DELAY: MOV R5, #10H //load register R5 with 10/
TWO: MOV R6, #200 //load register R6 with 200//
ONE: MOV R7, #200 //load register R7 with 200//
DJNZ R7, $ //decrement R7 till it is zero//
DJNZ R6, ONE //decrement R7 till it is zero//
DJNZ R5, TWO //decrement R7 till it is zero//
RET //go back to the main program //
END
7. Problem: To write an assembly language program to add two 8 bit numbers in 8051
microcontroller using ports.
Example:

Block diagram:
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

Algorithm:
Initialize Ports P0 and P1 as input ports.
Initialize Ports P2 and P3 as output ports.
Initialize the R1 register.
Move the contents from Port 0 to B register.
Move the contents from Port 1 to A register.
Add contents in A and B.
If carry is present increment R1.
Move contents in R1 to Port 2.
Move the sum in step 6 to Port 3.
Program:
ORG 00H // Indicates starting address

MOV P0,#0FFH // Initializes P0 as input port


MOV P1,#0FFH // Initializes P1 as input port
MOV P2,#00H // Initializes P2 as output port
MOV P3,#00H // Initializes P3 as output port

L1:MOV R1, #00H // Initializes Register R1


MOV B,P0 // Moves content of P0 to B
MOV A,P1 // Moves content of P1 to A
CLR C // Clears carry flag
ADD A,B // Add the content of A and B and store result in A
JNC L2 // If carry is not set, jump to label L2
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

INC R1 // Increment Register R1 if carry present


L2: MOV P2, R1 // Moves the content from Register R1 to Port2
MOV P3,A // Moves the content from A to Port3
SJMP L1 // Jumps to label L1
END

Explanation:
ORG 00H is the starting address of the program.
Giving the values as #0FFH and #00H initializes the ports as input and output ports
respectively.
R1 register is initialized to 0 so as to store any carry produced during the sum.
MOV B, P0 moves the value present in P0 to the B register.
MOV A, P1 moves the value present in P1 to Accumulator.
ADD AB adds the values present in Accumulator and B register and stores the result in
Accumulator.
JNC L2 refers to jump to label L2 if no carry is present by automatically checking whether
the carry bit is set or not.
If the carry bit is set to increment register R1.
MOV P2, R1, and MOV P3, A refers to moving the carry bit to P2 and result in Accumulator
to P3.

8. Describe how to program and interface an LCD to an 8051 using Assembly language
programming.
9. Explain the different modes of operation of microcontroller 8051 Timer.
10. Explain with suitable example concept of serial port programming.
11. What is the difference between the microprocessor and microcontroller.
12. Name any four additional hardware features available in microcontrollers when compared to
a microprocessors and explain it.
13. Explain in detail about instruction format.
14. Explain in detail about Data transfer instruction and compare with Control transfer
instructions.
15. Explain in detail about interrupt programming.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

UNIT II

Memory And I/O Devices Interfacing – Programming Embedded Systems in C – Need For RTOS
– Multiple Tasks and Processes – Context Switching – Priority Based Scheduling Policies.

PART - A

1. What is the relation between RPM and steps per second in stepper motor interfacing.
If N is the speed in revolution per minute (rpm), S is the steps per second (sps), then step per
revolution (spr) is given as, sps=N×S60=rpm×spr60
2. Write short notes on interrupts in 8051
Interrupts are the events that temporarily suspend the main program, pass the control to the
external sources and execute their task. It then passes the control to the main program where it had
left off. 8051 has 5 interrupt signals, i.e. INT0, TFO, INT1, TF1, RI/TI
3. What is the purpose of Interrupt priority (IP)Control register in 8051
8051 has two levels of interrupt priorities: high or low. By assigning priorities, we can control
the order in which multiple interrupts will be serviced. Priorities are set by bits in a special function
register called IP, which is at the byte address B8H. This register is also bit addressable .
4. What is the purpose of counters in 8051 microcontrollers?
The 8051 microcontroller has 2 timers/counters called T0 and T1. As their names suggest, their
main purpose is to measure time and count external events. Besides, they can be used for
generating clock pulses to be used in serial communication, so called Baud Rate
5. Explain the operating mode0 of 8051 serial port?
Mode 0: In this mode, the serial port works like a shift register and the data transmission works
synchronously with a clock frequency of fosc /12
6. What is the basic difference between a timer and a counter?
FEATURE TIMER COUNTER
Measures and keeps Counts events from an external
Purpose track of time intervals signal or an internal clock
Operates in timer mode
(incrementing on timer
frequency ticks) and
counter mode
(incrementing on
external or internal
Mode events) Operates only in counter mode
1. Increment/decrement 1. Increment/decrement based on
based on timer external/internal events.
Capabilities frequency or 2. Useful for counting rapid
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

external/internal events. events or tracking the number of


2. Can be used as a rotations of a high RPM motor.
general-purpose timer
or counter.
3. Implements
capture/compare
registers for precise
measurements.
Generates interrupts Generates interrupts based on
Interrupts and events based on compare channel matches and
and Events timer/counter values. underflow conditions.
7. Define watchdog timer.
A watchdog timer (WDT) is a timer that monitors microcontroller (MCU) programs to see if they
are out of control or have stopped operating
8 List out the advantages of LCD over LED.
1. Extremely low power consumption.
2. Providing a silver display.
3. Being extremely thin
4. Giving two types of displays
9. How a pressed key is detected in keyboard interfacing?
For detecting the pressed key, the microcontroller grounds all rows by providing 0 to the input
latch, and then it reads columns
10. What is the significance of BUSY flag in LCD interfacing?
The reason to use busy flag is that delay produced is almost for the exact amount of time for which
LCD need to process the time.
11. What are the serial communication modes available in 8051
Serial data communication uses two methods, asynchronous and synchronous. The synchronous
method transfers a block of data(characters) at a time, while the asynchronous method transfers a
single byte at a time
12. What are the various types of sensors that can be interfaced with 8051?
Microcontrollers accept two types of sensors based on their input i.e. analog or digital. Analog
Sensors measure the external parameters and give an analog voltage as an output.
13. Compare polling and interrupt
The main difference between interrupt and polling is that, in interrupt, the system informs the CPU
that it needs attention, while in polling, the CPU constantly checks the status of the system to find
whether it needs attention
14. Define RTOS
A real-time operating system (RTOS) is an OS that guarantees real-time applications a certain
capability within a specified deadline. It can often make sense to use a real-time operating system
(RTOS) to gain efficiencies in task management and resource sharing.

15. What are the qualities of RTOS


1. Performance
2. Error-free
3. Maximum Consumption
4. Task shifting is very less.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

16. Difference between c language and embedded c language


C is the general purpose programming language which is used to designing a type of desktop
based applications. Embedded C is the extension of C language which it is utilized to developing
microcontroller applications
17. What is the need for RTOS
RTOS’s are designed to handle multiple processes at one time, ensuring that these processes
respond to events within a predictable time limit. Processing in an RTOS occurs within defined
time constraints and monitors the priority of tasks.
18. What are tasks?
There are four types of task classes in real-time operating systems viz. Periodic Tasks,
Dynamic Tasks. (Dynamic tasks are further classified into two types Aperiodic Tasks and Sporadic
tasks), Critical Task and Non-critical Task.
19. Define multirate systems.
Systems that internally employ multiple sampling rates are collectively referred to as multirate
systems. In most cases, these systems are time-varying or, at most, periodically time-invariant. The
basic operations of the multirate systems are decimation and interpolation.
20. What are scheduling policies?(May/June-13)
Scheduling policies determine how the processes are selected for execution. Scheduling policies
can also deliver higher CPU utilization. Right scheduling policies meet all the timing requirements
and also properly utilize the CPU. Some of the scheduling policies are discussed in detail.
21. Define context switching.(Nov/Dec-13,Apr-14,Apr/May-15)
The context switch procedure consists of getting the values of the CPU register during the
execution and saving them at the bottom of the stack of the currently running task. Then, restore
the values for the next task, to resume its execution.
22. Define Kernel.
The kernel is the part of the OS that determines what process is running.The Kernal is activated
periodically by the timer. The length of the timer period is known as the time quantum.
23. Define PCB.
Process Control Block (PCB) is a data structure maintained by the operating system to store
information about each process. The role of PCB is to give identity to each process so that the
Operating System can easily distinguish between processes.

24. What are the ways of communication in process?(Apr-14)


A process can send a communication in two ways
1.Blocking
2.Non-blocking
25. Define Multitasking. (Nov/Dec-14)
When more than one program is running at the same time in a computer, the CPU is said to be
multitasking.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
QUESTIONBANK

PART – B

1. With necessary hardware & software details explain how to interface LCD’S with
8051.
2. How do you interface 8051 microcontrollers with keyboard? Explain in detail.

3. Explain in detail the procedure to interface stepper motor with 8051.

4. How do temperature sensor interfacing with 8051.

5. Explain the different modes of operation of serial port in 8051, indicating various registers
associated with it.
6. Describe in detail about the scheduling policies with suitable examples.

7. Explain in detail rate monotonic scheduling with an example.

8. Explain the interrupt structure of 8051 microcontroller and explain how interrupts are
prioritized.
9. Explain in detail about 8051 connection to RS232.

10. Write an assembly language program to display counters 0 on 7 segment LEDs. Assume that
clock input is connected to pin (p3.4)
11. Explain how memory interfacing take places in 8051 microcontroller.

12. Discuss the functions of Input Output interfacing.

13. Discuss about multi rate System.

14. Explain about basic structure of embedded C programming.

15. Describe the need of context switching.

You might also like