KEMBAR78
1 - Microcontroller | PDF | Computer Science | Office Equipment
0% found this document useful (0 votes)
22 views35 pages

1 - Microcontroller

The document provides a comprehensive question bank and study materials for the 8051 microcontroller and its architecture, covering various aspects such as instruction sets, special function registers, and memory organization. It includes both theoretical questions and practical assembly language programming tasks. Additionally, it outlines the key features and components of the 8051 architecture, including its CPU, ports, and power-saving modes.

Uploaded by

BALAJI D
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)
22 views35 pages

1 - Microcontroller

The document provides a comprehensive question bank and study materials for the 8051 microcontroller and its architecture, covering various aspects such as instruction sets, special function registers, and memory organization. It includes both theoretical questions and practical assembly language programming tasks. Additionally, it outlines the key features and components of the 8051 architecture, including its CPU, ports, and power-saving modes.

Uploaded by

BALAJI D
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/ 35

ET – 3491 – Embedded Systems and IOT Design

Question Bank and Study Materials

UNIT – I / MICROCONTROLLER

PART – A

1. How to set 8051 in idle mode (Nov/Dec‘17)


2. Illustrate DJNZ instruction. (Nov/Dec‘17)
3. Which port used as multi functions port? List the signals.[Apr‘17]
4. Illustrate the CJNE instruction.[Apr‘17]
5. What is the significance of EA pin? [Dec‘16]
6. How does the processor 8051 knows whether on-chip ROM or external program memory
is used? [Apr‘14]
7. Draw the pin diagram of 8051.[Dec‘16] (Apr/may‘18)
8. What are the different ways of operand addressing in 8051. [Apr‘16]
9. Mention the different operand types used in 8051 microcontroller. [Dec‘12]
10. Write an 8051 ALP to toggle P1 a total of 200 times. Use RAM location 32H to hold your
counter value instead of registers R0-R7. [Apr‘16]
11. Mention the number of register banks and their addresses in 8051. [Dec‘15]
12. What is the jump range? [Dec‘15] 13. Draw the diagram for processor status word in
8051. [Apr‘15]
14. How do you select the register bank in 8051 microcontroller? [Apr‘15]
15. How the selection of particular register bank is done in 8051? [Apr‘13]
16. List the SFRs involved in interrupt programming of 8051.[Dec‘14]
17. Why it is necessary to have external pull up for port 0 in 8051. [Dec‘14]
18. Which of the 8051 port need pull-up registers to function as I/O port? [Dec‘13]
19.What is the difference between AJMP and LJMP instruction? [Apr‘14]
20. How do you place a specific value in the DPTR register? [Dec‘13]
21. What happens in power down mode of 8051 microcontroller? [Apr‘13]
22. Specify the size of memory systems used in 8051 microcontroller? [Dec‘12]
23.What are the bit manipulation instructions?(Apr/may‘18)

PART-B

1.Explain the parallel port architecture of 8051 microcontroller. [Dec‘12(8 Mark)]


2.Explain the architecture of 8051 microcontroller with neat sketch. (Apr/may‘18)
3.Give PSW of 8051 and describe the use of each bit in PSW. [Dec‘15(8 Mark)]
4.Explain in detail about the architecture of 8051 microcontroller with a neat
diagram.[Dec‘16(16 Mark)]
5.Draw the pin diagram of 8051 microcontroller and explain the functions of each
pin.[Apr‘13(10 Mark)]
6.Describe the functions of the following signals in 8051. RST, EA, PSEN and
ALE.[Dec‘15(8 Mark)]
7.Discuss briefly the various registers in 8051 microcontroller. [Apr‘13(8 Mark)]
8.Explain in detail about the special function registers in 8051. [Dec‘15(8 Mark)]
9.Write the available special function registers in 8051. Explain each register with its format
and functions. [Apr‘17(16 Mark)]
10.Write a brief note on external data move operation in 8051.[Dec‘13(6 Mark)]
11.Briefly explain the data transfer instructions available in 8051 microcontroller. [Dec‘14(8
Mark)]
12.Explain about arithmetic and control instruction set in 8051. [Apr‘15(10 Mark)]
13.Explain the TMOD function register and its timer modes of operations. [Apr‘15(8Mark)],
[Dec‘13(6 Mark)]
14.Enumerate about the ports available in 8051 microcontroller. [Apr‘14(8 Mark)]
15.Discuss the ports and its circuits of 8051. [Nov‘17(13 Mark)]
16.Write an assembly language program for 8051 to find the largest of three numbers.
[Apr‘14(8 Mark)]
17.Write an 8051-assembly language program to add three BCD numbers stored in internal
RAM locations 25H, 26H and 27H and put the result in RAM location31H(MSB) and
30H(LSB). Use register R0 to store the intermediate result. [Dec‘13 (10Mark)]
18.Explain in detail the memory organization of 8051 microcontroller. [Dec‘14(16 Mark)]
19.Write a program to bring in data in serial form and send it out in parallel form using8051.
[Apr’15 (6 Mark)]
20.Briefly explain about addressing modes of 8051. [Dec‘15(8 Mark)](or) Discuss the types
of addressing mode with suitable example in 8051. [Apr‘17(8 Mark)] (Apr/may‘18)
21.Write an 8051 ALP to create a square wave of 66% duty cycle on bit 3 of port 1.
[Apr‘16(16 Mark)]
22.Write an 8051 assembly language program to multiply the given number 48H and 30H.
[Apr‘17(8 Mark)]
UNIT 4
MICROCONTROLLER

