0% found this document useful (0 votes)
28 views281 pages

Important Instructions To Examiners:: Subject Code: Page No: 1/ 26

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views281 pages

Important Instructions To Examiners:: Subject Code: Page No: 1/ 26

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 281

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
WINTER– 14 EXAMINATION
Subject Code: 17509 Model Answer Page No: 1/ 26
Important Instructions to examiners:
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.
_______________________________________________________________________________________________

Q. 1

a) Attempt any THREE of the following.

i)Compare between Microprocessor and Microcontroller (any FOUR points)


Ans: (any FOUR points 1 mark each)

1
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

ii) Draw the pin diagram of 20 × 4 LCD display .what is the function of RS,EN and R/W pins.
Ans) (Diagram 1 mark, function 1 mark each)
Diagram:

4 line X 20 character

Functions:

RS(register select)
If RS=0, the instruction command code register is selected , allowing the user to send the command such as
clear display, cursor at home, etc.
If RS=1, the data register is selected ,allowing the user to send data to be displayed on the LCD.

R/W (read/write)

 R/W input allows the user to write information to the LCD or read information from it.

 R/W=1 when reading ;R/W=0 when writing.

EN(enable)

 The enable pin is used by the LCD to latch information presented to its data pin.

 When data is supplied to its data pin, a high-to-low pulse must be applied to this in order for the LCD to latch in
the data presented at the data pins.
This pulse must be a minimum of 450 ns wide

2
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

iii) What are the different data types used in C? Also give their value range.
Ans) (any FOUR data types 1 mark each)
Data types used in C:
i)Unsigned character
range :– 0-255
2)Signed character
range :- (-128+0+127)
3)Unsigned integer
Range :- 0-65535(0000-FFFFH)
4)signed integer
range ;- (-32768 to 32767)
5) Bit
Range RAM bit addressable only
6)SFR
Range RAM addresses 80 –FFH only
7) Sbit
Range SFR bit addressable only

3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

iv) Draw and explain reset circuit used for 8051 microcontroller
Ans) (Diagram 1 mark ,Explanation 3 mark)
Diagram:

4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

Q. 1 b. Attempt any ONE of the following.

i) Describe the timer modes of 8051 microcontroller


Ans) (11/2 mark each mode)

the timer low-byte (TLx) to form a 13-bit timer.

5
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

.8-bit auto-reload mode


• The timer low-byte (TLx) operates as an 8-bit timer while the timer high-byte (THx) holds a
reload value.
• When the count overflows from FFH, not only is the timer flag set, but the value in THx is
loaded into TLx.

.Timer 1 is stopped in mode 3 but can be started by switching it into one of the other modes. The only
limitation is that the usual Timer I overflow flag, TF1, is not affected by Timer 1
overflows, since it is connected to TH0.
• The 8051 appears to have a third timer.

6
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
• Timer 1 can be turned on and off by switching it out of and into its own mode 3. It can
still be used by the serial port as a baud rate generator.

ii) List the addressing modes of 8051 microcontroller with examples each.

Ans) (Listing of modes 1/2M each, Example 1/2M each)

Addressing modes of 8051:

1) Register addressing mode : E.g. MOV A, R7

2) Direct addressing mode:E.g. MOV A,54 OR MOV A,SFR

3) Register indirect addressing mode: E.g. MOV A, @RP Where RP = R0 or R1

4) Immediate addressing mode: E.g. MOV A, #45H

5) Register specific addressing mode : DA A OR RLA ,RRA

6) Indexed addressing mode : E.g MOVC A,@A+PC or MOVC A,@A+DPTR

Q 2. Attempt any FOUR of the following.

a) Classify the instruction set of microcontroller 8051 Give one example of each.

Ans) (Classification 1 mark each ,Example 1 mark each, Any four type )

Classification of instruction of 8051:


1. Data transfer instructions.
MOV R0, direct.
2. Arithmetic instruction.
ADD A,@R0
3. Logical Instruction
ANL A,# data
4. Branch Instructions
SJMP radd.
5. Bitwise instruction
CPL C

b) Draw the interfacing diagram of ADC 0809 with microcontroller 8051. Write C language program
7
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
to generate 50 Hz sq. wave with crystal freq.=12MHz.

Ans) (Diagram 4 M , Program : 4 M)

Note:( Any other program logic to generate square wave should be given marks )

Diagram:

Note: diagram with direct clock can be given full marks.

Program to generate square wave of 50 Hz :

#include<reg51.h>

Void T0Delay(void);

Void main(void)

While(1)

P1=0x55;

T0Delay();

P1=0xAA;

T0Delay();

8
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
}

Void T0Delay()

TMOD=0x01;

TL0=0x0F0;

TH0=0x0D8;

TR0=1;

While(TF0==0);

TR0=0;

TF0=0;

C. Draw the interfacing diagram of stepper motor with 8051 microcontroller. Draw the flow chart for rotating
stepper motor in clockwise direction. (Program not expected)

Ans) (Diagram 4 M , Flowchart 4 M)

Diagram:

9
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

„OR‟

Flow chart:

10
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

Q 3. Attempt any FOUR of the following.

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

Ans)( Format – 2M, Explanation – 2M)

PSW register –

Format:-

D7 D0

Cy AC F0 RSI RS0 0V X P

Bit7: Carry/Borrow bit: When two 8-bit operands are added, the result may exceed 8-bit and the 9th bit is copied in the
carry bit. During subtraction, if the borrow occurs, the carry bit is set and otherwise, it is cleared.

Bit 6: Auxiliary carry/borrow bit: This bit indicates a carry from lower nibble during 8 bit addition. If AC flag is set, it
means there is a carry from 3rd to 4th bit position.

Bit5: F0: Flag 0 is available to user for general purpose.

Bit 4-3: RS1:RS0: Register Bank selects bits

RS1 RS0 Bank selected

0 0 Register Bank 0

0 1 Register Bank 1

1 0 Register Bank 2

1 1 Register Bank 3

Bit 2: OV: Over flow flag is used to detect errors in signed arithmetic operations. When two signed numbers are added,
it the result exceeds the destination, overflow flag is set, else it is reset.

Bit1: Undefined flag

Bit 0: Parity Flag: P flag is set, if the result contains an odd number of 1 bit, else it is reset, if the result contains an even
number of 1 bit.

11
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

b) Compare between 8051 and 8052 microcontroller.

Ans: (any 4 points each 1 mark)

Feature 8051 8052


ROM(bytes) 4K 8K
RAM(bytes) 128 256
Timers 2 3
I/O pins 32 32
Serial Port 1 1
Interrupts 6 8
Watchdog timer No No

c) Write C program to continuously toggle all bits of port O with same delay.

Ans) (4 M for correct logic)

#include <reg51.h>

Void MSDelay(unsigned int) ;

Void main(void)
{
While(1) //repeat forever

P0=0x55;

MSDelay(250) ;

P0=0xAA;

MSDelay(250);

}
}

Void MSDelay(unsigned int itime)

{
Unsigned int i, j;

For(i=0;i<itime;i++)

12
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
For(j=0;j<itime;j++) ;

d) Compare between
RISC CISC
RISC and CISC
machines. Reduced instruction set computer Complex instruction set computer.
Ans) (any 4 Instruction set is simple and Instruction set is very large. points each 1
mark) limited.

Instruction set is not flexible, Instruction set is flexible, hence the program is
hence the program is long. short

Provides few addressing modes Provides many addressing modes


normally register.

Large memory is required Less memory required

Provides large number of No. of registers are less.


registers

Process architecture & control Processor architecture and control unit is


unit is simple complicated.

Instruction are shorter, hence Instructions are lengthy hence execution speed
execution speed is fast. is slow.

External memory is accessed External memory is accessed frequently


rarely

Each instruction required few bus Each instruction requires many bus cycle.
cycle.

e. g. ARM, ATMEL, AVR, Interx86, Motorola, 68000 series.


MIPS, PIC, POWER PC, etc.

13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

e) Draw the interfacing diagram of four common cathode 7 segment display connected in

multiplexed mode with 8051 microcontroller.

Ans) Diagram :

Q.4 A) Attempt ant THREE of the following.

i) Draw the interfacing diagram of temperature measurement using LM35, ADC0808 with microcontroller 8051.

Ans) ( Correct diagram : 4marks)

Diagram:

14
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

ii) Write instruction to perform following task using C operators:

Ans) (2 marks each)

P0= 0x56 >>4; shift 4 times to right

P0= 0x56 <<4 ; shift 4 times to left

iii) Compare between EPROM and flash memory.

Ans) (any 4 points each 1 mark)

15
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
iv) List the alternate function of port 3.

Ans) ( ½ MARK EACH)

P3.0-RXD (Receive serial data)


P3.1-TXD (Transmit serial data)
P3.2-INTO (External Hardware Interrupt 0)
P3.3-INT1 (External Hardware Interrupt 1)
P3.4-TO ( External pulses given to counter0)
P3.5-T1 (External pulses given to counter1)
P3.6-WR (Active low Write signal enables writing into external data memory)
P3.7-RD (Active low Read signal enables reading external data memory)

Q 4 B) Attempt any ONE of the following

i) Describe the functions of following instructions of 8051 Microcontroller.

1. SWAP A

2. DIV AB

3. RLA

4. XCH A,RO

5. SETB C

6. DA A

Ans) ( 1 mark each for every instruction)

1) SWAP A

SWAP nibbles within the accumulator .This instruction interchanges the low order and high order nibbles of the
accumulator.

EG. A = 05H

SWAP A

A = 50H

2) DIV AB

This instruction divides the content of Register A by the contents of register B. Quotient is stored in register A &
remainder is stored in register B .

( Dividend is in Register A , Divisor is in Register B )

Flags affected : CARRY FLAG ( C ) = 0 & OVER FLOW FLAG ( OV ) =X


16
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
3) RLA

Rotate the contents of Accumulator to LEFT without including Carry flag.

For e.g A=10h

4) XCH A, R0.

(A) (R0)

Exchange the content of A with register R0.

For e.g. A=23h, R0=78h

After execution: A=78h, R0=23h

5) SETBC

Set the carry flag. After the execution CY=1.

6) DA A

Decimal Adjust Accumulator

Only after the addition of two BCD numbers this instruction can be used. Result stored in Accumulator is converted
into equivalent BCD form.

For eg. A=0Ch

After execution A=12 BCD

17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
ii) With suitable diagram describe the memory organization of internal program and data memory.

Ans) (1 mark for ROM explanation, 3 marks for RAM explanation, 2 marks for Internal RAM diagram)

Internal RAM of 8051 is organized in to three different areas.


1) Working registers
2) bit / byte addressable
3) general purpose

1) Working registers
First 32 bytes from address 00H to 1FH are organized as four register banks.
The four register banks are named as Bank 0, Bank 1, Bank 2 & Bank 3.
Each register bank consist of eight register denoted as R0 to R7. each register is of 8-bits.
The register bank is selected by setting or resetting bits. RSO & RS1 of PSW register.
2) bit / byte addressable
The memory location area from 20H – 2FH, total 1B memory locations are used for bit-bytes addresses. One
memory location as 8-bits.Each bit has its own address. Therefore one memory location has 8- addresses. Hence 16-
memory location that is 16×8=128 addresses. Therefore bit addresses of this area varies from OOH-7FH.Thus single
128 bits can be stored in this area.
4) general purpose

18
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
the remaining memory location of RAM from 30H-7F can be used as general purpose data memory where data results
are stored. These area can be used as stack memory.
8051 also consists of 4KB of internal ROM from the address 000h to FFFh where codes can be stored.

Q.5 Attempt any TWO of the following:

a)Write ‟C‟ program to transfer message “INDIA” serially at baud rate 4800bps, 8-bit data, 1 stop bit, assume
crystal frequency 11.0592 MHz.

Ans) ( Baud rate calculation : 2 marks , Correct program with comments : 6 marks )

Baud rate calculation: ( for 4800)

Baud Rate = 2SMOD X (Timer 1 Overflow Rate)


32
= 2SMOD X Oscillator Frequency
32 12 X [256 - ( TH1 ) ]
Upon reset SMOD =0

Baud Rate = (1 / 32 ) X (11.0592 MHZ / 12[256-TH1] )

Baud Rate = 28800 HZ / [256 – TH1]

4800 = 28,800 / [256 – TH1]

TH1= FA H = -6
„C‟ PROGRAM :
#include<reg51.h>
void main(void)
{
unsigned char msg[]= "INDIA";
int i;
TMOD=0X20;// timer 1,mode 2
TH1= - 6 ;// count for 4800 BAUD
SCON=0x50; // 8 bit ,1 stop bit (serial mode 1)
TR1=1;//start timer 1
for (i=0;i<5;i++)
{
SBUF = msg[i];//send message “INDIA” serially
while(TI==0);//wait for transmission to complete
TI=0;//clear TI flag for next transmission
}
}
19
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
NOTE: ( ANY OTHER CORRECT PROGRAM LOGIC SHOULD ALSO BE CONSIDERED AND GIVEN
MARKS)

b) Write assembly language program to transfer array of ten numbers stored in memory location 50H to
memory location 70H.
Ans) (ALGORITHM/FLOWCHART : 4 MARKS
PROGRAM : 4 MARKS

Algorithm:

1. Start
2. Initialize count R2=0AH
3. Initialize source pointer R0 with starting address 50h
4. Initialize destination pointer R1 with starting address 70h
5. Move number pointed by R0 to accumulator
6. Move number from accumulator to destination address pointed by R1
7. Increment source pointer R0
8. Increment destination pointer R1
9. Decrement count & if count not equal to zero repeat step 5 to step 9
10. Else stop

20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

FLOW CHART:

yes

stop

21
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

Assembly language program:


MOV R2,#0AH ; load count 10 in register R2
MOV R0,#50H; load source address in register R0
MOV R1,#70H ; load destination address in register R1
UP: MOV A , @R0 ; take source data pointed by R0 in Accumulator
MOV @R1 , A ; Move data in accumulator to address pointed by R1
INC R0 ; Increment source pointer R0
INC R1 ; Increment destination pointer R1
DJNZ R2 , UP ;Decrement count and jump UP if count = 0
HERE: SJMP HERE ; terminate program

Note: ( ANY OTHER CORRECT PROGRAM LOGIC SHOULD ALSO BE CONSIDERED AND
GIVEN MARKS)

c) Draw interfacing diagram to connect 8 LED‟s on port 2 and 8 switches on port 0. Write C program to read
the status of switches and send to port 2.

Ans) (Interfacing diagram : 4 marks ,„C‟ Program : 4 marks)

Interfacing diagram

22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

„C‟ PROGRAM

#include<reg51.h>
void main(void)
{
unsigned char MYBYTE;
P0=0XFF; //SET PORT0 AS INPUT
While(1)
{
MYBYTE=P0; //GET SWITCH STATUS FROM PORT 0
P2=MYBYTE; //SEND DATA BYTE TO PORT 2
}
}

Q.6. Attempt any FOUR of the following:


a) Draw and describe IP SFR format for 8051 microcontroller.
Ans) (IP FORMAT : 2 MARKS, DESCRIPTION :2 MARKS)

 The IP ( INTERRUPT PRIORITY) SFR FORMAT

MSB LSB

- - - PS PT1 PX1 PT0 PX0

DESCRIPTION:

Bit Name Description

IP.7 - Reserved

IP.6 - Reserved

IP.5 - Reserved

IP.4 PS Serial Port Interrupt priority

IP.3 PT1 Timer 1 Interrupt priority (TF1)

IP.2 PX1 External Interrupt 1 priority (INT1)

IP.1 PT0 Timer 0 Interrupt priority (TF0)

IP.0 PX0 External Interrupt 0 priority (INT0)

23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

Priority bit =1 , assigns higher priority , Priority bit 0 = assigns lower priority

b) Draw interfacing diagram to interface 3 X 3 key matrix to 8051 microcontroller.

Ans) (CORRECT DIAGRAM : 4 MARKS ( ANY PORT CAN BE USED))

c) Describe the following assembler directives with one examples.

i. ORG
ii. DB
iii. EQU
iv. END

Ans) ( Each directive explanation with example : 1 mark each)

1. ORG : ORIGIN
The ORG directive is used to indicate the beginning of the address. The number that comes after ORG is the
address from where program will begin. The number can be either in hex and decimal
e.g. ORG 1000H
It indicates that program shall start from memory address 1000h

2. DB : Define Byte
It is used to define the 8-bit data. It is used to write the value after DB , into the program memory. When DB
is used to define data, the numbers can be in decimal, binary, hex, ASCII formats
e.g. ORG 1000H
MYDATA: DB 20,21
After execution of this , location 1000h=20 & 1001h = 21

3. EQU: EQUATE
It is used to define a constant without occupying a memory location The EQU directive assigns a constant
value to a label. When the label appears in the program, its constant value will be substituted for the label.
e.g. COUNT EQU 10
MOV R2, #COUNT

24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________
When the instruction is executed , register R2 is loaded with value 10.

4. END: This indicates to the assembler the end of the source (asm) file . The END directive is the last line of an
8051 program. Means that in the program anything after the END directive is ignored by the assembler

e.g. MOV A , #20


ADD A , #10
END

d) Describe the dual role of port 0 of microcontroller 8051.


Ans) ( DIAGRAM: 2 MARKS ,EXPLAINATION :2MARKS)

Port 0 can be used as


a) Simple I/O Port and
b) Bidirectional low order address and data bus ( AD0 – AD7) for external memory access.
Port -0 has 8 pins (P0.0-P0.7).
The structure of a Port-0 pin is shown in fig below

Port0 pin circuit


When the control is '0', the port can be used as a normal bidirectional I/O port. When the port is used as an input
port, '1' must be written to the latch and to output 0 on the pin „0‟ must be written to the latch.
When the control is '1', the port can be used as address/data bus(AD0 – AD7 )for external data transfer.

e) Draw interfacing diagram to interface relay with 8051 microcontroller.

Ans) (CORRECT DIAGRAM : 4 MARKS)

25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
__________________________________________________________________________________________________

„OR‟

26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________________________
Important Instructions to examiners:
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.

______________________________________________________________________________________________

Q.1. A) Attempt any THREE of the following: 12M


(a) Write any four features of 8051 micro controller.
Ans: (Any 4 Features: 1 mark each)
8051 microcontroller features:

 Eight-bit CPU with register A (the accumulator) and B.

 Sixteen-bit program counter(PC) and data pointer (DPTR).

 Eight-bit program status word (PSW).

 Eight-bit stack pointer (SP).

 Internal ROM or EPROM (8051) to 4K (8051).

 Internal RAM of 128 bytes:


o Four register banks, each containing eight registers.
o Sixteen bytes, which may be addressed at the bit level.
o Eighty bytes of general-purpose data memory.

 Thirty-two input/ output pins arranged as four 8-bit ports: P)-P3.

 Two 16-bit timer/counter: T) and T1.

 Full duplex serial data receiver/ transmitter : SBuf.

 Control registers: TCON,TMOD,SCON,PCON,IP,and IE.

 Two external and three internal interrupt sources.

1
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________________________
 Oscillator and clock circuits.

(b) State function of following pins of 8051 microcontroller.


1) PSEN
2) ALE
3) EA
4) INTO
Ans: (1 Mark each)
1. PSEN
It is active low output control signal used to activate enable signal of external ROM/ EPRM . it is activated
every six oscillator periods while reading the external memory.

2. ALE: (Either Diagram or Explanation)


There are two ALE pulses per machine cycle. The Ale pulse, which is primarily used as a timing pulse for
external memory access, indicates when every instruction byte is fetched.
3. EA :
It is active low output control signal. When EA = 1, µc accesses internal and external program memory when
EA =µc accesses only external program memory.

4. INTO
It is external interrupt 0, active low pin.
It is external hardware interrupt I/P signal. Through this user, programmer or peripheral interrupts to
microcontroller. This is connected to port pin p3.2

(c) Describe ‘sbit’ and ‘sfr’ data types used in C programming for 8051.
Ans: (2 Mark each)

sbit

With typical 8051 applications, it is often necessary to access individual bits within an SFR. The C51 compiler
makes this possible with the sbit data type. The sbit data type allows you to access bit-addressable SFRs. For
example:
sbit EA = 0xAF;

This declaration defines EA to be the SFR bit at address 0xAF. On the 8051, this is the enable all bit in the
interrupt enable register.

2
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________________________
sfr Types:

SFRs are specified as sfr . For example:

sfrP0 = 0xFF00; /* Port-0, address FF00h */

sfr P1 =0xFF04; /* Port-1, address FF04h */

Names for sfr types are defined using the same method as other C variables. In the above
example, P0 and P1are the SFR name declarations. Any symbolic name may be used in an sfr declaration.

The address specification after the equal sign ('=') must be a numeric constant.

Data type Bits Bytes Value Range

sbit 1 0 or 1

sfr 8 1 0.255

Note: Any relevant example should be given marks


(d) List control signals of LCD display and state their functions.
Ans: (List signals 1 Mark, Each pin function 1 Mark)
List : RS, R/W, EN
Functions :
1) RS: RS is the register select pin used to write display data to the LCD (characters), this pin has to be high
when writing the data to the LCD. During the initializing sequence and other commands this pin should low.

2) R/W: Reading and writing data to the LCD for reading the data R/W pin should be high (R/W=1) to write the
data to LCD R/W pin should be low (R/W=0)

3) EN: Enable pin is for starting or enabling the module. A high to low pulse of about 450ns pulse is given to this
pin.

3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________________________
B) Attempt any ONE of the following: 6M
(a) Draw the organization of data memory(RAM) of 8051 and describe in brief.
Ans: (Diagram 4 Mark(1 M for working register, 1 M for General purpose, 2 M for bit Addressable)
Explanation 2 Mark)
Diagram:

Fig. Internal RAM organization


Explanation:
8051 has 128-byte internal RAM. Which is organized into 3 distinct areas.

 Thirty-two bytes from address 00h to 1Fh that make up 32 working registers organized as four banks of eight
registers each. The four register banks are numbered 0 to 3 and are made up of eight registers named R0 to R7.

 A bit-addressable area of 16 bytes occupies RAM byte addresses 20h to 2Fh, forming a total of 128 addressable
bits.an addressable bit may be specified by its bit address 00h to7Fh.

 A general-purpose RAM area above the bit area, from 30h to 7Fh.

 A general-purpose RAM area above the bit area, from 30h to 7 Fh, addressable as bytes.

4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________________________
(b) Describe following instructions with reference to their function and addressing mode:
1) ADD A,R1
2) SUBB A,R0
3) ORL A, # 30H
Ans: (Each instruction 2 Mark, 1 M for function, 1 M for addressing mode)
1) ADD A,R1
Add contents of R1 to Accumulator and store the results into accumulator
OR
(A) + (R1) A
Addressing mode: Register

2) SUBB A,R0
Subtract contents of R0,contents of carry flag from accumulator and store the results into accumulator.
(A)- (R0)-cy A
Addressing mode: Register

3) ORL A, # 30H
Logically Or contents of accumulator with given data and store the results in accumulator.
Addressing mode: Immediate

5
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
Q2. Attempt any Two of the following: 16M
a) Write assembly language program to find largest number of an array containing 16 numbers. Store this
number in the internal RAM location 50H. write appropriate comments.

Ans: (Correct Program – 6 Marks And Comments – 2 Marks)

PROGRAM :
To find largest number of an array containing 16 numbers
; 16 numbers are stored from 40H internal RAM location

ORG 0000H ;START FROM 0000H


MOV R0,#40H ;LOAD THE STARTING ADDRESS IN R0
MOV R7,#15 ;LOAD THE COUNTER IN R7
MOV A,@R0 ;TAKE NUMBER IN A AFROM ARRAY
MOV 50H,A ;STORE THE NUMBER AT 50H
UP: INC R0 ;GO FOR NEXT NUMBER
MOV A,@R0 ;TAKE THE NEXT NUMBER
CJNE A,50H,CHECK_BIG ;COMPARE THE NUMBERS
UP1: DJNZ R7,UP ;DEC THE COUNTER BY 1
H: SJMP H ;TERMINATE THE PROGRAM

CHECK_BIG:
JNC EXCHANGE ;FIND THE BIG NUMBER
SJMP UP1

EXCHANGE : ;SAVE LARGEST NUMBER IN 50H


MOV 50H,A
SJMP UP1

NOTE: Program may change. Student can also use the other logic.
Please check the logic and understanding of students.

6
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
b) Draw interfacing diagram of 7 segment display with Port 1 of 8051 micro controller. Write C program to
display BCD numbers from 0 to 9.

Ans: (Interfacing Diagram – 4 Marks And Correct Program – 4 Marks)

Interfacing Diagram:

Fig. Interfacing diagram of 7 segment

7
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
Program:

// C language program for 7 Segment display interfacing

#include <Intel\8052.h>

#include <standard.h>

