You are on page 1of 23

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

SUMMER – 2023 EXAMINATION


Model Answer – Only for the Use of RAC Assessors
Subject Name: Microcontroller & Application Subject Code: 22426
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.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and Bilingual
(English + Marathi) medium is introduced at first year of AICTE diploma Programme from academic year
2021-2022. Hence if the students write answers in Marathi or bilingual language (English +Marathi), the
Examiner shall consider the same and assess the answer based on matching of concepts with model
answer.

Q. Sub Answer Marking


No Q.No Scheme
1. Attempt any FIVE of the following: 10M
a) State two points of comparison between microcontroller & microprocessor 2M
with respect to Memory, I/O ports
Ans Comparison between microcontroller & microprocessor: 1 Mark
Microcontroller Microprocessor Each
Memory Inbuilt RAM and ROM. Do not have inbuilt RAM and ROM. point
Separate memory to store Program and data are stored in same
program and data. memory.
I/O ports I/O ports available I/O ports are not available

(Note: Marks may be given to any other valid point)


b) State the pins on ADC 0808/09 used for handshaking with the microcontroller 2M
8051.
Ans Pins on ADC 0808/09 used for handshaking with the microcontroller 8051. Any 4
Address lines: A, B, C ½ Mark
Address latch enable: ALE each
Start of Conversion: SOC
Output Enable: OE
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

Subject Name: Microcontroller & Application Subject Code: 22426

End of Conversion: EOC


Digital Output bits: D0- D7
c) State the function of following directives (1) DB (2) EQU 2M
Ans DB: - Define Byte 1 Mark
It is used to define data bytes 8-bit wide
Byte may be binary, Hex, decimal or ASCII form.
Syntax: LABEL: DB BYTE
EQU: Equate 1 Mark
It is used to define constant. The data label is associated with the constant
value; so wherever the label appears, the constant is substituted for the label.
Syntax: Label EQU Numeric value
d) State the use of GATE bit in TMOD SFR format, in 8051 microcontroller. 2M
Ans The Gate bit is used to operate the Timer with respect to the INT pin or 2 Mark
regardless of the INT pin.
If Gate=1; Enable Timer/Counter only when the INT0/INT1 pin is high and
TR0/TR1 is set.
If Gate=0; Enable Timer/Counter when TR0/TR1 is set.
e) State the use of Boolean processor of 8051 microcontroller with one example. 2M
Ans Use of Boolean processor of 8051 microcontroller: The 8051 instruction set is Use 1
optimized for the one bit operations. The Boolean processor provides direct Mark
support for bit manipulation and testing of individual bit allows the use of single
bit variable to perform logical operations therefore 8051 can be used to solve Example
Boolean expression. Bits may be set or cleared in a single instruction. 1 Mark
Example: CLR C; clear the carry bit
SETB 20h; set the memory bit with bit address 20h.
f) State the necessity of External memory interfacing with 8051 microcontroller. 2M
State the status of EA pin during external memory access.
Ans Necessity of External memory interfacing with 8051 microcontroller: Necessit
External memory interfacing in 8051 microcontroller involves connecting external y
memory devices such as RAM and ROM to the microcontroller to provide additional 1 Mark
memory space. This allows the microcontroller to execute larger and more complex
programs, store more data, and perform more complex operations.
Status of EA pin during external memory access. Status
The status of EA pin is Low. 1 Mark
g) Write an Assembly language program to generate square wave on Port Pin P 2M
1.5 of 8051 microcontroller using Timer 0 in mode 1. Assume clock frequency
as 12 MHz
Ans Crystal frequency= 12 MHz Progra
Timer Frequency = (12 X 106)/12= 1MHz m with
Tin = 1/ Timer Frequency = 1/1MHz = 1μ sec correct
Assume frequency of square wave is 1KHz. logic
For 1 kHz square wave 2Marks

Page No: 2/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

Fout = 1 KHz
Tout = 1/ 1X 103
Tout = 1000μ sec
Consider half of it = Tout = 500μ sec
Count Value for 500μ sec
(65536 – count) * Tin =Tout
(65536 – count) * 1μ sec = 500μ sec
(65536 – count) = 500/1 = 500
Count = 65536-500= (65036)10 = (FE0C)16