Architecture of 8051:
The Architecture of 8051 is shown below

116
8-bit CPU
on-chip oscillator
4KB of ROM(program memory)
128 bytes of RAM(Data memory)
21 special fuction register.
32 I/O lines(Port P0 to P3)
64KB address space for external data memory
64KB address space for program memory
Two 16-bit timer/counter.
5 source interrupt structure
full duplex serial port
bit addressability.
powerful bit processing capability.
-51 family includes pin compatible chips like
Intel 8031
Intel 8051
Intel 8751
The 8031 is the ROM-

In 8051,the on-chip 4 KB EPROM can be programmed for any application.


Power saving features like Idle mode & power down mode are used.
In Idle mode, CPU is turned OFF, devices like RAM & on-chip unit remain active, power
drawn in the idle mode is 15% of full power.
In power down mode, all on-chip activates are suspended. The on-chip RAM continues to
hold the data,
8051 system bus composes of an 8 bit data bus and a 16 bit address bus and bus control
signals. It consists of memory; ports, timers, and the central processing unit are all interfaced
together through the system bus.
Central processing unit
The CPU consists of ALU and supporting registers.

117
ALU (Arithmetic and logical Unit)
It does the Arithmetic function like addition, subtraction, multiplication and division. It
does the logical function like AND, OR, XOR and etc.
A and B Registers
The A register is located in the SFR memory location 0xE0. The A register works in a similar
fashion to the AX register of x86 processors. The A register is called the accumulator, and by
default it receives the result of all arithmetic operations. The B register is used in a similar
manner, except that it can receive the extended answers from the multiply and divide
operations. When not being used for multiplication and Division, the B register is available as
an extra general-purpose register.

General Purpose Registers

The 8051 has 4 selectable banks of 8 addressable 8-bit registers, R0 to R7. This means that
there are essentially 32 available general purpose registers, although only 8 (one bank) can be
directly accessed at a time. To access the other banks, we need to change the current bank
number in the flag register.

Special Function Register

The Special Function Register (SFR) is the upper area of addressable memory, from address
0x80 to 0xFF. A, B, PSW, DPTR are called SFR.This area of memory cannot be used for data
or program storage.

SFR s in 8051

ACC
B register
PSW Program status word
SP- stack pointer
DPL- Data pointer low
DPH- Data pointer high
P0
P1
P1
118
P2
P3
IP- interrupt priority
IE- interrupt enable
TMOD- timer mode control register(8 bit)
TCON timer control register (8 bit)
SCON serial ports control register (8bit)
PCON power control register (8bit)
SBUF serial data buffer
TH0 higher byte of 16 bit timer register 0
TLO - lower byte of 16 bit timer register 0
TH1 - higher byte of 16 bit timer register 1
TL1 - lower byte of 16 bit timer register 1

Program Counter

Program Counter is an engine running the program and points to the memory address
containing the next instruction to execute. After each instruction execution, the value of the
counter is incremented by 1

Program Status Word (PSW) Register

PSW register is one of the most important SFRs. It contains several status bits that reflect the
current state of the CPU. Besides, this register contains Carry bit, Auxiliary Carry, two
register bank select bits, Overflow flag, parity bit and user-definable status flag.
P - Parity bit. If a number stored in the accumulator is even then this bit will be automatically
set (1), otherwise it will be cleared (0). It is mainly used during data transmit and receive via
serial communication.
- Bit 1. This bit is intended to be used in the future versions of microcontrollers.
OV Overflow occurs when the result of an arithmetical operation is larger than 255 and
cannot be stored in one register. Overflow condition causes the OV bit to be set (1).
Otherwise, it will be cleared (0).
119
RS0, RS1 - Register bank select bits. These two bits are used to select one of four
register banks of RAM. By setting and clearing these bits, registers R0-R7 are stored in
one of four banks of RAM.