/*SEVEN SEGMENT DISPLAY

DP G F E D C B A

NO D7 D6 D5 D4 D3 D2 D1 D0

0 0 1 0 0 0 0 0 0 =40H

1 0 1 1 1 1 0 0 1 =79H

2 0 0 1 0 0 1 0 0 =24H

3 0 0 1 1 0 0 0 0 =30H

4 0 0 0 1 1 0 0 1 =19H

5 0 0 0 1 0 0 1 0 =12H

6 0 0 0 0 0 0 1 0 =02H

7 0 1 1 1 1 0 0 0 =78H

8 0 0 0 0 0 0 0 0 =00H

9 0 0 0 1 0 0 0 0 =10H

A = P1.0 B = P1.1 C = P1.2 D = P1.3

E = P1.4 F = P1.5 G = P1.6 DP= P1.7

*/

void main ()

P1 = 0xFF; //DISPLAY OFF

while(1)

8
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
P1 = 0x40; //DISPLAY 0

delay_ms(1000);

P1 = 0x79; //DISPLAY 1

delay_ms(1000);

P1 = 0x24; //DISPLAY 2

delay_ms(1000);

P1 = 0x30; //DISPLAY 3

delay_ms(1000);

P1 = 0x19; //DISPLAY 4

delay_ms(1000);

P1 = 0x12; //DISPLAY 5

delay_ms(1000);

P1 = 0x02; //DISPLAY 6

delay_ms(1000);

P1 = 0x78; //DISPLAY 7

delay_ms(1000);

P1 = 0x00; //DISPLAY 8

delay_ms(1000);

P1 = 0x10; //DISPLAY 9

delay_ms(1000);

NOTE: Program may change. Student can also use the other logic.
Please check the logic and understanding of students.

9
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
c) Draw interfacing diagram where P1.0 pin of 8051 microcontroller is used to control relay contact in turn;
controls the fan connected to 230V. Describe operation of this circuit.

Ans: (Interfacing Diagram – 4 Marks And Operation of circuit – 4 Marks)

Any other suitable diagram should be considered.

Interfacing Diagram :

Operation of circuit:

 Fan is operating on 0 to 230Vac and Microcontroller is operating on 0 to 5 Vdc.

 We can‟t connect FAN directly to microcontroller; therefore we have to connect RELAY in between FAN and
Microcontroller.

 RELAY is electromechanical switch. It operates on 12Vdc. Therefore we can‟t connect RELAY directly to the
microcontroller.

 To drive the relay we are using relay driver i.e transistor BC547.

10
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
 Microcontroller will operate transistor, Transistor will operate relay and relay will operate fan.

 When P1.0 is logic HIGH i.e 5V, transistor turns ON, Relay turns ON. The NO contact will become NC. And
FAN will turns ON.

 When P1.0 is logic LOW i.e 0V, transistor turns OFF, Relay turns OFF. The NO contact remains NO. And
FAN will turns OFF.

 LED is used to indicate Relay is ON or OFF.

 Instructions to turn ON and OFF the FAN are as follow:

o SETB P1.0 is used to turn ON the Relay as well as FAN.

o CLR P1.0 is used to turn OFF the Relay as well as FAN.

Q.3 Attempt any FOUR: 16 M


(a) Draw the format of PSW register of 8051 and state the functions of each bit.
Ans: (Format 2 Marks, Function 2 marks)
Format of PSW register of 8051:

Functions:
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.
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.

11
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
P, the parity flag-
The parity flag reflects the number of 1s in the A (accumulator0 register only. If the A register contains an odd
number of 1s, then P=1. Therefore, P=0 if A has an even number of 1s.

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.

(b) Write alternate functions of port 3 of 8051.


Ans: (each function ½ Mark)

P3 Bit Function Pin

P3.0 RxD ( Serial data receive pin.) 10

P3.1 TxD ( Serial data transmit pin.) 11

P3.2 INT0 ( External interrupt 0.) 12

P3.3 INT1 ( External interrupt 1). 13

P3.4 T0 ( Clock input for counter 0) 14

P3.5 T1 ( Clock input for counter 1) 15

P3.6 WR ( Write pin used for external RAM.) 16

P3.7 RD (Read pin used for external RAM.) 17

12
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
(c) Describe the following C program for 8051.
Ans: (4 marks comments )

Program: (1 Mark for each comment)


# include <reg51.h>…………………..Include header file
Void main (void)
{
Unsigned char z; …………………Initialize „z‟ as a char
For (z=0; z<=8; z++)……………..increment „z‟ from 0 till 8
P1=z; ………………………...send value of „z‟ to port 1.
} once z > 8……………..end of the program.

(d) Compare EEPROM and Flash memory (any four points).


Ans: (each point 1 Mark)

EEPROM: Flash memory:

1.Data is erased using electric current 1.The erasure is caused by flower- nordheium tunneling in
which electrons pierce through a thin dielectric material
which remove an electronic charge from a floating gate
associated with each memory cell.

2.Data is within/ programmed at the byte level. 2.It is done at the block (group of bytes) level.

3.Slower updation (time required 5 ms) 3.Faster (flashes within 10 µs)

4.Program / erase cycle refers to the no. of times that chip 4.Flash 100,000 times.
can be erased and programmed before it becomes
unusable EPROM 1000 times.

5.No. of cells / unit is less package density is less. 5. No. of cells / unit is less package density is more.

13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
(e) Draw interfacing diagram of 8 key connected to P0 of 8051 and label it.
Ans: (4 Mark for correct diagram)

Fig. Key connected to P0

Note. We are using P0 therefore Pull up register is compulsory.

14
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
Q4. A) Attempt any three of the following: 12M
a) Draw the interfacing diagram of stepper motor to Port 1. Use ULN2003 driver IC.

Ans: (Interfacing diagram- 4Marks)

Stepper Motor Interfacing Diagram:

Fig. Stepper motor to Port 1

b) Describe bitwise Left / Right Shift operator used in 8051 C programming with example.
Ans:(Left Shift operator with example – 2 Marks And Right Shift operator with example – 2 Marks )

Bitwise Left Shift Operator in C:

4) It is denoted by <<
5) Bit Pattern of the data can be shifted by specified number of Positions to Left
6) When Data is Shifted Left , trailing zero‟s are filled with zero.
7) Left shift Operator is Binary Operator [Bi – two]

15
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
Example:

Syntax : Bitwise Left Shift Operator


[variable]<<[number of places]

P0=0x3C << 2

After execution of this instruction


Shift number 2 times to left:
3C=0011 1100
F0=1111 0000
So,
P0=0xF0

Bitwise Right Shift Operator in C:

 It is denoted by >>
 Bit Pattern of the data can be shifted by specified number of Positions to Right
 When Data is Shifted Right , leading zero‟s are filled with zero.
 Right shift Operator is Binary Operator [Bi – two]

Example:
Syntax : Bitwise Right Shift Operator
[variable]>>[number of places]
P0=0x3C >> 2
After execution of this instruction
Shift number 2 times to Right:
3C=0011 1100
0F=0000 1111
So,
P0=0x0F

NOTE: Example May change. Please check the logic and understanding of students.

16
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
c) Compare microprocessor and micro controller(any 4 points).

Ans: Comparison : (Any 4 points 4 Marks)

Sr.No
Microprocessor Microcontroller
1 Microprocessor don‟t have inbuilt Micro controller has inbuilt ROM and
ROM and RAM RAM

2 Microprocessor don‟t have inbuilt Micro controller has inbuilt Timer and
Timer and Counter Counter

3 Microprocessor don‟t have inbuilt Micro controller has inbuilt UART


UART

4 Microprocessor don‟t have inbuilt Micro controller has inbuilt 4 I/O


I/O PORTs PORTS

5 It has many instructions to move It has one or two instructions to move


data between memory and CPU. data between memory and CPU.

6 It has one or two bit handling It has many bit handling instructions.
instructions.

7 Access times for memory and I/O Less access times for built-in memory
devices are more. and I/O devices.

8 Microprocessor based system Micro controller based system requires


requires more hardware. less hardware reducing PCB size and
increasing the reliability.

17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
d) Draw the format of TMOD and describe each bit.

Ans:- (TMOD Format – 2 Marks And Each bit description – 2 Marks )

TMOD format:

TMOD
(89h) SFR :
Bit Name Explanation of Function Timer
When this bit is set the timer will only run when INT1 (P3.3) is high.
7 GATE1 1
When this bit is clear the timer will run regardless of the state of INT1.
When this bit is set the timer will count events on T1 (P3.5). When this
6 C/T1 1
bit is clear the timer will be incremented every machine cycle.
5 T1M1 Timer mode bit 1
4 T1M0 Timer mode bit 1
When this bit is set the timer will only run when INT0 (P3.2) is high.
3 GATE0 0
When this bit is clear the timer will run regardless of the state of INT0.
When this bit is set the timer will count events on T0 (P3.4). When this
2 C/T0 0
bit is clear the timer will be incremented every machine cycle.
1 T0M1 Timer mode bit 0
0 T0M0 Timer mode bit 0

The
modes of operation are:

TxM1 TxM0 Timer Mode Description of Mode


0 0 0 13-bit Timer.
0 1 1 16-bit Timer
1 0 2 8-bit auto-reload
1 1 3 Split timer mode

18
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
Q4. B) Attempt any one : 6M
a) Describe following branching instructions:

1) DJNZ R0,UP

2) CJNE @R1, #80H, LOOP

3) JB P1.5,Here

Ans:- (Each instruction description – 2 Marks )


1) DJNZ R0,UP

Decrement R0 register and if it is not zero then jump to UP lable.

DJNZ instruction decrements the value of register R0 by 1. If the new value of register is not 0 the
program will branch to the address indicated by relative address UP. If the new value of register is 0 program
flow continues with the instruction following the DJNZ instruction.

2) CJNE @R1, #80H, LOOP

Compare the data (indirectly Pointed by R1) with immediate number 80H. If both numbers are not equal
then jump to LOOP label

CJNE compares the value of operand1i.e the data (indirectly Pointed by R1) and operand2, i.e 80H and
branches to the indicated relative address LOOP, if operand1 and operand2 are not equal.
If the two operands are equal program flow continues with the instruction following the CJNE
instruction.
3) JB P1.5, Here

If port pin P1.5 is set then jump to the address pointed by label Here.

JB branches to the address indicated by reladdr-Here if the bit indicated by bit addrP1.5 is set. If the bit
is not set program execution continues with the instruction following the JB instruction.

19
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
b) Compare 8051 micro controller with 8052, with reference to

1) On chip ROM

2) On chip RAM

3) Timers

4) Interrupt Sources.

Ans: (Any 1 point 1 ½ Marks)


Sr. No. Parameter 8051 8052

1 On chip ROM 4 KB 8 KB

2 On chip RAM 128 Byte 256 Byte

3 Timers 2 3

4 Interrupt Sources 5 6

Q.5.Attempt any TWO 16

a) Draw the format of SCON register and describe function of each bit. State the importance of SMOD bit
when it is set. If XTAL =12 MHZ, Calculate baud rate for

TH1= -12 and SMOD=1.

ANS: ( SCON format:2 marks , SCON bit explanation :2 marks , Significance of SMOD bit :2 marks , Baud
rate calculation: 2 marks )

SERIAL PORT CONTROL REGISTER :SCON

20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
SM2 enables the multiprocessor communication feature in Modes 2 and 3. In Modes 2 or 3, if SM2 is set to 1 than RI will not be activated if the
received 9th date bit(RB8) is 0. In Mode 1, if SM2 = 1 then RI will not be activated if a valid stop bit was not received. In Mode 0 SM2 should be
0

Significance of SMOD bit:

SMOD is PCON.7 bit , which when set to 1 doubles the serial communication baud rate. When 8051 is powered up,
SMOD is 0.

Baud Rate = 2SMOD X (Timer 1 Overflow Rate)


32

Baud rate calculation for Fosc=12 MHZ , TH1 = -12 , SMOD =1 :

Baud Rate = 2SMOD X (Timer 1 Overflow Rate)


32
= 2SMOD X Oscillator Frequency
32 12 X [256 - ( TH1 ) ]
FOR SMOD=1,
Baud Rate = ( 2/ 32 ) X (12 MHZ / (12X[256-TH1] ) )

Baud Rate = (62500 HZ / [256 – TH1] )

Given, TH1 = -12 = f4h =244

Baudrate = (62500 HZ / [256-244]) = 62500 / 12

Baudrate = 5208 bps

(b) Write assembly language program for 8051 to generate square wave of 10 KHZ on port pin P1.7 Assume
XTAL =12MHZ , use Timer0 to generate delay.( show delay calculation with comments)
ANS: (delay calculation: 2 marks , Program : 6 marks)

Frequency = 10 khz
Therefore Time period T = 1 / 10KHZ = 0.1 ms
Therefore TON = TOFF = 0.1ms / 2 = 0.05 ms = 50 usec

Required time delay = ( 12 / Fosc ) x number of increments (N)


50 usec = ( 12 / 12MHZ ) x number of increments (N)
50usec = 1 usec x N
N = 50
21
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
Using TIMER 0 in MODE 1,
COUNT = 216 - N
COUNT =65536 – 50 =65486 = FFCE H

Assembly language program :

ORG 0000H

MOV TM0D,#01H ;TIMER 0, MODE 1


AGAIN:MOV TH0,#0FFH ;Load higher byte of count
MOV TL0,#0CEH ; load lower byte of count
SETB TR0 ;start timer 0
HERE: JNB TF0,HERE ;CHECK IF TF0 IS SET
CPL P1.7 ; Complement P1.7
CLR TR0 ; STOP TIMER 0
CLR TF0 ; CLEAR TF1
SJMP AGAIN ;REPEAT AGAIN
END
OR

Using TIMER 0 in MODE 2 (8 bit AUTO RELOAD timer mode),


COUNT = 28 - N
COUNT = 256 – 50 =206 = CE h
Therefore TH0 = TL0 = CE h

Program:
MOV TMOD,#02H ;Timer0, Mode 2
MOV TH0,#0CEh ;Load higher byte of count
SETB TR0 ; start timer0
HERE:JNB TF0,HERE ;Check if TF0 is set
CPL P1.7 ;COMPLEMENT P1.7
CLR TF0 ; CLEAR TF0
SJMP HERE ;REPEAT
END
Note: ( Any other correct program logic can be used)

22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________

C) Draw interfacing diagram to interface 8 switches to PORT 0 and 8 LEDs to PORT 1


Write program for 8051 in C language rom read switch status and display it on LEDs

ANS: (Diagram : 4 marks , Program : 4marks )


Any otherc suitable diagram and program related to that should be considered.

( Note : LEDs can be connected in common anode mode also )

’C’ Language program:

#include <reg51.h>
void main(void)
{
unsigned char mybyte;
P0=0xFF; //make Port0 input port
P1=0X00; // make Port1 output port
while (1)
{
mybyte=P0; //get a byte from P0
P1= ~ mybyte; //send compliment of it to P1
}
}

Note: When switch is not pressed port pin of P0 status is logic 1 and when switch is pressed port pin of P0 is
logic 0. So we have to complement the status of P0 i.e mybyte variable.

23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________

Q.6) Attempt any FOUR 16

a) Draw diagram of port 0 of 8051 and label it. Write the process to read port 0 pin status.

ANS: (neat labeled Diagram : 2 marks , Explanation: 2 marks)


PORT 0 diagram:

Process to read pin status:


When the port is used as an input port, '1' must be written to the latch. In this situation both the output MOSFETs are
'off'. Hence the output pin floats in high impedance state, and pin is connected to input buffer . Data on the pin can be
read by asserting “Read pin “ signal when read pin instruction is executed

24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________

b) Draw labeled diagram interfacing diagram of ADC0809 with 8051 microcontroller

Ans: ( neat labeled diagram : 4 marks)

C) State addressing modes of 8951. Describe any two addressing modes with example

ANS: Stating addressing modes: 1 mark , explanation of any two addressing modes with one example each : 3
marks ( one example each :1/2 mark )

Following are addressing modes of 8051

1. Immediate addressing mode 2. Register addressing mode


3. Direct addressing mode 4. Indirect / register indirect addressing mode
5. Indexed addressing mode 6. Register specific addressing mode

1. Immediate addressing mode


The value of a constant i.e. operand is specified in instruction itself. The data is part of instruction. The
immediate data must be preceded by the “#” sign
MOV A, #64H
MOV DPTR,#6080H
2. Register addressing mode
Registers are used to hold the operands ( data to be operated on ). The register banks, containing registers R0
through R7, can be accessed by this addressing mode
MOV A, R3
25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
ADD A,R4
3. Direct addressing mode
In direct addressing the operand is specified by an 8-bit address field in the instruction. i.e. in this mode data is
in internal RAM location whose address is specified in the instruction . Only internal Data RAM and SFRs can
be directly addressed.
MOV R2, 20H
ADD A,30H
MOV 30H,45H
MOV A , 50H
4. Indirect / register indirect addressing mode
In indirect addressing the instruction specifies a register which contains the address of the operand. Registers
are used to point towards data. Both internal and external RAM can be indirectly addressed. For internal RAM
Only registers R0 or R1 can be used as memory pointers . For external RAM ,16-bit “data pointer” register,
DPTR can be used

MOV A,@R0
ANL A,@R1
ADD A,@R0

5. Indexed addressing mode


Only program Memory can be accessed with indexed addressing, and it can only be read. This addressing mode
is intended for reading look-up tables in Program Memory. A 16-bit register (data pointer/program counter –
DPTR/PC) holds the base address of the lookup table and the accumulator holds an 8-bit displacement or index
value. The sum of these two registers forms the effective address for the instruction
MOVC A,@A+PC
MOVC A,@A+DPTR

6. Register specific addressing mode

Some instructions are specific to a certain register. For example, some instructions always operate on the
Accumulator, or Data Pointer, etc., so no address byte is needed to point to it. The opcode itself does that.
Instructions that refer to the Accumulator as A assemble as accumulator specific opcodes.

RLC A
RRC A
SWAP A
DAA

26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER-15 EXAMINATION
Subject Code:17509 Model Answer Page No: 27/ N
__________________________________________________________________________________________________
d) Draw format of IE register and describe each bit
ANS: format : 2 marks , bit explanation: 2 marks

e) Assuming temperature control system using LM35 as temperature sensor and ADC 0809. Draw flow chart of
this system to keep temperature within
25 ◦ C to 35◦ C
ANS: correct flow chart : 4 marks
( Note: Any other correct logic can be used)

27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:1/ 13
Important Instructions to examiners:
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 anyequivalent 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.
Q1-A. Atempt any Three : 12
i) Draw the block diagram of Von-Neumann and Harvard architectures 4
2+2

ii) Draw the interfacing of two seven segment display with 8051 microcontroller. 4

iii) Wri te C language program for 8051 microcontroller to toggle all 8 lines of port 0 with delay. 4
#include <REG51.H>
void delay(void);
void main(void)
{
while(1)
{
P0= 0xaa;
delay();
P0 =0x55;
delay();
}
}

Pages 1/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:2/ 13
void delay(void)
{
unsigned int count;
for(count =0;count<1000;count++);
}
iv) Describe the function of PC and DPTR 4
PC: Program counter 2+2
It is a 16 bit register in 8051. It points to the address of the next instruction to be executed. As the cpu
fetches the opcode, contents of PC are incremented to point to next opcode fetch location. PC is not part of
any instruction in 8051.
DPTR: Data Pointer
It is a 16 bit register. It is used to hold address of the internal and external program memeory and external
data memory. It consists of two 8 bit registers: DPH(high order byte) and DPL(low order byte)
Q1 B) Attempt any one 6
i) Draw and describe the internal RAM memory organisation of 8051 microcontroller 4+2

The internal RAM of 8051 is of 128 bytes (00-7F). It is divided in following sections:
1) Four register banks: Each register bank has eight registers(R0-R7) of 8bits each. Any one register bank is
active at a given time. A register bank can be selected by using RS0,RS1 registers in PSW register.
2) Bit addressable memory area: Memory address 20H-2FH is called as bit addrresable memory. There are
128 addressable bits. The bit address ranges from 00H-7FH.
3) General purpose area: Memory address 30H to 7FH is general purpose scratch pad area of the RAM. This
area is used to store temporary variables, for initializing stack pointer etc.
ii) Write an assembly language program to find largest number out of five numbers. Data is stored in internal 6
RAM memory location 10 H onwards. Store the result at 20 H. (Credit to any suitable and logical program)
ORG 0000h SKIP: INC R0 ;point to next address
LJMP MAIN DJNZ R1,LOOP ; decr r1 and loop back
ORG 0030H MOV 20H,0F0H ;transfer largest to 20h
MAIN: MOV R0,#10h ; intialize start address END
MOV R1,#05h ; init counter to 5
MOV 0F0H,#00H ;initialize B reg as largest
LOOP: MOV A,@R0 ; transfer data to acc
CJNE A,0F0H,CHK ; compare with B register
SJMP SKIP ; if equal do nothing
CHK: JC SKIP ; if less do nothing
MOV 0F0H,0E0H ;if ACC is greater then transfer to B

Pages 2/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:3/ 13
Q2. Attempt any two: 16
a. Describe the addressing modes of 8051 microcontroller with one example. 8
1) Immediate addressing mode: Data is provided as part of the instruction. The data follows the instruction 1
each
opcode
Example: MOV A,#0AH
2) Register addressing mode: It involves use of registers to hold the data.
Example: MOV A,R0
3) Direct adrresing mode: 8 bit direct address of the internal RAM of 8051 is specified in the instruction.
Example: MOV A, 40H
4) Indirect addressing mode: It uses registers to hold the address of the memory location to access. Registers
R0, R1 are used to point to internal memory and DPTR is used to point to external data memory.
Example: MOV A, @R0, MOVX A, @DPTR
5) Indexed addressing mode: It uses 16bit registers PC and DPTR to hold the base address. And accumulator
to hold the offset which is relative to the base address.
Example: MOVC A,@A+DPTR
6) Relative addresing Mode: It is used with conditional jump instructions.
Example: SJMP NEXT (NEXT is calculated relative to preset location)
7) Absolute Adressing mode: It is used by ACALL and AJMP instructions. They are two byte instructions with
11bit address specified in instruction opcode. The upper 5 bits are taken from PC. It can branch to
anywhere in 2Kbyte page of the program memory. Example: ACALL LOOP1
8) Long addressing mode: It is used by LCALL LJMP instruction. These are 3 byte instructions in which 16 bit
direct address is specified. It can jump any where in the entire 64K program memory.
Example: LJMP MAIN

b. Draw the interfacing of DAC 0808 with 8051 microcontroller. Write C language program to generate 8
triangular waveform by using DAC 0808. 4+4

Pages 3/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:4/ 13
/* Program to generate triangular wave */
#include <REG51.H>
sfr DACDATA = P1;
void main(void)
{
unsigned char wavevalue[12] = { 0, 8,16,32,64,128,255,128,64,32,16,8};
unsigned char x;
while(1)
{
for(x=0;x<12;x++)
{
DACDATA = wavevalue[x];
}
}
}

c. Draw the interfacing of stepper motor with 8051 8


microcontroller. Draw a flow chart to rotate stepper motor 4+4
through 360° in anticlock
wise direction.

Assume that :
The stepper motor is uniploar type. The four leads of motor
are controlled by P1.0 to P1.3 of 8051.
Motor Step angle = 20
Steps per revolution = 180
Four step sequence for anticlock wise movment as shown in folllwing table:
Step A B C D
1 0 0 1 1
2 0 1 1 0
3 1 1 0 0
4 1 0 0 1
0
One four step sequence = 8 .
No of four step sequneces required for 3600 = 45 i.e. 180 steps

Pages 4/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:5/ 13
Q3. Attempt any Four
16
a. Draw the block diagram of internal architecture of 8051 microcontroller. 4

b. Describe the four timer modes of8051 microcontroller with suitable diagram. 4
Timer mode 0: 13 bit timer mode 1
each

Internla clock pulses are counted by (THx-8bits and TLx-5bits). When the count rolls over to 0 after 8191 counts
(213), TFx bit is set.
Timer mode 1: 16 bit timer mode

Internal clock pulses are counted by (THx-8bits and TLx-8bits). When the count rolls over to 0 after 65535 counts
(216), TFx bit is set.
Timer mode 2: 8 bit auto reload mode

Pages 5/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:6/ 13

Pages 6/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:7/ 13
TLx acts as 8 bit timer. The reload value is stored in THx register. When TLx register rolls over from FF to 0, the
reload value stored in THx is loaded into TLx register.
Timer Mode 3: split timer mode

Splits Timer 0 into two 8-bit timers


- TL0 sets TF0
- TH0 sets TF1
c. Wri le C language program for 8051 microcontroller to read data from port 1 and send it to port 3. 4
#include <REG51.H>

void main(void)
{
Unsigned char portdata;
While(1)
{
portdata = P1;
P3 = portdata;
}
}

d. Distinguish between microprocessor and microcontroller (any four points). 4


Micoprocessor Micocontroller