Program: -
ORG 0000H
MOV TMOD, # 01H ; Set timer 0 in Mode 1, i.e., 16 bit timer
AGAIN: SETB P1.5 ;Make P 1.5 high
ACALL DELAY ; Call Delay Program
CLR P1.5 ;Make P 1.5 low
ACALL DELAY ; Call Delay Program
SJMP AGAIN ; re-load timer with count as mode 1 is not
auto reload
DELAY: MOV TL0, # 0CH ; Load TL register with LSB of count
MOV TH0, # FEH ; Load TH register with MSB of count
SETB TR0 ; start timer 0
HERE: JNB TF0, HERE ; poll till timer roll over
CLR TR0 ; stop timer 0
CLR TF0 ;clear timer flag 0
RET
END

OR (By using Complement instruction)

ORG 0000H
MOV TMOD, # 01H ; Set timer 0 in Mode 1, i.e., 16 bit timer
L2: MOV TL0, # 0CH ; Load TL register with LSB of count
MOV TH0, # FEH ; 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.5 ;complement P 1.5 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

Page No: 3/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

END
(Note: The above program can be considered for any frequency of square)
wave.

2. Attempt any THREE of the following: 12M


a) With neat labelled interfacing diagram, explain the working of water level 4M
controller using 8051 microcontroller.
Ans Interfacing diagram of water level controller with 8051 microcontroller: 2M –
Diagr
am
2M –
Expla
nation
or
progr
am
Consider
r other
relevant
answer

• The level sensor probes for the overhead tank are interfaced to the port1 of
the microcontroller i.e. P1.0 (high level sensor) and P1.1 (low level
sensor).
• We have assumed that when water is touched to sensor then logic 1 will be
available at sensor probe. When port pins p1.0 and p1.1 are high means the
tank is full and when port pins P1.0 and P1.1 are low means the tank is empty.
• We also assumed that P1.2-P1.7 are grounded.
• Port pin P2.0 is used to control the pump.
• Considering this assumptions the program will be as follows,

MOV P1,#11111111B // initiates P1 as sensor input


UP: MOV A,P1 // moves the current status of P1 to
A
CJNE A,#00000011B,LABEL1 // checks whether tank is full
CLR P2.0 // switches the pump OFF
LABEL1: MOV A,P1 // moves the current status of P1 to
A
CJNE A,#00000000B, UP // checks whether tank is
empty
SETB P2.0 // switches the pump ON
SJMP UP
END

Page No: 4/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

b) Compare Harvard and Von-Neumann architecture. (Any four points of 4M


comparison)
Ans Harvard and Von-Neumann architecture comparison: Any
4
Sr. Von Neumann architecture Harvard architecture point
No. s
1 1M–
Each
point

2 The Von Neumann The Harvard architecture uses


architectureuses single physically separate memories for
memory for storing storing instructions and data.
instructions and data.
3 Requires single bus for Requires separate & dedicated buses
instructions and data for instructions and data.
4 Instructions and data have to Instructions and data can be fetched
be fetched in sequential order simultaneously as there is separate
limiting the operation buses for instruction and data which
bandwidth. increasing operation bandwidth.
5 Width of address and data bus Width of address and data bus for
for program and data memory can be
program and data memory are different
same
6 Its design is simpler Its design is complicated
7 Suitable when memory is Suitable when memory is on-chip
external
8 For e.g. general purpose For e.g. microcontrollers, PIC, DSP
microprocessors
c) Write a program in Assembly language for 8051 to transfer data "A" serially 4M
at 4800 baud rate continuously. (Assume suitable data)
Ans Program to transfer data "A" serially: 3 Marks
ORG 0000H Progra
MOV TMOD, #20H ; timer 1, mode2 m,
MOV TH1,#-6 or MOV TH1,#0FAh ; 4800 baud rate 1 Mark
MOV SCON, #50H ; 8-bit data,1 stop bit, commen
SETB TR1 ; Start timer 1
ts
AGAIN: MOV SBUF,# “A” ; transfer “A”
HERE: JNB TI, HERE
CLR TI
SJMP AGAIN
END
d) Draw interfacing diagram of LCD with microcontroller 8051. Explain the 4M