RS1 RS0 SPACE IN RAM

0 0 Bank0 00h-07h

0 1 Bank1 08h-0Fh

1 0 Bank2 10h-17h

1 1 Bank3 18h-1Fh

F0 - Flag 0. This is a general-purpose bit available for use.


AC - Auxiliary Carry Flag is used for BCD operations only.
CY - Carry Flag is the (ninth) auxiliary bit used for all arithmetical operations and shift
instructions.
TMP2 & TMP1- Temporary Register
It is a 8 bit register
During ALU Operation , It is used to store one of the operand
Users can not access the temporary register, it is internally used by controller
Input/output ports
8051 has 4 ports
port 0, port1, port2, port3
Each port has 8 port lines , p0.0 to p0.7 , p1.0 to p1.7, p2.0 to p2.7, p3.0 to p3.7
Each port line can be used as input or as an output under the software control
(SBUF) Serial data buffer(16 bit)
It contains two 8 bit registers. One of them is a Transmit buffer and a receive buffer
Instruction register(IR) (8 bit)
This register decodes the opcode of an instruction to be executed and gives the information
to timing and control unit to generate necessary signals for the execution of an instruction
Program address register(16 bit)
It is used to address the EPROM
RAM address register
This block provides internal 128 bytes of RAM and mechanism to address it internally.

120
Timer register (T0 & T1)
T0 is a 16 bit register
TL0 represents the lower byte of timing register 0
TH0 represents the higher byte of timing register 0
T1 is a 16 bit register
TL1 represents the lower byte of timing register 1
TH1 represents the higher byte of timing register 1
Timing and control circuit
This unit drives all necessary timing and control signals for the internal operation of the
circuit.

S
These registers have some special functions like controlling the timer/counter, enabling
interrupts, controlling the serial port operations etc.
21 special function registers in the 8051.
Some SPF are bit addressable.
Special function registers are as below.
ACC - Accumulator
B - B Register
PSW - Program Status Word
SP - Stack Pointer
DPTR (Low) - Data Pointer Low
DPTR (High) - Data Pointer High
P0 - Port 0
P1 - Port 1
P2 - Port 2
P3 - Port 3
IP - Interrupt Priority
IE - Interrupt Enable
PMOD - Timer / Counter Mode
PCON - Timer / Counter Control
TH0 - (Timer / Counter) 0 High
TL0 - (Timer / Counter) 0 Low
121
TH1 - (Timer / Counter) 1 High
TL1 - (Timer / Counter) 1 Low
SCON - Serial Control
SBUF - Serial Data Buffer
PCON - Power Control
Accumulator:
ACC is also called A register.
There are many instructions that use the accumulator as the destination.
ACC is used as one of the operands and after the operation, the result is also stored in the
ACC.

B Register:
Used for Multiply and divide operations.
This register acts as one of the operands and after the operations a part of the result is
stored in this register.
Register is just like a scratch pad i.e. a temporary register.
Stack Pointer:
is a 8-bit wide register.
This pointer can point to any location in the internal data RAM i.e. location from 0-127.
When the chip is reset, this register is initialized to 07H.
During PUSH and CALL instructions the stack pointer is first incremented and then the
data is stored in the stack.
Data Pointer:
is a 16-bit register, consisting of a high byte (DPH) and a low byte (DPL).
This register contains a 16-bit address.
Ports 0-3:
4 bidirectional Input / Output Ports of 8-bits each.
These are directly represented as pins of the 8051 chips and are bit addressable.
These are multi functional resources that can be programmed based on the application
needs
Serial Data buffer(SBUF):
This register holds the data that has to be transmitted through the serial port and also the
data that is received.

122
this register is interconnected to two 8-bit shift registers.
When data is written in to the SBUF, it is loaded in to the transmit shift register and hence
the process of moving a data byte in to the SBUF starts the transmission process.
During reception, the data coming to the 8051 is clocked in to the receive shift register &
once all the 8-bits of data or a frame is received it is transferred to the SBUF.
Control & Status Registers:
These registers contain the control & status bit of the interrupt systems, timers & serial port
operations,
The instruction decoding & control signal generation are performed using the timing &
control circuit block.
The bidirectional ports P0 to P3 have the basic structure containing drivers & latches.
The port drivers are connected to I/O ports.

The 8051 contains 128 bytes RAM as data memory & 4KB ROM as program memory on
the chip.
Internal data RAM with address register is connected to the internal bus
The address register will get the address from the internal bus & the data will be transferred
to the specified register through the bus.

