Model Answer

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

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

MODEL ANSWER
SUMMER– 17 EXAMINATION
Subject Title: Microcontroller and Applications Subject Code: 17509
I m p o r t a n t In str uc ti o ns t o ex a m i n ers:
1) The answers should be examined by key words and not as word-to-word as given
in the model answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner
may try to assess the understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more
Importance (Not applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components
indicated in the figure. The figures drawn by candidate and model answer may
vary. The examiner may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the
assumed constant values may vary and there may be some difference in the
candidate’s answers and model answer.
6) In case of some questions credit may be given by judgement on part of examiner
of relevant answer based on candidate’s understanding.
7) For programming language papers, credit may be given to any other program
based on equivalent concept.

Page 1 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

Q1.A) Attempt any THREE: 12M

i) Compare between microprocessor and microcontroller on any four points.


Ans: 1M-each correct point

ii) Draw the interfacing diagram of four 7-segment display with 8051
microcontroller.
Ans: 4M- correct diagram

Page 2 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

iii) What are the different data types used in ‘C’? Give their value range.
Ans:2M- datatypes, 2M-range
Data types in C Language
Data types specify how we enter data into our programs and what type of data we enter.
C language has some predefined set of data types to handle various kinds of data that we
use in our program. These datatypes have different storage capacities.
C language supports 2 different type of data types,
Primary data types
These are fundamental data types in C namely integer(int), floating(float), charater(char)
and void.
Derived data types
Derived data types are like arrays, functions, stuctures and pointers. These are dicussed in
detail later.
Integer type
Integers are used to store whole numbers.
Size and range of Integer type

Type Size(bytes) Range


int or signed int 2 -32,768 to 32767
unsigned int 2 0 to 65535
short int or signed short int 1 -128 to 127
long int or signed long int 4 -2,147,483,648 to 2,147,483,647
unsigned long int 4 0 to 4,294,967,295
Floating type
Floating types are used to store real numbers.
Size and range of Integer type
Type Size(bytes) Range

Page 3 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

Float 4 3.4E-38 to 3.4E+38


Double 8 1.7E-308 to 1.7E+308
long double 10 3.4E-4932 to 1.1E+4932
Character type
Character types are used to store characters value.
Size and range of Integer type
Type Size(bytes) Range
char or signed char 1 -128 to 127
unsigned char 1 0 to 255
Void type
Void type means no value. This is usually used to specify the type of functions.

iv) State the alternate pin functions of port3 of 8051 microcontroller.


Ans: ½ M-each pin function

Pin Name Alternate Function


P3.0 RXD Serial input line(Receive)

P3.1 TXD Serial output line(Transmit)


P3.2 External interrupt 0
INT0
P3.3 External interrupt 1
INT1
P3.4 T0 Timer 0 external input
P3.5 T1 Timer 1 external input
P3.6 External data memory write
WR strobe
P3.7 External data memory read
RD strobe

B) Attempt any ONE: 6M


a) Draw the organization of internal RAM of 8051 and describe in brief.
Ans: 4M-diagram, 2M-explanation
There are 256 bytes of internal RAM on the 8051. 28 = 256, therefore the internal RAM
address bus is 8 bits wide and internal RAM locations go from 00H to FFH.The first 128
locations (00H to 7FH) of internal RAM are used by the programmer for storing data
while the second 128 locations (80H to FFH) are the Special Function Registers
(SFRs).The diagram below is a summary of the 8051 on-chip RAM.

Page 4 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

Register Banks
There are four register banks from 00H to 1FH. On power-up, registers R0 to R7 are
located at 00H to 07H. However, this can be changed so that the register set points to any
of the other three banks (if you change to Bank 2, for example, R0 to R7 is now located
at 10H to 17H).
Bit-addressable Locations
The 8051 contains 210 bit-addressable locations of which 128 are at locations 20H to
2FH while the rest are in the SFRs. Each of the 128 bits from 20H to 2FH have a unique
number (address) attached to them, as shown in the table above. The 8051 instruction set
allows you to set or reset any single bit in this section of RAM.
With the general purpose RAM from 30H to 7FH and the register banks from 00H to
1FH, you may only read or write a full byte (8 bits) at these locations.
However, with bit-addressable RAM (20H to 2FH) you can read or write any single bit in
this region by using the unique address for that bit. We will later see that this is a very
powerful feature.
Special Function Registers (SFRs)
Locations 80H to FFH contain the special function registers. As you can see from the
diagram above, not all locations are used by the 8051 (eleven locations are blank). These
extra locations are used by other family members (8052, etc.) for the extra features these
microcontrollers possess.