Page No: 5/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

function of following pins:


(1) RS (2) VEE
Ans Interfacing diagram of LCD with microcontroller 8051: 2M –
Diagr
am

Funct
ion 1
Mark
each
RS: RS is the register select pin.
We need to set it to 1, if we are sending some data to be displayed on LCD. And
we will set it to 0 if we are sending some command instructions during the
initializing sequence like clear the screen etc.
VEE: VEE pin is use to adjust the display contrast, through a variable resistor.
3. Attempt any THREE of the following: 12M
a) Explain the power saving options of microcontroller 8051 with suitable 4M
diagram.
Ans Power saving modes of operation : 2 M-
diagram
8051 has two power saving modes. They are -
1M
each for
1. Idle Mode
the two
2. Power Down mode. modes

The two power saving modes are entered by setting two bits IDL and PD in the
special function register (PCON) respectively.
The structure of PCON register is as follows

Page No: 6/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

Power control circuit

Note: Any other similar diagram may be considered

Idle mode
Idle mode is entered by setting IDL bit to 1. (). The clock signal is gated off to
CPU but not to interrupt, timer and serial port functions. The CPU status is
preserved entirely. SP, PC, PSW, Accumulator and other registers maintain their
data during idle mode. The port pins hold their logical states they had at the time
Idle was initiated. ALE and PSEN are held at logic high levels
Ways to exit Idle Mode:
1. Activation of any enabled interrupt will clear PCON.0 bit and hence the Idle
Mode is exited. The program goes to the Interrupt Service Routine (ISR). After
RETI is executed at the end of the ISR, the next instruction will start from the
one following the instruction that enabled Idle Mode.
2. A hardware reset exits the idle mode. The CPU starts from the instruction
following the instruction that invoked the 'Idle' mode.
Power Down Mode:
The Power down Mode is entered by setting the PD bit to 1. The internal clock to
the entire microcontroller is stopped (frozen). However, the program is not dead.
The Power down Mode is exited (PCON.1 is cleared to 0) by Hardware Reset
only. The CPU starts from the next instruction where the Power down Mode was
invoked. Port values are not changed/ overwritten in power down mode. Vcc can
be reduced to as low as 2V in Power Down mode. However, Vcc has to be
restored to normal value before Power Down mode is exited.
b) Develop an assembly language program for 8051 to add data stored at five 4M
consecutive address location starting from 30 H. Store the result at 40 H and
carry at 41 H.
Ans ORG 0000 H ; Initialize 4 M for
MOV R0,#30H ;Source memory pointer the
MOV R2,#05 H ;Counter correct
CLR A ;Make Accumulator 0
Page No: 7/23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

Subject Name: Microcontroller & Application Subject Code: 22426

MOV R7,A ; Copy the contents of accumulator to Register R7 program


to store Carry
UP: ADD A,@R0 ;Add number from source to accumulator
JNC NEXT ; Jump to label next if there is no carry
INC R7 ;else increment R7
NEXT: INC R0 ;Increment source pointer
DJNZ R2 , UP ;Decrement counter and jump to UP if not 0
MOV 40 H, A ; Copy the result into RAM location 40 H
MOV A, R7 ; Copy the carry from R7 into into RAM location
40 H
MOV 41 H, A
END ; End the program
c) State and explain software development cycle used for application development 4M
with microcontroller.
Ans Software Development cycle 2 M for
The steps involved in Program Development and Execution of assembly language diagram
programs. Following fig. shows these steps. The left side of the figure shows the
time period, at which each step in the overall process takes place. 2 M for
the
descripti
on

The first step in the development process is to write an assembly language program.
The assembly language program can be written with an ordinary text editor such as
word star, edit and so on. The assembly language program text is an input to the
assembler.

The assembler translates assembly language statements to their binary equivalents,


Page No: 8/23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

Subject Name: Microcontroller & Application Subject Code: 22426

usually known as object code. Time required to translate assembly code to object
code is called Assemble Time. During assembling process assembler checks for
syntax errors and displays them before giving object code module.