A mircoprocessor does not have on-chip memory Has program as well as data memory on-chip

A microprocessor does not have on-chip timer, I/O Timers, I/O ports, serial ports are on-chip.
ports

It is mainly used for computing purpose. Use of microcontroller is for mainly for device control.

Memeory and other peripheral deveices need to be It is a computer on-chip with small computing power
connected externally to make complete computer required for device control

Cost of the system is higher as compared to Results into a cheaper solution for the given
microcontroller . application

Circuit size becomes larger. Small circuit size

Pages 7/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:8/ 13
e. Draw the interfacing of 8 LEDs to port 2 of8051 microcontroller. Write C language program to (turn ON and 4
OFF LEDs of port 2 with delay. 2+2

#include <REG51.H>

void delay(void);
void main(void)
{ void delay(void)
while(1) {
{ unsigned int cnt;
P2 = 0xff; for(cnt=0;cnt<2000;cnt++);
delay(); }
P2 = 0x00;
delay();
}
}

4. A) Attempt any three: 12


i) Draw the interfacing of relay and optoisolatorwith 8051 microcontroller 4

ii) What is bus ? Describe the function of address, data and control bus. 4
Bus is bunch of wires running from one device to other for communicating information.
Address Bus: It holds binary address of the device connected in system.
Data Bus: It carries data from device toCPU or vice versa
Control Bus: It carries control signals such as clock signals, chip select signals, Read/Write signals, interrrupt
request signals

Pages 8/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:9/ 13
iii) Write the instruction for following using C operator: 4
a) Bit wise shift data left 4 times. 2+2
b) Bit wise shift data right 4 times.

unsigned char x,y;

x = y<<4; //left shift 4 times

x = y>>4; //right shift 4 times


iv) Draw the format of PS W register of8051 microcontroller and describe the function of any two flags. 4

Parity Flag: It is set when number of 1s in ACC are odd and reset when number of 1s are even
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 be also set or reset by using SETB C, CLR C instructions.
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.
OV flag: It is overflow flag. It is set when there is carry from D6 to D7 but no carry from D7 or carry from D7
but no carry from D6 to D7.
B. Attempt any one: 6
i) Write an assembly language program for 8051 microcontroller to find average of ten 8-bit numbers stored in 6
internal RAM location 20 H onwards. Store the result at 30 H.
ORG 0000h
LJMP MAIN
ORG 0030H
MAIN: MOV R1,#0AH ;LOAD COUNTER OF 10
MOV R0,#20H
XRA A ; CLEAR ACC AND CY FLAG
NEXT: ADD A,@R0 ;ADD NUMBAR TO ACC AND STORE SUM IN ACC
INC R0
DJNZ R1,NEXT
MOV B,#0AH
DIV A,B
MOV 30H,A
RET
ii) Draw the format of TMOD register of 8051 microcontroller. Describe the function of each bit. 6
3+3

Pages 9/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:10/ 13
TMOD register is divided in two sections lower 4 bits are for timer T0 and upper 4 bits are for timer T1
GATE: Gating control when set. Timer/counter is enabled only while the INTx pin is high and the TRx control pin
is set. When cleared, the timer is enabled whenever the TRx control bit is set.
C/T : Timer or counter selected cleared for timer operation (input from internal system clock). Set for counter
operation (input from Tx input pin).
M1 : Mode bit 1
M0 : Mode bit 0

Q5. Attempt any two: 16


a. Draw the interfacing of ADC 0809 with 8051 microcontroller. Write C language program to read the data at 8
channel O of ADC 0809 and store it to 10 H memory location. 4+4

#include <reg51.h> ADDR_C = 0;


^
sbit ALE = P2 4; ADDR_B = 0;
sbit OE = P2^5; ADDR_A = 0;
sbit SC = P2^6; MSDelay(1);
sbit EOC = P2^7; ALE = 1;
A
sbit ADDR_A = P2 0 MSDelay(1);
sbit ADDR_B = P2^1 SC = 1;
sbit ADDR_C = P2^2 MSDelay (1);
Sfr MYDATA = P1; ALE = 0;
char idata result _at_ 0x10; SC = 0;
void main() while(EOC==l);
{ while(EOC==0);
unsigned char value; OE = 1;
MYDATA = OxFF; MSDelay(1);
EOC = 1; value = MYDATA;
ALE = 0; OE = 0;
OE = 0; result = value;
SC = 0;
while(1) }
{ }

Pages 10/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:11/ 13
b. Describe the following assembler directives with example. 8
i) DB ii) ORG iii) EQU iv) END. 2
each

DB: 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 formats.

Example:
DATA1 DB 28 (decimal data stored as 1C hex)
DATA2 DB 01010101B (Binary data)
DATA3 DB 5Fh
Text DB “ABCDE” ASCII character array named as Text

ORG: 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.

Example:
ORG 0000H
LJMP main
ORG 0030H
MAIN: ….

EQU: This is used to define a constant without occupying a memory location. When the label appears in the
program, constant value will be substituted for the label.
Example:
NUMBER EQU 25H

MOV R3,#NUMBER ; R3 = 25H as 25H will be substituted for NUMBER

END: This indicates to the assembler 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

c.
i)Write C language program for 8051 microcontroller to add five 8-bit numbers 8
#include <REG51.H> 4+4
void main(void)
{
unsigned char num [5], i; // declare five element array and counter i
unsigned int sum; // to store result;

for(i=0;i<5;i++)
{
sum = sum + num[i];
}
}
iii) State any four C data types with their range of value.
1) unsigned char 0 -255 2) char -128 to 127 3) unsigned int 0 -65535 4) int 32767 to -32768

Pages 11/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:12/ 13
Q6. Attempt any Four 16
a. Distinguish between 8051 and 8052 microcontrollers (any four points). 4
8051 8052
4 KB program memory 8 KB program memory
128 bytes internal RAM 256 bytes internal RAM
Two timers Three timers
Five interrupt sources Six interrupt sources
b. Write C language program for 8051 microcontroller to transmit message'WELCOME'serially at baud rate 4
9600,8-bit data, 1 -stop bit Assume crystal frequency is 11.0592 MHz.

#include <REG51.H>
void main(void)
{
unsigned char text[] = “WELCOME”;
unsigned char i;
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while(1)
{
for(i =0;i<7;i++)
{
SBUF= text[i];
while(TI ==0);
TI = 0;
}
}
}
c. Write an assembly language program for 8051 microcontroller to transfer 10 bytes starting from 20 H 4
onwards to 30 H onwards.

ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: MOV R0,#20H
MOV R1,#30H
MOV B,#0AH
NEXT: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ B,NEXT
END

Pages 12/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Subject Code: 17509
Model Answer
WINTER – 15 EXAMINATION Page No:13/ 13
d. Describe alternative functions of port 3 of8051 microcontroller. 4

e. Draw the interfacing diagram for temperature measurement using 8051 microcontroller and adc 0809. 4

Pages 13/13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
Summer 2016 EXAMINATIONS

Subject Code: 17509 Model Answer

Important Instructions to examiners:

1) The answers should be examined by key words and not as word-to-word as given in
the 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 judgment 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.

1
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

Q.1 A) Attempt any THREE


a) Compare microprocessor and microcontroller (any four points)
Ans: (4M-each point)

2
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

b) Draw and explain format of SCON register of microcontroller 8051.


Ans: (2M-format, 2M-explaination)
SM0
SM0 SM1 SM2 REN TB8 RB8 TI RI
SCO
N.7 Serial port mode specifier
SM1 SCON.6 Serial port mode specifier.
SM2 SCON.5 Used for multiprocessor communication (Make it 0.)
REN SCON.4 Set/ cleared by software to enable/ disable reception.
TB8 SCON.3 Not widely used.
RB8 SCON.2 Not widely used
TI SCON.1 Transmit interrupt flag. Set by hardware at the beginning of the
stop Bit in mode 1.Must be cleared by software.
RI SCON.0 Receive interrupt flag. Set by hardware halfway through the
stop bit time in mode 1.Must be cleared by software.
Note: Make SM2, TB8 and RB8 = 0.
SM0 SM1
0 0 Serial Mode 0
0 1 Serial Mode 1, 8-bit data, 1 stop bit, 1 start bit
1 0 Serial Mode 2
1 1 Serial Mode 3
SM2: SM2 is the D5 bit of the SCON register. This bit enables the multiprocessing capability of the
8051. Make SM2= 0 since we are not using the 8051 in a multiprocessor environment.

REN: The REN (receive enable) bit is D4 of the SCON register. The REN bit is also referred to as
SCON.4 since SCON is a bit addressable register.
When the REN =1, it allows the 8051 to receive data on the RxD pin of the 8051. As a result if we
want the 8051 to both transfer and receive data, REN must be set to 1.
By making REN=0, the receiver is disabled. Making REN=1 or REN=0 can be achieved by the
instructions “SETB SCON.4” and “CLR SCON.4”, respectively.
This bit can be used to block any serial data reception and is an extremely important bit in the
SCON register.

TB8: TB8 (transfer bit 8) is bit D3 of SCON. It is used for serial modes 2 and 3. We make TB8=0
since it is not used in our applications.

RB8: RB8 (receive bit 8) is bit D2 of the SCON register. In serial mode 1, this bit gets copy of the
stop bit when an 8 bit data is received. This bit (as is the case for TB8) is rarely used anymore. In all
our applications we will make RB8=0. Like TB8, the RB8 bit is also used in serial modes 2 and 3.

TI: TI (transmit interrupt) is bit D1 of the SCON register.


This is an extremely important flag bit in the SCON register.
When the 8051 finishes the transfer of the 8 bit character, it raises the T1 flag to indicate that it is
ready to transfer another byte. The TI bit is raised at the beginning of the stop bit.

3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
RI: RI(receive interrupt) is the D0 bit of the SCON register. This is another extremely important
flag in the SCON register. When the 8051 receives data serially via RxD, it gets rid of the start and
stop bits and places the byte in the SBUF register. Then it raises the RI flag bit to indicate that a
byte has been received and picked up before it is lost. RI is raised halfway through the stop bit.

c) Write ‘C’ language program to toggle all bits of Port 1 of 8051 continuously with some delay.
Ans: (4M-correct program)
#include <reg51.h>
Void MSDelay(unsigned int) ;
Void main(void)
{
While(1) //repeat forever
{
P0=0x55;
MSDelay(250) ;
P0=0xAA;
MSDelay(250);
}
}
Void MSDelay(unsigned int itime)
{
Unsigned int i, j;
For(i=0;i<itime;i++)
For(j=0;j<itime;j++) ;
}

d) State alternate pin functions of Port 3 of microcontroller 8051.


Ans: (1/2M – each pin function)
Pin Name Alternate Function
P3.0 RXD Serial input line

P3.1 TXD Serial output line

P3.2 External interrupt 0


INT0
P3.3 External interrupt 1
INT1
P3.4 T0 Timer 0 external input

P3.5 T1 Timer 1external input

P3.6 External data memory write strobe


WR
P3.7 External data memory read strobe
RD

B) Attempt any ONE


4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
a) Explain memory organization of 8051.
Ans: (3M-diagram,3M- explanation)

Internal memory organization

OR

Internal ROM The 8051 has 4K (4096 locations) of on-chip ROM. This is used for storing the
system program. 212 = 4096, therefore the internal ROM address bus is 12 bits wide and internal
ROM locations go from 000H to FFFH.
Internal RAM
There are 256 bytes of internal RAM on the 8051. 28 = 256, therefore the internal RAM address
5
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
bus is 8 bits wide and internal RAM locations go from 00H to FFH.
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.
General Purpose RAM
These 80 bytes of Internal RAM memory are available for general-purpose data storage. The general
purpose RAM can be accessed using direct or indirect addressing mode instructions.
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.
Not all SFRs are bit-addressable. Those that are have a unique address for each bit.

b) Explain following assembler directives with suitable examples


i) DB ii) ORG iii) EQU iv) END
Ans: (1.5M- each)
Ans: 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:

6
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
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.

Q.2 Attempt any TWO


a) Write an assembly language program to generate square wave of frequency 2KHz on port pin P3.0, using
timer 1of 8051.Assume oscillator frequency as 11.0592MHz.
Ans: (4M-correct program)
Crystal frequency= 11.0592 MHz
I/P clock = (11.059 X 106)/12= 1000000 = 921.58KHz
Tin = 1.085μ sec
For 2kHz square wave
Fout = 2 KHz
Tout = 1/ 2x 103
Tout = 500μ sec
Consider half of it = Tout = 250μ sec
N = Tout / Tin = 250/1.085 = 230.41
65536-231= (65305)10 = (FF1A)16

Program:-
MOV TMOD, # 10H ; Set timer 1 in Mode 1, i.e., 16 bit timer
L2: MOV TL1, # 1AH ; Load TL register with LSB of count
MOV TH1, # FFH ; load TH register with MSB of count
SETB TR1 ; start timer 1
L1: JNB TFO, L1 ; poll till timer roll over
CLR TR1 ; stop timer 1
CPL P3.0 ; complement port 1.5 line to get high or low
CLR TF1 ; clear timer flag 1
SJMP L2 ; re-load timer with count as mode 1 is not
auto reload

b) Interface 8 bit DAC 0808 to 8051 and write ‘C’ language program to generate staircase waveform.
Ans: (4m-diagram, 4M-correct program)

7
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

#include<reg51.h>
Void Delat2(unsigned int );
Void main(void)
{
While(1)
{
P2=0x00;
Delay2(10);
P2=0x33;
Delay2(10);

P2=0x66;
Delay2(10);

P2=0x99;
Delay2(10);

P2=0xCC;
Delay2(10);

P2=0xFF;
Delay2(10);

}
}
Void Delay2 (unsigned int t)
{
Unsigned int x,y;
For(x=0;x<=t;x++);

8
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
For(y=0;y<=t;y++);
}

c) Draw and explain interfacing diagram for DC motor speed control using 8051.Also develop flowchart for
the same operation.
Ans: (4M-diagram,4M-flowchart)

Q.3 Attempt any FOUR


a) Draw internal architecture diagram of 8051.
Ans: (4M-diagram)

9
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

OR

b) State the function of Program counter (PC) and Data Pointer (DPTR) registers of 8051.
Ans: (2M-each function)
The Data Pointer (DPTR)
The Data Pointer (DPTR) is the 8051s only user-accessible 16-bit (2-byte) register. The
Accumulator, "R" registers, and "B" register are all 1-byte values.
DPTR, as the name suggests, is used to point to data. It is used by a number of commands which
allow the 8051 to access external memory. When the 8051 accesses external memory it will access
external memory at the address indicated by DPTR.

10
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
While DPTR is most often used to point to data in external memory, many programmers often take
advantage of the fact that it is the only true 16-bit register available. It is often used to store 2-byte
values which have nothing to do with memory locations.
The Program Counter (PC)
The Program Counter (PC) is a 2-byte address which tells the 8051 where the next instruction to
execute is found in memory. When the 8051 is initialized PC always starts at 0000h and is
incremented each time an instruction is executed. It is important to note that PC isnt always
incremented by one. Since some instructions require 2 or 3 bytes the PC will be incremented by 2 or
3 in these cases.
The Program Counter is special in that there is no way to directly modify its value. That is to say,
you cant do something like PC=2430h. On the other hand, if you execute LJMP 2430h you have
effectively accomplished the same thing.

c) State any four ‘C’ data types with their range of values.
Ans: (1M-each)
Data types used in C:
i)Unsigned character
range :– 0-255
2)Signed character
range :- (-128+0+127)
3)Unsigned integer
Range :- 0-65535(0000-FFFFH)
4)signed integer
range ;- (-32768 to 32767)
5) Bit
Range RAM bit addressable only
6)SFR
Range RAM addresses 80 –FFH only
7) Sbit
Range SFR bit addressable only)

d) Give four important features of 8051.


Ans: (1M-each)
Features of 8051 micro controller are as follows:-
1) 8- bit data bus and 8- bit ALU.
2) 16- bit address bus – 64KB of RAM and ROM.
3) On- chip RAM -128 (256) bytes (“ Data Memory”)
4) On- chip ROM – 4 KB (“Program Memory”)
5) Four 8-bit bi- directional input/output ports Four 8-bit bi- directional input/ output ports.
6) Programmable serial ports i.e. One UART (serial port)
7) Two 16- bit timers- Timer 0& Timer 1
8) Six interrupts are available: Reset, Two interrupts Timers i.e. Timer 0 and Timer 1, Two external
hardware interrupts- INT0 and INT1, Serial communication interrupt for both receive and transmit

e) Draw neat interfacing diagram of 20x4 LCD display with 8051 in 8 bit mode

11
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

Q4 a)Attempt any three:

a)Draw the interfacing diagram for temperature measurement using LM 35 temperature sensor with8051
microcontroller.

b)Write ‘C” language program to send out the value 44H serially one bit at a time via P1.0 pin of
8051.TheLSB should go out first.

#include<reg51.h>
sbit=P1^o;
sbit reg_bdata=Acc^0;
12
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
Void main(void)
{
Unsigned char a=0x44,I;
ACC=a;
For(i=1;I<=8,i++)
{
t_bit=reg_bdata;
ACC=ACC<<1;
}
}
c)Compare Von –Neumann and Harvard architecture
Any 4 difference points --4 marks .

d)List interrupts of 8051 mic with their vector address and priority upon reset and explain SFR used to
enable interrupt of 8051

Interrupt Source Vector address Interrupt priority

13
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
External Interrupt 0 –INT0 0003H 1
Timer 0 Interrupt 000BH 2
External Interrupt 1 –INT1 0013H 3
Timer 1 Interrupt 001BH 4
Serial Interrupt 0023H 5

THE SFR used to enable interrupts is the IE SFR.

B) Attempt any 0ne:

a) Explain the operation of following instruction of 8051 with suitable example each.

i) MOVX A,@DPTR ii)SWAP A iii) SETB bit

i) MOVX A,@DPTR
Description: This instruction moves the contents of the external RAM memory pointed by (or
stored in) DPTR to accumulator.
No of bytes: 1 byte
Addressing mode: register
Example: MOV DPTR, # 2000H ; DPTR = 2000H(external RAM address)

MOV A, @DPTR ; 2000H = 0BH


;A = 0BH

ii). SWAP A
Description: This instruction exchanges bits 0-3 of the Accumulator with bits 4-7 of the
Accumulator. This instruction is identical to executing "RR A" or "RL A" four times.
No of bytes: 1 byte
Addressing mode: register specific
Example: MOV A, #59H ;A= 59H
SWAP A ; A= 95H
14
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

iii) SETB bit


Function:This sets high the bit.
.
Eg.SETB C
After execution
Set carry flag CY=1

b) Draw and explain format of TMOD and TCON registers of microcontroller 8051.

ANS:(2 marks –each format)

TMOD format:

TMOD
(89h) SFR:

15
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

TF1 TCON. 7 Timer 1 overflowflag. Set byhardwarewhen the Timer/Counter1 overflows


Cleared byhardware as processor vectors to theinterrupt service routine.

TR1 TCON. 6 Timer 1 run control bit. Set/cleared bysoftware to turn


Timer/Counter1ON/OFF.

TF0 TCON. 5 Timer 0 overflow flag. Set byhardwarewhen the Timer/Counter0


overflows.
Cleared by hardware as processor vectors to the service routine.

TR0 TCON. 4 Timer 0 run control bit. Set/cleared by software to turn Timer/Counter 0
ON/OFF.
IE1 TCON. 3 ExternalInterrupt 1 edge flag. Set byhardware when External
Interruptedgeis detected. Cleared by hardware when interrupt is processed.

IT1 TCON. 2 Interrupt 1 typecontrol bit. Set/cleared by softwareto specifyfalling

edge/lowlevel triggered External Interrupt.

IE0 TCON. 1 ExternalInterrupt 0 edge flag. Set byhardware when External


Interruptedgedetected. Cleared byhardwarewhen interrupt is processed.
IT0 TCON. 0 Interrupt 0 typecontrol bit. Set/cleared by softwareto
Specify falling edge/low level triggered External Interrupt.

Q5) Attempt any two:

a)Draw interfacing diagram of 3x3 matrix keyboard with 8051 and write ‘C” language program to read key
status

16
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

# include < reg51.h>

# define COL P2 // define ports for easier reading

# define ROW P1

void MSDelay ( unsigned int value) ;

void SerTX ( unsigned int value ) ;

unsigned char keypad [3] [3] = { ‘0’ , ‘1’ ,’2’ ,’3’ , ’4’, ‘5’ ,’6’ ,’7’ ,’8’};

void main()

Unsigned char colloc, rowloc ;

TMOD = 0X20; // timer 1, mode 2

THI= -3; // 9600 baud

SCON = 0X50;// 8 – bit , 1 stop bit

TR1 = 1;// start timer 1

// keyboard routine . This sends the ASCII

// code for pressed key to the serial port

COL = 0XFF; // make P2 an input port

While (1) // repeat for ever

17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
{

do

ROW = 0X00; // ground all rows at once

Colloc = COL; // read the columns

Colloc &=0X0F; // mask used bits

} while ( colloc ! = 0X0F); // check until all keys released

do

Do

MSDelay(20); // call delay

colloc = COL ; // see if any key is pressed

colloc &= 0X0F; //mask unused bits

} while (colloc = = 0X0F ); // wait for keypress

While(1)

ROW = 0XFE; // ground row 0

colloc = COL; // read columns

colloc &= 0X0F; // mask unused bits

if ( colloc ! = 0X0F // column detected

rowlock = 0; // save row location

break ; // exit while loop

ROW = 0XFD; // ground row 1

colloc = COL; // read columns


18
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
colloc &= 0X0F; // mask unused bits

if ( colloc ! = 0X0F // column detected

rowlock = 1; // save row location

break ; // exit while loop

ROW = 0XFB; // ground row 2

colloc = COL; // read columns

colloc &= 0X0F; // mask unused bits

if ( colloc ! = 0X0F // column detected

rowlock = 2; // save row location

break ; // exit while loop

// check column and send result to the serial port

If ( colloc = = 0X0E)

SerTX ( keypad[rowlock] [0]);

else if ( colloc = = 0X0D)

SerTX ( keypad[rowlock] [1]);

else if ( colloc = = 0X0B)

SerTX ( keypad[rowlock] [2]);

Void SerTX ( unsigned char x)

SBUF = x; // place value in buffer

While ( T1 = = 0) ; // wait until transmitted

TI = 0; // clear flag

Void MSDelay ( unsigned int value )


19
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
{

unsigned int x, y;

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

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

b)Write algorithm and assembly language program to add two BCD numbers stored at internal RAM
locations 40 H and 41H .store the result at internal RAM location 42H.

ALgorithm

Load the contents of mem location 40H into accumulator

Add contents of accumulator with contents of mem location

Adjust result to BCD

Store the result in mem location 42H

Program

MOV A,40H ;Load the contents of mem location 40H into accumulator

ADD A,41H ;Add contents of accumulator with contents of mem location

DAA ;Adjust result to BCD

MOV 42H,A ;Store the result in mem location 42H

Sjmp $

20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

c)Draw the diagram to interface 8 switches to Port 1 and 8 LED’s to Port 2 of 8051.Write “C” language
program to display switch status on LED’s

21
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

Q6)Attempt any four:

a) Explain the timer modes of 8051.

Ans: Operating modes of Timer: The timer may operate in any of the four modes that
aredeterminedbyM1 and M0 bit in TMOD register.

Mode0:

In mode0 the register THX is used as 8 bit counterand TLX is used as5 bitcounter.Thepulse i/p
isdivided by(32)10so that TH counts. Henceoriginal oscillatorfrequencyis divided
by(384)10.Thetimer flagis setwhenTHXrolls over fromFFto 00H.
Mode1:

It is similarto Mode0 except TLX is configured as a full8-bit counter. Hencepulse inputis divided
by25610so that TH counts the timer flagis set when THX rolls over fromFFto 00H

22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
In this modeonlyTLX isused as 8-bitcounter. THXis used to hold the value which is
loadedin TLX initially.EverytimeTLX overflows from FFH to 00H thetimer flagis set
and thevalue from THX is automaticallyreloaded in TLXregister.

Mode 3

In this mode, timer0 becomes two completed separate 8-bittimers. TL0 is controlled
bygatearrangement oftimer0and sets timer 0 flag when itoverflows.TH0 receives the timerclock
under the control of TR1 bit and sets TF1 flagwhen itoverflows. Timer 1 maybeused in mode 0, 1
and 2 with oneimportant exception that no interrupt will be generated bythe timer when the timer 0
is usingTF1 overflow flag

Draw circuit diagram to interface common anode 7 segment display to 8051 and write „C‟ language
program to display number 0.

8
0
5
1

OR

23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

Program:

// C language program for 7 Segment display interfacing


