Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

Year/sem: 02/04 Academic Year: 2014-2015 (even)


UNIT IV
THE 8051 MICROCONTROLLER

PART A

1. What is mean by microcontroller?

A device which contains the microprocessor with integrated peripherals like memory, serial ports,
parallel ports, timer/counter, interrupt controller, data acquisition interfaces like ADC,DAC is called
microcontroller.

2. Explain DJNZ instructions of intel 8051 microcontroller?


a) DJNZ Rn, rel
Decrement the content of the register Rn and jump if not zero.
b) DJNZ direct, rel
Decrement the content of direct 8-bit address and jump if not zero.

3. Specify the single instruction, which clears the most significant bit of B register of 8051, without
affecting the remaining bits.
Single instruction, which clears the most significant bit of B register of 8051, without affecting
the remaining bits is CLR B.7.

4.Explain the function of the pins PSEN and EA of 8051.


PSEN: PSEN stands for program store enable. In 8051 based system in which an external ROM holds
the program code, this pin is connected to the OE pin of the ROM.
EA: EA stands for external access. When the EA pin is connected to Vcc, program fetched to
addresses 0000H through 0FFFH are directed to the internal ROM and program fetches to addresses
1000H through FFFFH are directed to external ROM/EPROM. When the EA pin is grounded, all
addresses fetched by program are directed to the external ROM/EPROM.

5. Explain the 16-bit registers DPTR and SP of 8051.


DPTR: DPTR stands for data pointer. DPTR consists of a high byte (DPH) and a low byte (DPL). Its
function is to hold a 16-bit address. It may be manipulated as a 16-bit data register or as two independent
8-bit registers. It serves as a base register in indirect jumps, lookup table instructions and external data
transfer.
SP: SP stands for stack pointer. SP is a 8- bit wide register. It is incremented before data is stored
during PUSH and CALL instructions. The stack array can reside anywhere in on-chip RAM. The stack
pointer is initialized to 07H after a reset. This causes the stack to begin at location 08H.

6. Compare Microprocessor and Microcontroller.

Microprocessor Microcontroller
Microprocessor contains ALU, general purpose Microcontroller contains the circuitry of

EC6504-MP&MC, UNIT 4 Page 1


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

registers, stack pointer, program counter, clock microprocessor and in addition it has built- in
timing circuit and interrupt circuit. ROM, RAM, I/O devices, timers and counters
It has many instructions to move data between It has one or two instructions to move data
memory and CPU. between memory and CPU
It has one or two bit handling instructions. It has many bit handling instructions
Access times for memory and I/O devices are Less access times for built-in memory and I/O
more devices
Microprocessor based system requires more Microcontroller based system requires less
hardware. hardware reducing PCB size and increasing the
reliability

7.Write a program to load accumulator A, DPH and DPL with 30H.


MOV A, #30
MOV DPH, A
MOV DPL, A

8.Write a program to subtract the contents of R1 of Bank0 from the contents of R0 of Bank2.
MOV PSW, #10
MOV A, R0
MOV PSW, #00
SUBB A, R1

9. List the features of 8051 microcontroller?


The features are
*single_ supply +5 volt operation using HMOS technology
*4096 bytes program memory on chip(not on 8031)
*128 data memory on chip.
*Four register banks.
*Two multiple mode,16-bit timer/counter.
*Extensive Boolean processing capabilities.
*64 KB external RAM size
*32 bi-directional individually addressable I/O lines.
*8 bit CPU optimized for control applications.

10. Name the special functions registers available in 8051.


 Accumulator
 B Register
 Program Status Word.
 Stack Pointer.
 Data Pointer.
 Port 0
 Port 1
Port 2

EC6504-MP&MC, UNIT 4 Page 2


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

 Port 3
 Interrupt priority control register.
 Interrupt enable control register.

11. Give Few Applications Of 16 Bit Microcontrollers?


They are used in the field of:
I. Closed – loop control.
II. Modems
III. Printers
IV. Disk drives
V. Medical instrumentation.

12. What are Addressing Modes?


The various ways of accessing data are called addressing modes.

13. List the Five Addressing Modes of 8051 Microcontroller.


The five addressing modes are,
 Immediate addressing
 Register addressing
 Direct addressing
 Register indirect addressing
 Indexed addressing.

14. Explain the Immediate Addressing Mode.


In immediate addressing mode, the source operand is constant. In this mode, as the name implies, when
the instruction is assembled, the operand comes immediately after the opcode.
MOV A, #25+1 ; load 25H into A

15. Explain the Register Addressing Mode.


Register addressing mode involves the use of register to hold data to be manipulated.
Examples of register addressing mode is as follows:
MOV A, R0; Copy the contents of R0 into A.
MOV R2, A; Copy the contents of A into R2.

16. Mov R4, R7 Is Invalid. Why?


The movement of data between the accumulator and Rn (for n = 0 to 7) is valid. But movement of data
between Rn register is not allowed. That is why MOV R4, R7 is invalid.

17. What is SFR?