123
A bidirectional buffer has been provided to temporarily store the branch address as well as
the operand address information.
This will also facilitate the transfer of the program counter contents to other circuits
Port P0 & P2 facilitate the connection to the external memory
The lower-order address bits (A0 to A7) are send through port0(P0.0 to P0.7)
The higher-order address bits (A8 to A15) are send through port2(P2.0 to P2.7)
Data pointer register is interfaced to the address register, plays a major role in external
program and data memory addressing using MOVC & MOVX instructions.

pin diagram of 8051 microcontroller

VCC Power supply voltage (4-6V)

GND Ground ( Negative supply pole)

Port 0 (P0.0-P0.7) If configured as outputs, each of these pins can be connected to up to 8 TTL
inputs. If configured as inputs, the pins can be used as high-impedance inputs as their potential is not
defined relative to ground.

124
Port 1 (P1.0-P1.7) If configured as outputs, each of these pins can be connected to up to 4 TTL
inputs. When configured as inputs, these pins act as standard TTL inputs, that is, each of them is
internally connected to the positive supply voltage via a resistor of relatively high impedance. Power
supply voltage provided on these inputs is 5V. Also, the Port 1 pins have alternate functions as shown
in

RST Logic one (1) on this pin causes the microcontroller to be reset.

ALE/PROG When external memory is used, a signal from this pin is used to latch the low byte of an
address (A0-A7) from P0. During the process of writing a program to the microcontroller, this pin
also serves as a control input.

PSEN This pin provides a signal used for accessing external program memory (ROM).

EA/VPP When this pin is connected to ground, the microcontroller reads program instructions from
external program memory. If internal program memory is used, which is the common case, this pin
should be connected to the positive power supply voltage (VCC). During the process of programming
internal Flash memory, this pin is supplied with +12V.

XTAL 1 This is internal oscillator input. It is used for the purpose of synchronizing the operation of
the microcontroller with some other circuit or for connecting external oscillator when used.

XTAL 2 This pin is connected to internal oscillator output. Therefore, it is out of use when using
external oscillator.

125
Addressing mode 0f 8051:
The CPU can access data in various ways.
The data could be in a register, or in memory(RAM or ROM , or be provided as an
immediate value.
These various ways of accessing data are called addressing mode
Five addressing mode in the 8051
1. Immediate addressing mode
2. Register addressing mode
3. Direct addressing mode
4. Register indirect addressing mode
5. Indexed addressing mode

Immediate addressing mode

The source operand is a constant.


When the instruction is assembled, the operand comes immediately after the opcode.
The immediate vale can be loaded into any of the registers.
The .
Example:
MOV A, #18
MOV R4, # 04
MOV DPTR, #2040

Register addressing mode

Register addressing mode involves the use of registers to hold the data.
The source and destination registers must match in size.
Register addressing mode accesses the eight register (R0 to R7)
is illegal.
Example:
MOV A, R0

MOV R2, A

ADD A, R5

Direct addressing mode

There are 128 bytes of RAM in the 8051.


The RAM has been assigned address 00 - 7FH.
00-1FH the register banks and stack
20-2FH bit-addressable space to save single-bit data
30-7FH scratch pad RAM
In direct addressing mode, the data is in a RAM memory location whose address is known,
and this address is given as a part of the instruction.

address.

126
Example:

MOV R2, 61H


MOV 6F, A

Register indirect addressing mode

In the register indirect addressing mode, a register is used as a pointer to the data.
That is, this register holds the RAM address of the data.
Only registers R0 and R1 can be used to hold the address of an operand located in RA.
Usually, R0 and R1 are denoted by Ri.
When R0 and R1 hold the addresses of RAM

Example:
MOV @R0, A: Move contents of A into RAM location whose address is held by R0

MOV B, @R1,: Move contents of RAM location whose address is held by R1 into B

Indexed addressing mode

Indexed addressing mode is widely used in accessing data elements of look-up table entries
located in the program ROM space of the 8051.
A look-up table is a ROM block where the data is given previously (then you can
access it frequently).
The instruction used for this purpose is MOVC.
DPTR can be used to access memory externally connected to the 8051. Another register used
in indexed addressing mode is the PC

Example:

MOVC A, @A+DPTR
on-chip ROM).
A+DPTR is the address of the data element stored in on-chop ROM.
Put the ROM value to A.

127
Instruction set of 8051:
Types Of Instructions

1. Data transfer instructions.


2. Arithmetic instructions.
3. Logical instructions.
4. Logical instructions with bits.
5. Branch instructions

Data transfer instructions.

These instructions move the content of one register to another one.


