You are on page 1of 13

B.

TECH
Theory Examination (Semester-VI) 2015-16
MICROCONTROLLER & ITS APPLICATIONS
(NEC 022)
Solution Paper
Section A
1.
A.

B.

C.

D.
E.
F.
G.
H.
I.
J.

Microprocessor is a single chip CPU, microcontroller contains, a CPU and much of the remaining
circuitry of a complete microcomputer system in a single chip.
Microcontroller includes RAM, ROM, serial and parallel interface, timer, interrupt schedule
circuitry (in addition to CPU) in a single chip.
Microprocessors are most commonly used as the CPU in microcomputer systems. Microcontrollers
are used in small, minimum component designs performing control-oriented activities.
Microprocessor instruction sets are processing intensive, implying powerful addressing modes with
instructions catering to large volumes of data. Their instructions operate on nibbles, bytes, etc.
Microcontrollers have instruction sets catering to the control of inputs and outputs. Their instructions
operate also on a single bit.
When a microcontroller has an instruction set that supports many addressing modes for the arithmetic
and logical instructions, data transfer and memory accesses instructions, the microcontroller is said to
be of CISC architecture.
The typical CISC microcontroller has well over 80 instructions, many of them very powerful and very
specialized for specific control tasks.
The advantages of the CISC architecture are that many of the instructions are macro like, allowing the
programmer to use one instruction in place of many simpler instructions.
An example of CISC architecture microcontroller is Intel 8096 family.
8 bit registers of the 8051 are:
Acc,B,R0,R1,R2,R3,R4,R5,R6,R7,PSW,P0,P1,TCON,TMOD,SCON,SBUF,PCON,TH0,TL0,TH1,T
L1,IE,IP
16 bit registers of the 8051 are:
DPTR,PC
Immediate Addressing mode.
Port 0
Moves content of the address pointed by A+DPTR to A.
Timer frequency = 12MHz/12 = 1MHz
Time Period= 1/1MHz= 1us.
Memory =16KB
Port P2
PSEN is connected to CS and OE pins of external program memory. CS pin is used for chip selection
and OE pin is used to enable output buffer for read operation.
Section B

2. A.
Next:

MOV A, #0FFH //Program Port 1 as Input Port


MOV P1, A
MOV A, P1
//Get data x from Port 1

MOV B, A
MUL AB
MOV P2, A
MOV P2, B
SJMP Next
END

//Copy the data x from Register A into Register B


// Multiply the contents of Register B and Register A to get X 2
// Sent the lower 8-bit value of X2 to Port 2
// Sent the higher 8-bit value of X2 to Port 2
//Go to the memory location Next for next data

2. B. The 8051 has a flag register to indicate arithmetic conditions such as the carry bit. The flag
register in the 8051 is called the program status word (PSW) register.
PSW (program status word) register
The PSW register is 8 bits wide, only 6 bits of it are used by the 8051. The two unused bits are userdefinable flags. Four of the flags are called conditional flags, meaning that they indicate some conditions
that result after an instruction is executed. These four are CY (carry), AC (auxiliary carry), P (parity), and
OV (overflow).
As seen from Figure, the bits PSW.3 and PSW.4 are designated as RSO and RSI, respectively, and are
used to change the bank registers. The PSW.5 and PSW.l bits are general-purpose status flag bits and can
be used by the programmer for any purpose.

The following is a brief explanation of four of the flag bits of the PSW register.
CY, the carry flag
This flag is set whenever there is a carry out from the D7 bit. This flag bit is affected after an 8-bit
addition or subtraction. It can also be set to 1 or 0 directly by an instruction such as SETB C and CLR
C where SETB C stands for set bit carry and CLR C for clear carry.
AC, the auxiliary carry flag
If there is a carry from D3 to D4 during an ADD or SUB operation, this bit is set; otherwise, it is cleared.
This flag is used by instructions that perform BCD (binary coded decimal) arithmetic.
P, the parity flag
The parity flag reflects the number of 1 s in the A (accumulator) register only. If the A register contains an
odd number of Is, then P = 1. Therefore, P = 0 if A has an even number of Is.
OV, the overflow flag

This flag is set whenever the result of a signed number operation is too large, causing the high-order bit to
overflow into the sign bit. In general, the carry flag is used to detect errors in unsigned arithmetic
operations. The overflow flag is only used to detect errors in signed arithmetic operations.
2.C.

(A).
(B).
(C).
(D).
(E).

28H
28H
21H
25H
22H

2. D.

Serial Communication Procedure in 8051 through interrupts:


1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2 (8-bit
auto-reload) to set baud rate.
2. The TH1 is loaded with one of the values to set baud rate for serial data transfer.
3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8-bit data
is framed with start and stop bits.
4. Set IE.4 bit of IE register (i.e. load 90H in IE register) to enable serial interrupt.
5. TR1 is set to 1 to start timer 1
6. TI is cleared by CLR TI instruction
7. The character byte to be transferred serially is written into SBUF register(or the data starts
received serially into SBUF).
8. When RI/TI is raised, the microcontroller get interrupted (i.e. the data is completely
transmitted/received ) and jumps to memory address location 0023H to execute the ISR(the last
instruction of ISR is RETI).
9. Go to step 7 for next data for serially transmit/receive.