The object code module contains the information about where the program or
module to be loaded in memory. If the object code module is to be linked with other
separately assembled modules then it contains additional linkage information. At
link time, separately assembled modules are combined into one single load module,
by the linker.

The linker also adds any required initialization or finalization code to allow the
operating system to start the program running and to return control to the operating
system after the program has completed.

Most linkers allow assembly language modules to be linked with


object code modules compiled from high-level languages as well. This allows the
programmer to insert a time-critical assembly language routines, library modules
into a program.

At load time, the program loader copies the program into the computer’s main
memory, and at execution time, program execution begins

OR

The step of Assembly language program are outlines as follows:


1) First we use an editor to type a program, many excellent editors or word
processors are available that can be used to create and/or edit the program
• Notice that the editor must be able to produce an ASCII file
• For many assemblers, the file names follow the usual DOS conventions, but
the source file has the extension “asm“ or “src”, depending on which
assembly you are using
2) The “asm” source file containing the program code created in step 1 is fed to
an 8051 assembler
• The assembler converts the instructions into machine code

• The assembler will produce an object file and a list file

• The extension for the object file is “obj” while the extension for the list file
is “lst”
3) Assembler require a third step called linking
• The linker program takes one or more object code files and produce an
absolute object file with the extension “abs”

Page No: 9/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

• This abs file is used by 8051 trainers that have a monitor program

4) Next the “abs” file is fed into a program called “OH” (object to hex converter)
which creates a file with extension “hex” that is ready to burn into ROM
• This program comes with all 8051 assemblers
• Recent Windows-based assemblers combine step 2 through 4 into one step

Note: Any other relevant diagram maybe considered

d) Draw and explain the configuration & internal structure of Port 1 of 8051 4M
microcontroller.
Ans Port 1 2 M for
the
It has a D type latch for each pin. The data on the port latches need not be same as diagram
that on the pins.
2 M for
The 2 data paths have entirely separate buffer circuits that read the latch or pindata. descripti
The upper buffer is enabled when the latch data is read and the lower buffer when on
the pin state is read.

• No dual function

• When used as an input, a 1 is written to the latch, turning the lower FET off,
the pin and the input to the pin buffer are pulled high by the FET load

• If used as an output, 0 is written to the latch, lower FET is on, the pull up is
off and the pin can drive the input of the ext circuitry low.

Page No: 10/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

4. Attempt any THREE of the following: 12M

a) Write an ALP to rotate stepper motor in clockwise direction through 360°. 4M


Consider step angle of motor 1.8°/step. Write the sequence used for rotation.
Ans Given:
Step Angle of Motor=1.8°/step
Required rotation=360°
Hence No. of Steps= 360/1.8=200
Sequence for Rotation:
A1 A2 B1 B2 Data CW CCW 1 mark
1 0 1 0 A for steps
1 0 0 1 9 calculati
0 1 0 1 5 on
0 1 1 0 6 1 mark
Program: for
ORG 0000H sequence
MOV R1, #32H and data
REPEAT: MOV P1, #0AH
LCALL Delay 2 marks
MOV P1, #09H for
LCALL Delay program
MOV P1, #05H code
LCALL Delay
MOV P1, #06H
LCALL Delay
DJNZ R1, REPEAT
HERE: LCALL HERE

Delay: MOV R2, #12H


Page No: 11/23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

Subject Name: Microcontroller & Application Subject Code: 22426

AGAIN1:MOV R3, #0FFH


AGAIN: DJNZ R3, AGAIN
DJNZ R2 AGAIN1
RET
END
OR

Sequence for Rotation:


A1 B1 A2 B2 Data CW CCW
1 1 0 0 C
1 0 0 1 9
0 0 1 1 3
0 1 1 0 6
Program:
ORG 0000H
MOV R1, #200H
MOV A, #0CCH
REPEAT: MOV P1, A
LCALL Delay
RL A
DJNZ R1, REPEAT
HERE: LCALL HERE

Delay: MOV R2, #12H


AGAIN1: MOV R3, #0FFH
AGAIN: DJNZ R3, AGAIN
DJNZ R2 AGAIN1
RET
END
b) Compare 8031 & 8052 (Any four points of comparison) 4M