In the 8051 microcontroller registers A, B, PSW and DPTR are part of the group of registers commonly
referred to as special function registers (SFR).

EC6504-MP&MC, UNIT 4 Page 3


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

18. What are the Two Main Features of SFR Addresses?


The following two points should be noted SFR addresses.
I. The special function registers have addresses between 80H and FFH.
These addresses are above 80H, since the addresses 00 to 7FH are addresses of RAM memory inside the
8051.
II. Not all the address space of 80 to FH is used by the SFR. The unused locations 80Hto FFH are
reserved and must not used by the 8051 programmer.

19. Write Code to Send 55h to Ports P1 And P2 Using Their Names & Their Addresses.
MOV A, #55H ; A = 55H
MOV P1, A ; P1 = 55H
MOV P2, A ; P2 = 55H
II. P1 address = 80H ; P2 address = AOH
MOV A, #55H ; A = 55H
MOV 80H, A ; P1 = 55H
MOV OAOH, A ; P2 = 55H.

20. What Is the Main Advantage of Register Indirect Addressing Mode?


The main advantage of register indirect addressing mode is that it makes addressing data dynamic rather
than static as in the case of direct addressing mode.

21. What Is The Difference Between Direct And Register Indirect Addressing Mode?
Loop is most efficient and is possible only in register indirect addressing whereas looping is not direct
addressing mode.

22. What are Unsigned Numbers?


Unsigned numbers are defined as data in which all the bits are used to represent data, and no bit are set
aside for the positive or negative sign.

23. List Some Logical Instruction.


The logical instructions are:
 AND
 OR
 XOR
 CPL A

24. List out Some Compare Instructions.
The compare instructions are:
a. CJNE
b. CLR
c. CPL

25. Write A Program to Save the accumulator in R7 of Bank 2.


CLR PSW – 3

EC6504-MP&MC, UNIT 4 Page 4


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

SETB PSW – 4
MOV R7, A.

25. What are Single Bit Instructions? Give Example.


Instructions that are used for single bit operation are called single bit instructions.
Examples: SETB bit
CLR bit
CPL bit

26. Write A Program To Save The Status Of Bits P1.2 And P1.3 On Ram Bit Locations 6 And 7
Respectively.
MOV C, P1.2 ; save status of P1.2 on CY
MOV O6, C ; save carry in RAM bit location 06
MOV C, p1.3 ; save status of p1.3 on CY
MOV 07, C ; save carry in RAM bit location 07.

27. Write A Program To See If Bits 0 And 5 Of Register B R1. If They Are Not, Make Them So
And Save It In R0.
JNB OFOH, NEXT – 1 ; JUMP if B.0 is low
SET BOFOH ; Make bit B.0 high
NEXT – 1:JNB OF5H, NEXT – 2 ; JUMP if B.5 is low
SETB OF5H ; Make B.5 high
NEXT – 2: MOV R0, B ; Save register B.

28. Define PSW

29. Define Status Function Registers

EC6504-MP&MC, UNIT 4 Page 5


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

30. Define Input pin and output pin

Output pin
A logic zero (0) is applied to a bit of the P register. The output FE transistor is turned on, thus
connecting the appropriate pin to ground.
Input Pin

A logic one (1) is applied to a bit of the P register. The output FE transistor is turned off and the
appropriate pin remains connected to the power supply voltage over a pull-up resistor of high resistance.
Logic state (voltage) of any pin can be changed or read at any moment. A logic zero (0) and logic one (1)
are not equal. A logic one (0) represents a short circuit to ground.
31. Give the alternate functions for the port pins of port3
PIN ALTERNATE USE
P3.0-RXD Serial data input
P3.1- TXD Serial data output
P3.2-INTO External interrupt 0

P3.3-INT1 External interrupt 1


P3.4- TO External timer 0 input
P3.5- T1 External timer 1 input
P3.6-WR External memory write pulse

P3.7-RD External memory read pulse

32. Illustrate Indexed addressing mode with an example

EC6504-MP&MC, UNIT 4 Page 6


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

33. Give the function of 8051 Instruction Set: RET

Operation: RET
Function: ReturnFrom Subroutine
Syntax: RET

Byte
Instructions OpCode Flags
s

RET 0x22 1 None


Description: RET is used to return from a subroutine previously called by LCALL or ACALL.
Program execution continues at the address that is calculated by popping the topmost 2 bytes off the
stack. The most-significant-byte is popped off the stack first, followed by the least-significant-byte.

34. Draw the input/output circuit

35. List various instructions available in 8051 microcontroller

Data Transfer Instructions


Arithmetic Instructions
Logical Instructions
Boolean variable Manipulation Instructions
Program and Machine Control Instructions

PART-B

1. With neat sketch explain the architecture of 8051 microcontroller.


The 8051 Microcontroller is one of the basic type of microcontroller, designed by Intel in 1980’s.
This microcontroller was based on Harvard Architecture and developed primarily for use
in embedded systems technology. Normally, this microcontroller was developed using NMOS
technology, which requires more power to operate.. These latest Microcontrollers requires less
power to operate as compared to their previous versions. The 8051 Microcontroller has two buses
and two memory spaces of 64K X 8 size for program and data units. It has an 8 bit processing unit
and 8 bit accumulator units.