Data can be transferred to stack with the help of PUSH and POP instructions.

128
Arithmetic instructions.

Logical instructions.

129
Branch instructions

130
INPUT / OUTPUT PORTS CONFIGURATION:
PORT 0
Port 0 is also designated as AD0-AD7.
When connecting an 8051 to an external memory, port 0 provides both address and data.
The 8051 multiplexes address and data through port 0 to save pins.
ALE indicates if P0 has address or data.
When ALE=0, it provides data D0-D7
When ALE=1, it has address A0-A7

PORT 1

131
PORT 2

PORT-3

132
UNIT 5
INTERFACING MICROCONTROLLER

Timers/counters in 8051:
8051 has two 16-bit timers/counters
These two timers/counters can be programmed independently.
There is a bit in the TMOD special function register that specifies whether it is a timer
or a counter.
If this bit is set, the timer/counter will work as a counter.
If this bit is reset, the timer/counter will work as a timer.
Timer Mode:
In timer mode, the timer register (TH1 and/or TL1 for timer 1 or TH0 and /or TH0 for
timer 0) is incremented after every machine cycle.
It will be working at 1/12th of the oscillator frequency because each machine cycle has
got 12 oscillator periods
Counter Mode:
It is required to count the number of occurrence of a particular event.
When a timer/counter is used as an event counter, the registers are incremented
whenever a 1 to 0 transition is sensed at the T0 or T1 pins of the 8051.
Timers can function in four different modes.
Mode 0
Mode 1
Mode 2
Mode 3
These modes are achieved by setting certain bits in the TMOD register.
Mode 0:
TL0 and TH0 for timer 0 are used as a 13-bit register i.e. all the 8 bits of the TL0 or
TL1 are utilized and the five lowermost bits of the TH0 or TH1 are used for
counting purposes.
set.
This timer interrupt flag is a bit, normally TF0 in the TCON, which is a special
function register.

133
Fig: Timer 0,Mode 0-13 bit counter
If C/T = 0, the register is incremented after every machine cycle is at the rate of
1/12th of the oscillator frequency.
For the register to get incremented, the control switch should be closed, this switch
is logic controlled to close the switch, we must fulfill this logic.
To implement this logic some of the ways are given below.
Case 1
TR0 = 1 (high)
Gate = 0 (low) & INT0 = 0 (low)
Case 2
TR0 = 1 (high)
INT0 = 1 (high) & Gate = 1 (high)
Gate and TR0 are bits in the TMOD & TCON registers and can be set or reset
through the software.
INT0 is one of the interrupt pins of the 8051.
Mode 0 for both the timers/counters is the same, only change TR0 to TR1, INT0 to
INT1 and gate bit for timer 0 to gate bit for timer 1.
Mode 1:
This mode is also same for both the timers.
Mode 1 is similar to Mode 0 except that, full TL0 and TH0 for timer 0 are used for
counting.

134
Fig: Timer 0,mode 1-16 bit counter

Mode 2:
The timer register is 8 bits wide.
TL0 for timer 0 is used for this purpose.
This mode is also called the auto-reload mode as the timer generates an interrupt on
overflow and after generating the interrupt will also reload the preset value form
TH0 in to TL0.
This present value can be put in the TH0 through a software.

Fig: Timer 0,mode 2-autoreload

After generating an interrupt, it also reloads the TL0 with the value form TH0 and
then starts counting again.
135
Mode 3:
If timer 0 is put into mode 3, it act as two 8-bit counters.
All the timer 0 control bits are used by TL0 itself and TH0 register is locked in to a timer
function.

Fig: Timer 0,Mode 3-Split to two 8-Bit Counters

TH0 is counting machine cycles and has taken over the use of TR1 & TF1 from
timer 1.
TH0 will control timer 1 interrupt.
If timer 1 is put in to mode 3, it just hold the count.
The effect is same as setting TR1=0, hence opening the switch.

136
SERIAL PROGRAMMING:
Computers transfer data in two ways:
1. Parallel
2. Serial

Serial data communication uses two methods:


Synchronous method transfers a block of data at a time.
Asynchronous method transfers a single byte at a time.

It is possible to write software to use either of these methods, but the programs can be tedious and
long
There are special IC chips made by many manufacturers for serial communications
UART (universal asynchronous Receiver transmitter)
USART (universal synchronous-asynchronous Receiver-transmitter)

SBUF REGISTER :
SBUF is an 8-bit register used solely for serial communication

For a byte data to be transferred via the TxD line, it must be placed in the SBUF register
The moment a byte is written into SBUF, it is framed with the start and stop bits and
transferred serially via the TxD line
SBUF holds the byte of data when it is received by 8051 RxD line
When the bits are received serially via RxD, the 8051 deframes it by eliminating the stop and
start bits, making a byte out of the data received, and then placing it in SBUF