Ans 1 mark
for each
Point of Difference 8031 8052 correct
Inbuilt ROM available 0KB 8KB point
Inbuilt RAM available 128 Bytes 256 Bytes
No. of Timers/ Counters 2 3
No. of interrupts 6 8

Page No: 12/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

c) Draw & explain interfacing diagram of DAC 0808 with microcontroller 8051. 4M

Ans Interfacing of DAC0808 with 8051 microcontroller:


• Microcontroller generates output which is in digital form but many controlling
system requires analog signal as they don't accept digital data thus making it 2 marks
necessary to use DAC which converts digital data into equivalent analog for
voltage. descripti
• To interface 8051 with DAC0808 we can use any port let’s consider here Port1. on
Port1 pins 0 to 7 are connected to D0 to D7 pins of DAC0808. When the 8 bit
Hex data is given to these pins it converts the digital data into equivalent analog
current.
• In the figure shown, we use 8-bit DAC 0808. This IC converts 8 bit digital data 2 marks
into equivalent analog current. Hence we require an I to V converter to convert for
this current into equivalent voltage. diagram

d) Write an ALP in 8051 to generate triangular waveform using DAC 0808. 4M

Ans Program:

ORG 0000H
REPEAT: MOV A, #00H ; Clear A
INCR: MOV P1, A ; Send value to P1 4 marks
INC A ; increment value for
CJNE A, #0FFH, INCR ;Compare with highest value correct
DECR: MOV P1, A program
DEC A ; Decrement value
code
CJNE A,#00H, DECR ;Compare with lowest value
SJMP REPEAT ; repeat
END

e) Write an ALP for 8051 microcontroller to generate a delay of 1m sec. Using 4M


timer operation. (Consider clock freq. 12 MHz)
Ans Given Crystal frequency= 12 MHz 1 mark
I/P clock = (12*10^6 )/12= 1 MHz for
Tin = 1μ sec calculati
Required Delay = 1 msec
Page No: 13/23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

Subject Name: Microcontroller & Application Subject Code: 22426

N = Required Delay/ Tin = 1 msec /1 μ sec = 1000 on of


Timer Count= 65535 – 1000+1 = (64536)10 = (FC18)16 timer
count
Program:-Lets consider timer0 is used to generate delay
MOV TMOD, # 01H ; Set timer 0 in Mode 1, i.e., 16 bit timer 3 marks
MOV TL0, # 18 H ; Load TL register with LSB of count for
MOV TH0, # 0FC H ; load TH register with MSB of count
program
SETB TR0 ; start timer 0
L1: JNB TF0, L1 ; poll till timer roll over
CLR TR0 ; stop timer 0
CLR TF0 ; clear timer flag 0
L2: SJMP L2 ; Stop

5. Attempt any TWO of the following: 12M


a) Explain the application of stack in microcontroller 8051, with suitable example. 6M
Ans • STACK: Stack
It s part of RAM in which data will be stored temporarily during execution of the applicati
program. The CPU needs this storage area considering limited number of registers. on -2 M
STACK works on last in first out principle (LIFO).to store and retrieve data
during program execution. Push and Pop instruction are used for stack operation
• PUSH:
its used to store data into stack.
• POP:
to retrieve data from stack.
• SP:
stack pointer is 8 bit register which store value of top of the stack. by default stack
pointer contain 07h.

Example
Example: When executing PUSH instructions: (Refer fig 1)
of PUSH
–2M

Fig(1)

MOV R6, #25H


MOV R1, #12H
MOV R4, #0F3H
PUSH 6
PUSH 1
PUSH 4
MOV R6, #25H
Page No: 14/23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

Subject Name: Microcontroller & Application Subject Code: 22426

MOV R1, #12H


MOV R4, #0F3H
PUSH 6
PUSH 1
PUSH 4
Example: When executing POP instructions: (Refer fig 2)

Example
of POP
–2M

Fig (2)

POP 3; POP stack into R3


POP 5; POP stack into R5
POP 2; POP stack into R2

b) Write an ALP for 8051 microcontroller, to move a block of data stored at


location 40 H to 44 H to location 50 H to 54 H. (Consider suitable data)

Ans ORG 0000H ;Initialize 6M for