Page 5 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

Also note that not all SFRs are bit-addressable. Those that are having a unique address
for each bit.

b) Explain any four assembler directives with suitable examples.


Ans: 4M-each correct directive ,1/2 M -each example
i) ORG:- ORG stands for Origin

Syntax: ORG Address

The ORG directive is used to indicate the beginning of the address. 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 assemblers use “. ORG”
(notice the dot) instead of “ORG” for the origin directive.
ii) DB:- (Data Byte)
Syntax: Label: DB Byte

Where byte is an 8-bit number represented in either binary, Hex, decimal or ASCII form.
There should be at least one space between label & DB. The colon (:) must present after
label. This directive can be used at the beginning of program. The label will be used in
program instead of actual byte. There should be at least one space between DB & a byte.
Following are some DB examples:

iii) EQU: Equate


It is used to define constant without occupying a memory location.
Syntax:
Name EQU Constant
By means of this directive, a numeric value is replaced by a symbol.
For e.g. MAXIMUM EQU 99 After this directive every appearance of the label
“MAXIMUM” in the program, the assembler will interpret as number 99
(MAXIMUM=99). iv) END:
This directive must be at the end of every program.meaning that in the source code
anything after the END directive is ignored by the assembler.
This indicates to the assembler the end of the source file(asm).
Once it encounters this directive, the assembler will stop interpreting program into
machine code.
e.g. END ; End of the program.

Page 6 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

Q2. Attempt any TWO: 16M


a) Describe the addressing modes of 8051 microcontroller with 2 examples of each.
Ans: 8M- correct explanation
There are a number of addressing modes available to the 8051 instruction set, as follows:
1. Immediate Addressing mode
2. Register Addressing mode
3. Direct Addressing mode
4 Register Indirect addressing mode
5. Relative Addressing mode
6. Absolute addressing mode
7. Long Addressing mode
8. Indexed Addressing mode
1) Immediate Addressing mode:
Immediate addressing simply means that the operand (which immediately follows the
Instruction op. code) is the data value to be used.
For example the instruction:
MOV A, #25H ; Load 25H into A
Moves the value 25H into the accumulator. The # symbol tells the assembler that the
immediate addressing mode is to be used.
2 ) Register Addressing Mode:
One of the eight general-registers, R0 to R7, can be specified as the instruction Operand.
The assembly language documentation refers to a register generically as Rn.
An example instruction using register addressing is :
ADD A, R5 ; Add the contents of register R5 to contents of A (accumulator)
Here the contents of R5 are added to the accumulator. One advantage of register
addressing is that the instructions tend to be short, single byte instructions.
3) Direct Addressing Mode:
Direct addressing means that the data value is obtained directly from the memory
location specified in the operand.
For example consider the instruction:
MOV R0, 40H; Save contents of RAM location 40H in R0.
The instruction reads the data from Internal RAM address 40H and stores this in theR0.
Direct addressing can be used to access Internal RAM, including the SFR registers.
4) Register Indirect Addressing Mode:
Indirect addressing provides a powerful addressing capability, which needs to be
appreciated.
An example instruction, which uses indirect addressing, is as follows:
MOV A, @R0; move contents of RAM location whose address is held by R0 into A
Note the @ symbol indicated that the indirect addressing mode is used. If the data is
inside the CPU, only registers R0 & R1 are used for this purpose.
5) Relative Addressing Mode:
This is a special addressing mode used with certain jump instructions. The relative
address, often referred to as an offset, is an 8-bit signed number, which is automatically
added to the PC to make the address of the next instruction. The 8-bitsigned offset value
gives an address range of + 127 to –128 locations.
Consider the following example:

Page 7 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