#include <Intel\8052.h>
#include <standard.h>
/*SEVEN SEGMENT DISPLAY
DP G F E D C B A

NO D7 D6 D5 D4 D3 D2 D1 D0
0 0 1 0 0 0 0 0 0 =40H
A = P1.0 B = P1.1 C = P1.2 D = P1.3
E = P1.4 F = P1.5 G = P1.6 DP= P1.7
*/
void main ()
{
P1 = 0xFF; //DISPLAY OFF
while(1)
{
P1 = 0x40; //DISPLAY 0
24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
delay_ms(1000);
}
}
NOTE: Program may change. Student can also use the other logic.
Please check the logic and understanding of students.
c)List any four addressing modes of 8051 with one example each.

Ans: (1 Mark—each addressing mode with example --any four)

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:

25
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
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:
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.
d) Draw the format of PSW register of 8051 with one example each.

CY AC F0 RS1 RS0 OV -- P

CY PSW.7 CarryFlag.

AC PSW.6 Auxiliarycarryflag.
F0 PSW.5 Available to the userforgeneral purpose.
RS1 PSW.4 Register bank selector bit 1.

RS0 PSW.3 Register bank selector bit 0.


OV PSW.2 Overflowflag.

26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________
-- PSW.1 User-definable bit.
P PSW.0 Parity flag. Set/cleared by hardware each instruction cycle to

1. CY:the carry flag.This flag is set whenever there


indicateand is a carryout
Odd/even from1the
numberof bit D7 bit.accumulator.
in the The flag bitis
affected after an 8 bit addition or subtraction.

It can also be set to 1 or0 directly by an instruction such as“SETBC” and


CLR C”where“SETBC”stands for “set bit carry”and“CLR C” for “clear carry”.

2. AC:the auxiliary carry flag If there is a carry from D3 and D4 during an ADD or SUB operation,
this bit is set; it is cleared. This flag is used by instructions that perform BCD (binarycoded
decimal)arithmetic.

3. F0:Available to theuser forgeneral purposes.

4. RS0, RS1: register bank selects bits These two bits are used to select one of the four register
banks n internal RAM in the table. By writing zeroes and ones to these bits, a group of registers R0-
R7can be used out off our registers banks in internal RAM.

RS1 RS0 Spacein RAM


0 0 Bank 0 (00H-07H)
0 1 Bank 1 (08H-0FH)
1 0 Bank2 (10H-17H)
1 1 Bank3 (18H-1FH)

.OV:
Overflow
flag

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

6.P:Parity
flag
The parity flag reflects the number of 1sin the A(accumulator) register only.If the A register
contains an odd number of 1s, then P=1.P=0 if A has an even number of 1s.

27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_____________________________________________________________________________________________

e)Draw interfacing diagram to interface relay to port pin P3.0 and opto isolator to port pin P3.7 of 8051
microcontroller

28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
WINTER– 16 EXAMINATION (Subject Code: 17509)
Model Answer
Important Instructions to examiners:
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.

Q. Sub Answer Marking


No. Q.N. Scheme
Q.1 A Attempt any three: 12-Total
Marks
1 a) State any eight features of 8051 microcontroller. 4M
Ans:  It is an 8bit microcontroller. ½M
 8bit accumulator, 8bit Register and 8bit ALU. Each
 On chip RAM 128 bites (data memory).
 On chip ROM 4 Kbytes (program memory).
 Two 16bit counter/ timer.
 A 16 bit DPTR(data pointer)
 Two levels of interrupt priority.
 4 byte bi-directional input/ output port.
 Power saving mode (on some derivatives).
 16bit address bus:-it can access 2^16 memory locations:-64kb (65536) each of RAM
and ROM.
 It is an inclusion of Boolean processing system, have an ability to allow logic
operations to be carried out on registers and RAM.
 8bit data bus:-it can access 8bit of data in one operation.
 It also consist of 3 internal and two external interrupts
 UART (this serial communication port makes chip to use simply as a serial
communication interface)
 It has four separate Register set. (Each contains 8 Registers (R0 to R7)).

Microcontroller & Applications Page 1


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
b) Draw format of PSW register in 8051 microcontroller and state significance of each bit. 4M

Ans: Format:
2M
Significa
nce:2M

PSW register is one of the most important SFRs. It contains several status bits that reflect the
current state of the CPU. Besides, this register contains Carry bit, Auxiliary Carry, two
register bank select bits, Overflow flag, parity bit and user-definable status flag.

P - Parity bit. If a number stored in the accumulator is even then this bit will be
automatically set (1), otherwise it will be cleared (0). It is mainly used during data transmit
and receive via serial communication.

- Bit 1. This bit is intended to be used in the future versions of microcontrollers.

OV Overflow 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

RS0, RS1 - Register bank select bits. These two bits are used to select one of four register
banks of RAM. By setting and clearing these bits, registers R0-R7 are stored in one of four
banks of RAM.

Microcontroller & Applications Page 2


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
RS1 RS0 SPACE IN RAM
0 0 Bank0 00h-07h
0 1 Bank1 08h-0Fh
1 0 Bank2 10h-17h
1 1 Bank3 18h-1Fh

F0 - Flag 0. This is a general-purpose bit available for user.

AC - Auxiliary Carry Flag is used for BCD operations only. If there is a carry from D3 and
D4 during an ADD or SUB operation, this bit is set.

CY - Carry Flag is set whenever there is a carry out from D7 bit. It is affected after all
arithmetical operations and shift instructions.

It also can be set to 1 or 0 using instructions SETB c and CLR c

c) Explain the interfacing of 3x 3 key matrix with 8051 microcontroller. 4M

Ans: Diagram
:2M
Explanat
ion:2M

Microcontroller & Applications Page 3


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
Explanation:

• It is the function of the microcontroller to scan the keyboard continuously to detect


and identify the key pressed
• First microcontroller checks whether all keys are open before the start of operation,
by grounding all the rows and ensuring that the input port has 111.
• To detect a pressed key, the microcontroller again grounds all rows by providing 0 to
the output latch, then it reads the columns
• If the data read from columns is D2 – D0 = 111, no key has been pressed and the
process continues till key press is detected
• If one of the column bits has a zero, this means that a key press has occurred
• Then the program waits for 20ms (debounce time) and check for the key pressed
again. If still the key pressed is detected, it proceeds.
• After detecting a key press, microcontroller will go through the process of identifying
the key
• Starting with the top row, the microcontroller grounds it by providing a low to row
D0 only
• It reads the columns, if the data read is all 1s, no key in that row is activated and the
process is moved to the next row
• It grounds the next row, reads the columns, and checks for any zero
• This process continues until the row is identified
• After identification of the row in which the key has been pressed Find out which
column the pressed key belongs to
• Upon finding the row that the key press belongs to, it sets up the starting address for
the look-up table holding the scan codes (or ASCII) for that row
• To identify the key press, it rotates the column bits, one bit at a time, into the carry
flag and checks to see if it is low
• Upon finding the zero, it pulls out the ASCII code for that key from the look-up table
• Otherwise, it increments the pointer to point to the next element of the look-up table

d) State any four C data types with their value range. 4M

1M
Each

Microcontroller & Applications Page 4


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
B) Attempt any one: 6M

a) Draw internal RAM organization of microcontroller 8051 and show address areas for 6M
each Section.
Ans: 6M

Microcontroller & Applications Page 5


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________

Microcontroller & Applications Page 6


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
b) Write an ALP to find the largest number in an array of 10 numbers stored in internal 6M
RAM
Ans: ORG 0000H 6M
MOV R1,#0AH
MOV R0,#40H
DEC R1
MOV 60H, @R0
UP: INC R0
MOV A, @R0
CJNE A,60H,DN
AJMP LARGE
DN: JC LARGE
MOV 60H, A
LARGE: DJNZ R1, UP
END

( Any other relevant correct logic can be given full marks)

Q2 Attempt any two: 16M


a) Write a assembly language program for 8051 microcontroller to generate a delay of 1 8M
second. Use timerl.Assume crystal frequency =12 MHz. Draw flowchart.
Ans: Calculations: calculati
Crystal freq = 12MHz on:1m,
Timer frequency= 12MHz/12= 1MHz Program
Input Time= 1/1MHz= 1us : 3M,
For delay of 50ms comment
50ms/1us= 50000 s:1M
Therefore count to be loaded in TH1 and TL1 can be calculated as 65536-50000= 15536d = flowchar
3CB0H t:3M
Program:
MOV TMOD, #10H ; Timer 1 , mode 1
HERE: MOV R0, #20 ; counter for 1s delay (50ms*20=1sec)
CPL P2.0 ; complement P2.0
BACK: MOV TL1, #0B0H ; load count value in TL1
MOV TH1, #3CH ; load count value in TH1
SETB TR1 ; start Timer1
AGAIN: JNB TF1, AGAIN ; stay until timer rolls over
CLR TR1 ; stop timer
CLR TF1 ; clear timer flag
DJNZ R0, BACK ; if R0 is not equal to 0,reload timer
SJMP HERE ; repeat

Microcontroller & Applications Page 7


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________

Microcontroller & Applications Page 8


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
b) Draw interfacing diagram of 8 bit serialADC, MAX112 with 8051 microcontroller. 8M

Write aC language program to read data.


Ans: Diagram
:4M
Program
:4M

Program:

# include <reg51.h>

sbit CS =P2^0;

sbit SCLK =P2^1;

sbit DIN =P2^2;

sbit DOUT=P2^3;

sbit LSBRA = ACC^0;

void main( )

Unsigned char x;

CS=0; //select max1112

SCLK =1; //an extra H to L pulse

Delay( );

SCLK=0;

Microcontroller & Applications Page 9


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
Delay( );

for (x=0; x<8; x++) //get all 8 bits

SCLK=1

Delay( );

SCLK=0;

Delay ( )

LSBRA=DOUT; // bring in bit from DOUT

//pin to DO of Reg A

ACC=ACC <<1; //Keep shifting data

// for all 8 bits

CS=1; //deselect ADC

P1=ACC; //display data on P1

c) Draw interfacing diagram of stepper motor control with 8051 microcontroller. Draw 8M
flow chart to rotate a stepper motor clockwise through 360°.Assume step angle of 1.8 ° .
Ans: Diagram
:4M,
Flowcha
rt:4M

Microcontroller & Applications Page 10


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________

Microcontroller & Applications Page 11


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
Q. 3 Attempt any four: 16M
a) Draw neat labeled interfacing diagram of LCD with 8051 microcontroller. 4M
Ans: Diagram
:4M

b) Compare Von-Neumann and HarwardArchitecture. Give examples. 4M


Ans: Any four
points:4
M

Microcontroller & Applications Page 12


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
c) Write down instructions to READ input port and send hex data to output port using 4M
“C”operators.
Ans: #include <reg51.h> 4M
void main(void)
{
P1=0xFF; //make P1 input port
P3=0x00; //make P0 output port
while (1)
{
P3=P1;
}
}

Note: Any other correct program logic can be given marks.


d) Describe timer operations of 8051 microcontroller in mode 1 and mode 2 with respect 4M
to application and advantages.
Ans: Mode 1 - 16-bit mode Mode1:2
M
Mode2:2
M

The high byte (THx) is cascaded with the low byte (TLx) to produce a 16-bit timer. This
timer counts from 0000H to FFFFH - it has 216 (65,536) states. An overflow occurs during
the FFFFH to 0000H transition, setting the overflow flag.This is a very commonly used
mode to generate time delay using 16bit count.

Mode 2- 8-bit auto-reload mode

The timer low byte (TLx) operates as an 8-bit timer (counting to FFH) while the high-byte (THx) holds a re
value. When the timer overflows from FFH, rather than starting again from 00H, the value in THx is loaded
TLx and the count continues from there. The auto-reload mode is very commonly used for generating baud r
.which is used for Serial Communication.

Microcontroller & Applications Page 13


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
e) Describe stack operations in 8051 microcontroller with suitable examples. 4M
Ans: Stack Memory is a part of internal data memory which is used for temporary data storage in PUSH
8051.Stack pointer is used to point to stack memory. Data is stored in stack memory using operatio
PUSH instruction and is retrieved using POP instruction. n:2M
POP
PUSH operation
operatio
n :2M
The PUSH instruction increments the stack pointer and stores the value of the specified byte
operand at the internal RAM address indirectly referenced by the stack pointer.

POP Operation

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.

Microcontroller & Applications Page 14


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
Q. 4 A) Attempt any three: 12M
a) Draw interfacing diagram for temperature measurement using LM35 with 8051 4M
Microcontroller.
Ans: Labeled
Diagram
:4M

OR

Microcontroller & Applications Page 15


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
b) Write C language program to toggle a bit of P 1.5 continuously with 250 msec. delay. 4M
Use timer 0, mode 2. Assume crystal freqn. 11.0592 MHz.
Ans: Solution: Calculati
CALCULATIONS on:2m,
Delay of 250ms=1000 X 250us Program
For 250us, calculation of count :2m
Crystal frequency= 11.0592 MHz
I/P clock = (11.059 X 106)/12= 1000000 = 921.58KHz
T-XTAL= 1/f-XTAL
=1/921.58 x 10^(3)
=1.085us
256-count = 250us/1.085us=230.42
The count which is to be loaded in timer register=256-230=26 decimal=1AH.
Load TL and TH with 1AH.
PROGRAM:
#INCLUDE <REG51.H>
SBIT TOGGLE = P1^5;
UNSIGNED INT X;
TMOD=0X02;
WHILE(1)
{
TL0=0XIA;
TH0=0X1A;
TOGGLE=~TOGGLE
TR0=1;
FOR (X=0;X<1000;X++)
{
WHILE(TF0==0);
TF0=0;
}
TR0=0;
}
c) Compare RISC and CISC machines with examples. 4M
Ans: RISC CISC Example
Emphasis on software. Due to few Emphasis on hardware. :1M,Any
instructions hardware implementation is three
less points:3
Single-clock, reduced instruction only Includes multi-clock complex instructions. M
Register to register: “LOAD” and Memory to memory: “LOAD” and “STORE”
“STORE” are independent instructions. incorporated in instructions.
Low cycles per second, large code sizes. Small code sizes, high cycles per second.
More Instructions to write the code for Code can be written effectively in few lines
the same task Instruction code becomes short, saving the
program memory space
Fewer, Faster and Simpler Instruction Larger instruction set Hence flexibility in
Set writing programmers.
Spends more transistors on memory Transistors used for storing complex
registers. instructions.
e.g. PIC microcontrollers by Microchip e.g. MCS-51 (Note the MULTIPLY
instruction )

Microcontroller & Applications Page 16


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
d) Describe operations of DPTR register in 8051, along with related instructions. 4M
Ans:  The SFRs. DPL and DPH work together to represent a 16- bit value called Data Pointer. Operatio
ns:2m,
related
instructi
 DPTR can also be accessed as two 8-bit registers, the high byte DPH and low byte DPL. ons:2m
 The Data Pointer, DPTR, is a special 16-bit register used to address the external code or
external data memory.
 Since the SFR registers are just 8-bits wide the DPTR is stored in two SFR registers,
where DPL (82h) holds the low byte of the DPTR and DPH (83h) holds the high byte of
the DPTR.
 For example, if you wanted to write the value 46h to external data memory location
2500h, you might use the following instructions:
MOV A, #46h ;Move immediate 8 bit data 46h to A (accumulator)
MOV DPTR, #2500h ; Move immediate 16 bit address value 2504h to A.
; Now DPL holds 04h and DPH holds25h.
MOVX @DPTR, A ; Move the value in A to external RAM location
2500h.Uses indirect addressing.
 Note the MOVX (Move X) instruction is used to access external memory

 MOV DPTR, # 16 bit data ; 16 bit data is transferred to DPTR register.


(DPTR) (DPTR) + 1
 MOVC A,@A+DPTR
Operation: MOVC
(A) ((A) + (DPTR))
 MOVX A,@DPTR
Operation: MOVX
(A) ((DPTR))

B) Attempt any one: 6M


a) Describe any four assembler directives used in 8051 programing. 6M
Ans: i)DB ii) ORG iii) EQU iv) END Each
i) DB: directive
LABEL: DB BYTE : 11/2
Marks
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.

ii) EQU: Equate


It is used to define constant without occupying a memory location.
Syntax:
Name EQU Constant

Microcontroller & Applications Page 17


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
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).

iii) ORG: Origin


It is used to indicate the beginning of address.
Syntax:
ORG Address

The address can be given in either hex or decimal there should be a space of at least
one character between ORG & address fields. Some assemblers use ORG should not
begin in label field.

i v ) 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

b) Draw the format of TCON register in 8051 and describe in short. 6M


Ans: Format
2M
Descripti
on:
4M

TF1 TCON. 7 Timer 1 overflow flag. Set by hardware when the


Timer/Counter 1 Overflows. Cleared by hardware as
processor vectors to the interrupt service routine.

TR1 TCON. 6 Timer 1 run control bit. Set/cleared by software to turn


Timer/Counter 1 ON/OFF.

TF0 TCON. 5 Timer 0 overflow flag. Set by hardware when the


Timer/Counter 0 overflows. Cleared by hardware as processor
vectors to the service routine.

TR0 TCON. 4 Timer 0 run control bit. Set/cleared by software to turn


Timer/Counter 0 ON/OFF.

IE1 TCON. 3 External Interrupt 1 edge flag. Set by hardware when


External Interrupt edge is detected. Cleared by hardware
When interrupt is processed.

IT1 TCON. 2 Interrupt 1 type control bit. Set/cleared by software


Microcontroller & Applications Page 18
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
To specify falling edge/low level triggered External
Interrupt.

IE0 TCON. 1 External Interrupt 0 edge flag. Set by hardware when


External Interrupt edge detected. Cleared by hardware
When interrupt is processed.

IT0 TCON. 0 Interrupt 0 type control bit. Set/cleared by software to


specify falling edge/low level triggered External
Interrupt

Q.5 Attempt any two: 16 M


a) Write a assembly language program for 8051 microcontroller to generate a square 8M
wave of 2 KHz frequency on Pin P 1.5. Assume crystal freqn. = 11.0592 MHz.
Ans: Crystal frequency= 11.0592 MHz Calculati
I/P clock = (11.059 X 106)/12= 1000000 = 921.58KHz on:3M,
Tin = 1.085μ sec Program
For 2 kHz square wave : 4M,
Fout = 2 KHz comment
Tout = 1/ 2X 103 :1M
Tout = 0.5msec =500us
Consider half of it = Tout = 250μ sec
N = Tout / Tin = 250/1.085 = 230.41
65536-231= (65305)10 = (FF19)16

Program:-

MOV TMOD, # 01H ; SET TIMER 0 IN MODE 1, I.E., 16 BIT


TIMER
L2: MOV TL0, # 19H ; LOAD TL REGISTER WITH LSB
OF COUNT
MOV TH0, # 0FFH ; LOAD TH REGISTER WITH MSB
OF COUNT
SETB TR0 ; START TIMER 0
L1: JNB TFO, L1 ; POLL TILL TIMER ROLL OVER
CLR TR0 ; STOP TIMER 0
CPL P1.5 ; COMPLEMENT PORT 1.4 LINE TO GET
HIGH OR LOW
CLR TF0 ; CLEAR TIMER FLAG 0
SJMP L2 ; RE-LOAD TIMER WITH COUNT AS MODE 1
IS NOT AUTO RELOAD

Microcontroller & Applications Page 19


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
b) Write C language program to receive bytes of data serially and put them in port P1. Set 8 M
baud rate of 4800, 8 bit data and 1 stop bit. Assume crystal freqn. = 11.0592 MHz.
Ans: Correct
Program
: 5M
Calculati
on: 2 M
comment
:1M

c) What is integrated development environment for microcontroller based systems? 8M


Describe at least four features of Keil µ -vision.
Ans: IDE (Integrated Development Environment) is used to develop the fully simulated, tested IDE-4M
and debugged sophisticated embedded systems with simpler efforts.IDE consists of Keil-4M
Microcontroller & Applications Page 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
Simulators, Editors, compilers, Assemblers etc. Some of the functions of IDE are:

 Provides Windows on the screen for the detailed information of source code part
with labels, registers as the execution continues, status of peripheral devices, status of
RAM and ports etc.
 Verifies the performance of a target system that an emulator built into the
development system, which remains independent of a particular targeted system
 Includes a logic analyzer for up to 256 or 512 transactions on the address and data
buses after triggering
 Simulates on a host system (PC), the hardware unit like emulator, peripherals, and
I/O devices.
 Debug by single stepping.

Features of Keil:
 The µVision IDE combines project management, run-time environment, build
facilities, source code editing, and program debugging in a single powerful
environment.
 µVision is easy-to-use and accelerates your embedded software development.
 µVision supports multiple screens and allows you to create individual window
layouts anywhere on the visual surface.
 The µVision Debugger provides a single environment in which you may test, verify,
and optimize your application code.
 The debugger includes traditional features like simple and complex breakpoints,
watch windows, and execution control and provides full visibility to device

Microcontroller & Applications Page 21


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
peripherals.

Q.6 Attempt any FOUR of following: 16 M


a) Draw format of IE register in 8051 microcontroller and explain each bit. 4M
Ans: (MSB) (LSB) Format:
EA - - ES ET1 EX1 ET0 EX0 2M
Explanat
ion:2m

Symbol Position Name and Significance

EA IE.7 EA = 1, interrupts are enabled and will be responded to if their


corresponding bits in IE are high. If EA = 0, no interrupt will be
responded to, even if the associated bit in the IE register is high.

- IE.6 (Reserved)

- IE.5 (Reserved)

ES IE.4 Enable Serial port control bit


Set/cleared by software to enable/disable interrupts from Tl or
Rl flags.
ET1 IE.3 Enable Timer 1 control bit.
Set/cleared by software to enable/disable interrupts from
timer/counter 1
EX1 IE.2 Enable External interrupt 1 control bit.
Set/cleared by software to enable/ disable interrupts from INT1.
ET0 IE.1 Enable Timer 0 control bit
Set/cleared by software to enable/disable interrupts from
timer/counter 0.
EX0 IE 0 Enable external interrupt 0 control bit.
Set/cleared by software to enable/disable interrupts from INTO.

b) Draw and explain the interfacing of ADC with 8051 microcontroller. 4M

Microcontroller & Applications Page 22


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
Ans: Diagram
:2M
Explanat
ion:2M

ADC808 Chip with 8 analog channels. This means this kind of chip allows to monitor 8
different transducers.
• ALE: Latch in the address
• Start : Start of conversion
• OE: output enable
• EOC: End of Conversion
Select an analog channel by providing bits to A, B, and C addresses.
2. Activate the ALE pin. It needs an Low-to-High pulse to latch in the address.
3. Activate SC (start conversion) by an High-to-Low pulse to initiate conversion.
4. Monitor EOC (end of conversion) to see whether conversion is finished.
5. Activate OE (output enable) to read data out of the ADC chip. A High-to-Low pulse to the
OE pin will bring digital data out of the chip.

c) Write an ALP for 16 bit multiplication. Assume numbers to be stored in internal RAM. 4M
Ans: (Assume first 16-bit number is stored in 40H and 41H and second 16-bit number is 4M
stored in 42H and 43H.;Result is in 20H,21H,22H & 23H)

MOV R1,41H
MOV R2,43H
MOV R3,40H
MOV R4,42H

MOV A,R3
MOV B,R4
MUL AB
MOV 20H,A
MOV 21H,B

MOV A,R3
MOV B R2
MUL AB
MOV 22H,B
ADDC A,21H
MOV 21H,A

MOV A,R1
MOV B,R4
MUL AB

Microcontroller & Applications Page 23


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
ADDC A,21H
MOV 21H,A
MOV A,B
ADDC A,22H
MOV 22H,A

MOV A,R1
MOV B,R2
MUL AB
ADDC A,22H
MO 22H,A
MOV A,B
ADDC A,#00H
MOV 23H,A
END

( Program with any other relevant logic can be given full marks)
d) State and explain the interrupts used in 8051 microcontroller. 4M
Ans: The 8051 provides five interrupt sources. These are listed below as per their default priority 4M
are:

1. Timer 0 (TF0)
2. External hardware interrupt, INT0
3. Timer 1 (TF1)
4. External hardware interrupt, INT1
5. Serial communication interrupt TI and RI

TIMER FLAG INTERRUPT:


When a timer/counter overflows, the corresponding timer flag, TF0 or TF1, is set to 1.
This can cause Timer 0 or Timer 1 interrupts. The flag is cleared to 0 when the resulting
interrupt generates a program call to the appropriate timer subroutine in memory.

EXTERNAL INTERRUPTS:
Pins INT0 and INT1are used by external circuitry. Inputs on these pins can set the
Interrupt flags IE0 and IE1 in TCON register to 1 by two different method. The IEX
flags may be set when the INTX pin signal reaches a low level, or the flags may be set
when a high-to-low transition takes place on the INTX pin. Bits IT0 and IT1 in TCON
program the INTX pin for low level interrupt when set to 0 and program the INTX pins
for transition interrupt when set to 1.

SERIAL PORT INTERRUPT:


If a data byte is received serially an interrupt bit ,RI, is set to 1 in the SCON register.
When a data byte has been transmitted serially an interrupt bit , TI, is set in SCON.

Microcontroller & Applications Page 24


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 17509
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
_________________________________________________________________________________________________________________
e) Draw neat labeled interfacing diagram to control a lamp at pin P1.0, by using 4M
Optoisolator with 8051 microcontroller.
Ans: 4M

Microcontroller & Applications Page 25


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
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

Important Instructions to examiners:


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.

Q. No. Sub Answer Marking


Q.N. Scheme
Q.1 (A) Attempt any THREE: 12-Total
Marks
a) Draw symbol and write truth table for AND and EXOR gate. 4M
Ans: Symbol and truth table of AND gate Each
symbol 1M
Each TT
1M

Symbol and truth table of EXOR gate

b) Draw the format of SCON register. 4M

Page1/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

Ans: SCON Register format- Correct


format 4M

c) List any four C-data types with its range and size. 4M

Ans: Any 4-1M


each

d) Compare 8051 and 8052 microcontrollers ( four points). 4M

Ans: Any 4
points-1M
each

B) Attempt any one. 6M

a) Draw the structure of internal RAM of 8051. 6M


Ans: Correct
labeled
diagram
Page2/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

6M

(OR)

Page3/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

b) Explain following instructions with example. 6M


i)MOVC A,@A+DPTR
ii)DAA
iii)XCHD A,@Ri

Ans: i)MOVC A,@A+DPTR Each


The instruction moves data from the external code memory to the accumulator. The instruction
2M
address of 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 is referred to as the index address.
No of bytes: 1 byte .Addressing mode: register
ii)DAA
DA A -Decimal Adjust Accumulator
DA adjusts the contents of the Accumulator to correspond to a BCD (Binary Coded
Decimal) number after two BCD numbers have been added by the ADD or ADDC
instruction.
If the auxiliary carry bit is set or if the value of bits 0-3(lower nibble)exceed 9, 0x06 is
added to the accumulator. If the carry bit is set or if the value of bits 4-7 (higher
nibble) exceed 9, 0x60 is added to the accumulator.
No of bytes: 1 byte .Addressing mode: register
For eg. A=0Ch After execution A=12 BCD
iii)XCHD A,@Ri
Exchange Digit-Exchanges bits 0-3 of the Accumulator with bits 0-3 of the Internal
RAM address pointed to indirectly by R0 or R1. Bits 4-7 of each register are
unaffected.
No of bytes: 1 byte .Addressing mode: register indirect.

Page4/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

Q2 Attempt any two. 16M


(a) Write an ALP to arrange 10 bytes in internal RAM location in ascending order. 8M

Ans: Flow chart for ascending order: Flowchart


3M
Program
5M

Page5/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

Program:

MOV R3,#09H
L2:MOV R2,#09H
MOV R0,#30H
L1:MOV A,@R0
INC R0
SUBB A,@R0
JC L0
MOV A,@R0
DEC R0
XCH A,@R0
INC R0
MOV @R0,A
L0:DJNZ R2,L1
DJNZ R3,L2
END
(b) Interface ADC 0809 to 8051 and write c program to read analog data at CH7 and 8M
convert it to digital
Ans: Interfacing of ADC with 8051: Diagram
4M
Program
4M

Page6/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

(OR)

Program:
#include <reg 51.h>
sbit ALE = P2^4;
sbit OE = P2^5;

Page7/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

sbit SC = P2^6;
sbit EOC = P2^7;
sbit ADDR_A = P2^0;
sbit ADDR_B = P2^1;
sbit ADDR_C = P2^2;
Sfr MYDATA = P1;
Void MSdelay(void);
void main()
{
unsigned char value;
MYDATA = OxFF;
EOC = 1;
ALE = 0;
OE = 0;
SC = 0;
while(1)
{ADDR_C = 1;
ADDR_B = 1;
ADDR_A = 1;
MSDelay(1);
ALE = 1;
MSDelay(1);
SC = 1;
MSDelay (1);
ALE = 0;
SC = 0;
while(EOC==1);
while(EOC==0);
OE = 1;
MSDelay(1);
value = MYDATA;
OE = 0;
}}
Void Msdelay(unsigned int itime)
{
Int i,j;
for(i=0;i<itime;i++)
{
for (j=0;j<1275;j++);
}
}
(c) Interface stepper motor with 8051 and explain logic to rotate it clockwise by 360. 8M
Assume step angle 1.8.(No program).
Ans: Stepper motor interfacing- Diagram
4M

Page8/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

Logic 4M

(OR)

Logic : (any other similar logic can be considered)


• Step angle is defined as the minimum degree of rotation with a single step.
• No of steps per revolution = 360° / step angle
• step angle = 1.8°
• No of steps per revolution = 200.
• The coils need to be energized for the rotation. This can be done by sending a
bits sequence to one end of the coil from microcontroller port while the other
end is commonly connected.
• The bit sequence sent can make either one phase ON or two phase ON for a full

Page9/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

step sequence or half step sequence.


• Stepper motor rotates 1.8° for each sequence
• After each sequence a delay is provided and procedure is repeated for 200 steps
to get the required rotation of 360.

Q. Sub. Answer Marking


No. Q. No. Scheme
3 Attempt any four 16 marks
a ̅̅̅̅̅̅̅̅ pins of 8051.
Write the function of ALE and 𝐏𝐒𝐄𝐍 4 marks
Ans. 1. ̅̅̅̅̅̅̅̅
𝐏𝐒𝐄𝐍 2 marks each
It is active low output control signal. It is used to fetch code from external program
memory by activating enable signal OE of the external ROM/ EPROM
2. ALE
ALE (address latch enable) is an active high output pin. It is used for demultiplexing the
lower order address and data. There are two ALE pulses per machine cycle. The ALE
pulse is generated every time an external memory is accessed.
b What will be the content of PSW after addition of 2Bh and 9Dh? 4 marks
Ans. 111 111 1 mark for
2Bh- 0010 1011 calculation,
9Dh- 1001 1101 1 mark each
After adding the two 11001000 – C8h for CY, AC
CY = 0 (no carry) & P values
AC = 1 (Auxiliary is 1)
P = 1 (odd no. of 1s)
OV =0
F0, RS1, RS2 remain unchanged

c Which are the components of IDE? Write function of any 4. 4 marks


Ans. Components of IDE: List:2 Marks,

Page10/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

• Compiler
• Cross assembler
• Cross compiler
• Linker/ Locators
• Loaders
• Simulators
• Debugger
Function: ( Any four component)
Compiler:
It is a computer program that transforms the source code written in a programming or
source language into another computer language i.e. target language i.e. binary code
known as object code. Each
Cross assembler: Function-
It is useful to convert object codes for microcontrollers or processor to other codes for ½M
another microcontrollers or processor and vice versa.
Cross compiler:
It is used to create executable code other than one on which the compiler is run.
They are used to generate executable for embedded systems or multiple platforms.
Linker/Locator:
It is used for relocation process.
It is done during compilation also it can be done at run time by a relocating loader.
It is a program that takes one or more objects generated by compiler and combines them
into a single executable program.
Simulators:
A simulator is the software that simulates an hardware unit like emulator, peripheral,
network and I/O devices on a PC. It defines a processor or processing device as well
as various versions for the target system. It also monitors the detailed information as
source code part with labels and symbols during the execution for each single step.
It provides the detailed information of the status of memory RAM and simulated ports,
simulated peripheral devices of the defined target system.

Page11/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

Debugger:
It is a program that is used to test and debug the target program. Debugger allows to
download code to the Emulator’s memory and then control from PC. It also allows the
programmer to examine and modify the On-chip register and program memory data

d Compare Von Neumann and Harvard architecture. 4 marks


Ans. (Any four points) 1 mark for

Sr. Von-Neumann Harvard architecture each correct

No. architecture point

1 Uses single memory for Uses separate memory


instruction and data for instruction and data
2 Same bus is used for Requires separate and
instruction and Dedicated buses for
data memory instruction and
data memory
3 Design is simpler Design is complicated
4 Instruction and data has Instruction and data can be
to be fetched fetched simultaneously
sequentially
5

e List modes of serial communication in 8051. Explain mode 3 in detail. 4 marks

1 mark for
Page12/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

Ans. list, 3 marks


Modes of Serial communication:
for correct
explanation
SM0 SM1 Mode Baud Rate

0 0 Mode 0 f/12

0 1 Mode 1 Variable determined by Timer 1

1 0 Mode 2 f/32 or f/64

1 1 Mode 3 Variable determined by Timer 1

Mode 3
In mode 3, 11 bits are transmitted through the TXD pin or received through the RXD
pin: a START bit (always 0), 8 data bits (LSB first), a programmable 9th data bit and a
STOP bit (always 1). On transmit, the 9th data bit is actually the TB8 bit of the SCON
register. This bit usually has a function of parity bit. On receive, the 9th data bit goes
into the RB8 bit of the same register (SCON).
The baud rate is decided by Timer1 Overflow time

TRANSMIT – Data transmit is initiated by writing data to the SBUF register. End of
data transmission is indicated by setting the TI bit of the SCON register.

Page13/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

RECEIVE – The START bit (logic zero (0)) on the RXD pin initiates data receive.
The following two conditions must be met: bit REN=1 and bit RI=0. Both of them are
stored in the SCON register. The RI bit is automatically set upon data reception is
complete.

4 A Attempt any three: 12marks


a Interface DC motor with 8051. 4 marks
Ans 4 marks for
correct
diagram

b Write C program to read P1 and send it to P2. 4 marks


Ans ’C’ Language program: 4 marks for
correct
#include <reg51.h>
void main(void) program
{
unsigned char mybyte;

Page14/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

P1=0xFF; //make Port1 input port


P2=0X00; // make Port2 output port
while (1)
{
mybyte= P1; //get a byte from P1
P2= mybyte; //send compliment of it to P2
}
}

c Use NAND gate to implement AND, OR and NOT gate. 4 marks


Ans. OR gate using NAND gate 2 marks for
OR and 1
mark for
each AND
and
NOT gate
̅̅̅̅̅
̅. 𝐁
𝐀 ̅=𝑨̅+ 𝑩
̅ = A+B

AND gate using NAND gate

NOT gate using NAND gate

Page15/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

d Draw block diagram of 8051. 4 marks


Ans. 4 marks for
correct
diagram

B Attempt any one: 6 marks


a Write an ALP to generate square wave of 1 KHZ frequency. Assume fosc = 12MHz 6 marks
Ans. Square wave Frequency = 1khz delay
Therefore Time period T = 1 / 1KHZ = 1 ms calculation:

Therefore TON = TOFF = 1ms / 2 = 0.5 ms = 500 µsec 2 marks ,


Program :
Required time delay = ( 12 / fosc ) x number of increments (N)
4 marks
500 µsec = ( 12 / 12MHZ ) x number of increments (N)
= 1 µsec x N
So, N = 500

Using TIMER 0 in MODE 1,


COUNT = 216 - N
COUNT =65536 – 500
=65036

Page16/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

= FE0C H

Assembly language program :


ORG 0000H

MOV TMOD, #01H ; TIMER 0, MODE 1


REP: MOV TL0, #0CH ; Load lower byte of count
MOV TH0, #0FEH ; Load higher byte of count
SETB TR0 ; Start timer 0
BACK:JNB TF0, BACK ; Check if TF0 is SET
CLR TR0 ; Stop the Timer
CPL P1.5 ; Complement P1.5
CLR TF0 ; Clear TF1
SJMP REP ; Repeat

b Draw interrupt structure of 8051 and explain it. 6 marks


Ans. 3 marks for
diagram,
3 marks
for correct
explanation

(OR)

Page17/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

When external interrupt INTX (X=0 or 1) is received,


ITX in TCON triggers the INTX, ITX=0 as level and ITX=1 as edge
triggering.
IEX in TCON=1 activates the interrupt
EXX in IE=1 enables the interrupt
If EA in IE=1, interrupt is generated
For TimerX interrupt
TFX in TCON = 1 activates the interrupt
ETX in IE=1 enables the interrupt
If EA in IE=1, interrupt is generated
For Serial interrupt

Page18/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

RI or SI in SCON =1 activates the interrupt


ES in IE=1 enables the interrupt
If EA in IE=1, interrupt is generated
Q. No. Sub Answer Marking
Q.N. Scheme

Q.5 Attempt any TWO: 16M

a) Interface DAC0808 with 8051and write C-program to generate saw tooth wave on 8M
P2.1

Ans: 4M

#include<reg51.h>

unsigned char d;

void main(void)

while(1)

for(d=0; d<255; d++)

Page19/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

{ 4M

P1 = d;

b) Write an ALP to multiply content of internal RAM location 50h and 51h. Store 8M
the result at 2000h(LSB) and 2001(MSB) in external RAM.

Ans: FLOWCHART: 2M

Page20/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

PROGRAM:

MOV A,50H ; Move the content of 50h to accumulator

MOV B,51H ; Move the content of 51h to accumulator

MUL AB ; Multiply the contents of A and B register

MOV DPTR,#2000H ; Load DPTR with 2000h

MOVX @DPTR,A ; Move the LSB to the External Memory pointed by DPTR

INC DPTR ; Increment DPTR 4M


Program
MOV A,B ; Move the MSB from B register to A
2M
MOVX @DPTR,A ; Move the MSB to the External Memory pointed by DPTR comments
END ; End

c) Explain bitwise shift operation for right shift and left shift with suitable examples. 8M

Ans: Bitwise Left Shift Operator in C: Explanation


:2M each,
• It is denoted by << Syntax: 1M
• Bit Pattern of the data can be shifted by specified number of Positions to Left each,
• When Data is Shifted Left , trailing zero's are filled with zero. Example :
• Left shift Operator is Binary Operator [Bi – two] 1M each
Example:

Syntax : Bitwise Left Shift Operator


[variable]<<<[ Number of Places]

P0=0x3C<< 2

After execution of this instruction


Shift number 2 times to left:
3C=0011 1100
F0=1111 0000

So, P0=0xF0
Bitwise Right Shift Operator in C:
• It is denoted by >>

Page21/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

• Bit Pattern of the data can be shifted by specified number of Positions to


Right
• When Data is Shifted Right , leading zero‟s are filled with zero.
• Right shift Operator is Binary Operator [Bi – two].

Example:
Syntax : Bitwise Right Shift Operator
[variable]>>[number of places]

P0=0x3C >> 2
After execution of this instruction
Shift number 2 times to Right:
3C=0011 1100
0F=0000 1111

So, P0=0x0F

NOTE: Example May change. Please check the logic and understanding of
students.

Q.6 Attempt any FOUR: 16M

a) What is stack memory? Explain PUSH and POP instruction. 4M

Ans: 1. The stack memory is part of RAM used by the CPU to store information Stack
temporarily. explanation
:2M
2. This information may be either data or address.
3. The CPU needs this storage area as there are only a limited amount of registers.

Page22/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

4. The register used to access stack memory is called stack pointer.

PUSH Instruction:
This instruction increments Stack pointer by 1 and then copies the data at the PUSH:1M

direct address to the location pointed by SP.

POP: 1M
POP Instruction:
This instruction copies the data at the location pointed by Stack Pointer to the
direct address given in the instruction and then decrements Stack pointer by 1.

b) Explain the function of RS,R/W and E pins in 16x4 LCD. 4M

Ans: 1. RS: RS is the register select pin used to write display data to the LCD RS: 2M
(characters), this pin has to be high when writing the data to the LCD. During R/W: 1M
the initializing sequence and other commands this pin should low.
EN: 1M

2. R/W: Reading and writing data to the LCD for reading the data R/W pin
should be high (R/W=1) to write the data to LCD R/W pin should be low
(R/W=0).

3. EN: Enable pin is for starting or enabling the module. A high to low pulse of
about 450ns pulse is given to this pin.

c) Explain any four assembler directives. 4M

Ans: DB :The DB directive is the most widely used data directive in the assembler. It is 1M each
used to define the 8-bit data. When DB is used to define data, the numbers can be in
decimal, binary, hex, or ASCII formats.

Example: DATA1 DB 28 (decimal data stored as 1C hex)

Page23/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

DATA2 DB 01010101B (Binary data)

DATA3 DB 5Fh Text

DB “ABCDE” ASCII character array named as Text

ORG: 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.

Example: ORG 0000H

LJMP main

ORG 0030H

MAIN: ….

EQU: This is used to define a constant without occupying a memory location. When
the label appears in the program, constant value will be substituted for the label.

Example: NUMBER EQU 25H

MOV R3,#NUMBER ; R3 = 25H as 25H will be substituted for NUMBER

END: This indicates to the assembler 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.

d) Write the size and function of PC and DPTR. 4M

Ans: PC: (Program Counter) 2M each


(1M size,
• It is a 16-bit register. 1M
• It holds the address of external and internal program memory.

Page24/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

• It points next instruction to be fetched. function)


• It is never used to hold the address of the data memory.
• It cannot be used as data memory location.

DPTR: (Data Pointer)

• It is a 16-bit register.
• It is used to hold the address of the external and internal data memory.
• It is used to store a 16-bit data.
• It is also divided into two 8-bit registers viz. DPH and DPL.
• Each registers can be used to hold a 8-bit data.

e) Explain the logic to measure temperature using LM35. Draw interfacing diagram. 4M

Ans: 2M-
DIAGRAM

2M -
EXPLANA
TION

 LM 35 is a temperature sensor which gives a change in output voltage of 10 mV


for every degree rise in temperature i.e. if the output voltage is 350mV,the
temperature ideally will be 35oC.

Page25/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
WINTER– 17 EXAMINATION
Subject Title: Microcontroller and applications Subject Code: 17509

 LM35 is connected to the input of ADC0809 or any other ADC.

 ADC converts the analog output voltage of LM35 to corresponding digital value.

 This digital value is proportional to the measured temperature.

 It can also be converted to corresponding temperature value using look up table


and can be displayed in LCD.

Page26/26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

Important Instructions to examiners:


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.

Q. Sub Answers Marking


No Q. Scheme
. N.

1 a Attempt any THREE: 12- Total


Marks

i Draw the format of TCON and state the function of each bit in it. 4M

Ans Format-2
: marks

Function-
2marks

Bit Symbol TCON Bit Function

7 TF1 Timer 1 Overflow flag. Set when timer rolls from all 1's to 0. Cleared
when processor vectors to execute interrupt service routine located at
program address 001Bh.

6 TR1 Timer 1 run control bit. Set to 1 by program to enable timer to count;
cleared to 0 by program to halt timer.

5 TF0 Timer 0 Overflow flag. Set when timer rolls from all 1's to 0. Cleared
when processor vectors to execute interrupt service routine located at

Page No: 1/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
program address 000Bh.

4 TR0 Timer 0 run control bit. Set to 1 by program to enable timer to count;
cleared to 0 by program to halt timer.

3 IE1 External interrupt 1 Edge flag. Set to 1 when a high-to-low edge signal is
received on port 3.3 (INT1). Cleared when processor vectors to interrupt
service routine at program address 0013h. Not related to timer
operations.

2 IT1 External interrupt 1 signal type control bit. Set to 1 by program to enable
external interrupt 1 to be triggered by a falling edge signal. Set to 0 by
program to enable a low-level signal on external interrupt 1 to generate
an interrupt.

1 IE0 External interrupt 0 Edge flag. Set to 1 when a high-to-low edge signal is
received on port 3.2 (INT0). Cleared when processor vectors to interrupt
service routine at program address 0003h. Not related to timer
operations.

0 IT0 External interrupt 0 signal type control bit. Set to 1 by program to enable
external interrupt 1 to be triggered by a falling edge signal. Set to 0 by
program to enable a low-level signal on external interrupt 0 to generate
an interrupt.
ii Compare between RISC and CISC machines (any four points). 4M

Ans Any 4
: points –
1mark
each

Page No: 2/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

iii Write a program in 'C' to read a byte of data from Port 1 if it is greater than 99 send it to 4M
Port 0 otherwise send it to Port 2.

Ans Program: Correct


: program-4
#include <reg51.h> marks
void main(void)
{
unsigned char x;
P1=0xFF; //make P1 input port
while (1)
{
x=P1; //get a byte from P1
if (x>99) //check if a byte is greater than 99h
{
P0=x;
}
else

Page No: 3/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
P2=x; //send it to P0
}
}

iv Define Baud rate. State the Baud rate of each mode in UART. 4M

Ans Baud rate :Baud rate is defined as the number of bits transmitted per sec.
: OR
Baud rate is defined as the number of signal changes per second.

Where f is oscillator frequency

b Attempt any ONE: 6- Total


Marks

I Describe the function of following instructions in terms of length of bytes and operation. 6M

a) RRC A

b) DIV AB

c) JNB P1.3, DOWN

Ans a) RRCA 1 mark for


: operation
The RRC A instruction rotates the eight bits in the accumulator and the one bit in the carry flag
right one bit position. Bit 0 of the accumulator is rotated into the carry flag while the original value
1mark for
of the carry flag is rotated in to bit 7 of the accumulator. Bit 7 of the accumulator is rotated into bit no. of
6, bit 6 into bit 5, and so on. bytes of
each
instructio
RRC
n
An = An+1 where n = 0 to 6

Page No: 4/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
A7 = C
C = A0

Bytes:1
.

b)DIV AB
The DIV instruction divides the unsigned 8-bit integer in the accumulator by the unsigned 8-bit
integer in register B. After the division, the quotient is stored in the accumulator and the
remainder is stored in the B register. The carry and OV flags are cleared.

AB = A / B

Bytes:1

c)JNB P1.3, DOWN

The JNB instruction branches to the specified address (DOWN) if the bit P1.3 has a value of 0.
Otherwise, execution continues with the next instruction. No flags are affected by this instruction.

JNB

PC = PC + 3

IF (bit) = 0

PC = PC + offset

Bytes:3

ii Draw the architecture of 8051 microcontroller. 6M

Ans Correct
: labelled
diagram-4
marks

Page No: 5/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

(OR)

Page No: 6/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

Page No: 7/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

Q. Sub Answers Marking


No. Q. N. Scheme

2 Attempt any TWO: 16- Total


Marks

a Write assembly language program to find largest number from the array of ten 8M
numbers stored in external memory RAM. Assume suitable data.

Ans: Assumptions: Array of ten numbers are stored from memory location 3000H onwards and Correct
program-8
result is stored in memory location 6000H
marks
Program:
CLR PSW.3 ; Select Bank 0 PSW.3
MOV R1, 0AH ; Initialize byte counter
MOV DPTR, # 3000H ; Initialize memory pointer
DEC R1 ; Decrement byte counter by 1
MOV X A, @DPTR ; Load number in accumulator
MOV 40 H, A ; Store number in memory location
UP: INC DPTR ; Increment memory pointer by 1
MOVXA, @DTPR ; Read next number
CJNE A, 40 H, DN ; if number≠ next number, and then go to NEXT
DN: JNC NEXT ; If next number < number then go to NEXT
MOV 40H, A ; Else replace NEXT number with number
NEXT: DJNZ R1, UP ; Decrement byte counter by 1, if byte counter≠ 0 then go to UP
MOV DPTR,#6000H ; Increment memory pointer by 1
MOV A, 40H
MOVX@ DPTR, A ; Store result t external memory location
LOOP: AJMP LOOP ; Stop

b Draw interface diagram of ADC 0809 with 8051. Write 'C' language program to generate 8M

Page No: 8/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
50 Hz sq. wave with crystal freq = 12 MHz.

Ans: Diagram-4
marks

Program-4
marks

'C' language program to generate 50 Hz sq. wave with crystal freq = 12 MHz.:
Square wave Frequency = 50Hz
Therefore Time period T = 1 / 50HZ = 0.02s

Therefore TON = TOFF = 0.02s / 2 = 0.01s


(65535-count+1)1MHZ=0.01s
65536-count=0.01s/1µs
Count=65536-10000
Count=55536
Count=D8F0H
Program:
#include<reg51.h>
void delay(void);
sbit sq=P1^5;
void main (void)
{
while (1)
{
sq=~sq;
delay();

Page No: 9/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
}
}
void delay()
{
TMOD=0X01; //set timer 0 in mode 1 i.e. 16 bit number
TL0=0X0F0; //load TL register with LSB of count
TH0=0X0D8 ; //Load TH register with MSB of count
TR0 =1; //Start timer 0
While(TF0==0); //wait until timer rolls over
TR0=0; //Stop timer 0
TF0=0; //Clear timer flag 0 }
}

c Draw interfacing diagram for stepper motor with 8051. Draw flow chart for rotating 8M
stepper motor in clockwise direction.

Ans: Diagram 4
marks

Flowchart-
4 marks

Page No: 10/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

Page No: 11/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
Q. Sub Answers Marking
No. Q. Scheme
N.

3 Attempt any FOUR: 16- Total


Marks

a i) Convert (1011101)2 to ( )10. 4M

ii) Subtract (1001)2 from (1100)2 by using 2's complement method.