MOV R0,#40H ;Source memory pointer the
MOV R1,#50H ;Destination memory pointer correct
MOV R7,#05H ;Counter program
UP: MOV A,@R0 ;Get number from source to accumulator
MOV @R1,A ;Move number to destination
INC R0 ;Point on next memory location
INC R1 ;Point on next memory location
DJNZ R7, UP ;Decrement counter& repeat the transfer till counter ≠0
END ;End of Program

Page No: 15/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

c) Draw an interfacing diagram of temperature controller, using LM35, & ADC c)


0808/09 with 8051 microcontroller.
Write an ALP to read the temperature. (consider suitable data)
Ans Diagram
-3 M

Progra
m-M

Program to read the temperature

ADDR_A BIT P2.0 ; Address A pin of ADC is connected to Port pin


P2.0
ADDR_B BIT P2.1 ; Address B pin of ADC is connected to Port pin
P2.1
ADDR_C BIT P2.2 ; Address C pin of ADC is connected to Port pin
P2.2
SC BIT P2.3 ; Start of conversion SC pin of ADC is connected to
Port pin P2.3
ALE BIT P2.4 ;ALE pin of ADC is connected to Port pin P2.4
OE BIT P2.5 ; OE pin of ADC is connected to Port pin P2.5
EOC BIT P2.6 ; End of conversion EOC pin of ADC is connected
to
Port pin P2.6
MY_DATA EQU P1 ;Digital Data out pins of ADC are connected to
Port P1
CLR ALE ; clear ALE
ORG 0000H
MOV MY_DATA,#0FFH ; make P1 as input
SETB EOC ; make EOC an input
CLR SC ; clear SC

Page No: 16/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

CLR OE ;clear OE
CLR ADDR_C ; C=0
CLR ADDR_B ; B=0
SETB ADDR_A ; A=0(select channel 0)
ACALL DELAY
SETB ALE ; latch address
ACALL DELAY
BACK: SETB SC ; start conversion
ACALL DELAY
CLR ALE
CLR SC
HERE: JB EOC,HERE ; wait
HERE1: JNB EOC,HERE1 ; wait for EOC to go high
SETB OE ; set output enable pin to make converted
data
available
ACALL DELAY
MOV A, MY_DATA ; Read converted digital data from ADC
MOV P0, A ; send read data to PORT P0
CLR OE ; Clear output enable
SJMP BACK
DELAY: MOV R3,#25 ; Delay Subroutine
L3:MOV R4,#100
L2: MOV R5,#100
L1: DJNZ R5,L1
DJNZ R4,L2
DJNZ R3,L3
RET
(Note : Marks may be given to any other program with correct logic)

Page No: 17/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

6 Attempt any TWO of the following: 12M


a) Write an ALP for traffic light controller using microcontroller 8051. Use 6M
timers in the 8051 to obtain delay. (Consider suitable data)
Ans
Four way traffic light control system:
2 marks
for
diagram
&
procedu
re

Lets consider the following traffic light control system


Traffic lights interfacing with Microcontroller 8051:

4 marks
for
Progra
m
Process:
1. Allow traffic from W to E and E to W i.e. WG, EG, NR, SR lights ON and all
other lights OFF.
2. Yellow light ON i.e. WY, EY, NR, SR lights ON and all other lights OFF.
3. Allow traffic from N to S and S to N i.e. NG, SG, ER, WR lights ON and all
other lights OFF.
4. Yellow light ON i.e. NY, SY, WR, ER lights ON and all other lights OFF.
5. Repeat Process

Page No: 18/23


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

Subject Name: Microcontroller & Application Subject Code: 22426

Lane Chart:
Lane Direction 8051 Port pins Light Indicators
North P0.1 [NR] RED
P0.2 [NY] YELLOW
P0.3 [NG] GREEN
South P0.4 [SR] RED
P0.5 [SY] YELLOW
P0.6 [SG] GREEN
East P0.7 [ER] RED
P0.8 [EY] YELLOW
P3.0 [EG] GREEN
West P3.1 [WR] RED
P3.2 [WY] YELLOW
P3.3 [WG] GREEN