EC6504-MP&MC, UNIT 4 Page 7


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

2. Draw the Pin Diagram of 8051 and explain the function of various signals
PINS AND SIGNALS OF 8031/8051 MICROCONTROLLER
• The INTEL 805 F is an 8-bit microcontroller with 128 byte internal RAM and 4kb internal
ROM.
• The INTEL 8031 is same, as 8051 except that it does not have internal ROM.
• The 8051 is a pin 40 pin IC available in Dual-In line package (DIP).
• Requires a single power supply of +5V.
• Its maximum internal clock frequency rating is 12 MHz.

EC6504-MP&MC, UNIT 4 Page 8


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

3. List and explain the various Instructions available in 8051 microcontroller.


8051 has about 111 instructions. These can be grouped into the following categories
1. Arithmetic Instructions
2. Logical Instructions
3. Data Transfer instructions
4. Boolean Variable Instructions
5. Program Branching Instructions

EC6504-MP&MC, UNIT 4 Page 9


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

EC6504-MP&MC, UNIT 4 Page 10


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

4. Define addressing modes and illustrate it with an example


Addressing Modes
What is an addressing modes ?
In short ,a way to addressing a operand is nothing but addressing mode. Operand means data on
which we are going to operate i.e source data. We can address the operand using direct address or
by using register or we can address the data using some numerical value etc. e.g. MOV A,#6BH
In this example 6BH is operand i.e. source data. After execution of this instruction 6BH is added
to the accumulator.We can execute this instruction by using 5 different ways i.e we can use 5
different addressing modes to execute this instruction. Following are the different type of
addressing modes.
 Immediate addressing mode
 Direct addressing mode
 Register addressing mode
 Register indirect addressing mode
 Indexed addressing mode.
Immediate addressing mode:
As word indicate 'immediate' this addressing mode transfer 8 bit immediate data to destination .
e.g MOV A, #6BH
Direct addressing mode:
This is type of addressing mode in which the address of the data (source data ) is given as
operand.. i.e. it is given directly in the form of numerical data.
e.g. MOV B,20H

Register addressing mode :

This is type of addressing mode in which we use the register name directly as source data.
e.g MOV A, R5

EC6504-MP&MC, UNIT 4 Page 11


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

Register direct addressing mode :

In this mode of addressing address of source data is given by value at register indirectly
e.g. MOV A, @R1

Indexed addressing mode :

In this type of addressing mode we use following instruction :


MOVC A, @A+DPTR and 2. MOVC A, @A+PC

3. Explain the I/O ports and circuits with neat diagrams wherever necessary

PORT 0:

The structure of a Port-0 pin is shown in fig 6.It has 8 pins (P0.0-P0.7).

PORT 1:
The structure of a port-1 pin is shown in fig below.It has 8 pins (P1.1-P1.7) .

PORT 2:

The structure of a port-2 pin is shown in fig. below. It has 8-pins (P2.0-P2.7).

EC6504-MP&MC, UNIT 4 Page 12


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

PORT 3:

Port-3 (P3.0-P3.7) having alternate functions to each pin,The internal structure of a port-3 pin is shown in
fig below.

EC6504-MP&MC, UNIT 4 Page 13


STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY COURSE MATERIAL (QB)

4. Describe Special Function registers

SFR Address Function

DPH 83 Data pointer registers (High). Only byte addressing possible.

DPL 82 Data pointer register (Low). Only byte addressing possible.

IP B8 Interrupt priority. Both bit addressing and byte addressing possible.

IE A8 Interrupt enable. Both bit addressing and byte addressing possible.

SBUF 99 Serial Input/Output buffer. Only byte addressing is possible.

Serial communication control. Both bit addressing and byte


SCON 98 addressing possible.

TCON 88 Timer control. Both bit addressing and byte addressing possible.

TH0 8C Timer 0 counter (High). Only byte addressing is possible.

TL0 8A Timer 0 counter (Low). Only byte addressing is possible.

TH1 8D Timer 1 counter (High). Only byte addressing is possible.

TL1 8B Timer 1 counter (Low). Only byte addressing is possible.

TMOD 89 Timer mode select. Only byte addressing is possible.

5. Write an ALP to perform arithmetic operations using 8051


ADDRESS LABEL MNEMONIC OPERAND HEX COMMENTS
CODE
4100 CLR C C3 Clear CY Flag
4101 MOV A, data1 74,data1 Get the data1 in Accumulator
4103 ADDC A, # data 2 24,data2 Add the data1 with data2
4105 MOV DPTR, # 90,45,00 Initialize the memory location
4108 MOVX 4500H F0 Store the result in memory location
4109 L1 SJMP @ DPTR, A 80,FE Stop the program
L1

EC6504-MP&MC, UNIT 4 Page 14


STUDENTSFOCUS.COM

You might also like