microcontroller
microcontroller
8051
• An embedded microcontroller is a chip which
is a computer processor with all it’s support
functions (clocking and reset), memory, and
i/O built into the device.
Control
Power dist
store
Reset
control
Clock and
timing RAM
instruction decode
program ROM
Data
Add memory
Variable RAM interface unit Processor and built-
Ctrl in registers
Stack RAM
Harvard architecture block diagram
Data
Add instruction
decode
Ctrl
PC Stack
program ROM Variable RAM
Data
Processor and
built-in Add
registers Ctrl
• CISC versus RISC
– RISC stands for “Reduced Instruction Set
Computers”. Instructions are as bare a minimum
as possible to allow users to design their own
operations.
– CISC stands for “Complex Instruction Set
Computers”. Large number of instructions, each
carrying out a different permutation of the same
operation.
Microcontroller memory types
• Control store
– program memory or firmware. this memory space
is the maximum size of the application that can be
loaded into the microcontroller and that the
application also includes all the low-level code and
device interface necessary to execute an
application.
– nonvolatile
– 8051 has 5 different types of control store : none,
mask ROM, PROM, EPROM and EEPROM/Flash
• Variable area (RAM)
– 4 types variable data storage: bits, registers,
variable RAM, PC stack.
– in 8051 they are implemented as SRAM.
– program counter stack
– part of the RAM.
– LIFO memory.
– must be initialized by the starting address of
the stack area.
• Hardware interface registers (I/O space)
– could be memory mapped or IO mapped.
– mostly in variable memory space.
IO in Princeton architecture
memory separate
mapped IO IO space
IO
program
registers
ROM program
ROM
IO registers
variable variable
RAM RAM
Stack Stack
Counter Counter
IO in Harvard architecture
IO
program registers IO
ROM registers
program program
ROM ROM
IO
registers
Microcontroller features
• Clock/Oscillator
• IO pins
Basic features
• interrupts
• timers
• Peripherals
• ADC inputs
• DAC outputs
• PWM outputs
Comparing µC with µP
• General-purpose
microprocessors contains
o No RAM Have the advantage of versatility on the
o No ROM amount of RAM, ROM, and I/O ports
o No I/O ports
• Microcontroller has
o CPU (microprocessor)
o RAM
The fixed amount of on-chip ROM, RAM,
o ROM and number of I/O ports and less
o I/O ports computing power; suitable for very
o Timer specific purpose with much less cost.
8051
CPU
up to 60 KB SF = Special Function
of external
ROM/
EPROM
up to 64
KB of 00F8 up to 64 KB
external 1000 of external
EPROM/ 21 SF registers RAM
ROM or and 0080
0FFF 007F
128 KB internal
4 KB of RAM
internal
ROM/
EPROM
0000 0000 0000
0000
F0H F7 F0 B
2F 83H DPH
E0H E7 E0 ACC
(16) bit/byte 82H DPL
D0H D7 D0 PSW
addressable
B8H BF B8 IP 81H SP
B0H B7 B0 P3
80H 87 80 P0
1F A8H AF A8 IE
(8) 8-bit registers bank
3 A0H A7 A0 P2
99H SBUF CY AC F0 RS1RS0 OV P PSW
17
4 register banks
(CountMax− Reload )
Interval=
ClockFreq
Timer/counter contd..
• A machine cycle instruction lasts for 12 quartz oscillator periods, which
means that by embedding quartz with oscillator frequency of 12MHz, a
number stored in the timer register will be changed million times per
second, i.e. each microsecond.
• 2 timers/counters called T0 and T1
• If the timer contains for example number 1000 (decimal), then the TH0
register (high byte) will contain the number 3, while the TL0 register (low
byte) will contain decimal number 232.
• Formula: TH0 × 256 + TL0 = T TH0 = 1000/256 = 3 (00000011)
so, 3 × 256 + 232 = 1000 TL0 = 1000 – 3x256 = 232 (11101000)
Timer/counter contd..
• The low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4
- bit7) refer to the timer 1.
GATE1 enables and disables Timer 1 by means of a signal brought to the INT1
pin (P3.3):
1 - Timer 1 operates only if the INT1 bit is set.
0 - Timer 1 operates regardless of the logic state of the INT1 bit.
C/T1 selects pulses to be counted up by the timer/counter 1:
1 - Timer counts pulses brought to the T1 pin (P3.5).
0 - Timer counts pulses from internal oscillator.
T1M1,T1M0 These two bits select the operational mode of the Timer 1.
T1M1 T1M0 MODE DESCRIPTION
0 0 0 13-bit timer
0 1 1 16-bit timer
1 0 2 8-bit auto-reload
1 1 3 Split mode
GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2):
1 - Timer 0 operates only if the INT0 bit is set.
0 - Timer 0 operates regardless of the logic state of the INT0 bit.
C/T0 selects pulses to be counted up by the timer/counter 0:
1 - Timer counts pulses brought to the T0 pin (P3.4).
0 - Timer counts pulses from internal oscillator.
T0M1,T0M0 These two bits select the operational mode of the Timer 0.
J2 Connector
PC
1 2 8 (9-pin)
42 1 7 3
Vd P0.1 Rx Vcc Vdrv Rx Tx
Silicon 39 3 5 2
P0.0 Tx DS275 Tx Rx
Laboratories
RS-232 5
8051
Transceiver GND
Microcontroller
GND
4
GND
39
GND
• UART communications is asynchronous (i.e. not
synchronous). This means that there is no master clock used
for timing data transfer between devices.
• The UART is also responsible for baud rate generation. This
determines the speed at which data is transmitted and
received. One baud is one bit per second (bps). As of this
writing, data rates can reach up to 230,400 baud. The cable
length between devices is limited by the baud rate -- the
higher the speed, the shorter the cable. The RS-232C
standard only permits transmission speeds up to 19200 baud
with a cable length of 45 feet. With modern UARTs,
230,400 baud can be achieved with a short cable length of a
few feet.
Configuring the Serial Port
• The 8051 serial port is configured and accessed using a
group of SFRs (Special Function Registers).
4 UART operational modes
TXD(P3.1) RXD
RXD(P3.0) TXD
• Another job of the UART is to frame the byte of data that is
serialized and transmitted. There is always one start bit (set to 0)
and one stop bit (set to 1). Looking at it another way, for every
byte of data, 10 bits are transmitted.
SBUF (Serial Data Buffer) This is a one-byte buffer for both receive and transmit.
ES (Enable Serial). IE.4
IE (Interrupt Enable) Set the bit to 1 to enable receive and transmit interrupts.
PS (Priority Serial). IP.4
IP (Interrupt Priority) Set the bit to 0 for a low priority or 1 for a high priority.
Baud rate(Mode1)=(2SMOD*Frequencyosc)/(32*Instructions*cycle(256-TRV))
Baud rate
Where:
• SMOD is the normal/double baud rate bit.
• Frequency Oscillator is the clock rate in hertz.
• Instruction Cycle is the machine instruction executed each clock
cycle. It is one for the 8051 microcontroller used in this book.
For comparison, the original 8051 by Intel used 12 clock cycles
for each instruction.
• TRV is the reload value for the timer.
Baud Summary
• Set the UART operational mode to 1. (SCON.6 = 1,
SCON.7 = 0)
• Set the REN bit to enable UART receive. (SCON.4 = 1)
• Set the UART enable bit (UARTEN) in the XBR0 register.
(XBR0.2 = 1)
• Set the bit for normal or double baud rate (SMOD) in the
PCON register. (PCON.7 = 1 for double)
• Determine the TRV (Timer Reload Value) based on
crystal frequency and desired baud rate.
Reading and Writing
1. The special function registers are maintained in the next 128 locations after the
general-purpose data storage and stack.
A.True
B. False
Answer: A
2. Which data memory control and handle the operation of several peripherals by
assigning them in the category of special function registers?
3. Why is the speed accessibility of external data memory slower than internal on-chip
RAM?
4. Which operations are performed by the bit manipulating instructions of boolean processor?
a. Complement bit
b. Set bit
c. Clear bit
d. All of the above
5. Which control signal/s is/are generated by timing and control unit of 8051
microcontroller in order to access the off-chip devices apart from the internal timings?
a. ALE
b. PSEN
c. RD & WR
d. All of the above
6. Which register usually store the output generated by ALU in several arithmetic and
logical operations?
a. Accumulator
b. Special Function Register
c. Timer Register
d. Stack Pointer
7) Which condition approve to prefer the EPROM/ROM versions for mass production in
order to prevent the external memory connections?
8) Which among the below mentioned devices of MCS-51 family does not possess two 16 -
bit timers/counters?
a. 8031
b. 8052
c. 8751
d. All of the above
a. A-Register
b. B-Register
c. Registers R0 through R7
d. All of the above
11) How many registers can be utilized to write the programs by an effective selection of
register bank in program status word (PSW)?
a. 8
b. 16
c. 32
d. 64
ANSWER: (c) 32
12) Which operations are performed by stack pointer during its incremental phase?
a. Push
b. Pop
c. Return
d. All of the above
13) Which is the only register without internal on-chip RAM address in MCS-51?
a. Stack Pointer
b. Program Counter
c. Data Pointer
d. Timer Register
a. 07H
b. 08H
c. 09H
d. 00H
ANSWER:(a) 07H
16) Which bit/s play/s a significant role in the selection of a bank register of Program
Status Word (PSW)?
a. RS1
b. RS0
c. Both a & b
d. None of the above
17) Which flags represent the least significant bit (LSB) and most significant bit (MSB) of
Program Status Word (PSW) respectively?
18) Which register bank is supposed to get selected if the values of register bank select bits
RS1 & Rs0 are detected to be ‘1’ & ‘0’ respectively?
a. Bank 0
b. Bank 1
c. Bank 2
d. Bank 3
19) It is possible to set the auxiliary carry flag while performing addition or subtraction
operations only when the carry exceeds _______
a. 1st bit
b. 2nd bit
c. 3rd bit
d. 4th bit
ANSWER: (c) 3rd bit
20) Which locations of 128 bytes on-chip additional RAM are generally reserved for
special functions?
a. 80H to 0FFH
b. 70H to 0FFH
c. 90H to 0FFH
d. 60H to 0FFH
21) Which commands are used for addressing the off-chip data and associated codes
respectively by data pointer?
22) Which instruction find its utility in loading the data pointer with 16 bits immediate
data?
a. MOV
b. INC
c. DEC
d. ADDC
23) What is the maximum capability of addressing the off-chip data memory & off-chip
program memory in a data pointer?
a. 8K
b. 16K
c. 32K
d. 64K
24) Which among the below stated registers does not belong to the category of special
function registers?
a. TCON & TMOD
b. TH0 & TL0
c. P0 & P1
d. SP & PC
25) Which timer is attributed to the register pair of RCAP2H & RCAP2L for capture
mode operation?
a. Timer 0
b. Timer 1
c. Timer 2
d. Timer 3
ANSWER:(c) Timer 2
26) Which registers are supposed to get copied into RCAP2H & RCAP2L respectively due
to the transition at 8052 T2EX pin in the capture mode operation?
27) Which mode of timer 2 allow to hold the reload values with an assistance of RCAP2H
& RCAP2L register pair?
28) Where should the pin 19 (XTAL1), acting as an input of inverting amplifier as well as
part of an oscillator circuit, be connected under the application of external clock?
a. to XTAL2
b. to Vcc
c. to GND
d. to ALE
30) What is the required baud rate for an efficient operation of serial port devices in 8051
microcontroller?
a. 1200
b. 2400
c. 4800
d. 9600
31) Which among the below mentioned functions does not belong to the category of
alternate functions usually performed by Port 3 (Pins 10-17)?
a. External Interrupts
b. Internal Interrupts
c. Serial Ports
d. Read / Write Control signals
32) What is the constant activation rate of ALE that is optimized periodically in terms of
an oscillator frequency?
a. 1 / 8
b. 1 / 6
c. 1 / 4
d. 1 / 2
ANSWER:(b) 1 / 6
33) Which output control signal is activated after every six oscillator periods while
fetching the external program memory and almost remains high during internal program
execution?
a. ALE
b. PSEN
c. EA
d. All of the above
34) Which memory allow the execution of instructions till the address limit of 0FFFH
especially when the External Access (EA) pin is held high?
35) Which value of disc capacitors is preferred or recommended especially when the
quartz crystal is connected externally in an oscillator circuit of 8051?
a. 10 pF
b. 20 pF
c. 30 pF
d. 40 pF
ANSWER: (c) 30 pF
36) Why are the resonators not preferred for an oscillator circuit of 8051?
37) Which version of MCS-51 requires the necessary connection of external clock source
to XTAL2 in addition to the XTAL1 connectivity to ground level?
a. HMOS
b. CHMOS
c. CMOS
d. All of the abov
a. Write-to-Read Signal
b. Write-to-Latch Signal
c. Read-to-Write Signal
d. Read-to-Latch Signal
39) Which among the below mentioned statements are precisely related to quasi-
bidirectional port?
a. A, B, C, D
b. A, B & C
c. A & B
d. C & D
40) What happens when the pins of port 0 & port 2 are switched to internal ADDR and
ADDR / DATA bus respectively while accessing an external memory?
41) The upper 128 bytes of an internal data memory from 80H through FFH usually
represent _______.
a. general-purpose registers
b. special function registers
c. stack pointers
d. program counters
ANSWER: (b) special function registers
42) What is the bit addressing range of addressable individual bits over the on-chip
RAM?
a. 00H to FFH
b. 01H to 7FH
c. 00H to 7FH
d. 80H to FFH
43) What is the divisional range of program memory for internal and external memory
portions respectively when enable access pin is held high (unity)?
44) Consider the following statements. Which of them is/are correct in case of program
execution related to program memory?
a. External Program memory execution takes place from 1000H through 0FFFFH only when the
status of EA pin is high (1)
b. External Program memory execution takes place from 0000H through 0FFFH only when the
status of EA pin is low (0)
c. Internal Program execution occurs from 0000H through 0FFFH only when the status of EA
pin is held low (0)
d. Internal program memory execution occurs from 0000H through 0FFFH only when EA pin is
held high (1)
a. A & C
b. B & D
c. A & B
d. Only A
46) Which address/location in the program memory is supposed to get occupied when
CPU jump and execute instantaneously during the occurrence of an interrupt?
a. Scalar
b. Vector
c. Register
d. All of the above
47) Which location specify the storage/loading of vector address during the interrupt
generation?
a. Stack Pointer
b. Program Counter
c. Data Pointer
d. All of the above
49) What kind of triggering configuration of external interrupt intimate the signal to stay
low until the generation of subsequent interrupt?
a. Edge-Triggering
b. Level Triggering
c. Both a & b
d. None of the above
ANSWER: (b) Level Triggering
50) Which among the below mentioned reasons is/are responsible for the generation of
Serial Port Interrupt?
a. Overflow of timer/counter 1
b. High to low transition on pin INT1
c. High to low transition on pin INT0
d. Setting of either TI or RI flag
a. A & B
b. Only B
c. C & D
d. Only D
51) What is the counting rate of a machine cycle in correlation to the oscillator frequency
for timers?
a. 1 / 10
b. 1 / 12
c. 1 / 15
d. 1 / 20
ANSWER: (b) 1 / 12
52) Which special function register play a vital role in the timer/counter mode selection
process by allocating the bits in it?
a. TMOD
b. TCON
c. SCON
d. PCON
ANSWER:(a) TMOD
53) How many machine cycle/s is/are executed by the counters in 8051 in order to detect
‘1’ to ‘0’ transition at the external pin?
a. One
b. Two
c. Four
d. Eight
a. TR0
b. TF0
c. IT0
d. IE0
55. Which among the following control/s the timer1 especially when it is configured as a
timer in mode’0′, where gate and TR1 bits are attributed to be ‘1” in TMOD register?
a. TR1
b. External input at (INT1)
c. TF1
d. All of the above
56) Which timer mode exhibit the necessity to generate the interrupt by setting EA bit in
IE enhancing the program counter to jump to another vector location?
a. Mode 0
b. Mode 1
c. Mode 2
d. Mode 3
57. Which among the below mentioned program segments represent the correct code?
a. MOV SP, # 54 H
MOV TCON ,# 0010 0000 C
SETC ET1
SETC TR0
SJMP $
b. MOV SP, # 54H
MOV TMOD ,# 0010 0000 C
SETC ET0
SETC TR0
SJMP $
c. MOV SP, # 54 H
MOV TMOD ,# 0010 0000 C
SETC ET1
SETC TR1
SETC EA
SJMP $
d. MOV SP, # 54 H
MOV TMOD ,# 0010 0000 C
SETC ET0
SETC TR1
SETC EA
SJMP $
ANSWER: (c)
MOV SP, # 54 H
MOV TMOD ,# 0010 0000 C
SETC ET1
SETC TR1
SETC EA
SJMP $
58) What is the maximum delay generated by the 12 MHz clock frequency in accordance
to an auto-reload mode (Mode 2) operation of the timer?
a. 125 μs
b. 250 μs
c. 256 μs
d. 1200 μs
59) Which among the below mentioned sequence of program instructions represent the
correct chronological order for the generation of 2kHz square wave frequency?
4. SETB TR0
5. CPL p1.0
6. ORG 0000H
a. 6, 5, 2, 4, 1, 3
b. 6, 1, 3, 2, 4, 5
c. 6, 5, 4, 3, 2, 1
d. 6, 2, 4, 5, 1, 3
ANSWER: (b) 6, 1, 3, 2, 4, 5
60) Why is it not necessary to specify the baud rate to be equal to the number of bits per
second?
a. Because each bit is preceded by a start bit & followed by one stop bit
b. Because each byte is preceded by a start byte & followed by one stop byte
c. Because each byte is preceded by a start bit & followed by one stop bit
d. Because each bit is preceded by a start byte &followed by one stop byte
ANSWER: (c) Because each byte is preceded by a start bit & followed by one stop bit
61. Why is CHMOS technology preferred over HMOS technology for designing the devices
of MCS-51 family?
Answer: Option C