Nicrocontroller & Applications Mod 1-2023
Nicrocontroller & Applications Mod 1-2023
& APPLICATIONS
Sub code : 4041
Baiju.G.S
Lecturer in Electronics Engineering
2/11/2023 Baiju.G.S 1
• Course Objectives:
• To equip students on architecture, interfacing
and Assembly Language Programming
• (ALP) of 8051 microcontrollers.
• To enable students to develop simple
interfacing applications for daily use
• To prepare students for troubleshooting of
microcontroller-based equipment
2/11/2023 Baiju.G.S 2
• Course Outcomes
• On completion of the course, the student will be
able to:
• CO1 : Explain the features and block diagram of
8051 Microcontroller.
• CO2 : Develop simple Assembly Language
Programs (ALP) for 8051.
• CO3 : Explain interrupts, timer and serial
communication in 8051
• CO4 : Illustrate the interfacing of various I/O
devices with 8051
2/11/2023 Baiju.G.S 3
CO1 : Explain the features and block diagram of 8051
Microcontroller.
• Contents:
• Features and Block diagram of 8051
• Introduction to microprocessors and microcontrollers, features of 8051, simple
block diagram of 8051, Data memory organization, program memory
organization, PSW register.
2/11/2023 Baiju.G.S 4
Microprocessors and
Microcontrollers
2/11/2023 Baiju.G.S 5
Microprocessor
• CPU: Central Processing Unit
• A An integrated circuit that contains all the
functions of a central processing unit of a
computer.
2/11/2023 Baiju.G.S 6
General-purpose microprocessor
2/11/2023 Baiju.G.S 7
Microcontroller
• A control device which incorporates a
microprocessor.
• A Microcontroller is a IC chip that executes
programs for controlling other devices or
machines. It is a micro (small size as its a
Integrated Circuit chip) device which is used for
control of other devices and machines thats why
it is called 'Microcontroller'. It is
a Microprocessor having RAM,ROM and I/O
ports.
2/11/2023 Baiju.G.S 8
• A microcontroller includes a processor, the
ALU, Instruction Decoder, registers, code storage
space(flash memory/ROM), RAM, general purpose
I/O pins, timers, interrupt controller, serial
communication module etc.
2/11/2023 Baiju.G.S 9
Components of a microcontroller
• CPU: Central Processing Unit
• I/O: Input /Output
• Bus: Address bus & Data bus
• Memory: RAM & ROM
• Timer
• Interrupt
• Serial Port
• Parallel Port
2/11/2023 Baiju.G.S 10
Microcontroller
2/11/2023 Baiju.G.S 11
2/11/2023 Baiju.G.S 12
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
2/11/2023 Baiju.G.S 15
8051 Microcontroller
2/11/2023 Baiju.G.S 16
The 8051 microcontroller
• 8051 microcontroller is designed by Intel in
1980. It is an 8-bitmicrocontroller. It is built
with 40 pins DIP (dual inline package), 4kb of
ROM storage and 128 bytes of RAM storage, 2
16-bit timers. It consists of four parallel 8-bit
ports, which are programmable as well as
addressable as per the requirement.
• Harvard architecture (separate instruction/data
memories)
2/11/2023 Baiju.G.S 17
Features of 8051 micro controller
2/11/2023 Baiju.G.S 22
Block Diagram
External interrupts
On-chip Timer/Counter
CPU
Bus Serial
4 I/O Ports
OSC Control Port
P0 P1 P2 P3 TxD RxD
Address/Data
2/11/2023 Baiju.G.S 23
8051 Registers
8 Bit Registers
A
16-bit Registers
B
R0
DPTR DPH DPL
R1
R2 PC PC
R3
R4
R5
R6
R7
24
2/11/2023 Baiju.G.S
• ACCUMULATOR(A / ACC)
It is used for data transfer and arithmetic
operations. After any operation result is stored
in ACC and can be accessed through its SFR
address of 0E0H.
• B REGISTER
It is used to store the upper 8 bit result of
multiplication and divisions. It is used as
temporary register and can be accessed through
its SFR address of 0F0H.
2/11/2023 Baiju.G.S 25
PROGRAM STATUS WORD(PSW)
CY AC FO RS1 RS0 OV P
2/11/2023 Baiju.G.S 26
DATA POINTER(DPTR)
2/11/2023 Baiju.G.S 27
The Stack and Stack Pointer
• The Stack Pointer, like all registers except DPTR
and PC, may hold an 8-bit (1-byte) value.
• The Stack Pointer is used to indicate where the
next value to be removed from the stack should
be taken from.
• When you push a value onto the stack, the 8051
first increments the value of SP and then stores
the value at the resulting memory location.
• When you pop a value off the stack, the 8051
returns the value from the memory location
indicated by SP, and then decrements the value
of SP.
2/11/2023 Baiju.G.S 28
• This order of operation is important. When the
8051 is initialized SP will be initialized to 07h. If
you immediately push a value onto the stack, the
value will be stored in Internal RAM address 08h.
This makes sense taking into account what was
mentioned two paragraphs above: First the 8051
will increment the value of SP (from 07h to 08h)
and then will store the pushed value at that
memory address (08h).
• SP is modified directly by the 8051 by six
instructions: PUSH, POP, ACALL, LCALL,
RET, and RETI. It is also used intrinsically
whenever an interrupt is triggered
2/11/2023 Baiju.G.S 29
Timers / Counters
• 8051 has two 16-bit on-chip timers that can be
used for timing durations or for counting
external events
• The high byte for timer 1 (TH1) is at address
8DH while the low byte (TL1) is at 8BH
• The high byte for timer 0 (TH0) is at 8CH while
the low byte (TL0) is at 8AH.
• Timer Mode Register (TMOD) is at address
88H
2/11/2023 Baiju.G.S 30
Interrupts
• As its name suggests, Interrupt is a subroutine
call that interrupts of the microcontrollers main
operations or work and causes it to execute any
other program, which is more important at the
time of operation. The feature of Interrupt is
very useful as it helps in case of emergency
operations. An Interrupts gives us a mechanism
to put on hold the ongoing operations, execute a
subroutine and then again resumes to another
type of operations. Generally five interrupt
sources are there in 8051 Microcontroller
2/11/2023 Baiju.G.S 31
Input/ Output Port
2/11/2023 Baiju.G.S 32
• Memory
• Microcontroller requires a program which is a
collection of instructions.. These programs
require a memory on which these can be saved
and read to perform specific . The memory
which is used to store the program of the
microcontroller is known as code memory or
Program . It is known as ROM memory .. The
data memory of the 8051 is used to store data
temporarily for operation is known RAM
memory. 8051 microcontroller has 4K B of
Program memory, ROM and 128 bytes of data
memory.
2/11/2023 Baiju.G.S 33
BUS
• Basically Bus is a collection of wires which work as
a communication channel or medium for transfer of
Data. These buses consists of 8, 16 or more wires.
Thus, these can carry 8 bits,16 bits or more
simultaneously. There are two types of buses in a
Microcontroller , Address Bus and Data Bus
2/11/2023 Baiju.G.S 35
RAM space allocation in 8051
• 8051 has 128 bytes of RAM
• RAM address space is 00H to 7FH
• 8051 RAM is divided into 3 groups
– Register banks and Stack
– Bit-addressable memory
– Scratch Pad memory
2/11/2023 Baiju.G.S 36
7F
D7 D6 D5 D4 D3 D2 D1 D0
CY AC F0 RS1 RS0 OV -- P
2/11/2023 Baiju.G.S 38
8051 Flags
• CY(Carry Flag) is SET
– if a carry is generated after addition
– if a borrow is generated after subtraction
• Can be SET/CLEARED by using
instructions such as
SETB C, CLR C
• AC(Auxiliary Carry Flag) is SET
– If there is a carry from bit D3 to D4
– Used for BCD arithmetic
2/11/2023 Baiju.G.S 39
8051 Flags
• P(Parity Flag) reflects no. of 1’s in register A
– SET if ODD no. of 1’s
– RESET if EVEN no. of 1’s
• OV(Overflow Flag)
– Used with signed numbers
– Detects the overflow of the higher-order bit to
the sign bit
2/11/2023 Baiju.G.S 40
PSW Register
2/11/2023 Baiju.G.S 41
8051 Register Banks
• 8051 has 4 register banks
• Each bank has 8 registers named R0 to R7
• Only one register bank can be accessed by
8051 at a time
• Bits RS0 & RS1 of PSW register are used to
select any one of the four register banks
2/11/2023 Baiju.G.S 42
7F
2/11/2023 Baiju.G.S 46
8051 Memory Organization
2/11/2023 Baiju.G.S 47
8051 Memory Organization..
• The 8051 memory organization is rather
complex.
• The 8051 has separate address spaces for
Program Memory, Data Memory, and
external RAM. Both program memory and
external data memory are 8 bits wide and use
16 bits of address. The internal data memory
is accessed using an 8-bit address.
• Since the same address can refer to different
locations the specific location is determined
by the type of instruction.
2/11/2023 Baiju.G.S 48
SFR Memory
• The 8051 provides 128 bytes of memory for
Special Function Registers (SFRs). SFRs are bit,
byte, or word-sized registers that are used to
control timers, counters, serial I/O, port I/O,
and peripherals.
2/11/2023 Baiju.G.S 49
2/11/2023 Baiju.G.S 50
Program Memory (ROM) of 8051
Microcontroller
2/11/2023 Baiju.G.S 51
2/11/2023 Baiju.G.S 52
External Data Memory
• Access to external memory is slower than access
to internal data memory. There may be up to
64K Bytes of external data memory. Several 8051
devices provide on-chip XRAM space that is accessed
with the same instructions as the traditional external
data space. This XRAM space is typically enabled via
proper setting of SFR register and overlaps the external
memory space. Setting of that register must be manualy
done in code, before any access to external memory or
XRAM space is made.
2/11/2023 Baiju.G.S 53
Interfacing External Memory
with 8051 Microcontroller
2/11/2023 Baiju.G.S 54
Thank you
2/11/2023 Baiju.G.S 55