137
SCON REGISTER :
SCON is an 8-bit register used to program the start bit, stop bit, and data bits of data framing,
among other things

SM2 Enables multiprocessor communication in modes 2 and 3.


REN Receiver enable
TB8 Transmit bit 8. This is the 9th bit transmitted in modes 2 and 3.
RB8 Receive bit 8. This is the 9th bit received in modes 2 and 3.
TI (transmit interrupt)
When 8051 finishes the transfer of 8-bit character
It raises TI flag to indicate that it is ready to transfer another byte
RI (receive interrupt)
When 8051 receives data serially via RxD, it gets rid of the start and stop bits and places the
byte in SBUF register
It raises the RI flag bit to indicate that a byte has been received and should be picked up
before it is lost
RI is raised halfway through the stop bit

138
INTERRUPT PROGRAMMING:
An interrupt is an external or internal event that interrupts the microcontroller to inform it that a
device needs its service
A single microcontroller can serve several devices by two ways
Interrupts
Whenever any device needs its service, the device notifies the microcontroller by sending it an
interrupt signal
Upon receiving an interrupt signal, the microcontroller interrupts whatever it is doing and
serves the device
The program which is associated with the interrupt is called the interrupt service routine (ISR)
or interrupt handler
Polling
The microcontroller continuously monitors the status of a given device
When the conditions met, it performs the service
After that, it moves on to monitor the next device until every one is serviced
Polling can monitor the status of several devices and serve each of them as certain conditions
are met
For the polling method, it is not possible to assign priority since it checks all devices in a
round-robin fashion
The microcontroller can also ignore (mask) a device request for service
When an interrupt is invoked, the microcontroller runs the interrupt service routine
For every interrupt, there is a fixed location in memory that holds the address of its ISR
The group of memory locations set aside to hold the addresses of ISRs is called interrupt
vector table
For every interrupt, there must be an interrupt service routine (ISR), or interrupt handler
Upon activation of an interrupt, the microcontroller goes through the following steps
1. It finishes the instruction it is executing and saves the address of the next instruction (PC) on the
stack
2. It also saves the current status of all the interrupts internally (i.e: not on the stack)
3. It jumps to a fixed location in memory, called the interrupt vector table, that holds the address of
the ISR
4. The microcontroller gets the address of the ISR from the interrupt vector table and jumps to it .
5. It starts to execute the interrupt service subroutine until it reaches the last instruction of the subroutine
which is RETI (return from interrupt)
6. Upon executing the RETI instruction, the microcontroller returns to the place where it was interrupted
7. First, it gets the program counter (PC) address from the stack by popping the top two bytes of the stack
into the PC
8. Then it starts to execute from that address .
Six interrupts are allocated as follows

139
Upon reset, all interrupts are disabled (masked), meaning that none will be responded to by the
microcontroller if they are activated
The interrupts must be enabled by software in order for the microcontroller to respond
to them
There is a register called IE (interrupt enable) that is responsible for enabling
(unmasking) and disabling (masking) the Interrupts

Interface 4×4 matrix keyboard with microcontroller:

140
1. The above figure shows 4×4 matrix connected to two ports.
2. The rows are connected to an output port (port1) and the columns are connected to an input port
(port2).
3. Controller access both rows and columns through ports.
4. When a key is pressed, a row and column make a contact; otherwise, there is no connection
between rows and columns.
5. If no key has been pressed, reading the input port yield 1s for all columns, since they are all
connected to high (VCC).
6. If all rows are grounded and a key is pressed, one of the columns will have 0, sine the key pressed
provides the path to ground.
7. It is the function of the microcontroller to scan the keyboard continuously to detect and identify the
key pressed.

8. To detect a pressed key, the microcontroller grounds all rows by providing 0 to the output latch,
and then it reads the column.

