[EJ/EN/ET/EX/DE/IS/IC/IE/EV/MU] Microcontrollervidyalankar.org/upload/MC_Soln.pdf · Prelim...
Transcript of [EJ/EN/ET/EX/DE/IS/IC/IE/EV/MU] Microcontrollervidyalankar.org/upload/MC_Soln.pdf · Prelim...
T.Y. Diploma : Sem. V [EJ/EN/ET/EX/DE/IS/IC/IE/EV/MU]
Microcontroller Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 100
Q.1(a) Attempt any THREE of the following: [12] Q.1(a) (i) Distinguish between Microprocessor and Microcontroller (any four). [4] (A) (Any four points 1 mark each)
Micro-processor Micro-controller 1) Micro-processors do not have
inbuilt RAM or ROM. Micro-controller do have inbuilt RAM or ROM.
2) Memory, I/O ports, timers, interrupts are not integrated inside the chip.
Memory, I/O ports, interrupts, timers, are integrated inside the chip.
3) Micro-processors to work as micro-computers requires many additional components to perform its operation.
Micro-controllers can be worked as micro-computers without any additional components.
4) Program and data are stored in same memory.
Separate program and data memory.
5) Booleans operations are not possible directly.
Boolean operations are possible directly.
6) e.g. Pentium series, Intel 8086 e.g. 8051, PIC 16F series
Q.1(a) (ii) Draw the block diagram of Harvard and Von-Neumann architecture.
[4]
(A) Harvard architecture
Von-Neumann architecture
CPU
Data Memory
Program Memory
Data bus
Address bus
Data bus
Address bus
CPU
Data bus
Address bus
Program Memory
Data Memory
307/379/e:1114/1114/TY/Pre_Pap/Ele/2014/CP/MC_Soln 1
Vidy
alank
ar[12][12
any four). [4][4]
o-controllerrolle arararroller do have inbuilt do have inbuROM.ROM kaaaory, I/O ports, interrupts, /O ports, interrupts,
mers, are integrated inside the re integrated insidechip. kaaaro-
tional Microcro--controllers can be workcontrollers can microro--computers without acomputers wadditional cadditional components.onklae stored in ored Separate programSeparate pmemory.memorlalalalaations are not are not
ectly.Boolean opeBooledirectly.dalalalalaium series, Intel 8086ries, Intel 8086 e.g. 8alllyaraw the block diagram of raw the block diagram
architecture.chitecture.Harvard architecturervard architecture
Von-NeumVidyCPUCPUdydydydydydydddd
VData busbus
Address
Da
V
Vidyalankar : T.Y. Diploma MC
Q.1(a) (iii) List any four important features of 8051 microcontroller. [4] (A) Features of 8051 Micro-controller are as follows :
1) It has 8-bit CPU. 2) It has 4kb on-chip program memory. 3) 128 bytes of on-chip data memory. 4) It has 32 bi-directional I/O lines. 5) It has two 16-bit timers/counters. 6) It has 5 vector interrupts. 7) It has full duplex asynchronous receiver transmitter (one serial port) 8) It has on-chip clock oscillators.
Q.1(a) (iv) Describe any four addressing modes of 8051 microcontroller
with one example each. [4]
(A) Types of addressing modes are as follows : (a) Immediate addressing mode : Immediate addressing mode means the
data is provided as a part of instruction (it immediately follows instructions opcode).
e.g. MOV A, 99 This instruction directly moves the data 99 to the accumulator.
(b) Register addressing mode : It uses registers to hold the data to be manipulated. There are 4 banks of 8 registers. Only one bank is activated at a time which contains R0 to R7 registers. Any one register can be specified as operand.
e.g. MOV A, R5 Here, content of R5 is copied to the accumulator.
(c) Direct addressing mode : This mode is provided to access internal data memory directly including SFR. In this, 8 bit internal data memory address is specified as a part of instruction. It can specify address only from 00H to FFH.
e.g. MOV A, 47H This reads the data from internal RAM address 47H and copies it to
accumulator.
(d) Indirect addressing mode : This is used to hold the actual address which will be used in data movement. R0, R1 and DPTR only can be used as data pointers R0 and R1 can hold 8 bit while DPTR can hold 16 bit address.
It cannot be used for SFR s. e.g. i) MOV A, @R1 R1 contains the address of internal RAM location, it copies
content of memory location pointer by R0 into A.
2
Vidy
alank
ar(one serial port)erial port)
8051 microcontroller 8051 microcontroller [4][
mmediate addressing mode meanse addressing modof instruction (it immediately ruction (it immed
y moves the data 99 to the accumy moves the data 99 to the
ng mode :e : It uses registers to It uses regisThere are 4 banks of 8 registare 4 banks of 8
a time which contains which contains R0 to R7Recified as operand.as operand.
MOV A, R5, R5e, content of R5 is copied to the ae, content of R5 is copied t
Direct addressing mode :ect addressing mo This memory directly including Semory directly includaddress is specified as ddress is specified as a pfrom 00H to FFH.rom 00H to FFHe.g.e.g MOV A, 47HMOV This reads the dThis accumulator.cumu
(d)(d) Indirect awill be poin
I
Prelim Question Paper Solution
ii) MOV X A, @ DPTR It copies the content of external data memory pointed by DPTR
into accumulator. Q.1(b) Attempt any ONE of the following : [6] Q.1(b) (i) Describe the power saving operation of 8051 microcontroller. [6] (A) There are 2 types of modes in power saving :
(i) Ideal mode (ii) Power down mode
(i) Ideal Mode : After setting the ideal bit in PCON register, micro-controller turns into ideal saving mode. In this, content of all registers, I/O ports remains unchanged serial ports, timers, interrupts continues operating normally. In this system turns of CPU. In order to come out from Ideal mode. Interrupt or Reset signal can be used which will automatically clear ideal bit.
(ii) Power Down Mode : After setting bit PD in the PCON register, micro-
controller turns into power down mode. In this mode, micro-controller turns off its internal oscillator which reduces power consumption which makes micro-controller works on 2V power supply and current upto 40 A. In this mode all contains of SFR s and I/O port remains as it is.
Q.1(b) (ii) Draw interfacing diagram of 2Kbyte EPROM and 2K byte RAM to 8051 microcontroller. Draw the memory map.
[6]
(A) For 2 K byte EPROM, 2 Kb = 211
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
For 2 K byte RAM, 2 Kb = 211
C2 C3 Chrystal
Oscillator
18 19 pins
PD
CPU
Interrupt serial port Clock
generator Oscr
IDL
3
Vidy
alank
ar[
er. [6][6]
ON register, microgister, mic -content of all registers, t of all registers,
mers, interrupts continues mers, interrupts continuesof CPU. In order to come out CPU. In order to come
t signal can be used which will can be used wh
) Power Der Downo M Mode :ode : After setcontroller turns into power ontroller turns into poturns off its internal oscurns off its internal omakes microakes micro--controller controller In this mode all contIn this mode
Q.1((b)b) (ii) Draw interfaciDraw to 8051 mic80
(A)(A) For 2 K byte EFor 2 Kb = A15 AVVVVVV0VVV
aalalyayalla
yaalalalla
19 pinsns
yaPDD
Clock genera
Vidyalankar : T.Y. Diploma MC
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 00 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
Q.2 Attempt any FOUR of the following : [16]Q.2(a) Draw the internal architecture of 8051 microcontroller. [4] (A) Internal Architecture of 8051 microcontroller
EA WR
PSEN RD
A15 A14 A13 A12 A11
ALE A8 to A10
AD0 to AD7 74LS 373
Latch
WR CS
OE
2kb 8 RAM
A8 to A10
A0 to A7
GND
2kb 8 EEROM
A8 to A10
D0 to D7
A0 to A7
WR CS
OE
+VCC +VCC
GND
RD
A11 to A15
D0 to D7
4
Vidy
alank
arowing :
re of 8051 microcontroller.8051 microcontro8051 microcontroller8051 microcontroller
kkar
nnnnkakakar
kkkkGNDGN kkkk2kb b 88EEROMEEROM
A8 to Ato A10
D0 to Do D7 7
A0 to Ao Ao 7
OE
GNDaa
nk
Prelim Question Paper Solution
Q.2(b) Explain a Boolean processor of microcontroller 8051 with two examples.
[4]
(A) The 8051 instruction set is optimized for the one-bit operations so often desired in real-world, real-time control applications.
The Boolean processor provides direct support for bit manipulation. This leads to more efficient programs that need to deal with binary input and output conditions inherent in digital-control problems.
Bit addressing can be used for test pin monitoring or program control flags. For example, instructions for Boolean function are as given below :
(a) ORL P0, #1 ; Set P0.0 (b) XRL P0, #1 ; Toggle P0.0 (c) ANL C, P1.4 ; AND the bit on P1.4 with carry (d) ANL C, !(P1.4) ; AND inverted bit on P1.4 with carry Q.2(c) Describe the function of following pins of 8051 microcontroller
(i) PSEN (ii) ALE (iii) EA (iv) RST [4]
(A) Functions : (i) PSEN (pin 29) Program strobe enable is the output control signal. It remains low while fetching data from external program memory.
During the internal program execution, it remains high.
(ii) ALE (pin 13) It is address latch enable which is used to demultiplex AD0 to AD7 of
port 0, it is a positive going pulse generated everytime during external memory access. It latches low order address bus and generates separate set of address lines as shown in diagram.
(iii) EA (pin 31) When external access pin is enabled, i.e. it is high, it select internal
program memory, if it is low, it selects only external program memory.
(iv) RST (pin 9) This is reset pin. It provides reset mechanism to establish initial
condition if micro-controller hangs. Reseting operation will clear all the content of memory location.
ALE
AD0 -AD7
8051 LATCH
A0 to A7 G ALE
D0 D7
5
Vidy
alank
arion. ThiThi
ry input and ut and
ogram control flags. control flags. given below :ow
with carryrryon P1.4 with carry4 with carry
pins of 8051 microcontroller8051 microcontro(iii)iii)
anEA (iv)(iv RST
ble is the output control signal.the output control sigwhile fetching data from extefetching data from
ternal program execution, it remaiprogram executio
n 13)address latch enable which is useatch enable which
t 0, it is a positive going pulse gt 0, it is a positive going memory access. It latches loemory access. Itseparate set of address lines aarate set of addres
(iii)(iii)VEA (pinWhen prog
(iv)
dydyAD 7yyyy
Vidyalankar : T.Y. Diploma MC
Q.2(d) Draw the internal RAM memory organization of 8051 microcontroller [4] (A) Internal RAM Memory
RAM Memory : There are 128 bytes of RAM in 8051 assigned address 00 to 7FH.
The 128 bytes are divided into 3 different groups as follows : (i) A total of 32 bytes from location 00 to 1F hex are set aside for
register banks and the stacks. (ii) A total of 16 bytes from locations 20H to 2FH are set aside for bit
addressable read/write memory. (iii) A total of 80 bytes from location 30H to 7FH are used for read and
write storage called as scratch pad.
Scratch PAD RAM 80 GPR
Bit Addressable RAM
Register Bank 3
Register Bank 2
Register Bank 1 [stack]
Register Bank 0
7F
30
2F
20
17
18
17
16,Bit addressable Registers
R7
R0
R7
10
0F 08
07
00
R0
R0
R0
R7
R7
6
Vidy
alank
ar
bytes of RAM in 8051 assigned adf RAM in 8051 assibytes are divided into 3 differentare divided into 3 d
total of 32 bytes from location32 bytes from register banks and the stacks.register banks and the sta
(ii) A totA total of 16 bytes from locaal of 16 bytaddressable read/write meaddressable read/w
(iii)ii) A total of 80 bytes froA total of 80 byteswrite storage called write storage called
arkankak 2
ankegister Bank 1 [stack]
anRegister Bank
llllaalaR0
0
a
Prelim Question Paper Solution
Q.2(e) Write an assembly language program for 8051 microcontroller to transfer ten bytes of data from source to destination in internal RAM (Assume suitable memory addresses)
[4]
(A) Algorithm : Flow Chart : 1. Start 2. Initialize memory pointer as source 3. Initialize memory pointer as destination 4. Initialize counter 5. Move content of 1st source location to A 6. Move content of A to 1st destination location 7. Increment source location 8. Increment destination location 9. Decrement iteration count if not 0, jump to step 5 10. Stop
Program : ORG 0000H MOV R0, #70H MOV R1, #80H MOV R4, #0AH UP : MOV A, @ R0 MOV @ R1, A INC R0 INC R1 DJNZ R4, UP END Q.3 Attempt any FOUR of following : [16] Q.3(a) Explain the following instruction of 8051 :
(i) RLA (ii) MOV add1, @Ri (iii) MUL AB (iv) CLRA
[4]
(A) (i) RLA : Rotate A left (ii) MOU add1 a Ri : Move the content of memory location pointed by Ri into
add1. (iii) MULAB : multiply A and B (iv) CLRA : Clear A
Start
Initialize M.P. as source
Initialize M.P. as destination
MOV content of 1st location to A
Move content of A to 1st destination location
Increment source location
Increment destination location
Decrement iteration count
Stop
if count = 0
No
Yes
7
Vidy
alank
ar0
R1, A0
C R1DJNZ R4, UPUPENDEN
Attempt any FOUR of followingmpt any FOUR of foll3(a)(a) Explain the following instrucExplain the following instru
(i)(i) RLALA (ii) MOMO(iii)ii) MUL ABMUL AB (iv) C
(A) (i) RLA : Rotate A leRLA : (ii)( MOU add1 a RU a
add1.(iii)(iii) MULAB (iv) CLRA
r as e
karalize M.P. as P. as
destinationtion
kaMOV content of 1content of 1stst
locatcation to AA
nkaMove content of A to 1ove content of A to st
destination locationstination locat
anknIncrement source Increment
locationlo
anIncrement dIloca De
kakaaakakakkkaka
Vidyalankar : T.Y. Diploma MC
Q.3(b) Describe the following directives with one example. (i) ORG (ii) DB (iii) EQU (iv) END
[4]
(A) Assembler directives : (i) ORG : The ORG directive is used to indicate the starting address. It
can be used only when program counter needs to be changed. It can be decimal or hex.
e.g. 2000H; set program counter 2000 (ii) DB (Define byte) : DB directive is used to define 8 bit data. It
initialized memory with 8 bit value. It can be decimal, binary or in ASCII formats.
e.g. (1) DB 40H ; Hex (2) DB 01011100B ; binary (3) DB 16 ; Decimal (4) DB HELLO ; ASCII (iii) EQU (or SET) : These directives assigns numerical value or register
name to the specified symbol name. EQU is used to define constant without storing it in memory. Symbol defined EQU should not be redefined whereas SET allows redefinition of symbol.
e.g. (1) SET R1 ; use R1 as pointer (2) EQU R1 ; use R1 as a counter (iv) END : This indicates END of program to assembler any text after END
is ignored, if END is missing assembler generates error message. Q.3(c) State the function of editor, assembler, linker and compiler. [4] (A) Software development cycle involves the use of following tools :
(i) Editor : Editor is used to type the program which produces ASCII file, it can be used to create or edit program. Software code is written in programming language i.e. assembly or C . The file extension is .asm or .src depending of assembly used.
(ii) Assembler : It converts the instructions into machine code assembler produces an object file and least file. Extension for object file and least files are .obj and .lst respectively.
(iii) Linker : Linker program takes one or more object code files and produces an absolute object file with the extension .abs.
(iv) Compiler : It is a software which monitors any flaw (error) in the program written by the programmer and draws the attention of the programmer to all the lines with errors.
8
Vidy
alank
art can
ne 8 bit data. It bit data. It decimal, binary or in , binary or in
ectives assigns numerical value oassigns numerical mbol name. EQU is used to defname. EQU is us
memory. Symbol defined EQU memory. Symbol definedET allows allows redefinitionedefinition of symbol.of s
; use R1 as pointeras pointer1 ; use R1 as a counteruse R1 as a counter
This indicates END of program to dicates END of progored, if END is missing assembler ND is missing as
ate the function of editor, assemthe function of edSoftware development cycle involvare development cyc(i) Editor :dito Editor is used to Editor is used
it can be used to creatcan be used to creatprogramming languageprogramming .sr.src c depending of adepend
(ii)( Assembler :ssemb Itproduces anleast files
(iii)(iii) Linkerpro
(iv)
Prelim Question Paper Solution
Q.3(d) Write an assembly language program for 8051 microcontroller to add two 8 bit numbers 55H and 67H. Store the result at 20H.
[4]
(A) Algorithm : Flow-Chart : 1. Initializaiton 2. Get 1st no. in accumulator 3. Get 2nd no. in R5 4. Add both numbers 5. Store the result in internal memory location 20H 6. Stop
Program : ORG 0000H MOV A, #55H MOV R5, # 67H ADD A, R5 MOV 20H, A
END
Q.3(e) Discuss the selection factors of microcontroller. [4] (A) Selection factors of microcontroller
Three criteria in choosing microcontroller are as follows : A) 1) Micro controller must be meet the computing need of the task at
hand efficiently and cost. 2) We must whether an 8 bit, 16 bit or 32 bit micro-controller can best
handle the computing needs of the task most effectively.
Some other consideration in this category are : i) Speed : What is the highest speed that the micro-controller
supports. ii) Packaging : Does it come in 40 pin DIP or QFP (Quad Flat Package) or
Some other packaging formats. This is important in terms of space, assembly and prototyping the end product.
iii) Power consumption : This is especially critical for battery powered product.
iv) The amount of RAM and ROM on chip. v) The number of I/O pins and Timer on chip. vi) Cost per unit.
B) Second criteria in choosing micro-controller is, how easy it is to developed product around it.
Key considerations includes the availability of a assembler, debugger, a code efficient C language compiler, emulator, technical support and both inhouse and outside expertise.
Start
Stop
Get 55H in accumulator
Get 67H in R5
Add both the numbers
Store the result in 20H
9
Vidy
alank
arrs of microcontroller.rs of microcontroller.
rocontrollercontrollersing microcontroller are as followsrocontroller are a
roller must be meet the computimust be meet the ciciently and cost.y and cost.
ust whether an 8 bit, 16 bit or 32her an 8 bit, 16 bindle the computing needs of the tacomputing needs of
me other consideration in this catme other consideration in ti) Speed : What is the highSpeed : What
supports.support ii)) Packaging : Does it comePackaging : Does it c
Some other packaginSome other packagiassembly and protassembly a
iii)iii) Power consumpPower cproduct.pro
iv) The amoTv) The nvi) Co
B) Se
nknktop
a7H in
R5
kaAdd both the the
numbersmb
nkaStore theStore the result result
in 20Hin 20Hkkkknknk
Vidyalankar : T.Y. Diploma MC
C) The third criteria in choosing the micro-controller is, its ready availability in needed quantity both now and in future currently, of the leading 8 bit micro-controller the 8051 family has the largest number of supplies. In case of 8051, which was diversify originated by Intel. Several companies also producing the 8051. These companies includes Intel, Atmel, Philips/Signetic, AMD, Infineon (formally known as Siemens), Matra and Dallas Semi-conductor.
Q.4(a) Attempt any THREE of the following : [12] Q.4(a) (i) Describe following 8051 microcontroller instructions
(a) SET B C (b) ADD A, @R0 (c) MOV A, #20H (d) XCH A, R0
[4]
(A) 8051 microcontroller instructions : (a) SET B C set carry flag (b) ADD A, @R0 Add indirect RAM to accumulator (c) MOV A, #20H Move immediate data to accumulator (d) XCH A, R0 Exchange register with accumulator
Q.4(a) (ii) Draw the format of SCON register and describe the function of
each bit. [4]
(A) SCON is a 8-bit register which indicates mode selection and flag generation of interrupt.
Bit 7 Bit 0 SM0 SM1 SM2 REN TB8 RB8 T1 R1
SM0 and SM1 :
SM0 SM1 Modes0 0 Serial mode 0 (synchronous comm) 0 1 Mode 1 (10 bit asynchronous comm) 1 0 Mode 2 1 1 Mode 3
SM2 Use for multiprocess communication REN (Received Enable) It is also referred as SCON.4. Since it is bit
addressable. When REN bit is high it allows 8051 to receive data on RxD pin, by making REN = 0 the receiver is made disable.
TB8 (Transfer bit 8) Use for serial modes 2 and 3. RB8 (Receive bit 8) Use for serial modes 2 and 3. T1 (Transmit Interrupt) When 8051 finishes transfer of 8 bit
character it raises T1 flag to indicate that it is ready to transfer another byte.
10
Vidy
alank
arinclud
known as as
[12]2]tions
R0R00
[4][4]
RAM to accumulatorto accumulatorediate data to accumulatordata to accumulato
nge register with accumulatorgister with accumula
CON register and describe the fCON register and describe
register which indicates modewhich indicateserrupt.
SM1 SMS 2 RENREN Tyyyyayayayayyyyayayaya0 and SMd SM1 : :SM00 SMSM1dddydydyddy0 00 Serial modeal mdddydydyiiddy0 1 Mode 1 Mode 1 iidididydydyViiddy11 00 Mode
ViVidididydydyViiddy11 1 M
ViVidididddViViViidiidSMS 2 Use for mUs
REN RE (ReceivaddR
TB8 RB
Prelim Question Paper Solution
R1 (Receive Interrupt) When 8051 receives data serially via RxD it raises R1 flag bit to indicate that a byte has been received.
Q.4(a) (iii) Draw the circuit diagram of port 2 and describe its functions. [4](A) Port 2 can be configured as I/O port or higher order address bus depending
upon the operation to be performed.
PORT 2 LINES AS AN ADDRESS BUS [A8-A15] A8 A15
Control input should be 1. This input will be provided internally by 8051 depending upon the instruction i.e. memory related instructions.
Thus, Control= 1, D Flip Flop will be isolated from mux, I1 will be connected to o/p Y. When, address line = 0 then, I1 = 0 y -= 0 and ouput of NOT Gate = 1 hence, it will turn ON transistor T (i.e. closed switch) Simultaneously, o/p of AND Gate = 0 as, address = 0 and Control = 1 this will turn OFF T (i.e. open switch)
As T is off and T is ON current will start from Vcc and flows towards ground through R and T. Accordingly respective port line sinks the current and hence that respective addressing line will be treated as Logic O.
When, address line = 1 then I1 = 1
2:1 MUX
Internal Data Bus
Write to latch
D Clk
Q
Q
Read latch
Addr Control +VCC
T1 R
pz.x
T
Read pin
I1
I0
S0
y
11
Vidy
alank
arependi
AN ADDRESS BUS [AESS BUS [A88-A-A15]
should be 1. This input will be pbe 1. This input wpon the instruction i.e. memory rele instruction i.e. mem
trol= 1,FlipFlip Flop will be isolated from muxop will be isolated fr
I1 will be connected to o/p Y.will be connected tWhen, address lihen, address line = 0 ne = 0
then, Ihen 1 = 0 = 0 y -= 0
and ouput of NOT Gaand ouput of N hence, it will turn hence, it wi Simultaneously,multa as, address = and Contr
this w
As Tgro
nanMUX nknknknknnkkkkkk
akkkkkankakakakakakakakakakakakakakakaakaa
T1 RR
pz
TT
Read pinRead
yy nknknknk
Vidyalankar : T.Y. Diploma MC
Y = 1 and output of NOT Gate = O Hence, it will turn OFF transistor T (i.e. open swich) Simultaneously, o/p of AND Gate = 1 as, Address = 1 and Control = 0 this will turn ON T (i.e. closed switch)
As T is ON and T is OFF current will start form Vcc and flow through T. Accordingly, respective port line sources the current and hence respective
address line will be treated as logic 1. PORT 2 LINES AS I/O PORT: When, D = 1 clk = 1 Q = 1 Q = 0 But Q is connected to Mux Thus I0 = 1 and o/p of NOT Gate = 0 Thus, T will turn OFF ( i.e. Open Switch) Therfore respective port line will source the current and Port2 X will be
treated as Logic 1 When , D = 0 clk = 0 Q = 0 Q = 1 but Q is connected to MUX Thus I0 = 0 and o/p of NOT Gate =1 Thus, T will turn ON (i.e. closed switch)
Therefore respective port line will sink the current and pz.x will be treated as Logic 0 .
Q.4(a) (iv) State four instructions related with external memory. [4] (A) Instructions related with external memory
i) MOV M, r [[HL]] [ r ] Moves the content of register r to external memory location whose
address is stored in HL register pair. e.g : MOV M, C This instruction moves the contents of register C into the memory
location whose address is in HL register pair.
12
Vidy
alank
arlow through T.rough T
and hence respective nce respect
to Muxxo/p of NOT Gate = 0o/p of NOT Gate = 0
urn OFF ( i.e. Open Switch)OFF ( i.e. Open Switchport line will source the current will source the c
0 k = 0
Q = 0 yQQ = 1
but Q is connected to MUXQ is connected toThus Ius I0 0 = 0 and o/p of NOT G= 0 and o/p of
Thus, T will turn ON (i.e. chus, T will turn ON (i.eTherefore respective port Therefore respective port as Logic 0 .as Logic 0 .
Q.4(a)(a) (i( v) State four instate (A)(A) Instructions reIn
i)i) MOV M, [[HL]]Mo
Prelim Question Paper Solution
Width : 1 byte. Addressing : indirect addressing Flags affected : none Machine cycle : 2 (op code fetch, memory write) T states : 7 (4 + 3) ii) MVI M, 8data [[HL]] 8data It moves the data specified in the instruction into the external memory
location whose address is stored in HL register pair. e.g. MVI M, 50 H [[HL]] 50 H This instruction moves 50 H into memory location whose address is stored
in HL register pair. Width : 2 bytes Addressing : immediate/indirect addressing. Flags affected : none. Machine cycle : 3 (op code fetch, operand fetch, memory write) T states : 10 (4 + 3 + 3)
iii) LDA addr [A] [addr] It moves the contents of external memory location whose address is
specified in the instruction into accumulator. e.g. LDA 3056 H [A] [3056 H] This instruction loads accumulator with the contents of memory location
3056 H. Width : 3 bytes Addressing : direct. Flags affected : none. Machine cycle : 4 (op code fetch, operand fetch, operand fetch, memory
read) T states : 13 (4 + 3 + 3 + 3) iv) STA addr [addr] [A] It stores the contents of accumulator into the external memory location
whose address is specified in the instruction.
13
Vidy
alank
arthe external memory ternal memory air.
ory location whose address is storcation whose address
irect addressing.addressing.
code fetch, operand fetch, memorode fetch, operand fetch,3 + 3)
[addr]
ves the contents of external mecontents of extercified in the instruction into accumcified in the instruction int
e.g.g LDA 3056 HLDA 3056 H [A] A] [3056 H]056 H]
This instruction loads accumhis instruction loads a3056 H.05
Width : 3 bytesWidth : 3 byteAddressing : direcAddressing Flags affected : Flags aMachine cyclehinread)T stat
iv) S
Vidyalankar : T.Y. Diploma MC
e.g. STA 2560 H [2056 H] [A] This instruction stores the contents of accumulator into memory location
2056 H. Width : 3 bytes Addressing : direct addressing. Flags affected : none. Machine cycle : 4 (op code fetch, operand fetch, operand fetch, memory
write) T states : 13 (4 + 3 + 3 + 3)
Q.4(b) Attempt any ONE of the following : [6] Q.4(b) (i) Write a program to arrange number in ascending order using
8051 instruction set. [6]
(A) Program : Arrange number in Ascending order Number are stored in memory from 30 to 3FH Arrange these numbers in Ascending order.
14
Vidy
alank
arnd fetch, memory h, memory
[6][in ascending order using ending order using [6]
der
Prelim Question Paper Solution
START : MOV R6, #0FH LOOP1 : MOV R0, #30H MOV R7, 06H (R7 R6) LOOP2 : MOV A, @R0 INC R0 CLRCu SUBB A, @ R0 JC SKIP MOV A, @R0 DEC R0 XCH A, @R0 INC R0 MOV @ R0, A SKIP : DJNZ R7, LOOP 2 DJNZ R6, LOOP 1 HERE : LJMP HERE Q.4(b) (ii) Draw the interfacing diagram of stepper motor with 8051
microcontroller and write an assembly language program to rotate stepper motor continuously in clock wise direction.
[6]
(A)
Gnd
+VCC
a(RST)
VPP
8051 C
20
D0.1
D0.2
D0.3
D0.4
D0.5
D0.6
D0.7
D0.0
ULN 2003
1
2
3
4
Coil
Rotor
Coil
+VCC
VCC (+ 12V) C2 = 33pf C1 = 33pf
11059 MHz
+VCC
0 0 0 1
Gnd
15
Vidy
alank
ardiagram of stepper motor withm of stepper m
write an assembly language prwrite an assembly langutor continuously in clock wise direcontinuously in clock w
idya
idyayyyyaaa
Vid
Vid
ViVVVVidddGnd
V
80C
2
D0.1
D0.2
D0
+V+VCC
C1 = 3
+VCC
0000
Vidyalankar : T.Y. Diploma MC
ORG 0000H MOV A, # 33H UP : MOV P1, A ACALL DELAY RR A SJMP UP DELAY : MOV R4, # 0FFH YY : MOV R5, # 0FFH XX: DJNZ R5, XX DJNZ R4, YY RET END
Q.5 Attempt any FOUR of the following : [16] Q.5(b) Draw and describe IE register of 8051 microcontroller. [4] (A) IE register can enable and disable various available interrupt
EA ET2 ES ET1 EX1 ET0 EX0 EA (IE7) Disable all interrupts. If EA = 0, no interrupt is acknowledge if EA = 1 each interrupt source is individually enabled/ disabled by setting/clearing its enable bit (IE6) Not implemented, reserved for future use ET2 (IE5) Enables/Disables timer 2 for further use. E S (IE4) Enables/Disables serial port interrupt. ET1 (IE3) Enable/Disables timer / overflow interrupt. EX1 (IE2) Enable/Disables external interrupt 1. ET0 (IE1) Enables/Disables timer o overflow interrupt. EX0 (IE0) Enables/Disables external interrupt o Q.5(b) Describe the timer modes of 8051 microcontroller. [4] (A) Timer Modes of 8051 Microcontroller
8051 microcontroller has 4 timer modes. Timer modes can be selected with the help of TMOD register.
16
Vidy
alank
ar[16
51 microcontrocontroller.roller.arious available interrupt vailable interrup
ES ETET11 EXEX11 ET0aaananannnaaaanananannnnall interrupts. If EA = 0, no interterrupts. If EA = 0, no= 1 each interrupt source is indiviterrupt source i
abled by setting/clearing its enabby setting/clearing it
Not implemented, reserved fot implemented, rese
IEIE55) ) Enables/Disables timer bles/Disables
E S (IEE4) 4) Enables/Disables ables/Di
ET1 (IEET1 (IE3) 3 Enable/DisaEnable/Disa EX1 (IE1 (IE2) 2) Enable ETET0 T (IE1) En
EXEX0 (IE0)
b) DesT
Prelim Question Paper Solution
M1 M0 Timer Mode 0 0 Mode 0 0 1 Mode 1 1 0 Mode 2 1 1 Mode 3
Mode 0
In mode 0, timer register is configured as 13 bit register, 8 bit for THX and 5 bit for TLX. Timer is enable when TRX = 1 and gate = 0 then register can hold values between 0000H to 1FFFH in TH and TL. When register value reaches its maximum it roles over to 0000H, when the register overflow it sets timer interrupt flag TF one or zero.
Mode 1
In mode 1, timer register is configured as 16 bit register where 8 bit for THX and 8 bit for TLX and gate = 0, then registers can hold value between 0000H to FFFFH in TH and TL.
Mode 2
INTX
Oscillator1
12
Tx pin CT
= 1
CT
= 0
8 bit 5 bit THX TLX
TFX
TRX
GATE
INTO
Oscillator1
12
Tx pin CT
= 1
CT
= 0
8 bit 8 bit THX TLX
TFX
TRX GATE
Overflow
Oscillator1
12
Tx pin CT
= 1
CT
= 0
TLX 8 bit
THX 8 bit
TFX
TRX GATE
INTO
17
Vidy
alank
ard as 13 bit register, 8 bit for THXbit register, 8 bit
en TRX = 1 and gate = 0 then regis 1 and gate = 0 theFFH in TH and TL.TH and TL
hes its maximum it roles over toes its maximum it roles ov 0s timer interrupt flag TF one or zer interrupt flag TF o
In mode 1, timer register In mode 1, timer register THX and 8 bit for TLX THX and 8 bit fo0000H to F0H to FFFH in T
Mode 2M
kkkakakakaTFX
INTOO idyayayyyydydydydydyidydyddddaaaayayadya
dyyyayaa
12
yaaddx pin yayaCCT = 1=aaCTT = 0= 0
THaTRXTRX
GATE dyVV
Vidyalankar : T.Y. Diploma MC
The operation is some for timer 0 and timer 1. In this mode, timer register is configured as TLX. When TLX overflows from FFH to 00H it sets the flag TFX and it loads THX. The reload leaves THX unchanged. In this mode timer 1 or timer 0 supports the automatic reload operation. The timer control logic is same as mode 0 or mode 1.
Mode 3
Timer 0 in mode 3 TL0 and TH0 are 2 separate registers as shown in figure. TL0 uses gate TR0, INT0 and TF0 control bit of timer 0 and TH0 uses TR1 and TF1 control bit of timer 1. When TL0 overflows from FFH to 00H, then it sets the timer flag TF0. If control bit TR1 is set, TH0 receives the timer clock. When counter TH0 overflows from FF to 00 then it sets the flag TF1. Timer 1 may still be used in mode 0/1/2 but it neither interrupt the processor nor sets the flag. When timer 0 is in mode 3, timer 1 can be used for baud rate generation in serial communication.
Q.5(c) List the various interrupts in 8051 microcontroller along with their priorities and vector locations.
[4]
(A) Various Interrupts in 8051 microcontroller Interrupt Location (ROM) Priority
RESET 0000H Highest INT0 (external hardware) 0003H
Timer 0 (TF0) 000BH Int1 (external hardware) 0013H
Timer 1 (TF1) 001BH Serial communication (R1/T1) 0023H Lowest
Oscillator1
12
CT
= 1
CT
= 0
TLO 8 bit TFO
TRO GATE
INTO
Overflow
Oscillator1
12
THO TF1
TR1
18
Vidy
alank
arand TH0 are 2 separate registersTH0 are 2 separate reg
INT0 and TF0 control bTF0 control bit of timeit t of timer 1.mer 1.
rflows from FFH to 00H, then it srom FFH to 00H, tTR1 is set, TH0 receives the timset, TH0 receives
s from FF to 00 then it sets the fto 00 then it se1 may still be used in mode 01 may still be used in m
cessor nor sets the flag. When tsor nor sets the flfor baud rate generation in serial ud rate generation in
5(c)5(c) List the various interrupts List the various interruptspriorities and vector locpriorities and vec
(A)) Various Interrupts inrious InterrInterrupViVid
Vi RESViViViINT0 (extIVVV TVVVIntVVV
kakakakaTF
verflow
ananHO nnnnkTF1
aaaaa
Prelim Question Paper Solution
Q.5(d) Write an assembly language program for 8051 microcontroller to generate square wave on P1.0 using delay subroutine.
[4]
(A) ORG 0000H SET B P1.0 A CALL DELAY CLR P1.0 main : SJMP main END DELAY : MOV R4, # 0FFH UP : DJNZ R4, UP RET
Q.5(e) Draw the internal structure of port3 & list alternate functions of port3.
[4]
(A) Structure of Port 3 : To configure PORT 3 as an input/output port the Alternate output function
pin provided to NAND Gate will be Logic 1, done by microcontroller depending on the instruction.
When D = 0, Q = 0, Then o/p of NAND Gate = 1, This will turn ON the transistor T i.e. closed switch. Accordingly, respective PORT 3 line will sink the current. This is treated as Logic 0 When D = 1 Q = 1,
Internal Data Bus
Write to latch
D
Q
Q
Read latch
Read pin
+VCC
R
p3:x
T
Alt input function [RXD, INTO , INT1 , T0, T1]
Alt output function
[TXD, WR , RD ]
19
Vidy
alank
art alternate functions of rnate functions of [4]
To configure PORT 3 as To configure PORpin provided to NANprovided tdepending on the independing
W
yadyalaalal
dydydyyyQQ
yaQQ
Read pRe
alalaalaalallalaaaaanananaaaanaanaaanaaaanaan
+V+VCC
RR
TlalaAlt output put functionction
[TXD, [TXD laWRWR , laRDRD ]
Vidyalankar : T.Y. Diploma MC
Then o/p of NAND Gate = 0 This will turn OFF the transistor T i.e. open switch, Accordingly, respective PORT 3 pin will source current. This is treated as Logic 1. PORT 3 AS AN ALTERNATE FUNCTION PORT: To use the Alternate Functions of PORT 3, 8051 will set D input of D
flip flop depending upon the instruction.
Consider Alternate o/p function to NAND Gate is O Then, o/p of NAND Gate = 1 Accordingly, T will turn ON i.e. closed switch Respective PORT 3 line will be at Logic 0
Consider Alternate output function to NAND Gate is 1 Then, output of NAND Gate = 0 Accordingly, T will turn OFF i.e. open switch Respective PORT3 line will be at Logic 1
Q.6 Attempt any FOUR of the following : [16] Q.6(a) Write an assembly language program to generate continuous square
of 2KHz frequency on P1.4 using timer 0. Assume crystal frequency of 8051 microcontroller is 11.0592 MHz.
[4]
(A) Given : Crystal frequency = 11.0592 MHz
Timer input clock frequency = 11.059212
MHz = 0.924 MHz
T 10.924 MHz
= 1.085 sec.
Give frequency of output square wave is 2 KHz.
Timer period of output square wave = 12KHz
= 500 sec.
TON = TOFF = 500 sec.2
= 250 sec.
Desire delay = 250 sec.
Desire count = Desired delayTime period of input clock
= 6
6
250 101.085 10
= 230 Max. count Desire count = Timer count 65536 230 = (65306)10 = (FFIA)h
20
Vidy
alank
arD input of D of
sed switch sed switchat Logic 0 ogic 0
D Gate is 11ate = 0
n OFF i.e. open switch.e. open switcine will be at Logic 1e at L
following : g : age program to generate continuge program to generate
on P1.4 using timer 0. As1.4 using timer microcontroller is 11.controller is 11.0592 MHz059
requency = 11.0592 MHzcy = 11.0592 MHz
put clock frequencyck frequency = = a11.059211.012
M
T
dya1
0.924 MHz.924 MHz = 1.08
ive frequency of output square waequency of output s
Timer period of outpimer period of ut squut
T TONON = T= TOFFO = 500
Desire delay esire
Desire coun
Prelim Question Paper Solution
ORG 0000H MOV TMOD, # 01H CLR TR0 CLR TF0 UP : MOV TH0, # 0FFH MOV TL0, # 1AH SET B, TR0 here : JNB TF0 here CPL P1.4 CLR TF0 SJMP UP END ET2 (IE5) Enables/Disables timer 2 for further use. ES (IE4) Enables/Disables serial port interrupt. ET1 (IE3) Enables/Disables timer/overflow interrupt. EX1 (IE2) Enables/Disables timer 0 overflow interrupt ET04 (IE1) Enables/Disables timer 0 overflow interrupt EX0 (IE0) Enables/Disables external interrupt 0
Q.6(b) Draw the format of TCON register and state the function of each bit.
[4]
(A) TCON register This register is 8-bit, bit addressable. It controls the timer/counter operation. First 4 bit indicates timer flag another 4 bit indicates interrupt flag.
TR0 and TR1 These flags are use to run the timer or ON/OFF the timer. TF1 and TF0 It indicates timer 1/0 overflow flag when timer/counter
overflows. IE1 / IE0 It indicates external interrupt 1/0. IT1 / IT0 It indicates timer 1/0 interrupt. When it is zero it is low
level trigger for level 1 falling edge trigger.
Q.6(c) Draw the control word register format of 8255 and describe the function of each bit.
[4]
(A) Control Word Register Format of 8255
D7 D6 D5 D4 D3 D2 D1 D0
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
Timer Interrupt
21
Vidy
alank
aror further use.ther use.
port interrupt.terrupt.er/overflow interrupt.rflow interrupt.
timer 0 overflow interrupt0 overflow interruptes timer 0 overflow interrupter 0 overflow inte
ables external interrupt 0ables external interrupt 0
TCON register and state the fgister and stat
er is 8--bit, bit addressable. Ibit, bit addressa
4 bit indicates timer flag a4 bit indicates timer flag another n
TRTR0 0 and TRnd T 1 These flagsThese flagsTFF1 1 and TFand TF0 0 It indicIt
overfIEI 1 / IEE0 0 ItITIT1 / IT0
6(c) Draw fun
TTFF11 TRTR11 TFTF0 TR0
ddydydyayayayayaaadddydydydyyyyyyyddydTimerer
Vidyalankar : T.Y. Diploma MC
D0 Port C (lower PC3 PC0) 1 = input 0 = output D1 Port B, 1 = input 0 = output D2 Mode select 0 = Mode0 1 = Mode1 D3 Port C (Upper PC7 PC4) 1 = input 0 = output D4 Port A, 1 = input 0 = output D5 and D6 Mode selection 00 Mode 0 01 Mode 1 10 Mode 2 D7 1 = I/O port 0 = BSR mode
Q.6(d) Draw and describe IP register format of 8051 microcontroller. [4] (A) IP register format of 8051 microcontroller
By programming IP (Interrupt Priority) register we can assign higher priority to any one of the interrupt. bit = 1, higher priority bit = 0, lower priority
PS PT1 PX1 PT0 PX0 (IP.7) Reserved (IP.6) Reserved (IP.5) Reserved
PS (IP.4) Serial port interrupt priority bit PT1 (IP.3) timer 1 interrupt priority bit PX1 (IP.2) External interrupt 1 priority bit PT0(IP.1) Timer 0 interrupt priority bit PX0(IP.0) External interrupt 0 priority bit
22
Vidy
alank
ar
e IP register format of 8051 megister format of 8rmat of 8051 microcontroller8051 microcontro
ming IP (Interrupt PrIP (Interrupt Priority) reioo any one of the interrupt.of the interrupt
t = 1, higher priorityt = 1, higher prioribit = 0, lower priority= 0, lower priority
Pddddydydyyyidididdddydydydyyyy(IP.7)(IP.7) ReservedRe(IP.6)(IP.6 Reserv(IP.5)P.5) Res
PSPS (IP.4)PT1PT1 (IP.3)PX1PX (IP.2)PT0(IPPX0
Prelim Question Paper Solution
Q.1(a) (v) Draw Block diagram of 8255. Discuss the operating modes of it. [4] (A) Block diagram of IC 8255
The following is an overview of each of the three available modes: 1) MODE 0 (Basic Input/Output):
Two eight bit ports and two 4 bit ports Any port can be either input or output Outputs are latched Inputs are not latched 16 different Input/output configurations are possible in this mode.
2) MODE 1 (Strobed Input/output): Two Groups (Group A and Group B) Each group contains one 8 bit data port and (1) 4 bit control/data port The 8 bit data port can be either input or output Both inputs and outputs are latched The 4 bit port is used for control and status of the 8 bit data port
3) MODE 2 (Strobed Bi directional Bus I/O): Used in Group A only One 8 bit bi directional bus port (Port A ) and one (5) bit control port (port C) Both inputs and outputs are latched The 5 bit control port (Port C) is used for control and status for the (8) bit, bi directional bus port (Port A)
23
Vidy
alank
arach of the three available modes:the three available m
put):and two 4 bit portsand two 4 bit ports
either input or outputer input or outputatched
not latchedatchederent Input/output configurationsnput/output configu
(Strobed Input/output):bed Input/output):Two Groups (Group A and Group B)s (Group A and GEach group contains one 8 bit Each group contains one port port The 8 bit dataThe 8 bit data port can beportBoth inputs and outputsBoth inputs and outpThe 4 bit port is useThe 4 bit port is us
3)3) MODE 2 (Strobed BiMODE 2 (StroUsed in GroupUsed inOne 8 bit Onport (poBoth Th