Model Answer
Model Answer
Model Answer
(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)
____________________________________________________________________________________________
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
Page 3 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________
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.
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:
Page 6 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________
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();
}
}
Page 9 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________
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)
____________________________________________________________________________________________
Page 11 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________
Page 12 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________
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.
NOTE: Program may change. Student can also use the other logic.
#include <reg51.h>
Page 14 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________
Unsignedintx,y;
for(x=0;x<i; x++)
for (y=0;y<1275;y++);
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
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.
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.
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.
Page 18 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________
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.
Page 19 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________
i) Onchip ROM
iv) Interrupts
Onchip RAM 4 KB 8 KB
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.
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)
____________________________________________________________________________________________
Program
SJMP L2 ; Reload timer with count as mode 1,is not auto reload
a) Draw the internal structures of port 0 of 8051. Label the same. Describe the process to
ready port 0 pin status.
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.
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.
Algorithm
Program
Page 25 of 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
____________________________________________________________________________________________
END ; Stop
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