Model Question 4
Model Question 4
8E4094
B.Tech. VIII Semester (Main/Back) Examination- 2013
Electronics and communication
Unit – I
Question 1
a) How can you differentiate 8051 microcontroller and 8085/8086 microprocessor? State
the various modes for timer in 8051 microcontroller.
The timer clock pulses are given to TLX (only lower 5 bits are used in a mode 0) register. The
TLX register will work as 5 bit up counter i.e. the contents of TLX will be incremented by 1
after every timer clock pulse. The TLX register will divide (at maximum) the timer clock
frequency by 32 based on initial value present in it (the timer registers can be preloaded with any
value as per requirement). The output pulse from TLX is given to THX register, which will
further divide (at maximum) the clock pulse by 256. Therefore THX and TLX (lower 5 bits)
collectively behave as a 13 bit up counter. When the count in this 13 bit counter reaches
maximum value i.e. 8191 (1FFFH), the contents of the counter will roll back to 0000 and it will
set the timer overflow flag (TFX) and also generate the timer interrupt.
In mode 0, 1and 2 both timers may operate independently. But if mode 3 is selected for timer 0,
they can not operate independently.
Timer 0 in mode 3 behaves as two completely separate 8 bit timers, TL0 is an 8 bit interval
timer/event counter controlled by timer 0 control bits (C/ , GATE, TR0, TF0 and ) and
TH0 is only 8 bit interval timer controlled by timer 1 control bits TR1 and TF1 and therefore
controls the timer 1 interrupt. Timer mode 3 is also referred as split timer mode
Refer topic 14.4 “TIMER CIRCUITS AS AN INTERVAL TIMER” for more
details on the modes of the timer.
b) Draw the pin diagram of 8051 microcontroller explain the role of each pin in brief.
Alternate Alternate
function 8X51/52 function
P1.0 1 40 VCC
P1.1 2 39 P0.0 AD0
P1.2 3 38 P0.1 AD1
P1.3 4 37 P0.2 AD2
P1.4 5 36 P0.3 AD3
P1.5 6 35 P0.4 AD4
P1.6 7 34 P0.5 AD5
P1.7 8 33 P0.6 AD6
RST 9 32 P0.7 AD7
RXD P3.0 10 31 EA VPP
TXD P3.1 11 30 ALE PROG
INT0 P3.2 12 29 PSEN
INT1 P3.3 13 28 P2.7 A15
T0 P3.4 14 27 P2.6 A14
T1 P3.5 15 26 P2.5 A13
WR P3.6 16 25 P2.4 A12
RD P3.7 17 24 P2.3 A11
XTAL 2 18 23 P2.2 A10
XTAL 1 19 22 P2.1 A9
GND 20 21 P2.2 A8
RST: Reset
Reset (Pin 9) is an active high input. When high pulse is applied to this pin, the microcontroller
will reset and terminates all activities and contents of all registers will be lost and default values
will be automatically loaded in to SFRs
Port 0
Port 0 (P0) is an 8 bit open drain bidirectional I/O port, it occupies 8 pins (Pin 32-39). Since all
pins are open drain, to use P0 as an input or output, the external pull-up resistor of 10KΩ (value
greater than 1.42KΩ) must be connected with each pin
Port 1
Port 1 (P1) is an 8 bit bidirectional I/O port, (Pin 1-8) with internal pull-up resistors. When 1 is
written to port 1 latch, it is pulled high by internal pull-ups and can be used as an input.P1
receives low order address bytes during on-chip flash memory programming and program
verification process.
Port 2
Like P1, port 2 (P2) is also an 8 bit bidirectional I/O port, (Pin 21-28) with internal pull-up
resistors. Port 2 also act as a higher order address bus (A8-A15) while accessing external program
memory as well as access to external data memory that uses 16 bit address ( MOVX A,@DPTR
or MOVX @DPTR,A)
Port 3
As P1 and P2, Port 3 (P3) can act as 8 bit bidirectional I/O port, (Pin 10-17) with internal pull-up
resistors. Although it can be used as I/O port, it is more commonly used for alternate functions.
P3 provides special signals as external interrupt inputs, transmit (TXD) and receive (RXD) for
serial communication, timers external inputs (T0 and T1) and read, write signals.
Refer topic “11.2 THE 8051 PIN DESCRIPTION” for more details on 8051 pin
description.
OR
Question 1
a) Describe the architecture of 8051 microcontroller with help of a neat diagram.
The architectural block diagram of the 8051 is shown in the following figure; it shows
organization of all hardware components and data path connections between them. It includes 8
bit ALU along with Boolean processing capabilities, program and data memory, four 8 bit I/O
ports, two timers/counters, UART, timing and control circuits and oscillator circuit.
PORT0 PORT2
DRIVERS DRIVERS
PROGRAM
ADDR.
REGISTER
BUFFER
PCON SCON TMOD TCON
ALU
INTERRUPT, SERIAL PORT AND
TIMER BLOCK PROGRAM
COUNTER
PSW
INSTRUCTION
ALE
REGISTOR
TIMING DPTR
AND
CONTROL
RST
PORT3
PORT1 LATCH
DRIVERS
OSC
PORT3
PORT1 DRIVER
DRIVERS
The 8051 has a built in UART, thus, the 8051 chip is capable of handling asynchronous
transmission and reception of serial data. The 8051 has two pins TXD (P3.1) and RXD (P3.0) for
transmission and reception of serial data respectively. The UART hardware is more commonly
referred as serial port.
Serial port of the 8051 is controlled by two registers: SBUF and SCON.
SCON is the control and status register programmed to configure bits contained in one serial
“word”, baud rate and synchronization clock source. It also contains status bits that indicate
whether data is transmitted completely, and any new data is received.
MODES OF OPERATION
UART can be configured to operate in one of the four operating modes selected by SM0 and
SM1 bits in the SCON register as discussed in previous section.
Mode 0 has a fixed baud rate which is 1/12 of the oscillator frequency.
UART is designed for mainly for this mode and frame format of this mode is compatible with
COM port of PCs. This mode transmits 10 bits through TXD pin and receives through RXD pin
as follows: a START bit (always 0), 8 data bits (LSB first) and a STOP bit (always 1).
Programmer can set its transmission/reception rate using Timer 1.
Transmission: Data transmission begins by writing data to the SBUF register. The START and
STOP bits are added by hardware to form a 10 bit frame, then, 10 bit parallel to serial conversion
is performed and one bit (LSB first) at a time is transmitted through TXD pin, once complete
frame is transmitted, TI flag is set automatically by serial port hardware to indicate end of the
data transmission. We need to monitor TI flag to conform that SBUF register is not overloaded.
Reception: The data reception begins when REN=1 and high to low transition (start bit) is
detected on RXD pin. The received byte is loaded in to SBUF register (the START and STOP
bits are separated by UART hardware once complete frame is received) and stop bit in to RB8
(SCON bit 2) only if following two conditions are met.
If these two conditions are not met, received character is ignored and RI is not set and receiver
circuit waits for next start bit.
Timer1 is used to determine and generate baud rate for mode 1. Timer 1 is usually configured in
mode 2 as an auto reload 8 bit timer.
This mode transmits 11 bits through TXD pin and receives through RXD pin as follows: a
START bit (always 0), 8 data bits (LSB first), a programmable 9th data bit and a STOP bit
(always 1).When transmitting, the 9th data bit is the TB8 bit of the SCON register. When
receiving, the 9th data bit is stored into the RB8 bit of the SCON register.
Mode 2 has a fixed baud rate which is 1/64 of the oscillator frequency when SMOD = 0, and
1/32 of the oscillator frequency when SMOD = 1.
Mode 3
Mode 3 is the same as Mode 2 in all respects except the baud rate. The baud rate in Mode 3 is
variable and generated using timer 1 similar to mode1.
Unit-II
Question 2
a) Define and explain the addressing modes of 8051 microcontroller.
The way by which source or destination (usually source) operands are specified in an instructions
is called addressing mode.
The addressing modes of the 8051 are listed as follows:
1. Immediate addressing
2. Register addressing
3. Direct addressing
4. Indirect addressing
Register indirect addressing
Indexed addressing
The data (constant) is specified as a part of instruction in a program memory. The data is
available immediately as a part of instruction itself, therefore immediate addressing is very fast.
However, since the data is fixed, at run time it is not flexible. The instructions using an
immediate operand have an 8 bit or 16 bit number following the op-code. For example,
In register addressing mode, the operands are specified by register names. Register A and R0 to
R7 may be named as a part of the instruction mnemonic. The advantage of register addressing
mode is that it occupies only one byte memory, and is fast because only on-chip registers are
accessed i.e. instruction takes only one machine cycle for execution. For example,
The data is accessed directly from the memory address specified as one of the operand i.e. one of
the operand is an 8-bit address for internal RAM location. Internal RAM includes 128 byte of
RAM from (00H-7FH) and any special function register. It is more flexible compared to
immediate and register addressing because the value to be accessed from address may be
variable. These are 2 byte instructions (3 bytes when source and destination are both direct
addresses). The address refers to either byte location or a specific bit in a bit addressable byte.
For example,
MOV direct1, direct2 // copy data from address direct2 to address direct1
MOV 50H, 83H // If (83H)=10H→ (50H)=10H
Register indirect addressing mode: The register indirect addressing uses only register R0 or R1
to hold address of the data in internal RAM, these two registers are also referred to as pointer
registers or simply pointers. The symbol @ is used along with R0 or R1 to indicate indirect
addressing. For example,
MOV @Ri, #data // load constant value in to address contained in Ri
MOV @R0, #30H // If R0=40H, → (40H)=30H
Indexed addressing mode: Two registers are used to form the address of the data. The contents
of either DPTR or PC are used as a base address and the A is used as index (or offset) address.
The final address is formed by adding these two registers. It results in a forward reference of 0 to
255 bytes from the base address. They are used to access only program memory (internal as well
as external)
Indexed addressing is used to access data tables (lookup tables) from the program memory and
implementing jump tables. They are also suitable for multidimensional array operations.
The instructions are:
MOVC A, @A+PC // copy data (or code) byte from program memory address formed by
//addition of contents of A and PC into A
MOVC A, @A+DPTR// copy data (or code) byte from program memory address formed by
// addition of contents of A and DPTR into A
Refer topic “4.2 ADDRESSING MODES” for more details and examples of
the addressing modes.
Assume that the array of 10 numbers is stored at internal RAM address 20H onwards
ORG 0000H
CLR C
CLR A
MOV R4, #00H // clear R4H to store upper byte of result
MOV R0, # 20H // load address of label START in the R0
MOV R2, # 10 // N numbers
NEXT: ADD A, @R0 // add array elements with A
JC AHEAD
SJMP SKIP
AHEAD: INC R4 // if C=1, increase upper byte of result
SKIP: INC R0 // next array element
DJNZ R2, NEXT // check all numbers are added
MOV R5, A // store lower byte of result in R5
HERE: SJMP HERE
END
OR
Question 2
a) Explain the following instruction giving the proper format and explain of each.
DAA
Function: Decimal-adjust Accumulator after Addition
It is used after addition of BCD numbers (packed BCD) to convert (adjust) the result in to BCD
form.
ADD or ADDC instruction may have been used to perform the addition. The result is adjusted in
following conditions.
i) Lower nibble of A is greater than 9 after addition
ii) AC=1 after addition
iii) Upper nibble of A is greater than 9 after addition
iv) C=1 after addition
Example:
i) When lower nibble greater than 9 after addition
28 BCD 0010 1000
+ 12 BCD 0001 0010
40 BCD 0011 1010 3A; lower nibble is greater than 9(Invalid BCD)
+ 0000 0110 add 6 to lower nibble (DA A will do it)
0100 0000 40 BCD, desired result
SWAP
Function: Swap nibbles within Accumulator
It swaps the nibbles of Accumulator i.e. it interchange the upper nibble with lower nibble. This
operation is equivalent to 4 bit rotation in either left or right direction. The operation of swap
instruction is illustrated in figure given below,
There are two types of CALL instruction in the 8051: ACALL and LCALL
ACALL: It calls subroutine located at the specified address within 2Kbyte page with respect to
PC. The instruction automatically saves address of the next instruction (address of instruction
itself +2) onto the stack (low byte first) and increments the stack pointer by two. The new value of
PC (destination address) is obtained by combining the five bits of the PC (PC15 through PC11),
opcode bits 7 through 5, and the second byte of the instruction. The program execution is then
transferred to new value of PC.
Format
ACALL addr 11 or Label // SP=SP+1;(SP)=PCL; SP=SP+1; (SP)=PCH; PC10-0= addr 11
Bytes: 2 Cycles: 2
LCALL:
It calls subroutine located at the specified address within entire 64K program memory. The
instruction automatically saves address of the next instruction (address of instruction itself +3)
onto the stack (low byte first) and increments the stack pointer by two. The new value of PC
(destination address) is obtained by loading second and third bytes of the LCALL instruction in
to PC lower byte and PC higher byte respectively. The program execution is then transferred to
new value of PC. Refer topic 7.3 for more details.
Flags affected: None
LCALL addr 16 or Label // SP=SP+1;(SP)=PCL; SP=SP+1; (SP)=PCH; PC= addr 16
Bytes: 3 Cycles: 2
RET:
It is used to return to main program from subroutine which was called by ACALL or LCALL
instruction. It pops (retrieves) two bytes from top of stack (return address) in to PC and SP is
decremented by two. The program execution continues at the return address, usually the
instruction immediately following an ACALL or LCALL.
Flags affected: None
RET // PCH=(SP); SP=SP-1; PCL=(SP);SP=SP-1 Bytes: 1 Cycles: 2
Rotate instruction
Rotate operations are useful for monitoring bits of a data byte without using logical test. The
status of bits may be used in decision making process for certain applications.
The 8051 has four different rotate instructions as described in the following section.
Rotate accumulator left by one bit
RL A // rotate A one bit position to the left, bit D0 to D1, bit D1 to D2, …, bit D6 to D7 and bit
D7 to D0 as illustrated in the following figure.
Figure: RL A instruction
Rotate accumulator right by one bit
RR A // rotate A one bit position to the right, bit D0 to D7, bit D7 to D6, …, bit D2 to D1 and
bit D1 to D0 as illustrated in the following figure.
Figure: RR A instruction
Rotate accumulator left through carry by one bit
RLC A // rotate A one bit position to the left through carry flag, bit D0 to D1, bit D1 to
D2, …, bit D6 to D7, bit D7 to CY and CY to D0 as illustrated in the following
figure.
b) Write a program of 8051 microcontroller and draw the flow chart to count the number
of zeros in a number.
ORG 0000h
MOV 3FH,#0FFH // Number Stored in 3FH
MOV A,3FH
CLR C
MOV R1,#8
AGAIN: RLC A
JC COUNT
INC R0
COUNT: DJNZ R1,AGAIN
HERE: SJMP HERE
END
Unit-III
Question 3
a) Describe the interrupt used in 8051 microcontroller give their priority and addresses.
Five interrupts are available in the 8051.Three of them are internal interrupts i.e. they are
generated because of internal operation of the 8051. They are timer 0 (TF0), timer1 (TF1) and
serial port (TI or RI) interrupts. Remaining two are external interrupts and i.e. they
are invoked by external signals given to pins and . The bar over INT0 and INT1
indicate that they are active low interrupt inputs. The external interrupts and are also
referred as IE0 and IE1 respectively. For each interrupt source there is a fixed location in a
program memory that contains its interrupt service routine (ISR). This part of memory which
stores the ISRs is called the interrupt vector table. It is shown in the following Table.
Table: Interrupt vector table of the 8051
b) Draw the format of timer control register (TCON) and describe it.
TCON register
OR
Question 3
a) 8051 microcontroller is most suitable for real time operation. Justify this statement.
The 8051 is suitable for real time operations because of the following features:
When the instructions uses register addressing modes (R0-R7), the instructions executes faster
because the access time of these registers is less (registers are present within the 8051)
The interrupt provides the following advantages that helps in real time operation:
Priorities can be given to different devices as per their importance and higher priority
device may be programmed to interrupt lower priority devices.
It makes system faster because more important activities are handled immediately.
More number of devices can be served (though, only one device at a time)
Bit addressability
The 8051 has unique and powerful feature of single bit addressability and single bit operations.
It contains a complete Boolean (single bit) processor and its instruction set is optimized for the
single-bit operations. It supports SET, CLEAR, COMPEMENT, AND and OR single bit
operations. This feature makes the 8051 one of the most obvious choice for real-time machine
control applications.
Bit processing operations provide the following advantages that will help in real time operation.
The timer mode control (TMOD) register is used to configure both timers in to various operating
modes and the timer control (TCON) register is used to control start/stop operations and also has
the overflow status flags of both timers in it.
TMOD (Timer mode control) register
TMOD is 8 bit special function register dedicated to both timers. The lower 4 bits configure the
timer 0 and upper 4 bits configure the timer 1. The bit assignment of the TMOD is shown in the
following Table.
Table: TMOD register
Timer 1 Timer 0
GATE C/ M1 M0 GATE C/ M1 M0
MSB LSB
Timers can be configured to work as an interval timer and event counter. They can be operated in
four modes.
In timer mode 1 the timer behaves as a 16 bit timer. Timer can be configured in mode 1 by
setting mode bits M1M0 in TMOD register as "01".Timer registers TLX and THX behaves as
eight bit up counters and collectively they form 16 bit up counter, allowing any value between
0000H to FFFFH to be loaded in these registers. In effect timer clock is divided by 256
(maximum) by TLX register and further it is divided by 256 (maximum) by THX register. The
operation of timer mode 1 is shown in the following figure.
As shown in the figure, the internal oscillator is the clock source for the timer operation (clock
source is selected by C/ = 0). The oscillator signal is divided internally by 12, therefore the rate
of timer clock is one pulse per machine cycle. Once timer is started by making TR0/1 =1, the
timer clock pulses are given to TLX (TL0 for timer 0 and TL1 for timer 1) register. The TLX
register will work as 8 bit up counter i.e. the contents of TLX will be incremented by 1 after
every clock pulse. The TLX register will divide (at maximum) the timer clock frequency by 256
based on initial value present in it (the timer registers can be preloaded with any value as per
requirement). The output pulse from TLX is given to THX register, which will further divide (at
maximum) the clock pulse by 256. Therefore THX and TLX collectively behave as a 16 bit up
counter. When the count in this 16 bit counter reaches maximum value i.e. 65535, the contents of
the counter will roll back to 0000 and it will set timer overflow flag (TFX) and also generate a
timer interrupt.
The major difference between interval timer and event counter is source of the clock pulse, when
timers are used as an event counters, pin T0/T1 (P3.4/P3.5) are basically used to provide external
pulses for timer 0/1, therefore external pulses will increment the timer registers TLX and THX.
The timer can be configured as an event counter by setting C/ = 1 in TMOD register. The other
difference between interval timer and event counter is that counter is normally started with initial
value of “0000” so TLX and THX normally initialized with value 00H. The operation of event
counter is illustrated in the following figure.
As shown in the figure, the pulses on external pin T0 (or T1 for timer 1) are selected as clock
source for the timer operation by setting C/ = 1 in TMOD register. The timer registers are
normally initialized with value 0000 and the count will increment by 1 when pulse on pin T0/1 is
applied, therefore, the circuit will count the number of pulses (events) applied externally to the
timer pins. The count in timer registers at any time will represent the number of pulses applied
(or external events occurred) till that time.
Unit-IV
Question 4
a) Interface external program memory with 8051 microcontroller and explain how the
data is transmitted.
The 8051 has 16 address lines, therefore it has 64Kbytes of program memory address space.
As discussed in the topic 21.4.2, of the microcontroller is normally connected with
of program memory (ROM) to access code bytes. is generated either when program
memory is accessed by ‘MOVC’ instructions or during program byte fetches. It may also be
connected with (chip enable) of memory chip if only one ROM chip is present in a
system. Interfacing of 16 Kbyte ROM is shown in figure 21.10. Since the chip capacity is
16K bytes, address range will be from 0000H to 3FFFH. It will require 14 (214=16K) address
lines.
__ _____
EA PSEN
___
OE
___
CE *
A8-A13 A8-A13
6
ALE
27128
(16K x 8)
EPROM
74LS373
AD7-AD0 A7-A0
Latch A7-A0
D7-D0
8 D7-D0
should be generated using address decoder circuit when there is more than one ROM
chips present in a system.
Note that A14 and A15 are not connected. These pins are not used and left unconnected,
because there is no requirement of address decoder since there is only one ROM chip
connected at address 0000H to 3FFFH. The disadvantage of this is that each memory
location will have four addresses. is connected to ground because only external code
memory is used. 74LS373 is 8 bit latch used to demultiplex lower address and data bus. ALE
signal is used to enable the latch when address is present on the lower address/data (AD7-
AD) bus.
b) Interface 4-digit 7-segment LED to 8051 microcontroller and write the assembly
language program to display 1234 on it.
ORG 0000H
:1234 = 06H,5BH,4FH,66H
OR
Question 4
a) Draw and explain the interfacing of ADC 0804 to 8051 microcontroller.
The interfacing diagram of the ADC 080X with the 8051 is shown in figure 19.2. Power on reset
and clock circuit of the 89C51 is not shown for simplicity. Port 2 of microcontroller is
configured as an input and connected with digital output (D7-D0) pins of ADC. Control signals
are connected with port 1 pins as shown in figure. VIN (-) of ADC is grounded, therefore
effective analog input voltage is voltage applied at Vin (+) pin. Here input voltage is applied
through potentiometer (by varying the value of resistor the input voltage can be varied between 0
to 5 V). In real life, input voltage is applied from transducer and signal conditioning circuit. Self
clocking is (internal oscillator) is used by connecting R and C as shown in figure 19.2, for the
values used, clock frequency is 606 KHz and conversion time is 110us. Note that VREF/2 pin is
open, therefore, analog input range is 0 to 5 V.
Interfacing ADC 080X with 8051
The steps to develop the program of data conversion is understood by following steps,
The conversion is going to start by these steps: make and simultaneously low, the
ADC will remain in a reset state until the and inputs remain low. Conversion will
start when one (or both) of these inputs make a low to high transition.
Monitor the ‘end of conversion’ ( ) pin until it becomes 0, when it is 0, it indicates that
conversion is completed.
To read data from ADC, make and low, this will output data on D7 –D0 pins, read this
data using appropriate instruction (read port to which digital output is connected). When
is made low, will become high automatically. Remember that the port should be
configured as an input.
Refer topic 13.1 The 8051 ports for the detailed discussion on Parallel I/O ports interface.