Timer Count:
Consider Crystal frequency= 12 MHz
I/P clock = (12*10^6 )/12= 1 MHz
Tin = 1μ sec
Required Delay = 50 msec
N = Required Delay/ Tin = 50 msec /1 μ sec = 50000
Timer Count= 65535 – 50000+1 = (15536)10 = (3CB0)16

Program:
NR EQU P1.0
NY EQU P1.1
NG EQU P1.2

SR EQU P1.3
SY EQU P1.4
SG EQU P1.5

ER EQU P1.6
EY EQU P1.7
EG EQU P3.0

WR EQU P3.1
WY EQU P3.2
WG EQU P3.3

MOV P1,#00H
MOV P3,#00H
MOV TMOD, # 11H ; Set timer 0 & timer1 in Mode 1, i.e, 16 bit timers
AGAIN: SETB NR ;North Red ON
SETB SR ; South Red ON
SETB EG ;East Green ON
SETB WG ; West Green ON
ACALL DELAY

Page No: 19/23


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

Subject Name: Microcontroller & Application Subject Code: 22426


CLR EG ;East Green OFF
CLR WG ;West Green OFF
SETB EY ; East Yellow ON
SETB WY ; West Yellow ON
ACALL Y_DELAY ; Small Delay for Yellow
CLR EY ; East Yellow OFF
CLR WY ; West Yellow OFF
SETB ER ; East Red ON
SETB WR ;West Red ON
CLR SR ; South Red OFF
CLR NR ; North Red OFF
SETB NG ; North Green ON
SETB SG ; South Green ON
ACALL DELAY
CLR NG ; North Green OFF
CLR SG ; South Green OFF
SETB NY ; North Yellow ON
SETB SY ; South Yellow ON
ACALL Y_DELAY
CLR NY ; North Yellow OFF
CLR SY ; South Yellow OFF
CLR ER ; East Red OFF
CLR WR ; West Red OFF
AJMP AGAIN
DELAY:MOV R1,#0F0 H ; Set counter to repeat delay 240 times to achieve delay of 2 min.
AGAIN: MOV TL0, # 0B0 H ; Load TL register with LSB of count
MOV TH0, # 3C H ; 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
CLR TF0 ; clear timer flag 0
DJNZ R1, AGAIN
RET

Y_DELAY:MOV R1,#3C H ; Set counter to repeat delay 60 times to achieve delay of 30sec
AGAIN1: MOV TL1, # 0B0 H ; Load TL register with LSB of count
MOV TH1, # 3C H ; load TH register with MSB of count
SETB TR1 ; start timer 0
L2: JNB TF1, L2 ; poll till timer roll over
CLR TR1 ; stop timer 0
CLR TF1 ; clear timer flag 0
DJNZ R1, AGAIN1
RET
END

b) Draw format of IE register in 8051 microcontroller & write instructions to 6M


enable serial interrupt, timer 0 interrupt and external hardware interrupt 1
(EX1)
Ans IE (Interrupt Enable) Register: Correct
Format
This register is responsible for enabling and disabling the interrupt. EA bit is set to 1 for
of IE
enabling interrupts and set to 0 for disabling the interrupts. Its bit sequence and their
register
Page No: 20/23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

Subject Name: Microcontroller & Application Subject Code: 22426

meanings are shown in the following figure. carries 2


marks,

Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 Bit


EA -- -- ES ET1 EX1 ET0 EX0 explanat
ion 2
marks
It disables all interrupts. When EA = 0 no interrupt will
be acknowledged and EA = 1 enables the interrupt and
EA IE.7
individually. Instructi
ons 2
- IE.6 Reserved for future use. marks

- IE.5 Reserved for future use.

ES IE.4 Enables/disables serial port interrupt.

ET1 IE.3 Enables/disables timer1 overflow interrupt.

EX1 IE.2 Enables/disables external interrupt1.

ET0 IE.1 Enables/disables timer0 overflow interrupt.

EX0 IE.0 Enables/disables external interrupt0.

Instructions to enable serial interrupt, timer 0 interrupt and external hardware


interrupt 1 (EX1):
SETB EA
SETB ES
SETB ET0
SETB EX1
OR
MOV IE, #96 H

c) Explain four addressing modes of 8051 microcontroller with suitable examples 6M


