Professional Documents
Culture Documents
Syllabus
04/30/18 2
References
04/30/18 3
What is a microcontroller ?
04/30/18 4
Types of Microcontrollers
Microcontrollers are divided into various categories based
on :
– Bits
– memory,
– architecture,
– instruction sets.
04/30/18 5
Based on bits
Based on bit configuration, the microcontroller is 8-bit ,16-
bit , 32-bit microcontroller
04/30/18 6
Based on architecture
04/30/18 7
Based on instruction set
04/30/18 8
RISC processor
04/30/18 9
Characteristics of RISC
04/30/18 10
CISC Processor
04/30/18 11
Characteristics of CISC
04/30/18 12
Special processor
These are the processors which are designed for some special
purposes. Few of the special processors are :
• Coprocessor
A coprocessor is a specially designed microprocessor,
which can handle its particular function many times faster
than the ordinary microprocessor. For example: Math
Coprocessor.
• Input/Output Processor
It is a specially designed microprocessor having a local
memory of its own, which is used to control I/O devices
with minimum CPU involvement. For example: DMA (direct
Memory Access) controller , Keyboard / mouse controller
04/30/18 13
Special processor
04/30/18 14
Types of Microcontrollers
04/30/18 15
Microprocessor Vs Microcontroller
Microprocessor is heart of Micro Controller is a heart of
Computer system. embedded system
Microprocessors are used for Microcontrollers are used to
Multiple applications. execute a single task within an
application.
It is just a processor. Memory Micro controller has a processor
and I/O components have to be along with internal memory and
connected externally i/O components
04/30/18 17
Major Microcontroller Families
There are several major “families” of microcontrollers
available from different manufacturers.
04/30/18 18
The MCS-51 Family of Microcontrollers
• Originally introduced by Intel in 1981.
– the most widely used microcontroller.
– 8-bit processor.
– 2 distinct separately addressable memory areas.
• Maximum of 64K on-chip ROM.
– Usually 0 to 4K.
• Maximum of 64K external data memory.
• Maximum of 64K external code memory.
• Basic version (8051) contains:
– 4K Bytes of on-chip ROM instruction memory.
– 128 Bytes of on-chip RAM for temporary data storage
and the stack.
– 2 timers, one serial port, and four 8-bit parallel I/O ports.
– Speeds starting from 12 MHz.
04/30/18 19
8051 architecture
04/30/18 20
Other 8051 featurs
04/30/18 21
Pins of 8051
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
P1.2 3 38 P0.1(AD1)
P1.3 4 8051 37 P0.2(AD2)
P1.4 5 36 P0.3(AD3)
P1.5 6 35 P0.4(AD4)
P1.6 7 34 P0.5(AD5)
P1.7 8 33 P0.6(AD6)
RST 9 32 P0.7(AD7)
(RXD)P3.0 10 31 EA/VPP
(TXD)P3.1 11 30 ALE/PROG
(INT0)P3.2 12 29 PSEN
(INT1)P3.3 13 28 P2.7(A15)
(T0)P3.4 14 27 P2.6(A14)
(T1)P3.5 15 26 P2.5(A13)
(WR)P3.6 16 25 P2.4(A12)
(RD)P3.7 17 24 P2.3(A11)
XTAL2 18 23 P2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21
P2.0(A8)
04/30/18 22
Pins of 8051
• Vcc ( pin 40 ):
– Provides supply voltage (+5V DC) to the chip.
04/30/18 24
Pins of 8051
• ALE ( pin 30 ): Address Latch Enable
– It is an output pin and is active high.
– The ALE pin is used for de-multiplexing the address
and data by connecting to the G pin of the 74LS373
latch.
04/30/18 26
Pins of 8051
Port1 (Pin1 to Pin8): these pins can be configured as input
or output pins.
04/30/18 28
Specific Features
• 8 bit cpu with registers A and B
• 4K Internal ROM
04/30/18 30
8051 programming model
• 8051 is a collection of 8 & 16 bit registers and 8 bit memory
location.
04/30/18 31
Internal memory
04/30/18 32
Internal memory
04/30/18 33
Memory And Register Organisation
• The 8051 has a separate memory space for code (programs) and
data.
04/30/18 34
Code / Data memory
• Code memory
– The executable program code is stored in this code memory.
• Data Memory
– This is read-write memory and is available for storage of data.
04/30/18 36
Internal RAM
04/30/18 37
Internal
Memory
04/30/18 38
Internal RAM – Divided into 3 parts
Ist
– 32 working registers organised as 32 Bytes from 00h to 1Fh
• Registers organized as 4 banks of 8 registers each
• 4 banks numbered 0 to 3 and 8 registers named R0 to R7
• Each register can be addressed by name or its RAM address
2nd
– A bit addressable area of 16 bytes occupies RAM address
from 20h to 2Fh
• Total addressable bits is 128
• Bit address from 00h to 7F h
• Byte address from 20h to 2fh
• Ex : Bit address 4Fh is also bit 7 of byte address 29h
3rd
– General purpose ; addressable as byte from 30h to 7Fh
04/30/18 39
Internal
RAM
04/30/18 40
Special function Register
• 8051 has 21 special function registers (SFRs) at the top of
internal RAM from address 80H to FFH.
• Each SFR has a very specific function. Each SFR has an address
(within the range 80h to FFh) and a name which reflects the
purpose of the SFR.
• All 8051 CPU registers, I/O ports, timers and other architecture
components are accessible in 8051 C through SFRs
04/30/18 41
SFR
04/30/18 42
SFR and their Addresses
04/30/18 43
Accumulator
• Aside from the MUL and DIV instructions, the "B" register is
often used as yet another temporary storage register
• much like a ninth "R" register.
04/30/18 45
The data pointer (DPTR)
• Many programmers often take advantage of the fact that it’s the
only true 16-bit register available. It is often used to store 2-
byte values which have nothing to do with memory locations.
04/30/18 46
Program counter (PC)
• The PC is a 2-byte address which tells the 8051 where
the next instruction to execute is found in memory.
04/30/18 47
The Stack Pointer (SP)
• On pushing a value onto the stack, the 8051 first increments the
value of SP and then stores the value at the resulting memory
location.
• On popping a value off the stack, the 8051 returns the value from
the memory location indicated by SP, and then decrements the
value of SP.
04/30/18 48
I/O Ports
One of the major features of a microcontroller is the versatility
built into the I/O circuits that connect the microcontroller to the
outside world .
8051 has four bidirectional 8-bit I/O ports P0, P1, P2 and P3 .
To reduce the overall package pin count, the 8051 employs multiple
functions for each port.
04/30/18 49
Timers and counters
• The 8051 has two 16-bit registers that can be used as either
timers or counters named T0 and T1 and are provided for general
use of the programmer.
• The counters are divided into two 8-bit registers called the timer
low (TL0, TL1) and timer high (TH0, TH1) bytes.
04/30/18 50
TMOD (timer mode) register
• TMOD is used to set various timer operations for T0 &T1
• TMOD is 8 bit register in which the lower 4 bits are set aside
for Timer 0 and upper 4 bits for timer 1
• Out of the 4 bits in each case, lower 2 bits are used to set
timer mode and upper 2 to specify the operation
04/30/18 51
TCON (timer control) register
04/30/18 52
Unit 2
04/30/18 53
Instruction
• An instruction is a command given to the computer to perform
a specified operation / task on given data.
04/30/18 54
The 8051 Instructions
• 8085 is an 8-bit device so it can have up to 28 ( =
256) instructions
04/30/18 55
Instruction format
04/30/18 56
The 8051 Instruction set
The instructions can be grouped into 05 different groups:
– Arithmetic operations
– Logical operations
04/30/18 57
Arithmetic operations
These instructions perform arithmatic operations:
04/30/18 58
Logical operations
04/30/18 59
Data Transfer Operations
This group of instructions copies data from a location called a source
to another location called a destination.
04/30/18 60
Boolean Variable Instructions
04/30/18 61
Branching operations
Ex
Jump : These instructions test for a certain conditions
( ex Zero or carry flag) and alter the sequence when the
condition is met. Ex JZ Over , JNZ Next
NOP : No operation
04/30/18 62
Addressing modes
Instructions need to specify where to get operands from
Some possibilities
– Values are in the instruction
– Values are in the register
• Register number is in the instruction
– Values are in memory
• address is in instruction
• address is in a register
– register number is in the instruction
• address is register value plus some offset
– register number is in the instruction
– offset is in the instruction (or in a register)
– Immediate addressing
– Register addressing
– Direct addressing
– Indirect addressing
04/30/18 64
Immediate addressing
In this mode, the source operand is specified in the instruction
itself.
An immediate mode instruction has an operand field rather than the
address field.
Example:
MOV A,#25h ; Load value 25 H into accumulator.
; 25 is the operand here.
MOV DPTR,#4521H ; Move 16-bit data constant 4521 into the 16-
; bit Data Pointer Register.
04/30/18 65
Register addressing
Ex
MOV A , R0 ; Copy the contents of
register R0 into accumulator
The register bank (Bank 0, 1, 2 or 3) must
be specified prior to this instruction.
04/30/18 66
Direct addressing
In this mode, effective address of
operand is present in instruction itself.
Ex
MOV R0,40h – save content of RAM
location 40h in R0
04/30/18 67
Indirect addressing
In this, the address field of
instruction gives the address where
the effective address is stored in
memory.
Ex
MOV @R1,B – Move contents of B into
RAM location ,whose address is held
by R1
04/30/18 68
Indexed Addressing Mode And On-Chip ROM Access
EA = A + (R), the address field holds two values, A (which is the base
value) and R (that holds the displacement), or vice versa.
Ex
•MOVC A,@A+DPTR :The address is formed by adding the content of
the DPTR register to the accumulator value. Here the DPTR = “base
address” ; Accumulator = “index address”.
04/30/18 69
8051 flag bits and the PSW register
Program Status word (PSW) Register
• It is an 8 bit register
• The PSW3 and PSW4 are designated as RS0 and RS1. They are
used to change the bank registers.
04/30/18 70
PSW
04/30/18 71
8051 flags
Carry flag ( CY)
This flag is set whenever there is carry out from D7 bit.
It can be set to 1 or 0 directly by instructions such as SETB C & CLR C
04/30/18 72
How to change register banks ?
04/30/18 73
Assembling And Running An 8051 Program
Step 1
Use an editor to type a program. The source file has the extension
“asm“ or “src”.
Step 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”
04/30/18 74
Assembling And Running An 8051 Program
Step 3
Assembler requires 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”
– This abs file is used by 8051 trainers that have a monitor
program
Step 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
04/30/18 75
Assembling And Running An 8051 Program
04/30/18 76
List file
04/30/18 77
Loop and Jump instructions
Loop
04/30/18 78
Example for loop using DJNZ
Ex : WAP to add value 3 to the Accumulator 10 times and
save result in R5
04/30/18 79
Example 2 for loop using DJNZ
Ex : WAP to add the first ten natural numbers and save result
in at RAM location 46H
04/30/18 80
Loop inside a loop
To repeat an action more than 256 times, a loop inside a loop
called nested loop is used
– � Here multiple registers are used to hold the count
04/30/18 81
Conditional jumps
Jump only if a certain condition is met
All conditional jumps are short jumps . The address of the target must
be within -128 to +127 bytes of the contents of PC
04/30/18 82
Example conditional jump
JZ ( jump if A=0)
Ex :
MOV A , R0 ; A = R0
JZ OVER ; jump if A = 0
MOV A , R1 ; A = R1
JZ OVER ; jump if A = 0
...
OVER:
04/30/18 83
Unconditional jump
In this jump control is transferred unconditionally to the target
location
04/30/18 84
Calculating the short address
All conditional jumps are short jumps as they are all 2 byte
instructions.
If the target address is more than -128 to +127 bytes from the
address below the short jump instruction
04/30/18 85
Calculating the short address
Line PC Opcode Label Mnemonic Operand
01 0000 ORG 0000
02 0000 78 00 MOV R0,#0
03 0002 74 55 MOV A,#55H
04 0004 60 03 JZ NEXT
05 0006 08 INC R0
06 0007 04 + AGAIN: INC A
07 0008 04 INC A
08 0009 24 77 NEXT: ADD A,#77H
09 000B 50 05 JNC OVER
10 000D E4 CLR A
11 000E F8 + MOV R0,A
12 000F F9 MOVR1,A
13 0010 FA MOV R2,A
14 0011 FB MOV R3,A
15 0012 2B OVER: ADD A,R3
16 0013 50 F2 JNC AGAIN
17 0015 80 FE HERE: SJMP HERE
18 0017 END
04/30/18 86
Time delay for various 8051 chips
CPU executing an instruction takes a certain number of clock cycles
� These are referred as to as machine cycles
Ex : Find the period of the machine cycle for 11.0592 MHz crystal
frequency
Solution: 11.0592/12 = 921.6 kHz;
1 machine cycle is 1/921.6 kHz = 1.085μs
04/30/18 87
Time delay for various instructions
For 8051 system of 11.0592 MHz, find how long it takes to execute
each instruction.
(a) MOV R3,#55 (b) DEC R3 (c) DJNZ R2 target (d) LJMP (e) SJMP
(f) NOP (g) MUL AB
Solution:
Machine cycles Time to execute
(a) 1 1x1.085μs = 1.085μs
(b) 1 1x1.085μs = 1.085μs
(c) 2 2x1.085μs = 2.17μs
(d) 2 2x1.085μs = 2.17μs
(e) 2 2x1.085μs = 2.17μs
(f) 1 1x1.085μs = 1.085μs
(g) 4 4x1.085μs = 4.34μs
04/30/18 88
Example of delay in program
Find the size of the delay, if the crystal frequency is 11.0592MHz.
04/30/18 89
Example 2 : delay in program
Ex : Find the size of the delay in the program, if the crystal
frequency is 11.0592MHz.
Machine Cycle
DELAY: MOV R3, #250 1
HERE: NOP 1
NOP 1
NOP 1
NOP 1
DJNZ R3,HERE 2
RET 2
Solution:
04/30/18 91
Arithmetic and logic instructions
ADD A , source ; A = A + source
�
The instruction ADD is used to add two operands
04/30/18 92
Example ADD
Ex : Assume that RAM locations 40 – 44H have the following
values. WAP to find the sum of the values. At the end , register
A should contain the low byte and R7 the high byte.
40 = (7D) ; 41 = (EB) ; 42 = (C5) ; 43 = (5B) ; 44 = (30)
Solution:
MOV R0, #40H ; load pointer
MOV R2, #5 ; load counter
CLR A ; A= 0
MOV R7, A ; clear R7
AGAIN: ADD A, @R0 ; add the byte ptr to A by R0
JNC NEXT ; if CY=0 don’t add carry
INC R7 ; keep track of carry
NEXT: INC R0 ; increment pointer
DJNZ R2, AGAIN ; repeat until R2 is zero
04/30/18 93
ADDC instruction
ADDC A , source byte ; Add with carry
1
3C E7
+ 3B 8D
78 74
04/30/18 94
Example ADDC
04/30/18 95
BCD number system
Unpacked BCD
Packed BCD
– In packed BCD, a single byte has two BCD number in it, one
in the lower 4 bits, and one in the upper 4 bits
04/30/18 96
Adding two BCD numbers
The addition of two BCD numbers must give a BCD result.
Ex :
MOV A, #17H
ADD A, # 28H
04/30/18 97
DA instruction
DA A ; decimal adjust for addition
Example
MOV A, #47H ; A=47H first BCD operand
MOV B, #25H ; B=25H second BCD operand
ADD A, B ; hex (binary) addition (A=6CH)
DA A ; adjust for BCD addition (A=72H)
04/30/18 98
Summary of DA instruction
04/30/18 99
Multiplication
The 8051 supports byte by byte multiplication only
– The byte are assumed to be unsigned data
Ex:
MOV A,#25H ; load 25H to reg. A
MOV B,#65H ; load 65H to reg. B
MUL AB ; 25H * 65H = E99 where
; B = 0EH and A = 99H
04/30/18 100
Division
The 8051 supports byte by byte division only
– The byte are assumed to be unsigned data
Ex:
MOV A, #95H ; load 95H to reg. A
MOV B, #10H ; load 10H to reg. B
MUL AB ; A= 09 (quotient)
; B = 05 (remainder)
04/30/18 101
Programming in C
C programming is less time consuming, but has larger hex file size
04/30/18 102
Data types
04/30/18 103
Data type – unsigned char
• ASCII characters
04/30/18 104
Template of 8051 C program
# include <reg51.h>
define variable ; /* Global variables – accessible by all functions */
04/30/18 105
Template
#
– This symbol calls header file.
– Header file is program which include many function.
#include reg51.h
– Preprocessor directive
– Used to include a header-file for the registers (SFRs) in the
source file
– Provides the related SFR declarations of the data type,
addresses, pointers and operations during the compilation of
the source file
04/30/18 106
WAP to send values 00 – FF to port P1
#include <reg51.h>
void main (void)
{
unsigned char z;
for (z=0;z<=255;z++)
P1=z;
}
04/30/18 107
WAP to toggle the bits of P1 continuously.
//Toggle P1 forever//
#include <reg51.h>
void main (void)
{
for (;;)
{
p1=0x55; //0x indicates data is in hex
p1=0xAA;
}
}
04/30/18 108
WAP to write 0x75 at port P0
04/30/18 109
WAP to send values of -4 to +4 to port P1.
Solution: use signed characters
#include <reg51.h>
void main (void)
{
Char mynum []={+1,-1,+2,-2,+3,-3,+4,-4};
unsigned char z;
for (z=0; z<8; z++)
P1= mynum [z];
}
04/30/18 110
WAP to toggle bit D0 of the port P1 (P1.0)
50,000 times.
void main(void)
{
unsigned int z;
for (z=0;z<=50000;z++)
{
MYBIT=0;
MYBIT=1;
}
}
04/30/18 111
Time delay
There are two ways to create a time delay in 8051 C
– � Using the 8051 timer
– � Using a simple ‘for’ loop
Compiler choice
– Different compilers produce different code
04/30/18 112
WAP to toggle bits of P1 continuously
forever with some delay.
Solution :Toggle P1 forever with some delay in between “on” and “off”
#include <reg51.h>
void main (void)
{
unsigned int x;
for (;;) //repeat forever
{
p1=0x55;
for (x=0;x<40000;x++); //delay size unknown
p1=0xAA;
for (x=0;x<40000;x++);
}
}
04/30/18 113
Unit 3
Timer Programming
04/30/18 114
Timer
The 8051 has 02 timers / counters, that can be used either as
– � Timers to generate a time delay or as
– � Event counters to count events happening outside the
microcontroller
Both Timer 0 and Timer 1 are 16 bits wide.
The timers are divided into two 8-bit registers called the
timer low (TL0, TL1) and timer high (TH0, TH1) bytes.
�
04/30/18 115
Timer
Both timers 0 and 1 use the same SFR register, called TMOD
(timer mode), to set the various timer operation modes.
� In each case,
– � The lower 2 bits are used to set the timer mode
– � The upper 2 bits to specify the operation
04/30/18 116
TMOD
04/30/18 117
TMOD - GATE
GATE :
The software way to start and stop the timer is when GATE=0
– The start and stop of the timer are controlled by the TR (timer
start) bits TR0 and TR1
– The SETB instruction starts it, and the CLR instruction stops it.
– Ex SETB TR1 and CLR TR1
04/30/18 118
TMOD – clock / timer
C/T ( clock / timer)
04/30/18 119
Example 1
Which mode and which timer are selected for each of the
following.
(a) MOV TMOD, #01H (b) MOV TMOD, #20H (c) MOV
TMOD, #12H
Sol :
Convert the value from hex to binary.
– TMOD = 00000001, mode 1 of timer 0 is selected.
– TMOD = 00100000, mode 2 of timer 1 is selected.
– TMOD = 00010010, mode 2 of timer 0, and mode 1
of timer 1 are selected.
04/30/18 120
Example 2
Find the timer’s clock frequency and its period for various
8051-based system, with the crystal frequency 11.0592
MHz when C/T bit of TMOD is 0.
Solution:
1/12 × 11.0529 MHz = 921.6 MHz;
T = 1/921.6 kHz = 1.085 us
04/30/18 121
Timer Mode 0
Timer Mode 0 is a 13 bit timer.
Only 13 bits are used. Bits 0-4 of TLX and bits 0-7 of
THX.
04/30/18 122
Timer mode 1
It is a 16 bit timer hence 65536 distinct values.
Operation of timer :
TH and TL are loaded with initial 16 bit value & timer is
started.
– done by SETB TR0 for timer 0 and SETB TR1 For
timer 1
It counts up until it reaches its limit FFFH
04/30/18 123
Timer Mode 1 contd
When it rolls over from FFFFH to 0000, Timer flag TF is set high.
– TF0 for timer 0, and TF1 for timer 1
– This timer flag can be monitored
When TF is raised, one option would be to stop the timer with the
instructions CLR TR0 or CLR TR1, for timer 0 and timer 1,
respectively
04/30/18 124
To generate time delay using Mode 1
1. Load the TMOD value register indicating which timer (timer 0
or timer 1) is to be used and which timer mode (0 or 1) is
selected
4. Keep monitoring the timer flag (TF) with the JNB TFx, target
instruction to see if it is raised . Get out of the loop when TF
becomes high
7. 04/30/18
Go back to Step 2 to load TH and TL again 125
WAP to create a square wave on P1.5
MOV TMOD,#01 ; Timer 0, mode 1(16-bit mode)
HERE: MOV TL0,#0F2H ; TL0=F2H, the low byte
MOV TH0,#0FFH ; TH0=FFH, the high byte
CPL P1.5 ; Compliment i.e toggle P1.5
ACALL DELAY ; Delay subroutine using timer is called
SJMP HERE ; Load TH and TL again
04/30/18 126
Amount of delay in previous slide
Calculate the amount of time delay in the DELAY subroutine .
Assume XTAL = 11.0592 MHz.
Solution:
Each clock pulse has a period of T = 1/921.6kHz = 1.085us.
04/30/18 127
Timer mode 2
04/30/18 128
Timer mode 2
For example let initially TH0 = FDh and TL0 = FEh. After
running the following will be the scenario :
04/30/18 129
To generate time delay using Mode 2
Load the TMOD value register indicating which timer (timer 0
or timer 1) is to be used, and the timer mode (mode 2) is
selected
Start timer
Keep monitoring the timer flag (TF) with the JNB TFx,target
instruction to see whether it is raised
– � Get out of the loop when TF goes high
04/30/18 130
Timer mode 2
04/30/18 131
Benefit of auto-reload
04/30/18 132
Mode 3
Mode 3 is split timer mode
All the control bits related to timer 1 are tied to TH0 i.e
TR1 and TF1
04/30/18 133
Basics of Serial communication
Computers transfer data in two ways:
Parallel
Often 8 or more lines (wire conductors) are
used to transfer data to a device that is
only a few feet away
Serial
To transfer to a device located many
meters
away, the serial method is used
The data is sent one bit at a time
04/30/18 134
Serial communication
Serial data communication uses two methods
04/30/18 135
8051 connection to RS232
As the RS232 is not compatible with today’s microprocessor and
microcontroller so a line driver (voltage converter) is required to
convert RS232 to TTL voltage levels that will be acceptable to
8051’s TxD and RxD pins
04/30/18 136
Data transfer rate in 8051
04/30/18 137
Baud rate in 8051
04/30/18 138
Serial communication using SBUF register
– When the bits are received serially via RxD, the 8051
deframes it by eliminating the stop and start bits,
making a byte out of the data received, and then
placing it in SBUF
04/30/18 139
SCON ( serial control) register
SCON is an 8-bit register used to program the start bit, stop
bit, and data bits of data framing
04/30/18 140
SCON Register
SM0 SM1
0 0 Serial Mode 0
0 1 Serial Mode 1, 8-bit
data, 1 stop bit, 1 start bit
1 0 Serial Mode 2
1 1 Serial Mode 2
04/30/18 141
SCON Register
REN (receive enable) : It is a bit-adressable register
– When it is high, it allows 8051 to receive data on RxD pin
– If low, the receiver is disable
04/30/18 142
Programming 8051 to transfer data serially
Following steps must be taken to transfer character bytes serially :
1. TMOD register is loaded with the value 20H, indicating the use
of timer 1 in mode 2 (8-bit auto-reload) to set baud rate
2. The TH1 is loaded with one of the values to set baud rate for
serial data transfer
04/30/18 143
Programming 8051 to transfer data serially
04/30/18 144
Interrupt structure of 8051
Interrupt is a signal send by an external device to the processor to
perform a particular task or work.
04/30/18 145
How to serve several devices?
A single microcontroller can serve several devices .
There are two ways to do it : a) Interrupt b) Polling
Interrupt :
Whenever any device needs its service, the device notifies the
microcontroller by sending it an interrupt signal
Polling process
• The microcontroller continuously monitors the status of a
given device
04/30/18 147
Interrupt vs Polling
04/30/18 148
Interrupt Vectors and the Vector Table
04/30/18 151
Steps in Executing an Interrupt
Upon activation of an interrupt, the microcontroller goes
through the following steps
04/30/18 152
Steps in Executing an Interrupt
4. The µC gets the address of the ISR from the interrupt vector
table and jumps to it
04/30/18 153
Enabling and Disabling an Interrupt
Upon reset, all interrupts are disabled (masked), meaning
that none will be responded to by the µC if they are
activated
04/30/18 154
Interrupt Enable Register
04/30/18 155
Enable an interrupt
To enable an interrupt, we take the following steps:
2. The value of EA
�
– If EA = 1, interrupts are enabled and will be responded
to, if their corresponding bits in IE are high i.e 1
�
– If EA = 0, no interrupt will be responded to, even if the
associated bit in the IE register is high i.e 1
04/30/18 156
THANK YOU
04/30/18 157