SJMP LABEL_X
An advantage of relative addressing is that the program code is easy to relocate in
memory in that the addressing is relative to the position in memory.
6) Absolute addressing Mode:
Absolute addressing within the 8051 is used only by the AJMP (Absolute Jump) and
ACALL (Absolute Call) instructions.
7) Long Addressing Mode: The long addressing mode within the 8051 is used with the
instructions LJMP and LCALL. The address specifies a full 16 bit destination address so
that a jump or a call can be made to a location within a 64KByte code memory space
(216 = 64K).
An example instruction is:
LJMP 5000h; full 16 bit address is specified in operand
8) Indexed Addressing Mode:
With indexed addressing a separate register, either the program counter, PC, or the data
pointer DTPR, is used as a base address and the accumulator is used as an offset address.
The effective address is formed by adding the value from the base address to the value
from the offset address. Indexed addressing in the 8051 is used with the JMP or MOVC
instructions. Look up tables are easy to implement with the help of index addressing.
Consider the example instruction:
MOVC A, @A+DPTR
MOVC is a move instruction, which moves data from the external code memory space.
The address operand in this example is formed by adding the content of the DPTR
register to the accumulator value. Here the DPTR value is referred to as the base address
and the accumulator value us referred to as the index address.

b) Draw neat diagram to interface 8 bit DAC 0808 with 8051.Write ‘C’ language
program to generate staircase waveform.
Ans: 4M- diagram,4M –correct program

Page 8 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

DAC interfacing:
#include<reg51.h>
void Delay(); // delay for frequency
{
int c;
for(c=0;c<1000;c++);
}

void main()
{
P1=0x00; // P1 as output port
while(1)
{
P1=0x00; // step by step increment
Delay();
P1=0x20; // values sent to P2
Delay();
P1=0x40;
Delay();
P1=0x80;
Delay();
}
}

c) Assuming temperature control system using LM35 as temperature sensor and


ADC 0809.Draw flowchart of this system to maintain temperature within 25°C
to 30°C.
Ans: 8M- correct flowchart

Page 9 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

3. Attempt any FOUR:

a) Draw the format of PSW SFR and describe the function of each bit.

Page 10 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

Ans:(2M format,2 M functions)

Page 11 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

b) Draw the block diagram of internal architecture of 8051 microcontroller.

Ans: (4 M correct answer)

c) Write the instructions for following operations using ‘C’ operators.

i) Bitwise shift data left 4 times

ii) Bitwise shift data right 3 times

Ans:( (2 M each correct answer)


P0= 0x56 >>4; shift 3 times to right
P0= 0x56 <<4 ; shift 4 times to left

Page 12 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

d) Compare RISC and CISC machines.

Ans: (1M each correct point)

Page 13 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

e) Draw the interfacing diagram to connect 8 LEDs to port 2 of 8051 microcontroller. Also write ‘C’
language program to turn ON and OFF LEDs with some delay.

Ans: (2M-diagram, 2M- for correct program)

(Note: LEDs should be connected to all the 8 lines of Port 2)

NOTE: Program may change. Student can also use the other logic.

Please check the logic and understanding of students.

#include <reg51.h>

void delay (unsigned int);

void main (void)

while(1) //repeat loop

Page 14 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

P2=0xff; //LEDs will turn ON

delay (400); //add delay

P2=0x00; //LEDs will turn OFF

delay (400); //add delay

void delay (unsigned inti)

Unsignedintx,y;

for(x=0;x<i; x++)

for (y=0;y<1275;y++);

4. A) Attempt any THREE:

a) Draw the interfacing of stepper motor with 8051 microcontroller. Also draw the flow chart to rotate
the motor through 360 degree in the clockwise

Ans : (2M correct diagram,2M flowchart)

Page 15 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

OR

Page 16 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

b) Write ‘C’ language program for 8051 microcontroller to toggle port 1.0 with some delay.

Ans :(Proper relevant program – 4 M)

Program:
# include <reg51.h>
sbit sw=P1^0;
void delay(int) // delay function
void main (void)
{
while (1) // infinite while loop
{
{
sw=1; //port pin is on
delay (100); //delay
sw= 0 ; //port pin is off
delay (100); //delay

}
}
void delay(int k)
{
int i,j;
for(i=0;i<k;i++);
for(j=0;j<100;j++);
}
}
c) Compare between Von-Neumann and Harvard architecture with neat diagram.

Ans (1 M each correct point)

Page 17 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

d) List the interrupts of 8051 microcontroller with their vector address and priority upon rest. Explain
SFR used to enable interrupts.

Ans: (2M List,2M SFR explaination)