of each.
Ans Addressing Modes of 8051 Microcontroller: Addressing is a way to access or Correct
address the operand. In microcontrollers the data may residing in registers, memory Explana
( RAM or ROM) or it may be user/ directly defined in instruction, also it may be tion of
single bit, one byte or two bytes. The operand is the data we are manipulating. each
Based on above there are different addressing modes used in 8051 microcontroller addressi
listed as below ng mode
carries 1
1. Immediate Addressing Mode
mark
2. Register Based Addressing Mode
Page No: 21/23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

Subject Name: Microcontroller & Application Subject Code: 22426

3. Direct Addressing Mode and


4. Register indirect Addressing Mode example
5. Indexed Addressing Mode
carries
6. Implied Addressing Mode
1. Immediate Addressing Mode: In Immediate Addressing Mode, the source data is ½ mark
8 bit or 16 bit provided in the instruction itself. The data is provided immediately
Any
after the opcode. To mention immediate data symbol “#” must mention before the
source data. Examples of Immediate Addressing Mode are four
MOV A, #78H ; Copies the data 78H into the Accumulator. addressi
MOV DPTR, #3478H ; Copies the data 3478H into data pointer register. ng
MOV P3, #0AAH ; Copies the data AAH to output port3. modes
MOV R5, #3CH ; Copies the data 3CH into the R5 register. carries 6
2. Register Based Addressing Mode: In the register addressing mode the source or
marks
destination data should be present in a register such as R0 to R7, A, B, DPH or
DPL, and so on. Examples of Register Addressing Mode are
MOV A, B ; Copies the data from B register to the Accumulator.
MOV DPL, R5 ; Copies the data from R5 register to data pointer lower register.
MOV P3, A ; Copies the data from Accumulator to output port3.
MOV R3, A ; Copies the data from Accumulator to the R3 register.
3. Direct Addressing Mode: This mode is used to access the internal memory of the
microcontroller 8051.In Direct Addressing Mode, the source or destination
address is specified by using 8-bit data in the instruction. Examples of Direct
Addressing Mode are
MOV A, 45H ; Copies the data from memory location 45H to the Accumulator.
MOV 60H, R5 ; Copies the data from R5 register to memory location 65H.
MOV 45H, 80H ; Copies the data from memory location 80H to memory location
45H.
4. Register indirect Addressing Mode: This mode is used to access an internal and
external memory locations. In this mode, the source or destination address is
given in the register. To locate 8-bit addresses R0 or R1 registers are used and for
16-bit addresses, the DPTR register is used, no other registers can be used for
addressing purposes. To transfer data to external memory symbol “X” is used.
Examples of Register Indirect Addressing Mode are
MOV A, @R1 ; Copies the data from memory location pointed by R1 register to the
Accumulator.
MOV @R0, B ; Copies the data from B register to memory location pointed by the
R0 register.
MOV A, @DPTR ; Copies the data from memory location pointed by DPTR to the
Accumulator.
MOVX A,@R0 ; Copies the data from external memory location pointed by R0
register to the Accumulator.
5. Indexed Addressing Mode: In the indexed addressing mode, the source data is
fetched form code memory or program memory only. The destination operand is
always the register A and the other operand register can be the Program counter
(PC) or Data Pointer (DPTR). The symbol “C” indicates the code memory
instruction set. Examples of Indexed Addressing Mode are
MOVC A, @A+PC ; Copies the data from memory location pointed by contents of
PC+A to the Accumulator.
MOVC A, @A+DPTR ; Copies the data from memory location pointed by contents
of DPTR+A to the Accumulator.
Page No: 22/23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)

Subject Name: Microcontroller & Application Subject Code: 22426

6. Implied Addressing Mode: In this addressing mode, only one operand specified in
the instruction. A specific register assigned for such instructions. These types of
instruction can work on specific registers only. These types of instructions are
also known as register specific instruction. Examples of Implied Addressing
Mode are
SWAP ; It swaps the lower nibble with higher nibble of Accumulator itself.
RLA ; It rotates the contents of accumulator by one bit position towards left.
RRA ; It rotates the contents of accumulator by one bit position towards right.

Page No: 23/23

You might also like