Ans 2M EACH
:

Page No: 12/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

b ̅ = 0 ii) E 𝐀
Draw program memory organization for i) E𝐀 ̅ = 1. 4M

Ans 2M each
:

Page No: 13/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
c Compare between 8051 and 8052 microcontroller. 4M

Ans 1M each
:

d Describe the standard data types in 'C' for 8051 with suitable example. 4M

Ans ( 4M for correct answer) Any four 1


: M each
DATA TYPES SIZE IN BITS DATA RANGE EXAMPLE

Unsigned char 8-bit 0 to 255 Unsigned char x;

(signed) char 8-bit -128 to +127 Signed char x;

Unsigned int 16-bit 0 to 65535 Unsigned int x;

(signed) int 16-bit -32768 to +32767 Signed int x;

SFR bit addressable


Sbit 1-bit Sbit LED=P1^2;
only

RAM bit addressable


Bit 1-bit Bit x;
only

RAM addresses
sfr 8-bit Sfr P1= 0x90;
80-FFH only

Page No: 14/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
e Draw interlacing diagram of DAC 0808 with 8051 microcontroller. 4M

Ans 4M
:

Q. Sub Answers Marking


No. Q. Scheme
N.

4 a Attempt any THREE: 12- Total


Marks

i State the alternate function of Port 3 pins of microcontroller 8051. 4M

Ans ½ M each
: point

Page No: 15/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

ii Compare EPROM and EEPROM (any four points). 4M

Ans 1M each
:

Page No: 16/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

iii Write 'C' program to toggle only bit P1.2 continuously with 200 ms delay. 4M

Ans (4M for correct program)


:
#include <reg51.h>

sbit LED= P1^2;

void delay(unsigned int);

void main()

while(1)

LED=0;

delay(200);

Page No: 17/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
LED=1;

delay (200);

void delay(unsigned int t)

unsigned int i,j;

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

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

iv Draw interfacing of LM 35 temperature sensor with 8051 microcontroller. 4M

Ans 4M
:

Note:(Diagrams drawn using any other ADC (0808,0848 etc.) also to be considered)

Page No: 18/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
b Attempt any ONE: 6- Total
Marks

i Write assembly language program to count time period of square wave using 8051 6M
counter. Assume suitable data.

Ans Assumptions : Correct


: program :
This program will display the time period in ms 6M
Oscillator frequency = 12 MHz, Timer0 as counter in Mode1, Timer1 for delay generation
in Mode1, Square wave whose time period to be found is applied to P3.4 (T0 input for
Timer0) , Higher byte of result is displayed in Port2 and lower byte in Port1.

Explanation: If we count the number of pulses applied to P3.4 in 1 ms, we will directly get
the time period in milliseconds. Timer0 is used to count the pulses and Timer1 is used to
generate a delay of 1ms.

The value to be given to TMOD register is 15H

The count value to generate time delay of 1ms is FC18H

Program:
MOV TMOD,#15H //LOAD 15H TO TOMOD REGISTER
SETB P3.4 //P3.4 AS INPUT
MOV TL0,#00H
MOV TH0,#00H //LOAD INITIAL VALUE FOR COUNTING
SETB TR0 //START COUNTER
MOV TL1,#18H
MOV TH1,#0FCH //LOAD COUNT VALUE FOR 1ms DELAY
SAME: JB P3.4,SAME //WAIT FOR FIRST FALLING EDGE OF SQUARE WAVE
SETB TR1 //START TIMER1
BACK: JNB TF1,BACK //CHECK FOR 1ms DELAY
CLR TF1 //CLEAR TF1
CLR TR1 //STOP TIMER1
CLR TR0 //STOP COUNTER0
MOV A,TL0

Page No: 19/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
MOV P1,A //LOWER BYTE OF COUNT IN P1
MOV A,TH0 //HIGHER BYTE OF COUNT IN P2
MOV P2,A
SJMP $

ii Draw the diagram to interface external RAM and ROM with 8051 microcontroller and 6M
explain the function of ALE and ̅̅̅̅̅̅̅̅
𝐏𝐒𝐄𝐍 pins of 8051.

Ans 4M
: (drawing)

1M each

(function)

PSEN pin stands for Program Store Enable. It is used to read a signal from the external
program memory.

ALE/PROG: Address Latch Enable output pulse for latching the low byte of the address
during accesses to external memory. This pin is also the program pulse input (PROG)
during EPROM programming.

Q. Sub Answers Marking


No. Q. Scheme
N.

5 Attempt any TWO: 16- Total


Marks

a Describe the addressing modes of 8051 with suitable example. 8M

Ans There are a number of addressing modes available to the 8051 instruction set, as follows: Any four, 2
: marks

Page No: 20/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
1. Immediate Addressing mode each (1
mark for
2. Register Addressing mode explanatio
3. Direct Addressing mode n and 1
mark for
4 Register Indirect addressing mode example)

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
Page No: 21/31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
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: 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 Write 'C' language program to transfer the message "AICTE" serially at baud rate 9600. 8M
Assume crystal frequency 11.0592 MHz.

Ans Calculatio
: Normally Serial communication MODE 1 is used (8 bit UART with variable baud rate). For n of count
setting baud rate, TIMER 1 to be programmed in Mode 2 – Auto reload mode. – 1M
Following formula is used for calculation of Count to be given to Timer 1 register, TH1 to
set standard baud rate. Program :-
7M
𝑓 2𝑠𝑚𝑜𝑑 𝑓
𝑜𝑠𝑐
𝑏𝑎𝑢𝑑= 32
𝑋 12 𝑋 (256−𝑇𝐻1)

Page No: 22/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
20 11059200
Hence for 9600 baud, 9600 = 𝑋
32 12 𝑋 (256−𝑇𝐻1)
From this formula we get value to be loaded to TH1 as FD H
(Any other logically similar method may also be used for calculation)

Program:
#include <REG51.H>
void main(void)
{
unsigned char text[] = “AICTE”;
unsigned char i;
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while(1)
{
for(i =0;i<5;i++)
{
SBUF= text[i];
while(TI ==0);
TI = 0;
}
}
}
c Draw and explain the interfacing of seven segment LED display in common cathode 8M
with 8051 microcontroller. Write 'C' language program to display digit 0 to 9.

Ans 4 marks
: diagram

4 marks
program

Page No: 23/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

A = P1.0 B = P1.1 C = P1.2 D = P1.3

E = P1.4 F = P1.5 G = P1.6 DP= P1.7

DB 3FH // digit drive pattern for 0


DB 06H // digit drive pattern for 1
DB 5BH // digit drive pattern for 2
DB 4FH // digit drive pattern for 3
DB 66H // digit drive pattern for 4
DB 6DH // digit drive pattern for 5
DB 7DH // digit drive pattern for 6
DB 07H // digit drive pattern for 7
DB 7FH // digit drive pattern for 8
DB 6FH // digit drive pattern for 9

void main ()

Page No: 24/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
{

P1 = 0xFF; //DISPLAY OFF

while(1)

P1 = 0x3F; //DISPLAY 0

delay_ms(1000);

P1 = 0x06; //DISPLAY 1

delay_ms(1000);

P1 = 0x5B; //DISPLAY 2

delay_ms(1000);

P1 = 0x4F; //DISPLAY 3

delay_ms(1000);

P1 = 0x66; //DISPLAY 4

delay_ms(1000);

P1 = 0x6D; //DISPLAY 5

delay_ms(1000);

P1 = 0x7D; //DISPLAY 6

delay_ms(1000);

P1 = 0x07; //DISPLAY 7

delay_ms(1000);

P1 = 0x7F; //DISPLAY 8

delay_ms(1000);

P1 = 0x6F; //DISPLAY 9

delay_ms(1000);

Page No: 25/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
}

NOTE: Program may change. Student can also use the other logic. Please check the logic
and understanding of students.

Q. Sub Answers Marking


No. Q. Scheme
N.

6 Attempt any FOUR: 16- Total


Marks

a Draw the format of IE register of 8051 and state the function of each bit. 4M

Ans 2 mark
: format 2
marks
function

b Describe the following assembler directives with one example. 4M

i) ORG

ii) DB

iii) EQU

iv) END

Ans 1 mark
: each
( Each directive explanation with example : 1 mark each)

1. ORG : ORIGIN The ORG directive is used to indicate the beginning of the address. The

Page No: 26/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
number that comes after ORG is the address from where program will begin. The number
can be either in hex and decimal

e.g. ORG 1000H

It indicates that program shall start from memory address 1000h

2. DB : Define Byte It is used to define the 8-bit data. It is used to write the value after
DB , into the program memory. When DB is used to define data, the numbers can be in
decimal, binary, hex, ASCII formats

e.g. ORG 1000H

MYDATA: DB 20,21

After execution of this , location 1000h=20 & 1001h = 21

3. EQU: EQUATE It is used to define a constant without occupying a memory location


The EQU directive assigns a constant value to a label. When the label appears in the
program, its constant value will be substituted for the label.

e.g. COUNT EQU 10

MOV R2, #COUNT

When the instruction is executed , register R2 is loaded with value 10.

4. END: This indicates to the assembler the end of the source (asm) file . The END
directive is the last line of an 8051 program. Means that in the program anything after
the END directive is ignored by the assembler

e.g. MOV A , #20

ADD A , #10

END

c Write down the function of 16 pin connector of LCD module. 4M

Ans 4 marks
Pin Name: Description
: Pin

Page No: 27/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

No:

1 Vss (Ground) Ground pin connected to system ground

2 Vdd (+5 Volt) Powers the LCD with +5V (4.7V – 5.3V)

Decides the contrast level of display. Grounded to get maximum


3 VE (Contrast V)
contrast.

Connected to Microcontroller to shift between command/data


4 Register Select
register

Used to read or write data. Normally grounded to write data to


5 Read/Write
LCD

Connected to Microcontroller Pin and toggled between 1 and 0


6 Enable
for data acknowledgement

7 Data Pin 0

8 Data Pin 1

9 Data Pin 2 Data pins 0 to 7 forms a 8-bit data line. They can be connected
to Microcontroller to send 8-bit data.

10 Data Pin 3
These LCD’s can also operate on 4-bit mode in such case Data
pin 4,5,6 and 7 will be left free.
11 Data Pin 4

Page No: 28/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

12 Data Pin 5

13 Data Pin 6

14 Data Pin 7

15 LED Positive Backlight LED pin positive terminal

16 LED Negative Backlight LED pin negative terminal

d Draw and describe the interfacing of opto-isolator with 8051 microcontroller. 4M

Ans 2 marks
: diagram 2
marks
explainati
on

Optocoupler is also called optoisolator, photocoupler and optical isolator. It is used to


provide isolation between two electrical circuits. It is a electrical component which is used
to transmit input signal by using light energy signals. It provides electrical coupling
between input and output through light waves. Its main purpose is to avoid changing in
voltages at output side to appearing at input side. Higher voltage fluctuations may

Page No: 29/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________
damage input side electrical components.

The output of opto coupler is given to relay which further operates the output device

e Explain system clock and machine cycle of 8051 microcontroller. 4M

Ans 2 marks
: each

An 8051
clock circuit is shown above. In general cases, a quartz crystal is used to make the clock
circuit. The connection is shown in figure (a) and note the connections to XTAL 1 and XTAL
2. In some cases external clock sources are used and you can see the various connections
above. Clock frequency limits (maximum and minimum) may change from device to
device. Standard practice is to use 12MHz frequency. If serial communications are
involved then its best to use 11.0592 MHz frequency.

Page No: 30/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 18 EXAMINATION
Subject Name: Microprocessor & Applications Model Answer Subject Code: 17509
__________________________________________________________________________________________________

One machine cycle has 6 states. One state is 2 T-states. Therefore one machine cycle is 12
T-states. Time to execute an instruction is found by multiplying C by 12 and dividing
product by Crystal frequency.

T=(C*12d)/crystal frequency

Page No: 31/31


MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
1

Important Instructions to examiners:


1) The answers should be examined by key words and not as word-to-word as given in themodel answer
scheme.
2) The model answer and the answer written by candidate may vary but the examiner may tryto assess the
understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given moreImportance (Not
applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in thefigure. The
figures drawn by candidate and model answer may vary. The examiner may give credit for anyequivalent
figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constantvalues
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.

Q. Sub Answers Marking


No. Q. Scheme
N.

1 (A) Attempt any THREE: 12- Total


Marks

(a) Perform following subtraction using 2’s compliment method 4M

1) (69)2 – (34)2
2) (18)2 – (27)2

Page 1/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
2

Ans: 2M EACH

(b) Describe function of following pins of 8051 microcontroller 4M

i) ̅̅̅̅̅̅̅̅
𝑷𝑺𝑬𝑵
ii) ̅̅̅̅
𝑬𝑨
iii) RST
iv) ALE

Page 2/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
3

Ans: 1. ̅̅̅̅̅̅̅̅
𝑷𝑺𝑬𝑵 − It is active low output control signal used to activate enable signal of external 1M each
ROM/ EPROM .it is activated every six oscillator periods while reading the external
memory.
2. ̅̅̅̅
𝑬𝑨 − It is active low output control signal. When EA = 1, µc accesses internal and
external program memory when EA =0, µc accesses only external program memory.
3. RST: It is a RESET pin, which is used to reset the microcontroller to its initial values.
4. ALE: There are two ALE pulses per machine cycle. The ALE pulse, which is primarily used
as a timing pulse for external memory access, indicates when every instruction byte is
fetched.

(c) With the help of ADD instruction, explain 4M

1) Direct addressing mode


2) Indirect addressing mode
3) Register addressing mode
4) Immediate addressing mode

Ans: 1.) Direct Addressing Mode: Direct addressing means that the data value is 1M each
obtained directly from the memory location specified in the operand.
For example: ADD A, 40H- ADD the content of Acumulator and the content of
memory location 40H and store the result in A.
2.) Indirect Addressing Mode: Indirect addressing means that the data value is
obtained from the memory location pointed by the register specified in the
operand.
Eg: ADD A, @R0 - ADD the content of A and the content of memory location
pointed by R0 and store the result in 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.
3.) Register Addressing Mode: One of the eight general-registers, R0 to R7, can be

Page 3/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
4

specified as the instruction Operand.


Example: ADD A, R5; Add the contents of register R5 to contents of A
(accumulator) and store the result in A.
4.) Immediate Addressing mode: Immediate addressing simply means that the
operand (which immediately follows the Instruction op. code) is the data value
to be used.
Example: ADD A, #25H - ADD the content of A and the immediate data 25H and
store the result in A.
The # symbol tells the assembler that the immediate addressing mode is to be used.
(d) Explain various modes of serial communication operation. 4M

Ans: Mode 0 – 8 bit shift Register- In this mode, the serial port works like a shift register 1M each
and the data transmission works synchronously with a clock frequency of fosc /12.
Serial data is received and transmitted through RXD. 8 bits are transmitted/ received
at a time. Pin TXD outputs the shift clock pulses of frequency fosc /12, which is
connected to the external circuitry for synchronization In Mode 0, the baud rate is
fixed at Fosc. / 12.
Mode 1 : 8-bit UART 10 bits are transmitted through TXD or received through
RXD. The 10 bits consist of one start bit (which is usually '0'), 8 data bits (LSB is
sent first/received first), and a stop bit (which is usually '1'). Once received, the stop
bit goes into RB8 in the special function register SCON. The baud rate is variable.

2SMOD X OSCILLATOR FREQ


BAUD RATE =
32 12 X [256-(TH1)]

Mode 2 : 9-bit UART- In this mode 11 bits are transmitted through TXD or received
through RXD.The various bits are as follows: a start bit (usually '0'), 8 data bits (LSB

Page 4/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
5

first), a programmable 9 th (TB8 or RB8)bit and a stop bit (usually '1'). While
transmitting, the 9 th data bit (TB8 in SCON) can be assigned the value '0' or '1'. For
example, if the information of parity is to be transmitted, the parity bit (P) in PSW
could be moved into TB8.On reception of the data, the 9 th bit goes into RB8 in
'SCON', while the stop bit is ignored.
2SMOD X OSCILLATOR FREQ
BAUD RATE=
64

Mode 3: 9-Bit UART with Variable Baud Rate- In this mode 11 bits are
transmitted through TXD or received through RXD. The various bits are: a start bit
(usually '0'), 8 data bits (LSB first), a programmable 9th bit and a stop bit (usually
'1'). Mode-3 is same as mode-2, except the fact that the baud rate in mode-3 is
variable (i.e., just as in mode-1).

2SMOD X OSCILLATOR FREQ


BAUD RATE =
32 12 X [256-(TH1)]

(B) Attempt any ONE : 06- Total


Marks

(a) Write ALP to find smallest number in an array of 10 numbers stored in Internal RAM. 6M

Ans: ORG 0000H 6M for


MOV R1, # 0AH ; Load R1 with 10 nos. correct
program
MOV R0, # 40H ; load R0 with 40h
DEC R1 ; decrement R1
MOV 60H,@R0 ; move content of mem. locn pointed by R0 to 60h mem. location
UP: INC R0 ; increment R0
MOV A,@R0 ; move content of mem. location pointed by R0 to A
CJNE A,60H,DOWN ; compare content of A and 60h and jump to down label if not

Page 5/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
6

equal
AJMP SMALL ; if equal jump to small label
DOWN: JNC SMALL ; jump to small label if no carry
MOV 60H, A ; move the content of A to 60h
SMALL: DJNZ R1,UP ; decrement R1 and jump to up label if not equal
END

(For any other relevant logic marks can be given)


(b) With the help of interfacing diagram, write ALP to rotate stepper motor clockwise. 6M

Ans: 3M
diagram,
3M
program

PROGRAM:
ORG 0000H
MOV A,#33H
L1: MOV P1,A
ACALL DELAY
RR A
SJMP L1

Page 6/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
7

DELAY:
MOV R1,#0FH
L2: MOV R2, # 0FFH
L: DJNZ R2, L
DJNZ R1, L2
RET
END

(For any other relevant logic marks can be given)

Q. Sub Answers Marking


No. Q. Scheme
N.

2 Attempt any TWO: 16- Total


Marks

a) Draw and explain internal RAM organization of microcontroller 8051, and show address 8M
areas for each section.

Ans: 4M
diagram,4
M
explanati
on

OR

Page 7/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
8

Internal ROM- The 8051 has 4K (4096 locations) of on-chip ROM. This is used for storing the system
program. 212 = 4096, therefore the internal ROM address bus is 12 bits wide and internal ROM
locations go from 000H to FFFH.
Internal RAM -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.
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 to set or reset any single bit in this section of RAM. With the general purpose RAM from 30H

Page 8/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
9

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.
General Purpose RAM- These 80 bytes of Internal RAM memory are available for general-purpose
data storage. The general purpose RAM can be accessed using direct or indirect addressing mode
instructions.
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. Not all SFRs are bit-addressable. Those that are have a unique
address for each bit.
b) Write ALP for 8051 microcontroller to generate a delay 0f 3μs using timer 1. Draw flow 8M
chart also. Assume crystal frequency 12MHz.

Calculations: 1M
Calculatio
Formula to calculate count n, 4M
Crystal freq. = 12MHz program,
3M
Timer freq. – 12/12 =1MHz flowchart

Timer Time period= 1 μs

So (FFFF- COUNT+1)X 1μs= 3μs

COUNT= FFFFH – 3 = FFFDH

TH1= 0FFH

TL1=0FDH

Program:

MOV TMOD, #10H ; Timer 1 , mode 1

UP: MOV TL1, #0FDH; load count value in TL1

MOV TH1, #0FFH; load count value in TH1

Page 9/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
10

SETB TR1 ; start Timer1

AGAIN: JNB TF1, AGAIN ; stay until timer rolls over

CLR TR1 ; stop timer

CLR TF1 ; clear timer flag

SJMP UP ; repeat

(For any other relevant logic marks can be given)

c) Draw and explain interfacing diagram for DC motor speed control using 8051 μc. Also 8M
develop flow chart for same operation.

Page
10/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
11

Ans: 3M
diagram,

3M
Explainati
on,

2M
flowchart

Explanation:

1. The maximum current which can be sunk from 89C51 is upto 15mA at 5V.

2. But DC motor needs more current depending on its type. Hence DC motor cannot
be connected directly to the microcontroller.

3. L293D motor driver stops the back emf produced by the motor from affecting the
microcontroller.

4. Port pins P1.0 and P1.1 are connected to the input pins 2 and 7 of L293D motor
driver.

5. The output pins of the L293D ,pin 3 and 6 are connected to the DC motor.

6. Direction of the rotation of the motor can be changed by inverting the output
terminals

Page
11/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
12

Q. Sub Answers Marking


No. Q. Scheme
N.

3 Attempt any FOUR : 16- Total


Marks

a) Compare microprocessor and microcontroller. 4M

Ans: Sr. Microprocessor Microcontroller Any four


No. points-
1 Microprocessor don’t have inbuilt Microcontroller has inbuilt ROM and 4M(Each
ROM and RAM RAM 1M)
2 Microprocessor don’t have inbuilt Microcontroller has inbuilt Timer and
Timer and Counter Counter
3 Microprocessor doesn’t have inbuilt Microcontroller has inbuilt UART
UART
4 Microprocessor doesn’t have inbuilt Microcontroller has inbuilt I/O

Page
12/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
13

I/O PORTs PORTs

5 It has many instructions to move It has one or two instructions to


data between memory and CPU. move data between memory and
CPU.
6 It has one or two bit handling It has many bit handling instructions.
instructions.
7 Access times for memory and I/O Less access time for built-in memory
devices are more. and I/O devices.
8 Microprocessor based system Microcontroller based system
requires more hardware. requires less hardware reducing PCB
size and increasing the reliability.

b) Draw block diagram of 8051 microcontroller. 4M

Ans: Diagram-
4M

c) Explain following assembler directives: 4M

i) DB
ii) ORG
iii) EQU
iv) END

Page
13/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
14

Ans: i) DB (define byte): Each


directive-
Syntax-
1M
LABEL: DB BYTE
Define Byte It is used to define the 8-bit data. It is used to write the value after DB , into the
program memory. When DB is used to define data, the numbers can be in decimal, binary,
hex, ASCII formats. Regardless of which type is used, the assembler will convert the
numbers into hex. The DB directive is the only directive that can be used to define ASCII
string larger than two characters.

Example:
DATA1: DB 28 ; (decimal data stored as 1C hex)
DATA2: DB 01010101B ;(Binary data stored as 35 in hex)
DATA3: DB 5FH ;(Hex)
DATA4: DB “ABCDE” ; ASCII characters

ii) ORG ( origin)

The ORG directive is used to indicate the beginning of the address. The number that comes
after ORG is the address from where program will begin. The number can be either in hex
and decimal.

e.g. ORG 1000H


It indicates that program shall start from memory address 1000H.
iii) EQU: Equate
Syntax:
Name EQU Constant

EQU: This is used to define a constant without occupying a memory location. When
the label appears in the program, constant value will be substituted for the label.

Page
14/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
15

Example:
NUMBER EQU 25H
MOV R3,#NUMBER ;
R3 = 25H as 25H will be substituted for NUMBER

iv) END
This indicates to the assembler 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.

e.g. END ; End of the program

d) State any four ‘C’ data types with their range of values. 4M

Ans: Any four


data
Data Type Size in Bits Data Range/Usage types-
4M(Each
Unsigned char 8-bit 0 to 255
1M)
Signed char 8-bit -128 to + 127

Unsigned int 16-bit 0-65535

signed int 16-bit -32768 to + 32767

sbit 1-bit SFR bit-addressable only

bit 1-bit RAM bit-addressable only

sfr 8-bit RAM addresses 80 –FFH


only

e) Draw and explain interfacing of 3 x 3 key matrix with 8051 microcontroller. 4M

Page
15/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
16

Ans: Interfacin
g
diagram-
2M

&
Explainati
on-2M

Explanation:
• It is the function of the microcontroller to scan the keyboard continuously to detect and
identify the key pressed
• First microcontroller checks whether all keys are open before the start of operation, by
grounding all the rows and ensuring that the input port has 111.
• To detect a pressed key, the microcontroller again grounds all rows by providing 0 to the
output latch, then it reads the columns
• If the data read from columns is D2 – D0 = 111, no key has been pressed and the process
continues till key press is detected
• If one of the column bits has a zero, this means that a key press has occurred
• Then the program waits for 20ms (debounce time) and check for the key pressed again. If
still the key pressed is detected, it proceeds.
• After detecting a key press, microcontroller will go through the process of identifying the
key
• Starting with the top row, the microcontroller grounds it by providing a low to row D0
only
Page
16/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
17

• It reads the columns, if the data read is all 1s, no key in that row is activated and the
process is moved to the next row
• It grounds the next row, reads the columns, and checks for any zero
• This process continues until the row is identified
• After identification of the row in which the key has been pressed Find out which column
the pressed key belongs to
• Upon finding the row that the key press belongs to, it sets up the starting address for the
look-up table holding the scan codes (or ASCII) for that row
• To identify the key press, it rotates the column bits, one bit at a time, into the carry flag
and checks to see if it is low
• Upon finding the zero, it pulls out the ASCII code for that key from the look-up table
• Otherwise, it increments the pointer to point to the next element of the look-up table