Page 18 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

B) Attempt any ONE:

a) Write an assembly language program for 8051 microcontroller to find the average of ten 8 bit
numbers stored in internal RAM location 20H onwards. Store the result in 31H.

Ans : (6M correct program)

b) Compare 8051 and 8052 microcontroller on the following points:

Page 19 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

i) Onchip ROM

ii) Onchip RAM

iii) Number of timers

iv) Interrupts

Parameter 8051 8052

Onchip RAM 4 KB 8 KB

On chip ROM 128 Bytes 256 Bytes

No, of timers Two timers Three timers

Interrupts Five interrupts Six interrupts

5. Attempt any TWO: 16

a) Draw the interfacing diagram to interface 8 switches to port 0 and 8 LEDs to port 1.
Write „C‟ language program to read switch status and display the same on the LEDs.
Ans:- ( Interfacing diagram- 4 mks, program – 4 mks)

Page 20 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

b) Write and assembly language program to transfer array of ten numbers stored in memory
location 50 H to memory location 60 H.

Ans:- ( Algorithm – 4 mks, program- 4 mks)

Page 21 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

Program

c) Write an assembly language program for 8051 to generate square ware of 1 KHZ on port
pin P1.1. User timer 1 and assume crystal frequency to be 12 MHZ. Clearly show the necessary
calculation with comments.

Page 22 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

Ans:- ( Calculations – 2 mks, program- 6 mks)

Calculations:-Crystal frequency= 12 MHz

i/p clock= 12*106/12= 1 MHz


Tin= 1 µsec
For 1 KHz square wave
Fout=1 KHz
Tout= 1/1*103 =1 msec
Consider half of it=Tout=500 µsec
N=Tout/Tin=500/1=500 µsec
65536-500=65036=FE0CH

Program

MOV TMOD,01H ; Set timer 0 in mode 1,ie 16 bit timer

L2: MOV TL0,#0C H ; load TL register with LSB of count

MOV TH0,#0FFH „ Load TH register with MSB of count

SETB TR0 ;Start timer 0

L1: JNB TF0,l1 ; Poll till timer roll over

CLR TR0 ; Stop timer 0

CPL P1.1 ; Complement port 1.1 to get high or low

CLR TF0 ; Clear timer flag 0

SJMP L2 ; Reload timer with count as mode 1,is not auto reload

6. Attempt any FOUR: 16

a) Draw the internal structures of port 0 of 8051. Label the same. Describe the process to
ready port 0 pin status.

Ans:- ( Diagram with proper label- 2 M ,Procedure- 2 M)

Page 23 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

b) Write „c‟ language program for 8051 to transmit message “MSBTE” serially a 9600
baud, 8 bit data, 1 stop bit, assuming crystal frequency to be 11,0592 MHZ.

Ans:- ( Proper program- 4 mks)

#Include < REG51.H>


Void main(void)
{
Unsigned chartext[]= “ MSBTE”;
Unsigned chari:
TMOD=0x20;
TH1=0Xfd;
SCON=0x50;
TR1=1;

Page 24 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

While (1)
{
For (i=0: i<5;i++)
{
SBUF=text[I];
While)T1==0);
T1=0;
}
}
}

c) With neat algorithm, write an assembly language program to add two BCD
numbers stored at internal RAM location 30 H and 31 H. Store the result in internal RAM
location 40 H.

Ans:- ( Algorithm- 2 M, program-2 M)

Algorithm

Initialize the first memory pointer

Initialize the second memory pointer

Move the first data into accumulator

Add the first and second data

Adjust result to BCD

Store the result in memory location

Program

MOV R0,#30H ; Initialize the first memory pointer

MOV R1, #31H ; Initialize the second memory pointer

MOV A,@R0 ;Move the contents of 30H into accumulator

ADD A,R1 :Add both the numbers

DAA ; Adjust result in BCD

MOV 40H,A ; Store the result in 40H

Page 25 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

END ; Stop

d) Draw and describe the format of IP SFR of 8051.

.Ans:- Diagram- 2 mks, description- 2 mks)

e) Draw interfacing diagram to interface relay at P1.0 and opto-isolator at P1.7 of 8051
microcontroller.
Ans:- ( Proper interfacing diagram- 4 mks)

Page 26 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________

Page 27 of 27

You might also like