9. If the data read from columns is D3- D0 = 1111, no key has been pressed. And the process
continues until a key pressed is detected.
10. If D3- D0 = 1101, this means that a key in D1 column has been pressed.
11. After a key pressed is detected, the microcontroller will go through the process of identifying the
key.
12. Starting with top row, the microcontroller grounds all the rows one by one and read the columns
and checks for any zero.
Program
1. In this program, it is assumed that P1 and P2 are initialized as output and input respectively.
2. Program goes through the following major stages.
3. To make sure that preceding key has been released, 0s are the outputs to all rows at once, columns
are read and checked repeatedly until all the columns are high.
4. When all columns are found to be high, the program waits for short amount of time before a key to
be pressed.
5. If any key is pressed, the columns are scanned again and again until one of them has a 0 on it.
6. After the key press detection, it waits 20milli seconds for the bounds and then scans the columns
again.
7. After 20milli seconds delay, the key is still pressed, it goes to detect which row it belongs to.
To detect the row it grounds one row at a time, reading the columns each time.
8. If all columns are high , the pressed key can not belong to that row , Therefore it grounds the
next row and continues until it finds the row the key press belongs to.
9. After finding the row , it sets up the starting address for the look-up table holding the ASCII codes
for that row and go to the next stage to identify the key
10. Now it rotate the column bits , one bit at a time in to the carry flag and check if it is low, When
carry flag is zero, it pulls out the ASCII code for that key from look up table; otherwise it increments
the pointer to point to the next element of the look up table.

141
142
37. Define Baud rate.
The number of bits transmitted per second is called baud rate. The standard baud rates are 75,
110, 150, 300, 600, 1100, 2400, 9600 and 19200.

38.Define interfacing.
Interfacing is the designing of logic circuits (i.e. Hardware) and writing the instructions (i.e.
Software) to enable the microprocessor to communicate with I/O devices.

39. Specify the bit which differentiates between I/O mode and the BSR mode in 8255.

Control Word

D7 D0

If D7=1, I/O mode


=0, BSR mode

40. Specify the two types of serial communication.


Synchronous serial data transmission
Asynchronous serial data transmission

41. What is handshake port?


The port used for exchanging the signals between I/O devices and port or between port and
processor for checking or informing various condition of the device is called handshake port.

UNIT 4
MICROCONTROLLER

PART- A
1. What are the advantages of the register indirect addressing mode in 8051 microcontroller?

Addressing mode R0 & R1 of each register bank can be used as an index or point register.
R0 &R1 points to the contents in the RAM
Determine the operand address.
used to access the program memory

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

There are five ways of addressing operands

Register addressing
Direct addressing
Register Indirect addressing
Immediate addressing
Base register plus Index register indirect addressing.
174
3. What happens in power down mode of 8051 microcontroller?

In power down mode all the on-chip activity are suspended. The on-chip RAM continues to hold the
data. The device draws only 10 micro ampere current.

4. What are the features of 8051?

8051 is a stand-alone high performance microcontroller intended for use in sophisticated real-
time applications, such as instrumentation, industrial control, automobiles and computer
peripherals.
Provides features like interrupts ,bit addressability and an enhanced set of instructions, which
make the chip very powerful and cost effective
Used as a controller for many applications
Interfaced with other peripheral chips, makes it quite versatile.

5. What is the role of SBUF register in serial data transfer?

Holds the data that has to be transmitted through the serial port & also holds the data that is
received.
This register is interconnected to two 8=bit shift register.
when data is written in to the SBUF,it is loaded in the transmit shift register & hence the
process of moving a data byte in to the SBUF starts the transmission process
During reception,the data coming to the 8051 is clocked in to the receive shift register & once
all the 8-bits of data or a frame is received it is transferred to the SBUF.

6. What is the role of SCON register in serial data transfer?

This register controls the operations of the serial port.


This register is used to define the operating modes.
This also receives the 9th bit and contains the transmit and receive interrupt flags as well.
7 6 5 4 3 2 1 0

SM0 SM1 SM2 REN TB8 RB8 T1 R1

7. Draw the format of PSW of 8051.

Bit No 7 6 5 4 3 2 1 0

PSW CY AC F0 RS1 RS0 OV X P

175
Where, CY=Carry flag
AC=Auxiliary carry flag
OV=Overflow flag
P=Odd parity flag
F0=User flag 0
RS1 RS0
0 0 Register bank 0
0 1 Register bank 1
1 0 Register bank 2
1 1 Register bank 3
8. What is the difference between a microprocessor and microcontroller?
S No Microprocessor Microcontroller

1 It has many operatioal It has one or two operatioal


codes(opcodes)for moving data from codes(opcodes)for moving data from
external memory to the CPU.
external memory to the CPU.
2 It has one or two types of bit handling It has many handling instructions
instructions
3 It is concerned with rapid movement It is concerned with rapid movement
of code and data from external of bits within the chip.
addresses to the chip.

4 ALU,PC,SP & registers are available, ALU,PC,SP & registers are available,

5 ROM,RAM,Parallel I/O,Serial ROM,RAM,Parallel I/O,Serial


I/O,Counters and a clock circuit are I/O,Counters and a clock circuit are
not available available and in build .
6 Microprocessor based system requires Microprocessor based system requires
more hardware less hardware

