SIDDARTHA INSTITUTE OF SCIENCE AND TECHNOLOGY :: PUTTUR
Siddharth Nagar, Narayanavanam Road – 517583
UNIT-III
QUESTIONS AND ANSWERS
Subject Code : Microprocessors and Microcontrollers(19EC0421) Course & Branch:
B.Tech – ECE,EEE
Year & Sem: III-B.Tech & II - Sem Regulation:R19
Q1a)Draw the internal Architecture of 8051 microcontroller
and explain the function of each block present in it.
CPU is the main component of any processor it is also called the heart of the processor.
It control and manages all processes that are carried out in microcontroller unit.
It also communicating with peripheral devices like Memory, Input and Output.
CPU contain Arithmetic Logic Unit (ALU) , a Control Unit (CU) and Registers.
Arithmetic and logic unit (ALU) perform arithmetic and logic operation. It
also manipulates data. Individual bit of register can be set, reset, cleared
complimented, tested used in logical computation. Control Unit (CU) is
responsible for timing of the communication process between the CPU and its
peripherals.
Memory
To perform any specific task microcontroller required a group of instructions
which is called program. So to store these program microcontroller having a
memory called program memory or code memory.
In microcontroller ROM (Read only memory) is used as a program memory
to store program or instructions.
EEPROM (Electrically Erasable Programmable Read – only Memory), which
is a type of non – volatile memory. In this type of memory, the data can be
erased and reprogrammed using special programming signals.
To store data, microcontroller having a separate memory called data memory.
Microcontroller used RAM (Random Access Memory ) for temporarily
storing of data and the auxiliary results generated during the runtime. RAM is
volatile memory since cutting off power to the IC will result in loss of
information or data.
In microcontroller 8051 there is code or program memory of 4 KB that is it
has 4 KB ROM and it also have data memory (RAM) of 128 bytes.
Bus
Group of wires is called BUS. which uses as a communication channel or it
acts as means of data transfer. In microcontroller buses consists of 8, 16 or
more wires. Thus, these can carry 8 bits,16 bits simultaneously.
There are two type of buses used in 8051 microcontroller:
Address Bus: 8051 microcontrollers has 16 bit address bus. It is used for transferring the
data from CPU (Central Processing Unit) to Memory.
Data Bus: 8051 microcontroller has 8 bits data bus. It is used for transferring the data
from one peripherals to other peripherals.
Input and Output Ports
The 8051 has four important ports Port 0, Port 1, Port 2 and Port 3. These
ports allow the microcontroller to connect with external devices, machines or
other peripherals. Each port has 8 pins. Thus the four ports jointly comprise
32 pins. All ports are bidirectional. Each port has a latch and driver (or
buffer).
When external memory is employed the port-0 lines will function as multiplexed low
byte address/data lines and port-2 lines will function as high byte address lines.
Timers/Counters
The 8051 has two 16-bit Programmable timers / counters (Timer 0 – Timer
1). Which can be used either as timer to generate a time delay or as counter to
count events happening outside the microcontroller.
Oscillator
The microcontroller is a digital device, therefore it requires clock pulses for
its operation. To synchronize all the part of microcontroller and perform
operation microcontroller has an on-chip oscillator which works as a clock
source for Central Processing Unit of the microcontroller.
Interrupts
Interrupts are the events that temporarily suspend the main
program executed by the microcontroller. Intimate the
microcontroller by sending it an interrupt signal (inform
microcontroller that a device needs its service).
When Microcontroller receiving an interrupt signal, the
microcontroller interrupts whatever it is doing and serves the
device. After that microcontroller resume the execution main
program.
The program which associated with interrupt is called ISR
(Interrupt Service Routine) or Interrupt handler. ISR is a set of
instructions when executed providing the service to
interrupted device. For every Interrupt, there is a fixed
location in memory that hold the address of its ISR. The group
of memory location set aside to hold the address of ISR is
called Interrupt vector table.
There are 5 types of Interrupts in 8051 are:
Timer 0 overflow interrupt- TF0
Timer 1 overflow interrupt- TF1
External hardware interrupt- INT0
External hardware interrupt- INT1
Serial communication interrupt- RI/TI
Flags are useful to programmers as they indicate certain
conditions, such as carry or overflow, that results from
execution of instructions.
Stack:The stack resides in the RAM space of the 8051.
Manipulation of the stack via POP and PUSH instructions.
Registers:
In the CPU, registers are used to store information temporarily. That
information could be a byte of data to be processed, or an address
pointing to the data to be fetched. The large number of 8051 registers
are 8-bit registers. With an 8-bit data byte, any data larger than 8 bits
must be broken into 8-bit chunks before it is used.
D7 D6 D5 D4 D3 D2 D1 D0
The most widely used registers of the 8051 are A[accumulator], B, R0, R1,
R2, R3, R4, R5, R6, R7, DPTR, and PC. All the registers are 8-bits except
'Data Pointer' DPTR and the 'Program Counter' PC. The accumulator, register
A, is used for all arithmetic and logic instructions.
8-Bit Registers of the 8051:
A B R0 R1 R2 R3 R4 R5 R6 R7
8051 16-Bit Registers:
DPTR [Data Pointer]
DPH DPL
PC [Program Counter]
Q2a) Describe the importance of the I/O port in the microcontroller.
I/O port is used to connect the different input or output devices with
microprocessor or microcontroller to interact with outside world.
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.
Q2b) Analyze the functionality of I/O ports present in 8051 microcontroller.
I/O ports of 8051: There are four ports P0, P1, P2 and P3 each use 8 pins,
making them 8-bit ports. All the ports upon RESET are configured as
output, ready to be used as output ports. To use any of these ports as an
input port, it must be programmed. Each port of 8051 has bidirectional
capability. Port 0 is called 'true bidirectional port' as it floats (tristated)
when configured as input. Port-1, 2, 3 are called 'quasi bidirectional port'
Structure
The above figures represents one bit (one line) of Port 0,1,2 & 3.Every port line has a one-bit
latch, in the form of a D Flip Flop
It is used to hold the value on the port, when used as an output port.
The latch will capture a “0” or a “1” from the internal bus, on getting “write to latch” signal.
The port also has buffers that allow us to either read from the latch or read from the port line.
Input operation
When a “1” is written to the latch, the port becomes an input port, by turning the FETs off.
Output operation
To send a “0”: Write a “0” on the latch. This turns ON the FET and the port pin gets grounded,
so the port pin
contains logic “0”.
To send a “1”: Write a “1” on the latch. This turns OFF the FET and the port line “floats”,
containing neither logic 0 nor 1 (just like input).
By connecting VCC using an external pull up resister, we can output a “1” on the port line.
Alternate function
Port 0 can also be used as the multiplexed bus AD7 – AD0, and can carry address or data.
Port 1 does not have alternate functions.
Port 2 can be used as the higher order address bus (A15 – A8).
The “control” signal shown in the Port 0, Port 2 diagrams directs the address line to the “gate”
of the FET.
Port 3 can be used as (P3.0-RXD, P3.1-TXD, P3.2-INT0, P3.3-INT1,P3.4- T0, P3.5 – T1, P3.6
– WR, P3.7 –
RD). The “Alternate Output function” signal directs the alternate function to the “gate” of
the FET.
Q2c) Explain the different types of directives used in microcontroller.
ORG:The origin (ORG) directive is used to indicate the beginning of the
addresses the number that comes after ORG can be either in hex or in decimal
if the number is not followed by H it is decimal and the assembler will
convert it to hex some assembler use “.ORG” instead of “ORG” for the origin
directive.
Ex:- ORG 0000H
EQU (equate):-
This is used to define a constant without occupying a memory location. The
EQU directive does not set aside storage for a data item but associates a
constant value with a data label so that when the label appears in the program
it constant value will be substituted for the label use EQU for the counter
constant and then the constant is used to load the R3 register.
Ex:-
COUNT EQU 25
MOV R3, # COUNT
END
END directive this indicates to the assembler at the end of the source (asm)
file the END directive is the last line of an 8051 program meaning that in the
source code anything after the END directive is ignored by the assembler.
DB (Define byte):-
The DB directive is the most widely used data directive in the assembler it is
used to define the 8-bit data when DB is used to define data, the numbers can
be in decimal binary, hex or ASCII format for decimal “D” after the decimal
number, for binary ‘B’ and hexadecimal ‘H’ required. DB directive is the only
directive that can be used to define ASCII strings larger than the character
therefore it should be used for all ASCII data definitions.
Ex: -
ORG 5000 H
DATA 1: DB 28 (Decimal)
DATA 2: DB 39H (HEX)
DATA 3: 0101001 B (Binary)
Q3a)Explain the importance of memory in microcontroller.
Importance of a memory in a µP or µC:
Microprocessors are used in computer systems and Microcontrollers are
used in appliances. Here programs are generally permanent in
nature and very rarely need to be modified. Moreover, the programs
must be retained even after the device is completely switched off.
Hence to store programs we require permanent (non- volatile)
memory like ROM.
Data on the other hand is continuously changed at runtime. Such
data is not permanent in nature and will certainly be modified in
every usage of the device. Hence Data is stored in writeable
memory like RAM is required.
3b)Describe how the RAM memory is organized in 8051 microcontroller.
8051 has a 128 Bytes of internal RAM. These are 128 locations of 1 Byte each.
The address range is 00H… 7FH.
This RAM is used for storing data.
It is divided into three main parts: Register Banks, Bit addressable area and a
general purpose area.
REGISTER BANKS
The first 32 locations (Bytes) of the Internal RAM from 00H… 1FH, are used by the
programmer as general purpose registers.
these 32 registers are divided into 4 banks, each having 8 Registers R0… R7.
The first 8 locations 00H… 07H are registers R0… R7 of bank 0.
Similarly locations 08H… 0FH are registers R0… R7 of bank 1 and so on.
BIT ADDRESSABLE AREA
The next 16-bytes of RAM, from 20H… 2FH, is available as Bit Addressable Area.
We can perform ordinary byte operations on these locations, as well as bit operations.
As each location has 8-bits, we have a total of è 16 × 8 = 128 Addressable Bits.
These bits can be addressed using their individual address 00H … 7FH.
GENERAL PURPOSE AREA
The general-purpose area ranges from location 30H … 7FH.
This is an 80-byte area which can be used for general data storage.
STACK OF 8051
In 8051, the Stack can only be present in the Internal RAM.
This is because, SP which is an 8-bit register, can only contain an 8-bit address and
External RAM has 16-bit address.
On reset SP gets the value 07H.
Q3c)Discuss different buses used to communicate by the processor to the I/O and memory
Fundamentally Bus is a group of wires which function as a communication
canal or means for the transfer of Data. These buses comprise 8, 16, or more
cables. As a result, a bus can bear 8 bits, 16 bits altogether. There are two
types of buses:
Address Bus: Microcontroller 8051 consists of a 16-bit address bus. It is also
utilized to transmit the address from the Central Processing Unit to Memory.
Data Bus: Microcontroller 8051 comprise of 8 bits data bus. It is employed to
carry data.
Control Bus:It is used to perform the mentioned task
4a) Define counter. List the applications of counter List
A counter is a device that stores (and sometimes displays) the number of
times a particular event or process occurred, with respect to a clock signal.
It is used to count the events happening outside the microcontroller
In electronics, counters can be implemented quite easily using register-
type circuits such as a flip-flop.
Applications of counters:
Frequency counters
Digital clocks
Analog to digital converters
Frequency dividers
Applications of Timer:
A timer uses the frequency of the internal clock, and generates delay.
Timers are used to measure specific time intervals.
4b)Illustrate the operation of timers present in 8051 microcontroller
8051 has 2, 16-bit Up Counters T1 and T0.
If the counter counts internal clock pulses it is known as
timer.
If it counts external clock pulses it is known as counter.
Each counter is divided into 2, 8-bit registers TH1 - TL1 and
TH0 - TL0.
The timer action is controlled mainly by the TCON and the
TMOD registers.
TCON - Timer Control (SFR) [Bit-Addressable As TCON.7 to TCON.0]
TF1 and TF0: (Timer Overflow Flag)
Set (1) when Timer 1 or Timer 0 overflows respectively i.e. its bits roll over from all 1's to all 0's.
Cleared (0) when the processor executes ISR (address 001BH for Timer 1 and 000BH for Timer 0).
TR1 and TR0: (Timer Run Control Bit)
Set (1) - Starts counting on Timer 1 or Timer 0 respectively.
Cleared (0) - Halts Timer 1 or Timer 0 respectively.
IE1 and IE0: (External Interrupt Edge Flag)
Set (1) when external interrupt signal received at INT1 or INT0 respectively.
Cleared (0) when ISR executed (address 0013H for Timer 1 and 0003H for Timer 0).
IT1 and IT0: (External Interrupt Type Cobtrol Bit)
Set (1) - Interrupt at INT1 or INT0 must be -ve edge triggered.
Cleared (0) - Interrupt at INT1 or INT0 must be low-level triggered.
TMOD - Timer Mode Control (SFR) [NOT Bit-Addressable]
C/T: (Counter/Timer)
Set (1) - Acts as Counter (Counts external frequency on T1 and T0 pin inputs).
Cleared (0) - Acts as Timer (Counts internal clock frequency, fosc/12).
Gate: (Gate Enable Control bit)
Set (1) - Timer controlled by hardware i.e. INTX signal.
Cleared (0) – Counting independent of INTX signal.
M1, M0: (Mode Selection bits)
Used to select the operational modes of the respective Timer.
Timer Counter Interrupts
To use the timer, a certain count value is placed in the Count Register.
This value is the Max Count - Desired Count + 1 .
On each count (rising edge of the input clock) the counter increments its value.
When the counter rolls over (i.e. form all 1's to all 0's) it is said to overflow.
Thus the Timer Overflow Flag, TFX (TF1 or TF0) is set.
If timer interrupt is enabled then the Timer Interrupt will occur on overflow.
As shown above, based on C/T bit the timer functions as a Counter or as a
Timer.
If it is a Timer, it will count the internal clock frequency of 8051 divided by
12d (f/12).
If it is a Counter, the input clock signal is applied at the TX (T1 or T0)
input pins for Timer1 or Timer0 respectively.
As shown the Timer is running only if the TRX bit (TR1 or TR0) is set.
Also if the Gate bit is set in the TMOD then the INTX ( INT1 or INT0 )
pin must be “high (1)” for the timer to count.
Q4c.Distinguish between polling method vs Interrupt method
Polling Method: Continuous loop checking input event is called polling
Interrupt method: Processor it can do its function whenever an event occur the processor is
interrupted to provide service to the interrupted device.Polling method is time consuming it is not
advisable for asynchronous event occurring
Q5a)List the features of 8051 microcontroller
The 8051 microcontroller is a very popular 8-bit microcontroller introduced by Intel in
the year 1981 and it has become almost the academic standard now a days.
The salient features of 8051 are:
1 8051 is an 8-bit Microcontroller, it has an 8 bit ALU. This means all arithmetic and
logic operations are of 8 bits.
2 8051 has an 8-bit data bus, so all external Data Transfers will be of 8-bits in one cycle.
3 It has internal ROM of 4KB used for storing programs.
4 It has internal RAM of 128 bytes used for storing data.
5 Since program memory (ROM) and data memory (RAM) are separate, 8051
follows Harvard Model. In contrast, Processors based on Von Neumann Model store
programs and data in a common memory space.
6 There are 4, 8bit, bidirectional I/O ports for interfacing external devices like
keyboards, displays etc. These ports can also be used for their alternate functions like
multiplexed address data buses and control signals.
7 It has a serial port for long distance communication.
8 The serial port can perform synchronous and asynchronous transfers.
9 8051 has two, 16bit Timers, which act as „up‟ counters.
10 They are used to produce hardware delays and for counting external events.
11 There are 5 interrupts, operating at two priority levels.
12 8051 has two power saving modes called “Idle mode” and “Power Down mode”.
13 In addition to internal memory, up to 64 KB of external RAM and External ROM
can be connected, as per user requirement. The figure 64 KB is due to the 16-bit
address bus.
14 8051 is a 40-pin IC and typically operates at 12 MHz frequency.
Q5b)Discuss the applications of microcontrollers in the industry.
Light sensing & controlling devices
Temperature sensing and controlling devices
Fire detection & safety devices
Industrial instrumentation devices
Process control devices
TV/AC Remote
Remote controlled air coolers
Washing machines
Refrigerators
Electricity meter
Hand-held metering systems
Security alarms
Microwave oven
Car airbag control systems
CD/DVD players
Q6a)Describe the functions of registers in the 8051 microcontroller.
R0-R7 is used to store data A as accumulator B is also used as one of the register in
multiplication and division instruction
PC – PROGRAM COUNTER
It is an 16-bit register.
It holds address of the next instruction in program memory (ROM).
PC gets automatically incremented as soon as any instruction is fetched.
That‟s what makes the program move ahead in a sequential manner.
In the case of a branch, a new address is loaded into PC.
DPTR – DATA POINTER
It is an 16-bit register.
It holds address data in data memory (RAM).
DPTR is divided into two registers DPH (higher byte) and DPL (lower byte).
It is typically used by the programmer to transfer data from External RAM.
It can also be used as a pointer to a look up table in ROM, using Indexed
addressing mode.
SP – STACK POINTER
It is an 8-bit register.
It contains address of the top of stack.
The Stack is present in the Internal RAM which has 8-bit addresses
from 00H… 7FH.
Hence SP is an 8-bit register.
It is affected during Push and Pop operations.
During a Push, SP gets incremented.
During a Pop, SP gets decremented.
Q6b) Draw the flag register of 8051 microcontroller and describe the functionality of each flag in detail.
PSW – PROGRAM STATUS WORD
It is an 8-bit register.
It is also called the “Flag register”, as it mainly contains the status
flags.
These flags indicate status of the current result.
They are changed by the ALU after every arithmetic or logic
operation.
The flags can also be changed by the programmer.
PSW is a bit addressable register.
Each bit can be individually set or reset by the programmer.
The bits can be referred to by their bit numbers (PSW.4) or by their
name (RS1).
It is an 8-bit register.
It is also called the “Flag register”, as it mainly contains the status
flags.
These flags indicate status of the current result.
They are changed by the ALU after every arithmetic or logic
operation.
The flags can also be changed by the programmer.
PSW is a bit addressable register.
Each bit can be individually set or reset by the programmer.
The bits can be referred to by their bit numbers (PSW.4) or by their
name (RS1).
CY - CARRY FLAG
It indicates the carry out of the MSB, after any arithmetic operation.
If CY = 1 : There was a carry out of the MSB
If CY = 0 : There was no carry out of the MSB
AC – AUXILIARY CARRY FLAG
It indicates the carry from lower nibble (4-bits) to higher nibble.
If the 8bits are numbered Bit 7 --- Bit 0, this is the carry from Bit 3 to Bit 4.
If AC = 1 : There was an auxiliary carry
If AC = 0 : There was no auxiliary carry
Note: It is particularly useful in an operation called DA A (Decimal Adjust after
Addition).
OVR - OVERFLOW FLAG
It indicates if there was an overflow during a signed operation.
An 8-bit signed number has the range -80H… 00H… +7FH.
Any result, out of this range causes an overflow.
If OVR = 1 : There was an overflow in the result
If OVR = 0 : There was no overflow in the result
Overflow is determined by doing an Ex-Or between the 2nd last carry (C6) and the
last carry (C7)
Note: After an overflow, the Sign (MSB) of the result becomes wrong.
P - PARITY FLAG
It indicates the Parity of the result.
Parity is determined by the number of 1‟s in the result.
If PF = 1 : The result has ODD parity
If PF = 0 : The result has EVEN parity
F0 – USER DEFINED FLAG
This flag is available to the programmer.
It can be used by us to store any user defined information.
For example: In an Air Conditioning unit, programmer can use this flag indicate
whether the
compressor is ON or OFF (1 or 0).
This flag can be changed by simple instructions like SETB and CLR.
SETB PSW.5; This makes F0 bit 1
CLR PSW.5; This makes F0 bit 0
RS1, RS0 – REGISTER BANK SELECT
RS1 and RS0 are used by the programmer to select the active bank.
Q6c)Discuss the TMOD Register
Q7 Draw the pin diagram of 8051 microcontroller and describe the functionality of each pin in detail.
Q8a) Compare serial communication and parallel communication.
Basis for Comparison Serial Communication Parallel Communication
Data transmission speed Slow Comparatively fast
Number of communication link used Single Multiple
Number of transmitted bit/clock cycle only one bit. n number of link will carry n bits.
Cost Low High
Crosstalk Not present Present
System Up-gradation Easy Quite difficult
Mode of transmission Full duplex Half duplex
Suitable for Long distance Short distance
High frequency operation More efficient Less efficient
Q8b)Explain how the 8051 microcontroller transfers the serial data input and
output using UART.
Program to transfer letter “D” serially at 9800baud, continuously:
MOV TMOD,#20H ; timer 1,mode 2(auto reload)
MOV TH1, #-3 ; 9600 baud rate
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
SETB TR1 ; start timer 1
AGAIN: MOV SBUF, #”D” ; letter “D” to transfer
HERE: JNB TI, HERE ; wait for the last bit
CLR TI ;clear TI for next char
SJMP AGAIN ; keep sending
Program to receive bytes of data serially, and put them in P2, set the baud rate at 9600, 8-bit data, and 1
stop bit:
MOV TMOD, #20H ; timer 1,mode 2(auto reload)
MOV TH1, #-3 ; 9600 baud rate
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
SETB TR1 ; start timer 1
HERE: JNB RI, HERE ; wait for char to come in
MOV A, SBUF ; saving incoming byte in A
MOV P2, A ; send to port 1
CLR RI ; get ready to receive next byte
SJMP HERE ; keep getting data
Q8c) Explain SBUF register
Q9a)Distinguish between the microprocessors and microcontrollers.
Q9b)Define microcontroller. List out the interrupts in the 8051microcontroller.
It is single chip microcomputer. It has CPU memory ,timer ,serial communication and Interrupt
controller .
Interrupt:
-Reset
-External two interrupts
-Timer two interrupts
-Serial Communication
Q9c)Describe the vector address of interrupts in 8051
Q10a)Illustrate the on chip data memory with neat diagram
Q10b)Sketch the neat timing diagram of internal to 1K bytes RAM
Q10c)Illustrate the MOV A,B with timing diagram