Bec405a Microcontrollers 2023-24 m1
Bec405a Microcontrollers 2023-24 m1
1
Cours General
e Information
REFERENCE BOOKS:
1.“The 8051 Microcontroller Based Embedded Systems”,
Manish K Patel, McGraw Hill, 2014, ISBN:978-93-329-
0125-4.
2. “Microcontrollers: Architecture, Programming, Interfacing
and System Design”, Raj Kamal, Pearson Education,
2005.
Course Outcome: Students will be able to as an individual or team
Environment and
Project manage-
Lifelong learning
Investigation of
Development of
Communication
Individual and
Engineer and
Sustainability
Engineering
Knowledge
Design and
Team work
problems
Solution
society
Ethics
Explain the difference between Microprocessors &
Microcontrollers, Architecture of 8051Microcontroller,
C246.1 3 2 2 1
Interfacing of 8051 to external memory and Instruction
set of 8051.
Write 8051 Assembly level programs using 8051
C246.2 instruction set, stacks, subroutines and interfacing of 3 3 3 2 2 1 2 2
simple switches, simple LEDs.
Explain the Interrupt system, operation of
C246.3 Timers/Counters and Serial port of 8051. 3 3 2 2 2 2 2
Resource Relevance
Date- % of to
Action Person
SN. Gap Month- student POs,
taken with
Year designation s PSOs
4
Mini Project1:
Measurement of Heart
Rate and Body
June-July, PO6,9,12,P
3 Industry related projects.
Temperature
2025
Group Activity All
SO2
Mini Project2:
RF ID Based object
Identification system
To Max Evidence Course
Tools Frequency
who Marks collected Outcomes
m
Marks Blue
Direct Assessment Methods
Twice books/Assignments
Internal
(Average /MCQ
assessment of two will be 50 1,2,3,4 and 5
/Seminars /Mini
tests computed) projects
+other
assessment
modes
End of course Answer scripts
End term
(Answer any 5 10 Maintained at 1,2,3,4 and 5
examinatio 0,s
Students out of 10 University
n cal
questions)
ing
to 1,2 and 4
Indirect Assessment
Middle of the
50- Feedback forms Delivery of the
course
ma course
Methods
rks 2 and 3
Surveys effectiveness of
Delivery of
End of course - Questionnaire
instructions and
Assessment
methods
Computer Internal Architecture
Source: https://automateinfra.com/category/computer/
MODULE 1: 8051 Microcontroller
1.1: Microprocessor Versus Microcontroller
MICROPROCESSORS
CPU for Computers Source: (Image: Intel) (Howley)
10
Microcontroller Internal Architecture
Source: https://www.iceeet.com/microcontroller/#google_vignette
Example: Peripheral Interface Controller (PIC) is
microcontroller developed by Microchip
Source: https://www.electronicshub.org/pic-microcontroller-architecture/
Microcontroller
As technology moved from LSI to VLSI, it became possible to
build the microprocessor, memory and I/O devices on a single
chip.
This came to be known as the ‘Microcontroller.
A single-chip computer
On-chip RAM, ROM, I/O ports...
Example : Motorola’s 6811, Intel’s 8051, Zilog’s Z8 and PIC 16X
A single chip
CPU RAM
Microcontroller
Serial
11 Port Port
Microcontroller :
• A microcontroller contains a
microprocessor and also one or more of the
following components.
Memory
Analog to Digital (A/D) converter
Digital to Analog (D/A) converter
Parallel I/O interface
Serial I/O interface
Timers and Counters
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
• CPU is stand-alone, • CPU, RAM, ROM, I/O and timer
RAM, ROM, I/O, timer are all on a single chip
• are separate • fixed amount of on-chip ROM,
Designer
amount ofcan decide
ROM, RAMonand
theI/O RAM, I/O ports
ports.
• for applications in which cost,
• Expensive, versatility power and space are critical
• general-purpose
• single-purpose (control-
• High processing power
• oriented)
• High power consumption
• Low processing power
• Instruction sets focus on
• Low power consumption
processing-intensive
• Bit-level operations
• operations
Instruction sets focus on control
• Typically 32/64 – bit
Typically deep pipeline (5-20 • and bit-level operations
stages) • Typically 8/16 bit
13 Typically single-cycle/two-stage
pipeline
1.2 The Typical Embedded System
FPGA/ASIC/DSP/SoC
Microprocessor/controller Embedded
Firmware
Memory
Communication Interface
System
I/p Ports Core O/p Ports
(Sensors)
(Actuators)
Other supporting
Integrated Circuits &
subsystems
Embedded System
Real World
Microcontroller for EMBEDDED SYSTEM
c. Input unit
d. Output unit
f. Communication channels
Examples
Personal information products: Cell phone, pager,
watch, pocket recorder, calculator
Laptop components: mouse, keyboard, modem, fax
card, sound card, battery charger
Home appliances: door lock,
alarm clock, thermostat, air
conditioner, TV remote, hair
dryer, video
Toys: VCR, games,
small refrigerator,
cars, dolls, etc., cars are about 20-
exercise equipment,
30% silicon today, mostly microcontrollers ($4b/yr)
washer/dryer, microwave
Smart cards [credit cardsoven
plus]
Usually anything with a keypad [simple calculators
however have dedicated calculator chips]
1.2: microcontrollers and embedded processors
The terms Harvard and Von-Neumann refers to the processor architecture design.
Microprocessors/controllers based on the Von-Neumann architecture shares a single
common bus for fetching both instructions and data. Program instructions and data are
stored in a common main memory
Microprocessors/controllers based on the Harvard architecture will have separate data bus
and instruction bus. This allows the data transfer and program fetching to occur
simultaneously on both buses
With Harvard architecture, the data memory can be read and written while the program
memory is being accessed. These separated data memory and code memory buses allow
one instruction to execute while the next instruction is fetched (“Pre-fetching”)
Program
CPU Data Memory
Memory
Prefetching
1.3: Harvard V/s Von-Neumann Processor/Controller Architecture
Separate buses for Instruction and Single shared bus for Instruction and Data
Data fetching fetching
Easier to Pipeline, so high Low performance Compared to Harvard
performance can be achieved Architecture
Comparatively high cost Cheaper
No memory alignment problems Allows self- modifying codes
Since data memory and program Since data memory and program memory
memory are stored physically in are stored physically in same chip, chances
different locations, no chances for for accidental corruption of program
accidental corruption of program memory
memory
RISC vs CISC
1.4: RISC V/s CISC Processors/Controllers
CISC RISC
Show the status of CY, AC, and P flags after the addition of
9CH and 64H in the following instruction.
MOV A, #9CH
ADD A, # 64H
1 0000 0000
Although 128 bytes of the SFR address space is defined, yet only 21
SFR registers are defined in the standard 8051.
Note that some of the SFR registers are bit addressable. SFRs are
accessed just like normal internal RAM locations.
ALE pin of 8051 and 74LS373 latch are used to demultiplex AD0– AD7.
DATA AND ADDRESS MULTIPLEXING USING
ALE
ALTERNATE FUNCTIONS OF PORT
3
EXTERNAL
ROM
When EA is connected to the ground, 8051 fetches
instructions from external ROM by using PSEN. Then, the
address of external ROM is 0000H to FFFFH.
• Pins 1 to 8 (Port 1): These pins are a bi-directional I/O port that can be
used for interfacing with external devices.
• Pin 9 (RESET): This pin is used to reset the microcontroller to its initial
values.
• Pins 10 to 17 (Port 3): These pins have multiple functions including
serving as interrupt inputs, timer inputs, control signals, and serial
communication signals.
• Pins 18 & 19 (XTAL1 & XTAL2): These pins are used for connecting
an external crystal oscillator that provides the clock signal for the
microcontroller.
• Pin 20 (VCC): This pin provides the power supply voltage (typically
+5V) to the microcontroller.
• Pin 21 to 28 (Port 2): These pins are another bi-directional I/O port that
can be used for various purposes.
• Pin 29 (PSEN): This pin is the Program Store Enable signal and is used
during the process of fetching instructions from program memory.
• Pin 30 (EA): This pin is the External Access input and is used to enable
or disable external memory interfacing.
• Pins 32 to 39 (Port 0): This is a bi-directional I/O port that also serves as
the lower order address bus for memory access.
• Pin 40 (GND): This pin is the ground connection for the
microcontroller.
8051 CONNECTED TO 12MHZ
CRYSTAL
AND RESET CIRCUIT
Ceramic oscillator-low cost but frequency stability and
accuracy is less compare to crystal oscillator.
Smallest time in μC is pulse. This Smallest time
accomplishes any simple instruction/complex instruction.
2 pulses=1 state(sub operations: fetch/ decode/ execute/
write data)
6 states= 1 machine cycle.
Any instruction execution time is
-
-
4 5 A2 a a
7 6 Al 9 9
a l 11 9 AO 10 1 8 1 6 13 1 1 I01a 16 13 11
I 19 17 15 12 19 17 15 12
30 ALE
C) •
= C 32 AD7
oi. AD6
33
> 34 AD5
35 AD4
36 AD3
37 AD2
38 ADl
39 ADO
PSEN Pulse
EN ' R OM
Read Pulse
I
Enable
RD
Read
I
I
I
Write Pulse
I
Enable
WR
Write
I
Accessina RAM Usina RD or WR
8051 Ports:
Introduction
• Number of 8051 ports : The ha fou
microcontroller
port P0,P1,P &8051P3.Th fou ports are s r
s 2
operations. Out ofe the 40r pin,32
require
pins are set fo i/o
aside for r fou
• ports P0,P1,P2&P3. Each port takes 8 th r
pins. e an
• When zero is written to a port , it becomes
All the ports
output. To are configured as input upon
Reset.
configure it as an input port, 1 needs to be sent to
the port.
PORT STRUCTURES AND
OPERATION
•These I/O pins allow the 8051 to monitor and
control other devices.
8051.
Its SFR address is 80H.It is bit addressable
port.
Function and use : It can be used as
simple input
/ output mode or for generating data
and lower
order address bus for external
memory (AD0 –AD7).
In order to use the pins of the port 0 as
input and output each pin must be
connected to 10KΩ pull up resistor as shown
Port
0
Port 0 as Simple input port
When port 0 is used as an input port, ‘1’ must be
written to the zer latch
correspondi will cause th outpu
ng
transistor to oswitch
thatoff and theboth e t in a
pin “floats”
high impedance
state. When configured input port the
microcontroller provides two facilities :
1. Read logic level on physical pin by asserting
read pin signal.
2. Read contents of internal latch by asserting
the
read latch signal. The latch is read when the
instruction is read- modify-write type
instruction. A read-modify-write signal is one,
wherein the instruction reads the data from
Port 0 as simple
output
When port 0 is configured as an output port, the
latch pins
that are programmed to 0 will cause the
lower FET to turn
ON and pin is grounded.
If a ‘1’ is written on to the latch pin the FET
will turn off and
the pin is pulled HIGH by external pull up
resistors.
PORT -
1
Port 1
Port 1 is a one bit simple i/o port of microcontroller.
Its SFR address is 90H.It does not have any extra
/alternate function like port 0.
Port 1 as simple input port
When port 1 is used as an input port, ‘1’ must be th
written to e
corresponding port 1 latch bit. This causes off
the lower FET turn The pin and input to pin .
• buffer are pulled to logic HIGH by internal th
pull up load. e
Port is called as ‘quasi-
bidirectional’ port as its
output is pulled high with pull up
Port 1 as simple output
port
When port 1 is used as an output port, the latch
pins that are
programmed to 0, will cause the lower FET
• turn on, the internal pull up to turn off and
input to the circuit is logic 0.
If ‘1’ is written onto the latch pin then it
will drive the input of external circuit high
through the pull up. The lower FET turns
off.
PORT
2
PORT
3
ALTERNATE
FUNCTIONS
BIT ADDRESS OF THE
PORTS
STACK
A stack is a last-in-first-out (LIFO) memory.
SThe stack allows
all read and write operations to be carried
out through one
end and hence, the information that goes in
last will come
out first.
The stack can be implemented in hardware
or by software.
Hardware stack is designed
PIC microcontroller containsby using a stack
hardware set
of
and high-speed
in the 8051registers in order to provide
a fast response. The disadvantage of this
microcontroller,
approach is that thethe stack isthe
size of implemented
stack is by
A software stack is a last-in-first-out
software.
limited.
data structure
implemented by using a number of
The
RAMsoftware stack provides an unlimited
locations.
stack size, that
STACK
POINTER
The address of the stack is contained in a
register called the
stackstack
The pointer.
pointer in bit register.The 8051
8051is an 8 has only
128
Two bytes of internal
instructions, namely can
and be
POPused
are as stack
usually
SRAM
stack and
PUSH space.
used in
operations. The PUSH operation is
defined as writing to
the top or bottom of the stack, whereas the
POP operation
means reading from the top or bottom of
the stack.
When stack is accessed from the bottom,
the stack pointer is
incremented in a push and decremented
after a pop operation
STACK AND STACK POINTER
SP=07h on RESET, data write and read is
illustrated as below.
CONTENTS OF THE STACK AFTER 3
PUSH INSTRUCTIONS
CONTENTS OF MEMORY AND STACK POINTER
AFTER 2 POP INSTRUCTIONS
8052 MICROCONTROLLER
The 8052 is an enhanced version of 8051
microcontroller. The pin diagram and
instruction set of 8051 and 8052 are
practically the same.
The 8052 differs from 8051 by internal
memory size and number of on-chip
timers.
The number of timers/counters in 8052 is
three.
The 8052 has 8 Kbytes of on-chip program
memory. The program memory can be
extended upto 64 Kbytes with external
PROGRAM MEMORY ORGANIZATION OF 8052
DATA MEMORY ORGANIZATION OF
8052
805
2
The 8052 has two on-chip data RAM. In addition to 256
bytes of on-
chip data RAM of 8051, the 8052 has another
128 bytes of data RAM
with address 80H–FFH.
The address of second data RAM has the same
address assigned to special function registers.
Direct addressing mode is used to access
special function registers.
To differentiate parallel address space, indirect
addressing mode is used to access second data
RAM. Registers R0 and R1 are used as pointers
and instructions MOV A, @R0 and MOV @R0, A
or MOV A, @R1 and MOV @R1, A are used to
access second data RAM.
Assignment -2
1. Describe the internal architecture of 8051
microcontroller with
2. block diagram. of
Explain the various flags in the PSW register.
3. discuss the function
each flag.
4. Explain the oscillator circuit and
5 timing of the 8051 microcontroller.
. What is stack? Explain the stack
6 operation with example. to
. Explain the
8051.The Internal
starting RAM
address of structure of and ROM
RAM is 05000h
7
8. 8051.
is 0B000h.
. List special function registers of 8051 including bit
What
a)ALare the functions
b)PSEN c) of the following 8051
addressable.
pins?
E EA
Interface 16 K Bytes of RAM and 32 K Bytes of
UNIT2
8051 INSTRUCTION SET
Logical instructions
Arithmetic instructions
Branch instructions
Subroutine instructions
• ANL A, Rn
• ANL A, direct
• ANL A, @Ri
• ANL A, #data
• ANL direct, A
• ANL direct, #data
• ANL C, bit
• ANL C,
/bit
Logical
Operations
XRL – Works on bytes only.
•XRL A, Rn
•XRL A, direct
•XRL A, @Ri
•XRL A, #data
• XRL direct, A
• XRL direct, #data
CPL / CLR
– Complement / Clear.
– Work on the accumulator or a bit.
Ex: CLR P1.2
Logical Operations
RL / RLC / RR / RRC
– Rotate
the
accumul
• RL and RR without the carry
ator.
• SWAP A
– Swap the upper and lower nibbles of the
• accumulator.
– No compare instruction.
Built into conditional branching instructions.
FIGURE 4.2 Register A Rotate Operations
7 6 5 4 3 2 lo
I
+ + + ± + + +--
·I- I
RLA
c 7 6 5 4 3 2 lo
--I · I ± ± 3: ± 3: 3"
Carry Flag
± RLCA
·I
[, ± + ± :E ± ± ± I • I
7 6 5 4 3 2 1 0
RRA
~
7
F
6
++
5 4
£ F
3 2
++
l 0
H
c
I• I
RRCA Carry Flag
7 6 5 4 3 2 l 0
High Nibble Low Nibble
I
I • . I
.
SWAP A
Bit Manipulation Instructions
This group of instructions is associated with
the single-bit operations of the 8051.
This group allows manipulating
the individual bits of bit addressable registers
and memory locations as well as the CY flag.
The P, OV, and AC flags be directly
cannot
altered.
• This group includes:
move.
Set, clear, and, or complement,
Conditional jumps.
Bit Manipulation Instructions
CLR – Clear a bit or the CY flag.
• CLR P1.1
• CLR C
SETB – Set a bit or the CY flag.
• SETB A.2
• SETB C
CPL – Complement a bit or the CY flag.
• JBC
– Jump to a relative address if a bit is set and clear
the bit.