Q. Sub Answers Marking


No. Q. Scheme
N.

4 A) Attempt any THREE : 12- Total


Marks

(a) Compare 8051 and 8052 microcontrollers. 4M

Ans: Any four


Feature 8051 8052 points-
4M
ROM(bytes) 4K 8K

RAM(bytes) 128 256

Timers 2 3

I/O pins 32 32

Serial port 1 1

Page
17/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
18

Interrupts 6 8

Watchdog No No
timer

(b) Draw format of PSW register of 8051 μc and explain function of any two flag. 4M

Ans: Format-
2M

&

Function
of any
two flag-
2M(1M
each)

PSW register is one of the most important SFRs. It contains several status bits that reflect
the current state of the CPU. Besides, this register contains Carry bit, Auxiliary Carry, two
register bank select bits, Overflow flag, parity bit and user-definable status flag.
P - Parity bit- If a number stored in the accumulator is even then this bit will be
automatically set (1), otherwise it will be cleared (0). It is mainly used during data transmit

Page
18/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
19

and receive via serial communication.


- Bit 1. This bit is intended to be used in the future versions of microcontrollers.
OV Overflow- 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
RS0, RS1 - Register bank select bits. These two bits are used to select one of four register
banks of RAM. By setting and clearing these bits, registers R0-R7 are stored in one of four
banks of RAM.

F0 - Flag 0. This is a general-purpose bit available for user.


AC - Auxiliary Carry Flag is used for BCD operations only. If there is a carry from D3 and D4
during an ADD or SUB operation, this bit is set.
CY - Carry Flag is set whenever there is a carry out from D7 bit. It is affected after all
arithmetical operations and shift instructions.
It also can be set to 1 or 0 directly by using instructions such as SETB C and CLR C.

(c) Describe function of following instructions of 8051 μc. 4M

1) MOVX A,@DPTR
2) SWAP A
3) MUL AB
4) MOV A, R0

Ans: 1) MOVX A,@DPTR Each


descriptio

Page
19/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
20

MOVX instruction allows access to external data memory space. This instruction is n-1M
used for general purpose access of data memory. This instruction will read the byte
of data pointed to by register DPTR and store it in the accumulator.
Operation: A  (DPTR)

2) SWAP A

Operation: A3 – 0 <- -> A7-4


Swap the nibbles of the accumulator. It swaps the lower nibble and the higher
nibble of the accumulator. The lower 4 bits are put into the higher 4 bits, and the
higher 4 bits are put into the lower 4 bits.

3) MUL AB
Operation: BA  A * B
In byte by byte multiplication, one of the operand must be in register A, and second
Page
20/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
21

operand must be in register B. after multiplication, the 16 bit result is held by A and
B registers as lower byte is in A, and upper byte is in B.
Addressing mode: Register addressing mode

4) MOV A,R0
No. of bytes – 1byte
Operation: A˂--- R0
Load the contents of R0 in the accumulator.
Addressing mode: Register addressing mode

(d) Write a program to send “ WELCOME” serially on 8051 μc, use baud rate of 2400. 4M

Ans: Assume crystal frequency= 11.0592 MHz Baud rate


calculatio
n-1M
The machine cycle frequency of the 8051 = 11. 0592 MHz / 12 = 921.6 KHz, and
&
921.6 KHz /32 = 28,800 Hz is the frequency provided by UART to Timer 1 to set baud rate. Program-
Therefore 28,800 / 2400 = -12 or F4 H is loaded into TH1. 3M

(OR)

Required baud rate=


2SMOD X fOSC /32 X 12 (256 –COUNT) =2400

20 X 11.0592 X 106 /32 X 12 (256 – COUNT) =2400


256 – COUNT = 11.0592 X 106 /32 X 12 X 2400
= 12

Page
21/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
22

Therefore COUNT = 256 – 12 =244D =F4 H.


From this formula we get value to be loaded to TH1 as F4 H

Program:
#include <REG51.H>
void main(void)
{
unsigned char text[] = “WELCOME”;
unsigned char i;
TMOD = 0x20;
TH1 = 0XF4;
SCON = 0x50;
TR1 = 1;
while(1)
{
for(i =0;i<7;i++)
{
SBUF= text[i];
while(TI ==0);
TI = 0;
}
}
}

B) Attempt any ONE : 06- Total


Marks

(a) List all I/O ports of 8051 μc and describe alternative functions of each ports. 6M

Page
22/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
23

Ans: 8051 Microcontroller provides 4 I/O ports as P0,P1, P2 & P3 each as 8 bit port. List-1M

Alternate functions of each port: Alternate


functions
i) Port 0 (P0)-Used as input or output. Port 0 also provides both address and data of P0,P1
as AD0-AD7 when connected to external memory. The 8051 multiplexes address & P2- 1M
each and
and data through port 0 to save pins. ALE indicates if P0 has address or data.
P3
When ALE = 1 ,it has lower 8 bit address A0-A7 and when ALE = 0 it provides
functions-
data D0 – D7. 2M
ii) Port 1 (P1)-- Used only as simple input or output port. This port is called as
dedicated I/O port.
iii) Port 2 (P2)-- - This port can be used for higher address byte with
addresses A8-A15.Used only as input or output port. However in external
memory connections P2 must be used along with P0 to provide the 16 bit
address for the external memory. P2 provides higher order bits A8- A15 of the
address.
iv) Port 3 (P3)- - Used as input or output port. Port 3 has additional function of
providing some alternate functions like interrupts , RxD and TxD signals for serial
communication.
Following table shows alternate functions provided by port 3.

Page
23/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
24

(b) With necessary interfacing diagram, write a ‘C’ program to generate a triangular wave 6M
using DAC.

Ans: Interfacin
g
diagram-
3M

&

Program-
3M

Page
24/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
25

#include<reg51.h>
void main(void)
{
unsigned char d;
while(1)
{
for(d=0; d<=255; d++)
{
P1 = d;
}
for(d=255; d>=0; d--)
{

Page
25/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
26

P1 = d;
}
}
}

Q. Sub Answers Marking


No. Q. Scheme
N.

5. Attempt any TWO: 16- Total


Marks

a) Write ALP to exchange 10 bytes of data from source location 20H to destination location 8M
60 H for 8051 μc.

Ans: ( Program with any other relevant logic can be considered) ( Correct
program
logic= 6
ORG 0000H marks,
MOV R0,#20H ; source pointer R0 = 20H Comment
s =2 marks
MOV R1,#60H ; Destination pointer R1= 60H )
MOV R2,# 0AH ; count = 10
UP: MOV A,@R0 ; Read first data byte
MOV B,@R1 ; Read second data byte
MOV @R0,B ; exchange numbers
MOV @R1,A ;
INC R0 ; increment source pointer
INC R1 ; increment destination pointer
DJNZ R2,UP ; decrement count and if count not equal to 0 jump UP
END ; end of program
b) Write ‘C’ language program to toggle all bits of port 1 of 8051 μc continuously with 5 ms 8M
delay.

Page
26/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
27

Ans: ( Correct
program
( Program with any other relevant logic can be considered)
logic= 6
marks,
#include < reg 51.h> Comment
s =2 marks
void delay (unsigned int); )
void main (void)
{
while(1) //repeat loop
{
P1=0xff; //toggle all bits of port1
delay (5); //add 5ms delay
P1=0x00; //toggle all bits of port1
delay (5); //add 5ms delay
}
}
void delay (unsigned inti)
{
Unsigned int x,y;
for(x=0; x<i ; x++)
for(y =0 ; y <1275 ; y++);
}
c) Draw neat labeled interfacing diagram to control lamp at pin 1.0, by using opto isolator 8M
with 8051 μc.

Page
27/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
28

Ans: ( CORRECT
DIAGRAM
: 8M)

Q. Sub Answers Marking


No. Q. Scheme
N.

6. Attempt any FOUR : 16- Total


Marks

a) Explain Von Neumann architecture with suitable diagram. 4M

Ans: (Diagram
: 2 marks
explainati
on : 2
marks)

 The Von Neumann architecture uses single memory for storing instructions and
data.
 It requires single bus for instructions and data.
 Width of address and data bus for program and data memory are same
 Instructions and data have to be fetched in sequential order limiting the
Page
28/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
29

operation bandwidth
 For e.g. general purpose microprocessors

b) With the help of neat diagram, describe timer modes of 8051 μc. 4M

Ans: There are four timer modes: Correct


explanati
1. Mode 0 : 13 bit timer/counter
on:4M
2. Mode 1 : 16 bit timer / counter
3. Mode 2 : 8bit Auto Reload Mode
4. Mode 3 : Split mode

1. MODE 0 - 13 bit Timer / Counter

In mode 0, the timer/counter is configured as a 13-bit timer/counter. The upper 8


bits of the count are in TH .The lower 5 bits are in the lower 5 bits of TL. The upper 3
bits of TL are not used. The TFx flag will be set when the timer /counter Overflows
from all 1’s to all 0’s. The timer continues to count.

2. MODE 1- 16 bit Timer / Counter


In mode 1, the timer/counter is configured as a 16-bit timer/counter. The upper 8
bits of the count are in TH & The lower 8 bits are in TL. The TFx flag will be set when
the timer / counter overflows from all 1’s to all 0’s. The timer continues to count.

Page
29/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
30

3. Mode 2 – 8 bit Auto Reload


TL operates as an 8-bit Timer / counter.TH holds a reload value. When TL overflows
(reached FFH), the TFx flag is set, TL is reloaded from the value in TH and counting
continues.

4. Mode 3- Split Mode


Timer 0 is split into two independent 8-bit timers.TL0 acts as 8 bit Timer / Counter
When TL0 overflows, it sets the TF0 flag.TH0 acts as 8 bit Timer ,When TH0
overflows, it sets the TF1 flag. Timer 1 is stopped in mode 3. It can be switched
independently to a different mode. However, when it overflows it will NOT set the
TF1 flag.

Page
30/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
31

c) What is integrated development environment for microcontroller based system? 4M


Describe at least four features of Keil μ-version.

Ans: Integrated Development Environment (IDE): ( IDE: 2M,


Any 4
 An integrated development environment (IDE) is a software application that features
provides comprehensive facilities to computer programmers for software of Keil:
2M)
development.

 An IDE normally consists of a project manager , source code editor, build


automation tools and a debugger.

 Integrated development environments are designed to maximize programmer


productivity by providing a single program in which all development is done.

 This program typically provides many features for authoring, modifying, compiling,
deploying and debugging software.

 Some IDEs contain a compiler, interpreter, or both.

 Example : keil µVision IDE


Features of Keil:
 The μVision IDE combines project management, run-time environment, build
facilities, source code editing, and program debugging in a single powerful
environment.

Page
31/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
32

 μVision is easy-to-use and accelerates your embedded software development.


 μVision supports multiple screens and allows you to create individual window
layouts anywhere on the visual surface.
 The μVision Debugger provides a single environment in which you may test, verify,
and optimize your application code.
 The debugger includes traditional features like simple and complex breakpoints,
watch windows, and execution control and provides full visibility to device
d) Write a program to read switch as shown below if switch is closed , turn ON the LED Else 4M
turn OFF the LED.

Ans: #include <reg51.h> (Correct


Sbit SW = P1.1; program
logic= 4
Sbit LED = P1.2; marks)
void main(void)
{
SW =1 ;// make P1.1 as input pin
LED =0;// make P1.2 as output pin
While (1) // repeat forever

Page
32/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

WINTER– 18 EXAMINATION
Subject Name: Microcontroller and Applications Model Answer Subject Code: 17509
33

{
if ( SW == 0) // check if switch is closed
{
LED =1;// turn LED ON
}
Else
{
LED = 0;// turn LED OFF
}
}// End of while loop
}// End of program
e) Draw interfacing diagram for temperature measurement using LM 35 sensor with 8051 4M
μc.

Ans: ( Correct
diagram :
4M)

Page
33/33
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

Important Instructions to examiners:


1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner may tryto assess the
understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given moreImportance (Not applicable for
subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in thefigure. The figures
drawn by candidate and model answer may vary. The examiner may give credit for anyequivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constantvalues 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.

Q. Sub Answers Marking


N Q. N. Scheme
o.

1 (A) Attempt any FIVE: 20- Total


Marks

(a) List any four feature of 8051 microcontroller 4M

Ans: Features Of 8051 Microcontroller: (Any Four) Each


Feature:1
 It is an 8bit microcontroller. M
 8bit accumulator, 8bit Register and 8bit ALU.
 On chip RAM 128 bites (data memory).
 On chip ROM 4 Kbytes (program memory).
 Two 16bit counter/ timer.
 A 16 bit DPTR(data pointer)
 Two levels of interrupt priority.
 4 byte bi-directional input/ output port.
 Power saving mode (on some derivatives).
 16bit address bus:-it can access 2^16 memory locations:-64kb (65536) each of RAM
and ROM.

Page 1/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

 It is an inclusion of Boolean processing system, have an ability to allow logic


operations to be carried out on registers and RAM.
 8bit data bus:-it can access 8bit of data in one operation.
 It also consist of 3 internal and two external interrupts
 UART (this serial communication port makes chip to use simply as a serial
communication interface).
 It has four separate Register set. (Each contains 8 Registers (R0 to R7)).

(b) Draw the format of PSW of 8051 and state the function of each bit 4M

Ans: PSW: Format:2


M

Function
2M

P - Parity bit. If a number stored in the accumulator is even then this bit will be automatically
set (1), otherwise it will be cleared (0). It is mainly used during data transmit and receive via
serial communication.

- Bit 1. This bit is intended to be used in the future versions of microcontrollers.

OV: Overflow 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

Page 2/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

errors in signed arithmetic operations

RS0, RS1 - Register bank select bits. These two bits are used to select one of four register
banks of RAM. By setting and clearing these bits, registers R0-R7 are stored in one of four
banks of RAM.

F0 - Flag 0. This is a general-purpose bit available for user.

AC - Auxiliary Carry Flag is used for BCD operations only. If there is a carry from D3 and D4
during an ADD or SUB operation, this bit is set.

CY - Carry Flag is set whenever there is a carry out from D7 bit. It is affected after all
arithmetical operations and shift instructions. It also can be set to 1 or 0 using instructions
SETB c and CLR c

(c) Describe the following assembler directive with one example each: 4M

(i) ORG

(ii)DB

(iii)EQU

(iv) END

Ans: i. ORG: Origin Each


It is used to indicate the beginning of address. Directive:
1M
Syntax: ORG Address
The address can be given in either hex or decimal there should be a space of at least
one character between ORG & address fields. Some assemblers use ORG should not
begin in label field.
ii. DB: (Data Byte)
Syntax: LABEL: DB BYTE

Page 3/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

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


(d) State any four data types in “C” with their value range 4M

Page 4/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

Ans: Any Four


Data
types.

Each data
type with
value:1M

(e) Draw the pin diagram of 20 X 4 LCD display and state the function of RS,EN & R/W
pins
Ans: Pin
Diagram:
2M

Function
of RS:1M

EN: ½M

R/W: ½ M

Page 5/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

RS: RS is the register select pin used to write display data to the LCD (characters), this pin has
to be high when writing the data to the LCD. During the initializing sequence and other
commands this pin should low.

R/W: Reading and writing data to the LCD for reading the data R/W pin should be high
(R/W=1) to write the data to LCD R/W pin should be low (R/W=0).

EN: Enable pin is for starting or enabling the module. A high to low pulse of about 450ns
pulse is given to this pin.

( f) List the alternate pin function of port 3

Ans: Each pin


function:
½M

(g) Describe the function of following instructions :


(i) MOVC A , @ A + D PTR
(ii) DA A
Ans Each
1. MOVC A,@A+DPTR: instructio
n: 2M
The instruction moves data from the external code memory to the accumulator. The address
of 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 is referred to as the index address.

Page 6/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

No of bytes: 1 byte

Addressing mode: register

2. DAA

Decimal Adjust Accumulator. DA adjusts the contents of the Accumulator to correspond to a


BCD (Binary Coded Decimal) number after two BCD numbers have been added by the ADD or
ADDC instruction.

If the auxiliary carry bit is set or if the value of bits 0-3(lower nibble) exceed 9, 0x06 is added
to the accumulator. If the carry bit is set or if the value of bits 4-7 (higher nibble) exceeds 9,
0x60 is added to the accumulator.

No of bytes: 1 byte

Addressing mode: register

For eg. A=0Ch after execution A=12 BCD

Q. Sub Answers Marking


N Q. N. Scheme
o.

2 Attempt any FOUR: 16- Total


Marks

a) Compare microprocessor and microcontroller ( any four points) 4M

Ans: Each
Point:1M
Sr. Parameter Microprocessor Microcontroller
No.
1 No. of Many instructions to Few instruction to read/ write
instruction read/write data to/ from data to/ from external memory
s used external memory

Page 7/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

2 Memory Do not have inbuilt RAM or Inbuilt RAM /or ROM


ROM.
3 Registers Microprocessor contains Microcontroller contains general
general purpose registers, purpose registers, Stack pointer
Stack pointer register, Program register, Program counter
counter register register additional to that it
contains Special Function
Registers (SFRs) for Timer ,
Interrupt and serial
communication etc.
4 Timer Do not have inbuilt Timer. Inbuilt Timer
5 I/O ports I/O ports are not available I/O ports are available
requires extra device like 8155
or 8255.
6 Serial port Do not have inbuilt serial port, Inbuilt serial port
requires extra devices like 8250
or 8251.
7 Multifuncti Less Multifunction pins on IC. Many multifunction pins on the
on pins IC
8 Boolean Boolean operation is not Boolean Operation i.e.
Operation possible directly. operation on individual bit is
possible directly
9 Application General purpose, Computers Single purpose(dedicated
s and Personal Uses application), Automobile
companies, embedded systems,
remote control devices.
b) Describe four timer modes of 8051 microcontroller 4M

Ans Each
Mode:1M
1. Mode 0 : 13 bit timer/counter

In mode 0, the timer/counter is configured as a 13-bit timer/counter. The upper 8 bits of the
count are in TH .The lower 5 bits are in the lower 5 bits of TL. The upper 3 bits of TL are not
used. The TFx flag will be set when the timer /counter Overflows from all 1’s to all 0’s. The

Page 8/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

timer continues to count.

2. Mode 1 : 16 bit timer / counter

In mode 1, the timer/counter is configured as a 16-bit timer/counter. The upper 8 bits of the
count are in TH & The lower 8 bits are in TL. The TFx flag will be set when the timer / counter
overflows from all 1’s to all 0’s. The timer continues to count.

3. Mode 2 : 8bit Auto Reload

TL operates as an 8-bit Timer / counter.TH holds a reload value. When TL overflows (reached
FFH), the TFx flag is set, TL is reloaded from the value in TH and counting continues.

4. Mode 3 : Split mode

Timer 0 is split into two independent 8-bit timers.TL0 acts as 8 bit Timer / Counter When TL0
overflows, it sets the TF0 flag.TH0 acts as 8 bit Timer, When TH0 overflows, it sets the TF1
flag. Timer 1 is stopped in mode 3. It can be switched independently to a different mode.
However, when it overflows it will NOT set the TF1 flag.

Page 9/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

10

c) Write an assembly language program to transfer the external memory location content of 4M
address 2400 H to internal RAM location42 H

Ans Program:
3M
(Consider Any other Correct Logic)
Comment
ORG 0000 :1M
MOV DPH, #24H; Move higher byte of external memory address to DPH

MOV DPL, #00H; Move lower byte of external memory address to DPL

MOV R0, #42H; Move address of internal RAM in register

MOVX A, @DPTR; Move content of location pointed by DPTR into Accumulator

MOV @R0, A; Move content of Accumulator into memory location pointed by register

END

d) Write the instructions to perform following task using “C” operators: 4M

(i) Shift data bitwise 3 times to right

(ii) Shift data bitwise 4 times to left

Ans Each
instructio
(i) P0= 0x56 >>3; shift 3 times to right n: 2M

Page
10/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

11

(ii) P0= 0x56<<4; shift 4 times to left

e) Draw the format of SCON register and describe each bit 4M

Ans: Format:1
M

SM0 SCON.7 Serial port mode specifier AND SM1 SCON.6 Serial port mode specifier.
Each pin
Descriptio
n: 1/2 M

SM2 SCON.5 Used for multiprocessor communication (Make it 0.)

REN SCON.4 Set/ cleared by software to enable/ disable reception. When the REN =1, it
allows the 8051 to receive data on the RxD pin of the 8051. As a result if we want the 8051
to both transfer and receive data, REN must be set to 1. By making REN=0, the receiver is
disabled.

TB8 SCON.3 TB8 (transfer bit 8) is bit D3 of SCON. It is used for serial modes 2 and 3. We
make TB8=0 since it is not used in our applications.

RB8 SCON.2 Not widely used. RB8 (receive bit 8) is bit D2 of the SCON register. In serial
mode 1, this bit gets copy of the stop bit when an 8 bit data is received.

TI SCON.1 Transmit interrupt flag. Set by hardware at the beginning of the stop Bit in
mode 1. Must be cleared by software. This is an extremely important flag bit in the SCON
register. When the 8051 finishes the transfer of the 8 bit character, it raises the T1 flag to
indicate that it is ready to transfer another byte. The TI bit is raised at the beginning of the
stop bit.

RI SCON.0 Receive interrupt flag. Set by hardware halfway through the stop bit time in
mode 1. Must be cleared by software. When the 8051 receives data serially via RxD, it gets
rid of the start and stop bits and places the byte in the SBUF register. Then it raises the RI
flag bit to indicate that a byte has been received and picked up before it is lost. RI is raised
Page
11/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

12

halfway through the stop bit.

(f) Write any four assembly language instructions to make accumulator contents to zero 4M

Ans: Each
instructio
1. MOV A, #00H
n: 1M
2. ANL A, A
3. XRL A, A
4. SUB A, A

Q. Sub Answers Marking


N Q. N. Scheme
o.

3 Attempt any FOUR : 16- Total


Marks

a) Convert : 4M

(i)(542)10into Hex

(ii)(4FDA)16into Binary

Ans: (i)(542)10into Hex 2M-Each


correct
Answer.
16 542
33 14(E)
2 1
2

=(21E)16
(ii)(4FDA)16into Binary
(4 F D A)16
=(0100 1111 1101 1010)2

b) List interrupts in 8051 microcontroller with their priorities and vector address 4M

Page
12/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer Subject Code:17509

13

Ans: l
Interrupt Source Vector address Interrupt priority l
i
External Interrupt 0 –INT0 0003H 1 u
u
Timer 0 Interrupt 000BH 2
i
External Interrupt 1 –INT1 0013H 3 s
t
Timer 1 Interrupt 001BH 4
-
Serial Interrupt 0023H 5
1

(List -1 mark, priorities and address—3 marks) a


3

c) List any four addressing modes of 8051 microcontroller with one example of each 4M

Ans: There are a number of addressing modes available to the 8051 instruction set, as follows: 1M—Each
1. Immediate Addressing mode addressin
2. Register Addressing mode g mode
3. Direct Addressing mode with
4 Register Indirect addressing mode example
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
Page
13/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

14

assembly language documentation refers to a register generically as Rn.


For 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: 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
Page
14/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

15

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.

d) Write a “C” language program to toggle pin PI 2 continuously with some delay 4M

Ans: Program: Relevant


program-
#include<reg51.h>
4M
sbit bit=P1^2; //make P1.2 as bit
void delay( unsigned int);
void main ()
{
bit=1;
delay(50);
bit=0;
while(1);
}
void delay (unsigned int itime)
{
unsigned int x,y;
for(x=0; x<itime; x++)
for (y=0; y<1275; y++);
}
e) Draw the interfacing diagram for temperature measurement using LM35 ADC 0808 with 4M
microcontroller 8051

Page
15/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

16

Ans 4M-
correct
interfacin
g diagram

f) Draw the format of IP register of 8051 microcontroller and state the function of each bit 4M

Ans: 2M-
format,
2M –
explanati
on

Q. Sub Answers Marking


N Q. N. Scheme
o.

4 A) Attempt any TWO : 16- Total


Marks

Page
16/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

17

(a) Write an assembly language program to find smallest number from the array of ten 8M
numbers stored in internal RAM 50 H onwards

Ans: Program: Select Bank 0 6M-