2.E.

Write an 8051 C program to toggle all the bits of P1 continuously:


//Toggle P1 forever
#include <reg51.h>
void main(void)
{
for (;;)
{
p1=0x55;
p1=0xAA;
}
}

2.F. ADC0808/0809 chip with 8 analog channels:


The ADC0808/0809 chip allows us to monitor up to 8 different analog inputs using only a single chip.
Notice that the ADC0808/0809 has an 8-bit data output. The 8 analog input channels are multiplexed and
selected using three address pins, A, B, and C.
In the ADC0808/0809, Vret<+) and Vref{-) set the reference voltage. If Vref(-) = Gnd and Vref(+) = 5 V, the
step size is 5 V/256 = 19.53 mV. Therefore, to get a 10 mV step size we need to set V ref{+) = 2.56 V and
Vref{-) = Gnd. Use A, B, and C addresses to select INO IN7, and activate ALE to latch in the address.
SC is for start conversion. SC is the same as the WR pin in other ADC chips. EOC is for end-ofconversion, and OE is for output enable (READ). The EOC and OE are the same as the INTR and RD
pins repectively. Notice that there is no Vref/2 in the ADC0808/0809 chip.

Steps to program the ADC0808/0809


The following are steps to get data from an ADC0808/0809.
1. Select an analog channel by providing bits to A, B, and C addresses .
2. Activate the ALE (address latch enable) pin. It needs an L-to-H pulse to latch
in the address.

3. Activate SC (start conversion) by an L-to-H pulse to initiate conversion.


4. Monitor EOC (end of conversion) to see whether conversion
L output indicates that the data is converted and is ready to
we do not use EOC, we can read the converted digital data
delay. The delay size depends on the speed of the external
to the CLK pin. Notice that the EOC is the same as the INTR
chips.

is finished. H-tobe picked up. If


after a brief time
clock we connect
pin in other ADC

5. Activate OE (output enable) to read data out of the ADC chip. An L-to-H pulse
to the OE pin will bring digital data out of the chip. Also notice that the OE is
the same as the RD pin in other ADC chips.

2.G.

Interfacing LM25 Temperature Sensor With 8051 Microcontroller:

This Digital Thermometer Design can be integrated by using the 8051 microcontroller and analog to
digital converter IC ADC 804 and interfaced with any microcontroller AT8051, AT8052, AT89C51,
AT89C52, AT89S51, AT89s52 and the output can be displayed on any output device may be computer
monitor or any LCD display. A circuit amplification is done between the LM35 and the microcontroller.

The ADC0804 is an analog to digital converter which is used to convert analog signals to digital so that
any microcontroller can sense the signal and works accordingly. Resolution of this IC is 8 bits and works
with +5V. If input voltage 5V then converted digital output is FF.
Pin description of ADC0804 :
CS : Chip Select:
It is an active low input used to activate the ADC0804 IC. To activate ADC0804, this pin must be low.
RD : Read:It is an active low input used to get the converted data out of the ADC chip. The ADC
converts the analog input to its binary equivalent and holds in an internal register. When a CS = 0 and
high-to-low pulse is applied to the RD pin, then 8-bit digital output is available at the D0-D7 data pins.
WR : Write:
This is an active low input used to inform the ADC to start the conversion process. ADC starts converting
analog input to digital, when CS = 0 and a low-to-high pulse is applied to WR pin. The amount it takes to
convert varies depending on the CLK IN and CLK R values. When the data conversion is complete, the
INTR pin is forced low by the ADC804.

Interfacing Circuit ADC 804 Analog To Digital Converter with 8051 Microcontroller
Here ADC 0804 is connected to port1 of 8051. WR and INTR of ADC is connected to P3.4 and P3.5
respectively. Analog input is applied to pin 6 of ADC. Here WR is the start of conversion and INTR is the
end of conversion.

2.H.

LCD INTERFACING:

Sending commands and data to LCDs with a time delay


To send any of the commands to the LCD, make pin RS = 0. For data, make RS = 1. Then send a high-tolow pulse to the E pin to enable the internal latch of the LCD.

LCD Timing for Read ( L-to-H for E line)

LCD Timing for Write (H-to-L for E line)


To read the command register we make R/W = 1 and RS = 0, and a L-to-H pulse for the E pin will
provide us the command register. After reading the command register, if bit D7 (the busy flag) is high, the
LCD is busy and no information (command or data) should be issued to it. Only when D7 = 0 can we
send data or commands to the LCD. Notice in this method that no time delays are used since we are
checking the busy flag before issuing commands or data to the LCD. Note that the E line is negative-edge
triggered for the write while it is positive-edge triggered for the read.

Section C
3.A.

Block diagram of 8051 architecture:

3.B.
Programming model of 8051:
All registers are accessed through Special Function Registers (SFRs) except for the PC. SFRs are
accessed in the low addresses of data space. All peripherals like a timer or UART are also accessed via
SFRs. In the new derivatives, the original SFRs are left at their original addresses for software
compatibility. The memory maps for all 8051 devices are really close to the original 8051. For reference,
here is a memory map for the SFRs of the original 8051.

3.C.

Specific features of 8051:


1) 8051 have 128 bytes of RAM
2) it consist of 16 bit address bus
3) it also consist of 3 internal and two external interrupts
4) less power usage in 8051 with respect to other micro-controller
5) it consist of 16-bit program counter and data pointer
6) 8051 can process 1 million one-cycle instructions per second
7) ROM on 8051 is 4 Kbytes in size
8) it also consist of Two 16 bit Timer/ Counter
Bit addressable registers:
B,Acc,PSW,IP,P3,IE,P2,SCON,P1,TCON,P0

4.A.

Internal RAM organization:

4.B.

Stack and Stack Pointer in the 8051:

The stack is a section of RAM used by the CPU to store information temporarily. This information could
be data or an address. The register used to access the stack is called the SP (stack pointer) register. The
stack pointer in the 8051 is only 8 bits wide, which means that it can take values of 00 to FFH. When the
8051 is powered up, the SP register contains value 07. This means that RAM location 08 is the first
location used for the stack by the 8051. The storing of a CPU register in the stack is called a PUSH, and
pulling the contents off the stack back into a CPU register is called a POP.
Pushing onto the stack

In the 8051 the stack pointer (SP) points to the last used location of the stack. As we push data onto the
stack, the stack pointer (SP) is incremented by one. we see that as each PUSH is executed, the contents of
the register are saved on the stack and SP is incremented by 1. Notice that for every byte of data saved on
the stack, SP is incremented only once. Notice also that to push the registers onto the stack we must use
their RAM addresses.
Popping from the stack
Popping the contents of the stack back into a given register is the opposite process of pushing. With every
pop, the top byte of the stack is copied to the register specified by the instruction and the stack pointer is
decremented once.

4.C.
SFRs are accessed as if they were normal Internal RAM. The only difference is that Internal
RAM is from address 00h through 7Fh whereas SFR registers exist in the address range of 80h through
FFh.

Name

Function

RAM Address

General purpose Register Used in MUL and DIV instructions

F0H

ACC

The Accumulator is one of the most-used SFRs on the 8051 since it is


involved in so many instructions.

E0H

P0

This is input/output port 0

80H

SP

This is the stack pointer of the microcontroller

81H

DPL/DPH

The SFRs DPL and DPH work together to represent a 16-bit value
called the Data Pointer.

82h/83h

PCON

The Power Control SFR is used to control the 8051's power control
modes.

87h

TCON

The Timer Control SFR is used to configure and modify the way in
which the 8051's two timers operate.

88h

TMOD

The Timer Mode SFR is used to configure the mode of operation of


each of the two timers.

89H

TL0/TH0

These two SFRs, taken together, represent timer 0.

8AH/8CH

TL1/TH1

These two SFRs, taken together, represent timer 1.

8BH/8DH

P1

This is input/output port 1. Each bit of this SFR corresponds to one of


the pins on the microcontroller.

90H

SCON

The Serial Control SFR is used to configure the behavior of the 8051's
on-board serial port.

98H

SBUF

The Serial Buffer SFR is used to send and receive data via the on-board
serial port.

99H

P2

This is input/output port 2. Each bit of this SFR corresponds to one of


the pins on the microcontroller.

A0H

IE

The Interrupt Enable SFR is used to enable and disable specific


interrupts.

A8H

P3

This is input/output port 3. Each bit of this SFR corresponds to one of


the pins on the microcontroller.

B0h

IP

The Interrupt Priority SFR is used to specify the relative priority of


each interrupt.

B8h

PSW

The Program Status Word is used to store a number of important bits


that are set and cleared by 8051 instructions.

D0h

5.A.

8031 based system with 8Kbyte of program ROM and 8Kbyte of data ROM:

5.B.

(i)The 256K8 NV-RAM has 18 address pins (A0 A17) and 8 data lines. A0 A15 go directly
to the memory chip while A16 and A17 are controlled by P1.0 and P1.1, respectively. Chip select
of external RAM is connected to P1.2 of the 8051.

(ii) The 256K bytes of memory are divided into four blocks, and each block is accessed as
follows:
Chip select A17 A16
P1.2 P1.1 P1.0 Block address space
0 0 0 00000H - 0FFFFH
0 0 1 10000H - 1FFFFH
0 1 0 20000H - 2FFFFH
0 1 1 30000H - 3FFFFH
1 x x External RAM disabled
For example, to access the 20000H 2FFFFH address space we need
the following :
CLR P1.2
;enable external RAM
MOV DPTR,#0 ;start of 64K memory block
CLR P1.0
;A16 = 0
SETB P1.1
;A17 = 1 for 20000H block
MOV A,SBUF ;get data from serial port
MOVX @DPTR,A
INC DPTR
5.C.

;next location

8031 connection to external program ROM and 8255:

You might also like