7 Microprocessor based system is more Microprocessor based system is


flexible for design comparatively less flexible for design.

9. What are the advantages of microcontroller over microprocessor?


1. The overall system cost is low, as the peripherals are integrated in a single chip.
2. The size is very small.
3. The system is easy to troubleshoot and maintain.
4. If required additional RAM, ROM and I/O ports may be interfaced.
5. The system is more reliable.

176
10. What is the function of DPTR register?
The data pointer register (DPTR) is the 16 bit address register that can be used to fetch any 8
bit data from the data memory space. When it is not being used for this purpose, it can be used as
two eight bit registers, DPH and DPL.

11.What is the possible branching range when an AJMP/ACALL of 8051 instruction is


executed?
2 K bytes.

12. How does the status of EA pin affect the access to internal and external program memory?
If EA = 0, 8051 can access the external program memory.
= 1, accesses the internal program memory.

13. State the difference between RET and RETI instruction in 8051.
RET Return from subroutine.
This instruction is used to return from a subroutine previously entered by CALL
instructions.
RETI Return from interrupt
This instruction is used at the end of interrupt service routine (ISR).

15. What are the register banks in 8051 microcontroller?


Register Bank 0, Bank 1, Bank 2 and Bank 3.

16. Differentiate RRA and RRCA instructions in 8051 microcontroller.


RRA: Rotate Accumulator Right
Each binary bit of the accumulator is rotated right by one position. The LSB is placed
in the position of MSB.

MSB LSB
RRCA: Rotate Accumulator Right through Carry.
Each binary bit of the accumulator is rotated right by one position through the carry
flag. LSB is placed in the carry flag and the carry flag is placed in MSB.

MSB LSB CY

177
17. What are the alternate function of Port 3 in the 8051 microcontroller?
P3.0 RxD
P3.1 TxD
P3.2 INT0
P3.3 INT1
P3.4 T0
P3.5 T1
P3.6 WR
P3.7 RD

18. What is the function of SM2 bit present in SCON register in 8051?
SM2 enables the multiprocessor communication feature in modes 2 and 3. If SM2=1, RI will
not be activated if the received 9th data bit (RB8) is 0.
In mode 1, if SM2 =1, RI will not be activated if a valid stop bit was not received.
In mode 0, SM2 should be 0.
19. What is the importance of special function registers available in 8051 microcontroller?
The 8051 operations that do not use the internal 128 byte RAM address from 00H to 7FH are
done by a group of special internal registers, SFRs (Special Function Registers), which may be
addressed like internal RAM.

20. What is the job of the TMOD register?


TMOD (timer mode) register is used to set the various timer operation modes. TMOD is
dedicated solely to the two timers (Timer 0 and Timer 1) and can be considered to be two duplicate
4-bit registers, each of which controls the action of the timers.

21. What are the features of 8051 microcontroller?


8 bit CPU with registers A and B
16 bit PC and DPTR
8 bit PSW
64 K Program memory
64 K Data memory
128 bytes of on-chip Data memory
32 I/O pins for Port 0, Port 1, Port 2 and Port 3
Two 16 bit Timers, T0 and T1
Full duplex UART: SBUF
Two external and three internal interrupt sources.

22. List any applications of Microcontroller.


1. Building control (Fire detection)
2. Industrial control (Process Control)
3. Motor speed control (Stepper motor Control)
4. Handheld Instruments (Digital level meter)
5. Peripheral devices (Printer)
6. Stand Alone devices (Color Xerox machine)
7. Automobile applications (Power steering)
8. Home applications (Washing machine)
9. Instrument sub functions (Spectrum Analyser)
178
23. Explain the contents of the accumulator after the execution of the following program
segments:
MOV A,#3CH
MOV R4,#66H
ANL A,R4
A=3C
R4=66
A=24

24. Write a program to load accumulator A, DPH and DPL with 30H.
MOV A,#30
MOV DPH,A
MOV DPL,A

25. 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
UNIT 5
INTERFACING MICROCONTROLLER

PART-A

1. Why do we need relay interface? What is SPDP relay?


Relay interface allows the isolation of two separate section of a system with two
different voltage sources.
SPDP relay is single pole double throw relay.
2. What are the precautions required while interfacing up with stepper motor?
Care should be taken to assure lifting in the direction intended in the design of the
lifting means.
Data lines for up should be connected to the data lines of the interfacing devices which
is connected to the motor.
3. What is Relay? How these are used in motor speed control?
A relay is an electrically controllable switch widely used in industrial controls,
automobiles and appliances. It allows the isolation of two separate sections of a system with
two different voltage sources.

179

You might also like