correct
MOV R1, #0AH ; initialize the counter program,
MOV R0, #50H ; initialize the memory pointer 2M-
DEC R1 ; decrement counter by one comment
MOV A,@R0 ; load number in accumulator s
MOV B, A ; move that number to register B
UP: INC R0 ; increment the memory pointer
MOV A,@R0 ; read the next number in A
CJNE A, B, DOWN ; compare the first two numbers, if not
equal go to DOWN
AJMP NEXT ; else go to NEXT
DOWN: JNC NEXT ; if number in A is smaller then go to
NEXT
MOV B, A ; else move the number in register B
NEXT: DJNZ R1, UP ; decrement the counter by one, if count ≠
Zero then go to UP
INC R0 ; increment the memory pointer
MOV A,B
MOV 50H, A ; store result at memory location 50H
HERE: SJMP HERE

(b) Write an assembly language program to generate square wave of 5 kHz , on port pin P2.4 8M
using timer 1. Assume XTAL = 12 MHz ( show delay calculation )

Ans: Solution : 1M –
Frequency = 5 KHZ delay
calculatio
Time period T = 1 / 5 KHZ = 0.2 ms
n, 6M—
Required time delay = TON = TOFF = T / 2 = 0.2ms / 2 = 0.1 ms = 100usec
correct
program
Required time delay = ( 12 / Fosc ) x number of increments (N) 1M:
100 us = ( 12 / 12MHZ ) x number of increments (N) comment
100 us = 1.0 usec. x N s
N = 100

Page
17/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

18

Using TIMER 1 in MODE 1,


COUNT = 216 - 100
COUNT = 65536 – 100 = 65436 = FF9CH
Therefore TH1 = FFH & TL1 =9CH

Program is as follows :
MOV TMOD, #10H ; timer 1, mode 1
AGAIN : MOV TL1, #9CH ; TL1 = 1A, low byte of timer
MOV TH1, #0FFH ; TH1 = FF, higher byte of timer
SETB TR1 ; Start the timer 1
BACK : JNB TF1, BACK ; stay until timer rolls over
CLR TR1 ; Stop timer 1
CPL P2.4 ; Complement P2.4 to get high, low
CLR TF1 ; Clear timer flag 1
SJMP AGAIN ; reload the timer

(c) Draw the interfacing diagram where P2.3 pin of 8051 microcontroller is used to control 8M
relay which in turn controls the fan connected to 230 V. Describe operations of this circuit.

Ans: Microcontroller are intelligent devices but they can’t switch ON or OFF your room fan as they 4 M—
can’t handle heavy current so we use relays to do so. correct
diagram,4
Microcontroller can power ON or OFF an Relay’s Electromagnet. M—
When Electromagnet is turned on or off you can easily hear a sound of ‘tick’ just like a Operation
practical room switch. However, there is a glitch here: Relays electromagnet requires heavy of the
current to operate which Microcontroller can’t possible handle. circuit

A relay takes 70mA or 50mA current to excite the inductor coil.

The current sinking cability of each port pin of 8052 is only 20mA.

Hence port pin to which relay is connected may get damaged.To avoid this problem
ULN2003/ULN2803 driver is used.

In the figure Port 2 pin P2.3 is connected to in1pin of ULN2803.The out1 pin of ULN2803 is
connected to the relat which is connected to the fan.

Page
18/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

19

After execution of the program the fan can be controlled .

Q. Sub Answers Marking


N Q. N. Scheme
o.

5. Attempt any FOUR: 16- Total


Marks

a) Draw the interfacing diagram of stepper motor to Port 1 pins of 8051. Use ULN 2003 driver 4M
IC

Ans: 4M

Page
19/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

20

b) State the function of following pins of 8051 microcontroller : 4M

(i)

(ii)ALE

(iii)

(iv)RST

Ans (i) : It is active low output control signal used to activate enable signal of external 1M- EACH
ROM/ EPRM . it is activated every six oscillator periods while reading the external memory.

(ii)ALE : There are two ALE pulses per machine cycle. The Ale pulse, which is primarily
used as a timing pulse for external memory access, indicates when every instruction byte is
fetched.

(iii) : It is active low output control signal. When EA = 1, μc accesses internal and external
program memory when EA =0, μc accesses only external program memory.

(iv)RST : It is a RESET pin, which is used to reset the microcontroller to its initial values.

Page
20/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

21

C) Draw the labelled interfacing diagram of ADC 0809 with 8051 microcontroller 4M

Ans 4M

d) Describe the dual function of port 0 in brief

Ans Port 0 can be used as Function:2


a) Simple I/O Port and M
b) Bidirectional low order address and data bus ( AD0 – AD7) for external memory access.
Port -0 has 8 pins (P0.0-P0.7). Diagram:2
The structure of a Port-0 pin is shown in fig below M

Page
21/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

22

When the control is '0', the port can be used as a normal bidirectional I/O port. When the port
is used as an input port, '1' must be written to the latch and to output 0 on the pin „0‟ must be
written to the latch. When the control is '1', the port can be used as address/data bus(AD0 –
AD7)for external data transfer.
e) Describe any four tools of IDE 4M

Ans: Components of IDE: 1M EACH


• Compiler
• Cross assembler
• Cross compiler
• Linker/ Locators
• Loaders
• Simulators
• Debugger
Function: ( Any four component)
Compiler:
It is a computer program that transforms the source code written in a programming or
source language into another computer language i.e. target language i.e. binary code
known as object code.
Cross assembler:
It is useful to convert object codes for microcontrollers or processor to other codes for
another microcontrollers or processor and vice versa.
Cross compiler:
It is used to create executable code other than one on which the compiler is run.

Page
22/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

23

They are used to generate executable for embedded systems or multiple platforms.
Linker/Locator:
It is used for relocation process.
It is done during compilation also it can be done at run time by a relocating loader.
It is a program that takes one or more objects generated by compiler and combines them
into a single executable program.
Simulators:
A simulator is the software that simulates an hardware unit like emulator, peripheral,
network and I/O devices on a PC. It defines a processor or processing device as well
as various versions for the target system. It also monitors the detailed information as
source code part with labels and symbols during the execution for each single step.
It provides the detailed information of the status of memory RAM and simulated ports,
simulated peripheral devices of the defined target system.
Debugger:
It is a program that is used to test and debug the target program. Debugger allows to
download code to the Emulator’s memory and then control from PC. It also allows the
programmer to examine and modify the On-chip register and program memory data.

Q. Sub Answers Marking


N Q. N. Scheme
o.

6. Attempt any FOUR : 16- Total


Marks

a) Draw internal RAM organization of 8051 microcontroller 4M

Ans: 4M

Page
23/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

24

b) Describe stack and stack pointer of 8051 microcontroller 4M

Ans: 2M
DIAGRAM,
1M STACK,

Page
24/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

25

1M
stackpointer

Stack: The stack is a section of a RAM used by the CPU to store information such as data or
memory address on temporary basis. The CPU needs this storage area considering limited
number of registers. The register used to access the stack is known as the stack pointer
register.
Stack pointer: The 8-bit stack pointer (SP) register is used to hold an internal RAM address
that is called the top of stack. The address held in the SP register is the location in internal
RAM where the last byte of data was stored by a stack operation.

c) Draw the interfacing diagram to interface 3 X 3 key matrix to 8051 microcontroller 4M

Page
25/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

26

Ans: 4M

d) Write “C” language program to transfer the character “A” serially at baud rate 9600 , 8 bit 4M
data. 1 stop bit. Assume crystal frequency 11.0592 MHz

Ans: ( For any other relevant logic, marks can be given) 3M-
PROGRAM,
#include<reg51.h> 1M-
COMMENTS
void main(void)
{
TMOD=0x20; //use timer1, mode 2
TH1=0xfd; // 9600 baudrate

Page
26/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

27

SCON=0x50h;
tr1=1;
while(1)
{
SBUF=’A’; // place value in buffer
while(TI==0);
TI=0;
}
}

e) Draw interfacing diagram to interface relay at P2 and opt-isolator at P2.7 4M

Ans: 4M

f) Draw the interfacing diagram of 7 segment display to port P1 of 8051 microcontroller 4M

Ans 4M

Page
27/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

SUMMER– 19 EXAMINATION
Subject Name : Microcontroller and Application Model Answer 17509
Subject Code:

28

Page
28/28
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
WINTER – 19EXAMINATIONS
Subject Name:Microcontroller and ApplicationsModel AnswerSubject Code: 17509
Important Instructions to examiners:
1) The answers should be examined by key words and not as word-to-word as given in themodel 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 moreImportance (Not applicable for
subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in thefigure. The figures drawn by
candidate and model answer may vary. The examiner may give credit for anyequivalent 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 judgment 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.

Q. No. Sub Answer Markin


Q. N. g
Scheme

Q.1 (A) Attempt any THREE of the following: 12- M

a) Draw symbol of NAND gate and write its truth table. 4M

Ans: Symbol: Symbol


:2M
Truth
Truth Table: Table:
2M

State function of following pins of 16*2 LCD.


(i) RS
b) (ii) R/ ̅ 4M
(iii)EN
(iv) LED+

Ans: RS: RS is the register select pin used to write display data to the LCD (characters), this pin 1M
hasto be high when writing the data to the LCD. During the initializing sequence and other each
commands this pin should be low.
R/W: Reading and writing data to the LCD, for reading the data R/W pin should be high
(R/W=1) to write the data to LCD R/W pin should be low (R/W=0).
EN: Enable pin is for starting or enabling the module. A high to low pulse of about 450ns
Pulse is given to this pin. Sends data to data pins when a high to low pulse is given at this
pin.

Page 1 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
iv)LED+
It is pin no 15, inputpin. Backlight LED pin positive terminal.
c) List any four C data types with its size and ranges. 4M

Ans: 1M
each

Write function of following pins of 8051µc.


(i) RST
d) (ii) ̅̅̅̅̅̅̅̅ 4M
(iii)RXD
(iv) ̅̅̅̅
Ans: (i) RST 1M
It is a RESET pin, which is used to reset the microcontroller to its initial values. each
(ii) ̅̅̅̅̅̅̅̅ pin
It is active low output control signal used to activate enable signal of external ROM/ EPRM
.it is activated every six oscillator periods while reading the external memory.
(iii)RXD
Serial input line (Receive).RXD pin is pin no 10 and input pin to the microcontroller. It is
used to input serial data to the microcontroller.
iv) ̅̅̅̅
It is active low output control signal. When EA = 1, μc accesses internal and external
program memory when EA =0, μc accesses only external program memory.
(B) Attempt any ONE of the following: 6M

a) State alternate functions of Port 3. 2M

Page 2 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans:

b) Describe addressing modes of 8051 with examples. 4M

Ans: Addressing modes of 8051:


1.Immediate Addressing mode
2. Register Addressing mode
3. Direct Addressing mode
4 Register Indirect addressing mode
5.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.
For 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 instruction.
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:
In Indirect addressing mode, the data is obtained from a memory location which is indirectly
specified in the instruction.
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
The @ symbol indicated that the indirect addressing mode is used. If the data is inside

Page 3 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
The CPU, only registers R0 & R1 are used for this purpose.
5) 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.

Q.2 Attempt any TWO of the following: 16- M


Write an ALP to find largest number from given array of 10 bytes in external RAM
a) 8M
location 2000h onwards. Store largest number in internal RAM location 40h.
CLR PSW.3 ; Select Bank 0 PSW.3 Correct
MOV R1, 0AH ; Initialize byte counter program:
MOV DPTR, # 2000H ; Initialize memory pointer 8M
DEC R1 ; Decrement byte counter by 1
MOV X A, @DPTR ; Load number in accumulator
MOV 40 H, A ; Store number in memory location
Ans UP: INC DPTR ; Increment memory pointer by 1
: MOVXA, @DTPR ; Read next number
CJNE A, 40 H, DN ; if number≠ next number, and then go to NEXT
DN: JC NEXT ; If next number < number then go to NEXT
MOV 40H, A ; Else replace NEXT number with number
NEXT: DJNZ R1, UP ; Decrement byte counter by 1, if byte counter≠ 0
then go to UP
LOOP: AJMP LOOP ; Stop

b) Draw interfacing diagram of DAC 0808 with 8051µC and write C program to generate 8M
triangular wave.
Ans Diagram:
: 4M

Page 4 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
#include<reg51.h>
void main(void)
{
unsigned char d;
while(1) Program
{ :4M
for(d=0; d<255; d++)
{
P1 = d;
}
for(d=255; d>0; d--)
{
P1 = d;
}
}
}
c) Draw the interfacing diagram of stepper motor with 8051. Write excitation code to rotate 8M
it in clockwise direction.
Ans Diagram:
: 6M

Code:2M

Q.3 Attempt any FOUR of the following: 12- M

a) Draw and explain Reset circuit of 8051µC. 4M

Page 5 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans 2 marks:
: circuit
diagram

Power on & manual reset circuit


The power on reset circuit consists of 8.2 KΩ resistor and 10 μF capacitor. The values of these 2marks :
components are sufficient to provide a delay to make RST pin high for two machine cycles. explanati
For manual reset function switch is provided. Upon power ON or Key Press the RST pin goes on
HIGH and as capacitor charges through resistor R, RST signal goes LOW. This generates
active high reset signal for specific time decided by values of R & C.
b) Describe mode 2 of timer. State application of it. 4M

Ans Mode 2 – 8 bit Auto Reload 3Marks:


: TL operates as an 8-bit Timer / counter.TH holds a reload value. When TL overflows mode 2
(Reached FFH), the TFx flag is set, TL is reloaded from the value in TH and counting descripti
continues.
on
1mark :
applicati
on

Application:
To generate baud rate in serial communication
c) 4M
Write C program to toggle bits of P2. Use software delay.
Ans #include <reg51.h>
: void delay(unsigned int);
void main(void)
{
4M for
P2=0X00; // PORT 2 as output port
correct
while(1) program)
{ Any
P2=0X00; amount
delay(200); of delay
P2=0XFF; can be
delay (200); considere
d
}
}
void delay(unsigned int t)
{
Page 6 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
unsigned inti,j;
for(i=0;i<=t;i++)
for(j=0;j<=1275;j++);
}
OR
#include <reg51.h>
void delay(unsigned int);
void main(void)
{
P2=0X00; // PORT 2 as output port
while(1)
{
P2= ~ P2;
delay(200);
}
}
void delay(unsigned int t)
{
unsigned inti,j;
for(i=0;i<=t;i++)
for(j=0;j<=1275;j++);
}
ANY OTHER CORRECT PROGRAM LOGIC SHOULD BE GIVEN MARKS
d) Convert (59)10 = (?)16 = (?)2. 4M

Ans
:

e) Draw the format of SCON SFR. 4M

Ans SCON Register format- Correct


: format
4M

Page 7 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Q.4 (A) Attempt any THREE of the following : 12- M

a) Draw interfacing diagram for temperature measurement using LM 35, ADC 0808 4M
with 8051 microcontroller.
Ans Correct
: diagram
4M

b) Explain bitwise shift operator with example. 4M

Ans Bitwise Left Shift Operator in C : << 2marks:


: [variable]<<[ Number of Places] left shift
P0=0x3C<< 2 operator
After execution of this instruction
explanati
Shift number 2 bits to left:
3C = 0011 1100 on
st
1 left shift = 0111 1000 2marks:
2nd left shift =1111 0000 Right
So, P0=0xF0 shift
Bitwise Right Shift Operator in C: >> operator
[variable]>>[number of places] explanati
P0=0x3C >> 2
on
After execution of this instruction
Shift number 2 bits to Right:
3C=0011 1100
1st right shift = 0001 1110
2nd right shift = 0000 1111
So, P0=0x0F
c) Subtract (25)10 from (52)10 using 2’s compliment method. 4M

Page 8 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans
:

d) Draw the format of TCON sfr and explain each bit. 4M


Ans Format-2
: marks
Function
-
2marks

(B) Attempt any ONE of the following: 6M

a) Explain T-state, Machine cycle and instruction cycle. 6M

Page 9 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans Explanat
: ion: 2
marks
each.

One T-state is the time period of one clock signal. It is the reciprocal of system clock
frequency.
Machine cycle is the minimum time taken by microcontroller to perform an operation.
One machine cycle has 6 states. One state is 2 T-states. Therefore one machine cycle is
12 T-states.
Time to execute an instruction, called instruction cycle is found by multiplying C by 12 and
dividing product by Crystal frequency.
T=(C*12)/crystal frequency
Where C is number of machine cycles
b) Explain stack memory. Write any two stack related instruction. 6M

Ans 1. The stack memory is part of RAM used by the CPU to store information temporarily. 4 marks:
: 2. This information may be either data or address. Stack
3. The CPU needs this storage area as there are only a limited amount of registers. memory
4. The register used to access stack memory is called stack pointer. explanati
5. Upon reset SP contains 07H; this causes the stack to begin to location 08H. So, Register
on
banks 2, 3, 4 (08H to 1FH) form the default stack area.
6. The stack is generally placed in the general-purpose area (30H to 7FH) of the internal Writing
RAM. Any two
Stack Related Instructions: (any two ) instructio
a) PUSH ns: 2
b) POP marks:
c) CALL ( ACALL, LCALL ) (1 mark
d) RET
each
instructio
n)

Q.5 Attempt any TWO of the following : 16- M

a) Write C program to transmit ‘MSBTE’ on TXD line. 8M

Ans 2Marks
: Baud Rate Calculation: for
Timer Value = 2SMOD  Oscfreq
Calculati
12  32  Re quired Baud rate
Considering SMOD = 1 on

Page 10 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
20  Oscfreq
Timer Value = 12  32  Re quired Baud rate

Oscfreq = 11.0592Mhz

11.059Mhz
Timer Value =
12  32  Re quired baud rate
Case – 1 ) Required Baud rate = 4800

28,800
Time value =
4800
Timer value = 6
- 6 must be loaded in Timer for Required Delay.
Case – 2) Required Baud rate =9600
Timer value = 28,800 / 9600
Timer value = 3
-3 must be loaded in Timer for Required Delay
C Program: 1 Mark
#include <REG51.h> for
void Trans(unsigned char x); calculatio
void main(void) n and 5M
{ For
TMOD = 0X20; Program
TH1 = -3; // for 9600 Baud rate
SCON = 0X50;
TR1 = 1;
while(1)
{
Trans(‘ ‘);
Trans(‘M');
Trans(‘S');
Trans(‘B');
Trans(‘T');
Trans(‘E’);
}
void Trans(unsigned char x)
{
SBUF = x;
while(TI = = 0)
{ }
TI=0;
}
b) Write an ALP to generate square wave of 1kHz frequency on p2.3, Use timer 1 in 8M
model1. fOSC= 12 MHz

Page 11 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans 2Marks
: for
TMOD

Timer Calculation for 1Khz :


Required Frequency f= 1khz
Time Period T = 2Marks
for
T0N = T0FF = 0.5msec Calculati
To calculate Timer reload value for 0.5msec following formula is used ons
Re quiredTimedelay  OscFreq
Timer Value = (65536  )
12
Timer Value =

Timer Value = ( 65036 )10


Timer Value = (FE0C)16 4Marks
Assembly Program: for
ORG 30H ; Main Program starting Program
location
MOV TMOD,#10H ; Timer 1, mode 1
AGAIN: MOV TL1, #0CH ; Timer value
MOV TH1, #0FEH
SETB TR1 ; Start Timer
BACK: JNB TF1, BACK ; Wait till timer overflows
CLR TR1 ; Stop Timer
CPL P2.3 ; Get Next State of Square wave
CLR TF1 ; Clear timer flag 1
SJMP AGAIN ; Reload timer & Continue
c) Describe IDE with its components and state their functions. 8M

Page 12 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans 2Marks
:
Diagram

 In Embedded systems Code generation tools are used for creating and compiling. Then 6Marks
codes are tested using simulators and a number of latest software tolls like simulators ,
Logic Analyzers, profiler, Emulators etc. Explanat
 When all of these programs are integrated in one software package then it is called as ion
Integrated Development environment (IDE)
 Integrated Development Environment ( IDE ) consists of simulators with editors ,
compilers, assemblers, emulators, logic analyzers .
IDE Components:
Editor:
 You can type your assembly program-using editor.
 An editor is a program which helps you to construct your assembly language program in
right format so that the assembler will translate it correctly to machine language. This
form of your program is called as source program.
 The assembly program written using DOS Editor is stored as .asm extension &The C
Program written using DOS Editor is stored as .C extension.
Cross Assembler:
 An Cross Assembler is program that allows an Assembly program written on one type of
microcontroller to be used on another type.
Simulator:
 Simulator Simulates (Duplicates) the behavior of Target Hardware (Microcontroller) in
Software.
 Provides the detailed information of the status of RAM and ports (simulated) of the
defined target system and can execute each instruction in Single step mode.
Emulation:
 An emulator in computer sciences duplicates (provides an emulation of) the functions of
one system using a different system, so that the second system behaves like (and appears
to be) the first system.
Logic Analyzer:
 A logic analyzer is an electronic instrument that captures and displays multiple signals
from a digital system or digital circuit. A logic analyzer may convert the captured data
into timing diagrams.
RTOS:
 RTOS are used in system to execute any task in defined time limits. It has following
functions.
1. Memory Management
2. File Management
3. Port Management
Page 13 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
4. Process Management
5. I/O Management
Target Process Evaluator:
 Target Evaluation is the systematic process of gathering and analyzing data and other
objective information on processes and outcomes to determine the quality, value, and
effectiveness of coding & performance improvement.
Q.6 16-M
Attempt any FOUR of the following:
a) Draw structure of Interrupt and explain it. 4M

Ans Interrupt Structure: 2Marks


: for
Diagram

There are five interrupt sources on the 8051:


1. External 0 Interrupt
2. Timer 0 Interrupt
3. External 1 Interrupt
4. Timer 1 Interrupt
5. Serial Interrupt
All Interrupt are disabled after a system reset and are enabled individually by software. In the
event of two or more simultaneous interrupts or an interrupt occurring while another interrupt
is being serviced, there is both a polling sequence and a two level priority scheme to
schedule the interrupts. The polling sequence is fixed but the interrupt priority is
programmable. 2Marks
As shown in the interrupt structure External 0 / External 1 interrupts can be level triggered or for
Edge triggered. Explanat
IT0 / IT1 i.e. (ITx) in TCON are used to decide level triggering or edge ion
triggering. If ITx = 0 then low level interrupt is used to trigger 8051 & if ITx =1 then Falling
edge will set IEx flag and interrupt is generated. IT0 & IT1 bits are available in TCON SFR.
Draw the interfacing diagram of 3*3 keyboard matrix with 8051. Also explain logic to
b) 4M
read key.

Page 14 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans 2Marks
: for
Diagram

Keyboard Logic to read keyboard:


1. Port P1 is used as an O/P port for microcontroller 8051 & Port 2 as an I/P port of
microcontroller 8051
2. Make all rows of port P1 low so that it gives low voltage when key is pressed.
3. See if any key is pressed by scanning the port P2 by checking all columns for zero
condition. 2Marks
4. If any key is pressed, to identify which key is pressed make one row low at a time. for
5. Initiate a counter to hold the count so that each key is counted. Explanat
6. Check port P2 for zero condition. If any zero number is there then start column scanning ion
by following step 8.
7. Otherwise make next row low in port P1 and repeat from step 6
8. If any key pressed is found, then content in accumulator is rotated right through the carry
until carry bit sets, while doing this increment the count in the counter till carry is found.
9. Move the content in the counter to display in data field or to memory location
10. To repeat the procedures go to step 2.
c) List any four assembler directive and explain it. 4M

Ans Following are Assembler directives 1Marks


: 1. ORG for Each
2. EQU Assemble
3. DB r
4. DW
5. END Directive

(1) ORG (Originate ):


Org xxxx Originate the following code starting at address xxxx.
Example Program
Address Hex
Org 0400h becomes 0400 79
Mov r2, #00h 0401 00
The ORG pseudo lets you put code and data anywhere in program memory you wish.
Normally the program starts at 0000h using an org 0000h.
(2) EQU (Equate):
Label equxxxx Equate the label name to the number xxxx

Page 15 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Example program
Address Hex
Org 0000h becomes 0000 74
Fredequ 12h 0001 12
Mov a, #fred
EQU turns numbers into names; it makes the program much more readable because the name
chosen for the label can have some meaning in the program, whereas the number will not.
(3) DB(Define Byte)
db xx Define a byte: Place the 8 bit number xx next in memory.
Example program
Address Hex
Org 0100h becomes 0100 34
db 34h 0101 56
db 56h
DB xx takes the number xx (from 0 to 255) and converts it to hex in the next memory location.
DB permits the programmer to place any hex byte anywhere in memory.
(4) DW ( Define word ):
dwxxxx Define aword: place the 16bit number xxxx in memory.
Example program
Address Hex
org 0abcdh becomes abcd 12
dw 1234h abce 34
DW is a 16 bit version of db.
(5) End:
The End: Tells the assembler to stop assembling
d) Draw the structure of internal RAM of 8051. 4M

Ans 4 Marks
: for
Correct
Diagram

e) Draw the interfacing diagram of relay connected at P2.1 with 8051 microcontroller. 4M

Page 16 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans 4Marks
: for
Correct
Diagram

Page 17 / 17

You might also like