SlideShare a Scribd company logo
Micro-Controller 8051Micro-Controller 8051
OverviewOverview
Ritula Thakur
NITTTR
Chapter 1Chapter 1
The 8051 MicrocontrollersThe 8051 Microcontrollers
OutlinesOutlines
Compare microprocessors & microcontrollers
Advantages of microcontrollers
Embedded systems
Choose a microcontroller
Speed, packaging, memory & cost per unit
Various members of 8051 family
Various manufacturers of 8051
04/07/15 Ritula Thakur 3
Microcontroller vs.Microcontroller vs.
MicroprocessorsMicroprocessors
04/07/15 Ritula Thakur 4
Embedded Computing SystemsEmbedded Computing Systems
Use a microprocessor or microcontroller to do
one task only
Printer
PC used for any number of applications
Word processor, print-server, bank teller terminal,
video game player, network server, internet
terminal
PC contains or is connected to various
embedded products
Keyboard, printer, modem, disk controller, sound
card, CD-ROM driver, mouse
X86 PC embedded applications04/07/15 Ritula Thakur 5
Embedded Products Using MicrocontrollersEmbedded Products Using Microcontrollers
Home
Appliances, intercom, telephones, security
systems, garage door openers, answering
machines, fax machines, home computers, TVs,
cable TV tuner, VCR, camcorder, remote
controls, video games, cellular phones, musical
instruments, sewing machines, lighting control,
paging, camera, pinball machines, toys,
exercise equipment
04/07/15 Ritula Thakur 6
Embedded Products Using MicrocontrollersEmbedded Products Using Microcontrollers
Office
Telephones, computers, security systems, fax
machines, microwave, copier, laser printer, color
printer, paging
04/07/15 Ritula Thakur 7
Embedded Products Using MicrocontrollersEmbedded Products Using Microcontrollers
Auto
Trip computer, engine control, air bag, ABS,
instrumentation, security system, transmission
control, entertainment, climate control, cellular
phone, keyless entry
04/07/15 Ritula Thakur 8
Choosing A MicrocontrollerChoosing A Microcontroller
Computing needs
Speed, packaging, power consumption, RAM,
ROM, I/O pins, timers, upgrade to high
performance or low-power versions, cost
Software development tools
Assembler, debugger, C compiler, emulator,
technical support
Availability & source
04/07/15 Ritula Thakur 9
Companies Producing 8051Companies Producing 8051
Table 1-2:Some Companies Producing a
Member of the 8051 Family
CompanyCompany Web SiteWeb Site
IntelIntel www.intel.com/design/mcs51www.intel.com/design/mcs51
AtmelAtmel www.atmel.comwww.atmel.com
Philips/SigneticsPhilips/Signetics www.semiconductors.philips.comwww.semiconductors.philips.com
SiemensSiemens www.sci.siemens.comwww.sci.siemens.com
Dallas SemiconductorDallas Semiconductor www.dalsemi.comwww.dalsemi.com
04/07/15 Ritula Thakur 10
Inside 8051 MicrocontrollerInside 8051 Microcontroller
Introduced by Intel in 1981
04/07/15 Ritula Thakur 11
8051 Family8051 Family
Table 1-4:Comparison of 8051 Family
Members
FeatureFeature 80518051 80528052 80318031
ROM (on chip program space in bytes)ROM (on chip program space in bytes) 4K4K 8k8k 0k0k
RAM (bytes)RAM (bytes) 128128 256256 128128
TimersTimers 22 33 22
I/O pinsI/O pins 3232 3232 3232
Serial portSerial port 11 11 11
Interrupt sourcesInterrupt sources 66 88 66
04/07/15 Ritula Thakur 12
Various 8051 MicrocontrollersVarious 8051 Microcontrollers
8751 microcontroller
UV-EPROM
AT89C51 from Atmel Corporation
Flash (erase before write)
DS5000 from Dallas Semiconductor
NV-RAM (changed one byte at a time), RTC (real-
time clock)
OTP (one-time-programmable) version of
8051
8051 family from Philips
AD, DA, extended I/O, OTP and flash04/07/15 Ritula Thakur 13
Chapter 2Chapter 2
8051 Assembly Language Programming8051 Assembly Language Programming
OutlinesOutlines
8051 registers
Manipulate data using registers & MOVE
instructions
Code simple assembly language instructions
Assemble and run a program
Sequence events upon power-up
Examine programs in ROM codes
ROM memory map
Execution of instructions
Data types
PSW register
RAM memory space
Stack
Register banks
04/07/15 Ritula Thakur 15
8051 Registers8051 Registers
D7D7 D6D6 D5D5 D4D4 D3D3 D2D2 D1D1 D0D0
DPTR
PC PC (Program counter)
DPH DPL
Figure2-1 (a): Some 8 bit Registers of the 8051
Figure2-1 (b): Some 8051 16 bit Registers
8 bit Registers
R6R6
R5R5
R4R4
R3R3
R2R2
R1R1
R0R0
BB
AA
R7R7
04/07/15 Ritula Thakur 16
MOV InstructionMOV Instruction
MOV destination, source ; copy source to dest.
MOV A,#55H ;load value 55H into reg. A
MOV R0,A ;copy contents of A into R0
;(now A=R0=55H)
MOV R1,A ;copy contents of A into R1
;(now A=R0=R1=55H)
MOV R2,A ;copy contents of A into R2
;(now A=R0=R1=R2=55H)
MOV R3,#95H ;load value 95H into R3
;(now R3=95H)
MOV A,R3 ;copy contents of R3 into A
;now A=R3=95H
04/07/15 Ritula Thakur 17
Notes on ProgrammingNotes on Programming
Value (proceeded with #) can be loaded directly
to registers A, B, or R0 – R7
MOV R5, #0F9H
If values 0 to F moved into an 8-bit register, the
rest assumed all zeros
MOV A, #5
A too large value causes an error
MOV A, #7F2H
04/07/15 Ritula Thakur 18
ADD InstructionADD Instruction
ADD A, source ;ADD the source operand
;to the accumulator
MOV A, #25H ;load 25H into A
MOV R2,#34H ;load 34H into R2
ADD A,R2 ;add R2 to accumulator
;(A = A + R2)
04/07/15 Ritula Thakur 19
Structure of Assembly LanguageStructure of Assembly Language
ORG 0H ;start (origin) at location 0
MOV R5,#25H ;load 25H into R5
MOV R7,#34H ;load 34H into R7
MOV A,#0 ;load 0 into A
ADD A,R5 ;add contents of R5 to A
;now A = A + R5
ADD A,R7 ;add contents of R7 to A
;now A = A + R7
ADD A,#12H ;add to A value 12H
;now A = A + 12H
HERE: SJMP HERE ;stay in this loop
END ;end of asm source file
Program 2-1:Sample of an Assembly Language Program
04/07/15 Ritula Thakur 20
Steps to Create a ProgramSteps to Create a Program
04/07/15 Ritula Thakur 21
8051 Program Counter & ROM8051 Program Counter & ROM
SpaceSpace
04/07/15 Ritula Thakur 22
8051 Program Counter & ROM8051 Program Counter & ROM
SpaceSpace
04/07/15 Ritula Thakur 23
8051 Program Counter & ROM8051 Program Counter & ROM
SpaceSpace
04/07/15 Ritula Thakur 24
Execute a Program Byte by ByteExecute a Program Byte by Byte
1. PC=0000: opcode 7D fetched; 25 fetched;
R5←25; PC+2
2. PC=0002: opcode 7F fetched; 34 fetched;
R7←34; PC+2
3. PC=0004; opcode 74 fetched; 0 fetched;
A←0; PC+2
4. PC=0006; opcode 2D fetched; A←A+R5;
PC+1
5. (Similarly…)
04/07/15 Ritula Thakur 25
8051 On-Chip ROM Address Range8051 On-Chip ROM Address Range
04/07/15 Ritula Thakur 26
Data Types & DirectivesData Types & Directives
ORG 500H
DATA1: DB 28 ;DECIMAL (1C in Hex)
DATA2: DB 00110101B ;BINARY (35 in Hex)
DATA3: DB 39H ;HEX
ORG 510H
DATA4: DB “2591” ; ASCII NUMBERS
ORG 518H
DATA6: DB “My name is Joe” ;ASCII
CHARACTERS
04/07/15 Ritula Thakur 27
PSW (Flag) RegisterPSW (Flag) Register
04/07/15 Ritula Thakur 28
Instructions Affecting Flag BitsInstructions Affecting Flag Bits
04/07/15 Ritula Thakur 29
ADD Instruction and PSWADD Instruction and PSW
04/07/15 Ritula Thakur 30
ADD Instruction and PSWADD Instruction and PSW
04/07/15 Ritula Thakur 31
ADD Instruction and PSWADD Instruction and PSW
04/07/15 Ritula Thakur 32
8051 RAM Allocation8051 RAM Allocation
04/07/15 Ritula Thakur 33
8051 Register Banks8051 Register Banks
04/07/15 Ritula Thakur 34
Access RAM Locations Using Register NamesAccess RAM Locations Using Register Names
04/07/15 Ritula Thakur 35
Access RAM Locations UsingAccess RAM Locations Using
AddressesAddresses
04/07/15 Ritula Thakur 36
Switch Register BanksSwitch Register Banks
04/07/15 Ritula Thakur 37
Switch Register BanksSwitch Register Banks
04/07/15 Ritula Thakur 38
Pushing onto StackPushing onto Stack
04/07/15 Ritula Thakur 39
Popping from StackPopping from Stack
04/07/15 Ritula Thakur 40
Stack & Bank 1 ConflictStack & Bank 1 Conflict
04/07/15 Ritula Thakur 41
Stack & Bank 1 ConflictStack & Bank 1 Conflict
04/07/15 Ritula Thakur 42
Chapter 3Chapter 3
JUMP, LOOP and CALL InstructionsJUMP, LOOP and CALL Instructions
OutlinesOutlines
Loop instructions
Conditional jump instructions
Conditions determining conditional jump
Unconditional long & short jumps
Calculate target addresses for jumps
Subroutines
Using stack in subroutines
Crystal frequency vs. machine cycle
Code programs to generate time delay
04/07/15 Ritula Thakur 44
LoopingLooping
04/07/15 Ritula Thakur 45
Loop inside a Loop (NestedLoop inside a Loop (Nested
Loop)Loop)
04/07/15 Ritula Thakur 46
8051 Conditional Jump8051 Conditional Jump
InstructionsInstructions
04/07/15 Ritula Thakur 47
Conditional Jump ExampleConditional Jump Example
04/07/15 Ritula Thakur 48
Conditional Jump ExampleConditional Jump Example
04/07/15 Ritula Thakur 49
Unconditional Jump InstructionsUnconditional Jump Instructions
All conditional jumps are short jumps
Target address within -128 to +127 of PC
LJMP (long jump): 3-byte instruction
2-byte target address: 0000 to FFFFH
Original 8051 has only 4KB on-chip ROM
SJMP (short jump): 2-byte instruction
1-byte relative address: -128 to +127
04/07/15 Ritula Thakur 50
Calculating Short Jump AddressesCalculating Short Jump Addresses
04/07/15 Ritula Thakur 51
Calculating Short Jump AddressesCalculating Short Jump Addresses
04/07/15 Ritula Thakur 52
Call InstructionsCall Instructions
LCALL (long call): 3-byte instruction
2-byte address
Target address within 64K-byte range
ACALL (absolute call): 2-byte instruction
11-bit address
Target address within 2K-byte range
04/07/15 Ritula Thakur 53
LCALLLCALL
04/07/15 Ritula Thakur 54
CALL Instruction & Role of StackCALL Instruction & Role of Stack
04/07/15 Ritula Thakur 55
CALL Instruction & Role of StackCALL Instruction & Role of Stack
04/07/15 Ritula Thakur 56
Using PUSH & POP in SubroutinesUsing PUSH & POP in Subroutines
04/07/15 Ritula Thakur 57
Using PUSH & POP in SubroutinesUsing PUSH & POP in Subroutines
04/07/15 Ritula Thakur 58
Using PUSH & POP in SubroutinesUsing PUSH & POP in Subroutines
04/07/15 Ritula Thakur 59
Calling SubroutinesCalling Subroutines
04/07/15 Ritula Thakur 60
Calling SubroutinesCalling Subroutines
04/07/15 Ritula Thakur 61
ACALL (absolute call)ACALL (absolute call)
04/07/15 Ritula Thakur 62
Programming EfficientlyProgramming Efficiently
04/07/15 Ritula Thakur 63
Time Delay Generation &Time Delay Generation &
CalculationCalculation
1 instruction = n × machine cycle
1 machine cycle = 12 clock cycles
04/07/15 Ritula Thakur 64
Delay CalculationDelay Calculation
04/07/15 Ritula Thakur 65
Delay Calculation ExampleDelay Calculation Example
04/07/15 Ritula Thakur 66
Delay Calculation ExampleDelay Calculation Example
04/07/15 Ritula Thakur 67
Increasing Delay Using NOPIncreasing Delay Using NOP
04/07/15 Ritula Thakur 68
Large Delay Using Nested LoopLarge Delay Using Nested Loop
04/07/15 Ritula Thakur 69
Chapter 4Chapter 4
I/O Port ProgrammingI/O Port Programming
OutlinesOutlines
8051 pin functions
4 ports of 8051
Dual role of port 0 for data & address
Code assembly language to use ports
Use of port 3 for interrupt signals
Code 8051 instructions for I/O handling
Code bit-manipulation instructions
04/07/15 Ritula Thakur 71
8051 Pin Diagram8051 Pin Diagram
04/07/15 Ritula Thakur 72
Clock GenerationClock Generation
04/07/15 Ritula Thakur 73
Clock GenerationClock Generation
04/07/15 Ritula Thakur 74
Machine & Clock CyclesMachine & Clock Cycles
04/07/15 Ritula Thakur 75
RESET Value of RegistersRESET Value of Registers
04/07/15 Ritula Thakur 76
RESET CircuitsRESET Circuits
04/07/15 Ritula Thakur 77
RESET CircuitsRESET Circuits
04/07/15 Ritula Thakur 78
Pins for External ROM/RAMPins for External ROM/RAM
EA (external access)
VCC: on-chip ROM
GND: external ROM
PSEN (program store enable)
to OE (output enable) pin of ROM
ALE (address latch enable)
to G (enable) pin of 74LS373
See Chapter 14
04/07/15 Ritula Thakur 79
Port 0: I/O, Open DrainPort 0: I/O, Open Drain
Initially configured as output
MOVMOV A,#55HA,#55H
BACK:BACK: MOVMOV P0,AP0,A
ACALLACALL DELAYDELAY
CPLCPL AA
SJMPSJMP BACKBACK
04/07/15 Ritula Thakur 80
Port 0: I/O, Open DrainPort 0: I/O, Open Drain
04/07/15 Ritula Thakur 81
Port 0 as Input: Write all 1sPort 0 as Input: Write all 1s
Dual role of port 0
Can be configured as AD0 – AD7
MOV A,#0FFH ;A = FF hex
MOV P0,A ;make P0 an input port
;by writing all 1s to it
BACK: MOV A,P0 ;get data from P0
MOV P1,A ;send it to port 1
SJMP BACK ;keep doing it
04/07/15 Ritula Thakur 82
Port 1: I/O, No Pull-up ResistorsPort 1: I/O, No Pull-up Resistors
Initially configured as output
MOV A,#55H
BACK: MOV P1,A
ACALL DELAY
CPL A
SJMP BACK
MOV A,#0FFH ;A=FF hex
MOV P1,A ;make P1 an input port
;by writing all 1s to it
MOV A,P1 ;get data from P1
MOV R7,A ;save it in reg R7
ACALL DELAY ;wait
MOV A,P1 ;get another data from
P1
MOV R6,A ;save it in reg R6
ACALL DELAY ;wait
MOV A,P1 ;get another data from P1
MOV R5,A ;save it in reg R5
04/07/15 Ritula Thakur 83
Port 2: I/O, No Pull-up ResistorsPort 2: I/O, No Pull-up Resistors
Initially configured as output
MOV A,#55H
BACK: MOV P2,A
ACALL DELAY
CPL A
SJMP BACK
MOV A,#0FFH ;A=FF hex
MOV P2,A ;make P2 an input port by
;writing all 1s to it
BACK: MOV A,P2 ;get data from P2
MOV P1,A ;send it to Port 1
SJMP BACK ;keep doing that
♦ Dual role of port 2: A8-A15Dual role of port 2: A8-A15
04/07/15 Ritula Thakur 84
Port 3: I/O, No Pull-up ResistorsPort 3: I/O, No Pull-up Resistors
04/07/15 Ritula Thakur 85
Different Ways of Accessing 8 bitsDifferent Ways of Accessing 8 bits
BACK: MOV A,#55H
MOV P1,A
ACALL DELAY
MOV A,#0AAH
MOV P1,A
ACALL DELAY
SJMP BACK
BACK:BACK: MOVMOV P1,#55HP1,#55H
ACALLACALL DELAYDELAY
MOVMOV P1,#0AAHP1,#0AAH
ACALLACALL DELAYDELAY
SJMPSJMP BACKBACK
MOV P1,#55H ;P1=01010101
AGAIN: XLR P1,#0FFH ;EX-OR
;P1 with 1111 1111
ACALL DELAY
SJMP AGAIN
04/07/15 Ritula Thakur 86
Single-bit Addressability of PortsSingle-bit Addressability of Ports
BACK: CPL P1.2 ;complement P1.2 only
ACALL DELAY
SJMP BACK
;another variation of the above program follows
AGAIN: SETB P1.2 ;change only P1.2=high
ACALL DELAY
CLR P1.2 ;change only P1.2=low
ACALL DELAY
SJMP AGAIN
04/07/15 Ritula Thakur 87
Single-bit Addressability of PortsSingle-bit Addressability of Ports
04/07/15 Ritula Thakur 88
Example 4-2Example 4-2
04/07/15 Ritula Thakur 89
Chapter 5Chapter 5
Addressing ModesAddressing Modes
OutlinesOutlines
Five addressing modes of 8051
Code instructions using each addressing
mode
Access RAM using various addressing
modes
SFR addresses
Access SFR
Operate stack using direct addressing mode
Code instructions to operate look-up table
04/07/15 Ritula Thakur 91
Five Addressing ModesFive Addressing Modes
Immediate
Register
Direct
Register indirect
Indexed
04/07/15 Ritula Thakur 92
Immediate Addressing ModeImmediate Addressing Mode
MOVMOV A,#25HA,#25H ;load 25H into A;load 25H into A
MOVMOV R4,#62R4,#62 ;load the decimal value 62 into R4;load the decimal value 62 into R4
MOV B,#40HMOV B,#40H ;load 40H into B;load 40H into B
MOVMOV DPTR,#4521HDPTR,#4521H ;DPTR=4521H;DPTR=4521H
MOVMOV DPTR,#2550HDPTR,#2550H
;is the same as:;is the same as:
MOVMOV DPL,#50HDPL,#50H
MOVMOV DPH,#25HDPH,#25H
04/07/15 Ritula Thakur 93
MOVMOV DPTR,#68975DPTR,#68975 ;illegal!! value > 65535 (FFFFH);illegal!! value > 65535 (FFFFH)
COUNTCOUNT EQU 30EQU 30
…… ……
MOVMOV R4,#COUNTR4,#COUNT ;R4=1E (30=1EH);R4=1E (30=1EH)
MOVMOV DPTR,#MYDATADPTR,#MYDATA ;DPTR=200H;DPTR=200H
ORGORG 200H200H
MYDATA:MYDATA: DB “America”DB “America”
04/07/15 Ritula Thakur 94
Register Addressing ModeRegister Addressing Mode
MOVMOV A,R0A,R0 ;copy the contents of R0 into A;copy the contents of R0 into A
MOVMOV R2,AR2,A ;copy the contents of A into R2;copy the contents of A into R2
ADDADD A,R5A,R5 ;add the contents of R5 to contents of A;add the contents of R5 to contents of A
ADDADD A,R7A,R7 ;add the contents of R7 to contents of A;add the contents of R7 to contents of A
MOVMOV R6,AR6,A ;save accumulator in R6;save accumulator in R6
MOVMOV DPTR,#25F5HDPTR,#25F5H
MOVMOV R7,DPLR7,DPL
MOVMOV R6,DPHR6,DPH
04/07/15 Ritula Thakur 95
Direct Addressing ModeDirect Addressing Mode
RAM addresses 00 to 7FH
MOVMOV R0,40HR0,40H ;save content of RAM location 40H in R0;save content of RAM location 40H in R0
MOVMOV 56H,A56H,A ;save content of A in RAM location 56H;save content of A in RAM location 56H
MOVMOV R4,7FHR4,7FH ;move contents of RAM location 7FH to;move contents of RAM location 7FH to
R4R4
MOVMOV A,4A,4 ;is same as;is same as
MOV A,R4MOV A,R4 ;which means copy R4 into A;which means copy R4 into A
MOVMOV A,7A,7 ;is same as;is same as
MOVMOV A,R7A,R7 ;which means copy R7 into A;which means copy R7 into A
04/07/15 Ritula Thakur 96
MOVMOV A,2A,2 ;is the same as;is the same as
MOVMOV A,R2A,R2 ;which means copy R2 into A;which means copy R2 into A
MOVMOV A,0A,0 ;is the same as;is the same as
MOVMOV A,R0A,R0 ;which means copy R0 into A;which means copy R0 into A
MOVMOV R2,#5R2,#5 ;R2=05;R2=05
MOVMOV A,2A,2 ;copy R2 to A (A=R2=05);copy R2 to A (A=R2=05)
MOVMOV B,2B,2 ;copy R2 to B (B=R2=05);copy R2 to B (B=R2=05)
MOVMOV 7,27,2 ;copy R2 to R7;copy R2 to R7
;since “MOV R7,R2” is invalid;since “MOV R7,R2” is invalid
04/07/15 Ritula Thakur 97
SFR Registers & Their AddressesSFR Registers & Their Addresses
MOVMOV 0E0H,#55H0E0H,#55H ;is the same as;is the same as
MOVMOV A,#55HA,#55H ;which means load 55H into A (A=55H);which means load 55H into A (A=55H)
MOVMOV 0F0H,#25H0F0H,#25H ;is the same as;is the same as
MOV B,#25HMOV B,#25H ;which means load 25H into B (B=25H);which means load 25H into B (B=25H)
MOVMOV 0E0H,R20E0H,R2 ;is the same as;is the same as
MOVMOV A,R2A,R2 ;which means copy R2 into A;which means copy R2 into A
MOVMOV 0F0H,R00F0H,R0 ;is the same as;is the same as
MOVMOV B,R0B,R0 ;which means copy R0 into B;which means copy R0 into B
04/07/15 Ritula Thakur 98
SFR Addresses ( 1 of 2 )SFR Addresses ( 1 of 2 )
04/07/15 Ritula Thakur 99
SFR Addresses ( 2 of 2 )SFR Addresses ( 2 of 2 )
04/07/15 Ritula Thakur 100
ExampleExample
04/07/15 Ritula Thakur 101
Stack and Direct Addressing ModeStack and Direct Addressing Mode
Only direct addressing is allowed for stack
04/07/15 Ritula Thakur 102
Register Indirect Addressing ModeRegister Indirect Addressing Mode
Only R0 & R1 can be used
MOVMOV A,@R0A,@R0 ;move contents of RAM location whose;move contents of RAM location whose
;address is held by R0 into A;address is held by R0 into A
MOVMOV @R1,B@R1,B ;move contents of B into RAM location;move contents of B into RAM location
;whose address is held by R1;whose address is held by R1
04/07/15 Ritula Thakur 103
Example ( 1 of 2 )Example ( 1 of 2 )
04/07/15 Ritula Thakur 104
Example ( 2 of 2 )Example ( 2 of 2 )
04/07/15 Ritula Thakur 105
Advantage of Register Indirect AddressingAdvantage of Register Indirect Addressing
Looping not possible in direct addressing
04/07/15 Ritula Thakur 106
ExampleExample
04/07/15 Ritula Thakur 107
Index Addressing Mode & On-chip ROMIndex Addressing Mode & On-chip ROM
AccessAccess
Limitation of register indirect addressing: 8-bit
addresses (internal RAM)
DPTR: 16 bits
MOVC A, @A+DPTR ; “C” means program
(code) space ROM
04/07/15 Ritula Thakur 108
Example ( 1 of 2 )Example ( 1 of 2 )
04/07/15 Ritula Thakur 109
Example ( 2 of 2 )Example ( 2 of 2 )
04/07/15 Ritula Thakur 110
Example ( 1 of 3 )Example ( 1 of 3 )
04/07/15 Ritula Thakur 111
Example ( 2 of 3 )Example ( 2 of 3 )
04/07/15 Ritula Thakur 112
Example ( 3 of 3 )Example ( 3 of 3 )
04/07/15 Ritula Thakur 113
Look-up Table & IndexedLook-up Table & Indexed
AddressingAddressing
04/07/15 Ritula Thakur 114
ExampleExample
04/07/15 Ritula Thakur 115
Chapter 6Chapter 6
Arithmetic Instructions and ProgramsArithmetic Instructions and Programs
OutlinesOutlines
Range of numbers in 8051 unsigned data
Addition & subtraction instructions for unsigned
data
BCD system of data representation
Packed and unpacked BCD data
Addition & subtraction on BCD data
Range of numbers in 8051 signed data
Signed data arithmetic instructions
Carry & overflow problems & corrections
04/07/15 Ritula Thakur 117
Addition of Unsigned NumbersAddition of Unsigned Numbers
ADD A, source ; A = A + source
04/07/15 Ritula Thakur 118
04/07/15 Ritula Thakur 119
Addition of Individual BytesAddition of Individual Bytes
04/07/15 Ritula Thakur 120
ADDC & Addition of 16-bitADDC & Addition of 16-bit
NumbersNumbers
1
3C E7
3B 8D
78 74
+
04/07/15 Ritula Thakur 121
BCD Number SystemBCD Number System
Unpacked BCD: 1 byte
Packed BCD: 4 bits
04/07/15 Ritula Thakur 122
Adding BCD Numbers & DAAdding BCD Numbers & DA
InstructionInstruction
MOVMOV A,#17HA,#17H
ADDADD A,#28HA,#28H
MOVMOV A,#47HA,#47H ;A=47H first BCD operand;A=47H first BCD operand
MOVMOV B,#25HB,#25H ;B=25 second BCD operand;B=25 second BCD operand
ADDADD A,BA,B ;hex (binary) addition (A=6CH);hex (binary) addition (A=6CH)
DADA AA ;adjust for BCD addition;adjust for BCD addition
(A=72H)(A=72H)
HEXHEX BCDBCD
2929 0010 10010010 1001
++ 1818 ++0001 10000001 1000
4141 0100 00010100 0001 AC=1AC=1
++ 66 ++ 01100110
4747 0100 01110100 0111
04/07/15 Ritula Thakur 123
ExampleExample
04/07/15 Ritula Thakur 124
Subtraction of Unsigned NumbersSubtraction of Unsigned Numbers
SUBB A, source ; A = A – source – CY
SUBB when CY = 0
Take 2’s complement of subtraend (source)
Add it to minuend
Invert carry
04/07/15 Ritula Thakur 125
Example (Positive Result)Example (Positive Result)
04/07/15 Ritula Thakur 126
Example (Negative Result)Example (Negative Result)
04/07/15 Ritula Thakur 127
SUBB When CY = 1SUBB When CY = 1
For multibyte numbers
04/07/15 Ritula Thakur 128
Multiplication of UnsignedMultiplication of Unsigned
NumbersNumbers
MUL AB ; A × B, place 16-bit result in B and
AMOVMOV A,#25HA,#25H ;load 25H to reg. A;load 25H to reg. A
MOVMOV B,#65HB,#65H ;load 65H in reg. B;load 65H in reg. B
MULMUL ABAB ;25H * 65H = E99 where;25H * 65H = E99 where
;B = 0EH and A = 99H;B = 0EH and A = 99H
Table 6-1:Unsigned Multiplication Summary (MUL AB)Table 6-1:Unsigned Multiplication Summary (MUL AB)
MultiplicationMultiplication Operand 1Operand 1 Operand 2Operand 2 ResultResult
bytebyte ×× bytebyte AA BB A=low byte,A=low byte,
B=high byteB=high byte
04/07/15 Ritula Thakur 129
Division of Unsigned NumbersDivision of Unsigned Numbers
DIV AB ; divide A by B
MOVMOV A,#95HA,#95H ;load 95 into A;load 95 into A
MOVMOV B,#10HB,#10H ;load 10 into B;load 10 into B
DIVDIV ABAB ;now A = 09 (quotient) and;now A = 09 (quotient) and
;B = 05 (remainder);B = 05 (remainder)
Table 6-2:Unsigned Division Summary (DIV AB)Table 6-2:Unsigned Division Summary (DIV AB)
DivisionDivision NumeratorNumerator DenominatorDenominator QuotientQuotient RemainderRemainder
byte / bytebyte / byte AA BB AA BB
04/07/15 Ritula Thakur 130
Example ( 1 of 2 )Example ( 1 of 2 )
04/07/15 Ritula Thakur 131
Example ( 2 of 2 )Example ( 2 of 2 )
04/07/15 Ritula Thakur 132
Signed 8-bit OperandsSigned 8-bit Operands
Covert to 2’s complement
Write magnitude of number in 8-bit binary (no
sign)
Invert each bit
Add 1 to it
04/07/15 Ritula Thakur 133
ExampleExample
04/07/15 Ritula Thakur 134
ExampleExample
04/07/15 Ritula Thakur 135
ExampleExample
04/07/15 Ritula Thakur 136
Byte-sized Signed Numbers RangesByte-sized Signed Numbers Ranges
DecimalDecimal BinaryBinary HexHex
-128-128 1000 00001000 0000 8080
-127-127 1000 00011000 0001 8181
-126-126 1000 00101000 0010 8282
…….. …………………… ....
-2-2 1111 11101111 1110 FEFE
-1-1 1111 11111111 1111 FFFF
00 0000 00000000 0000 0000
+1+1 0000 00010000 0001 0101
+2+2 0000 00100000 0010 0202
…… …………………… ......
+127+127 0111 11110111 1111 7F7F
04/07/15 Ritula Thakur 137
Overflow in Signed NumberOverflow in Signed Number
OperationsOperations
04/07/15 Ritula Thakur 138
When Is the OV Flag Set?When Is the OV Flag Set?
Either: there is a carry from D6 to D7 but no
carry out of D7 (CY = 0)
Or: there is a carry from D7 out (CY = 1) but no
carry from D6 to D7
04/07/15 Ritula Thakur 139
ExampleExample
04/07/15 Ritula Thakur 140
ExampleExample
04/07/15 Ritula Thakur 141
ExampleExample
04/07/15 Ritula Thakur 142
Chapter 7Chapter 7
LOGIC INSTRUCTIONS ANDLOGIC INSTRUCTIONS AND
PROGRAMSPROGRAMS
OutlinesOutlines
Define the truth tables for logic functions AND, OR,
XOR
Code 8051 Assembly language logic function
instructions
Use 8051 logic instructions for bit manipulation
Use compare and jump instructions for program
control
Code 8051 rotate and swap instructions
Code 8051 programs for ASCII and BCD data
conversion
04/07/15 Ritula Thakur 144
ANDAND
XX YY X AND YX AND Y
00 00 00
00 11 00
11 00 00
11 11 11
ANL destination, source ;dest = dest AND
source
04/07/15 Ritula Thakur 145
OROR
ORL destination, source ;dest = dest ORORL destination, source ;dest = dest OR
sourcesourceXX YY X AND YX AND Y
00 00 00
00 11 11
11 00 11
11 11 11
04/07/15 Ritula Thakur 146
XORXOR
XRL destination, source ;dest = dest XORXRL destination, source ;dest = dest XOR
sourcesourceXX YY X AND YX AND Y
00 00 00
00 11 11
11 00 11
11 11 00
XRL A,#04H ;EX-OR A with 0000 010004/07/15 Ritula Thakur 147
XORXOR
04/07/15 Ritula Thakur 148
XORXOR
04/07/15 Ritula Thakur 149
CPL (complement accumulator)CPL (complement accumulator)
MOVMOV A,#55HA,#55H
CPLCPL AA ;now A=AAH;now A=AAH
;0101 0101(55H) becomes;0101 0101(55H) becomes
;1010 1010 (AAH);1010 1010 (AAH)
04/07/15 Ritula Thakur 150
Compare instructionCompare instruction
CJNE destination, source ,relative addressCJNE destination, source ,relative address
04/07/15 Ritula Thakur 151
Table 7-1:Carry Flag Setting For CJNE InstructionTable 7-1:Carry Flag Setting For CJNE Instruction
CompareCompare Carry FlagCarry Flag
destination > sourcedestination > source CY = 0CY = 0
destination < sourcedestination < source CY = 1CY = 1
CJNE R5,#80,NOT_EQUAL ;check R5 for 80
…. ;R5=80
NOT_EQUAL: JNC NEXT ;jump if R5>80
…. ;R5<80
NEXT: ….
04/07/15 Ritula Thakur 152
04/07/15 Ritula Thakur 153
04/07/15 Ritula Thakur 154
04/07/15 Ritula Thakur 155
04/07/15 Ritula Thakur 156
Rotating the bits of A right and leftRotating the bits of A right and left
RRRR AA ;rotate right A;rotate right A
MOV A,#36H ;A=0011 0110
RR A ;A=0001 1011
RR A ;A=1000 1101
RR A ;A=1100 0110
RR A ;A=0110 0011
RL A ;rotate left A
04/07/15 Ritula Thakur 157
MOV A,#72H ;A=0111 0010
RL A ;A=1110 0100
RL A ;A=1100 1001
04/07/15 Ritula Thakur 158
Rotating through the carryRotating through the carry
RRCRRC AA ;rotate right through carry;rotate right through carry
CLR C ;make CY=0
MOV A,#26H ;A=0010 0110
RRC A ;A=0001 0011 CY=0
RRC A ;A=0000 1001 CY=1
RRC A ;A=1000 0100 CY=1
RLC A ;rotate left through carry
04/07/15 Ritula Thakur 159
SETB C ;make CY=1
MOV A,#15H ;A=0001 0101
RLC A ;A=0010 1010 CY=0
RLC A ;A=0101 0110 CY=0
RLC A ;A=1010 1100 CY=0
RLC A ;A=0101 1000 CY=1
04/07/15 Ritula Thakur 160
SWAPSWAP AA
04/07/15 Ritula Thakur 161
04/07/15 Ritula Thakur 162
RRC A ;first bit to carry
MOV P1.3,C ;output carry as data bit
RRC A ;second bit to carry
MOV P1.3,C ;output carry as data bit
RRC A ;third bit to carry
MOV P1.3,C ;output carry as data bit
…..
04/07/15 Ritula Thakur 163
BCD AND ASCII APPLICATIONBCD AND ASCII APPLICATION
PROGRAMPROGRAM
04/07/15 Ritula Thakur 164
Packed BCD to ASCII conversionPacked BCD to ASCII conversion
Packed BCDPacked BCD Unpacked BCDUnpacked BCD ASCIIASCII
29H29H 02H & 09H02H & 09H 32H & 39H32H & 39H
0010 10010010 1001 0000 0010 &0000 0010 & 0011 0010 &0011 0010 &
0000 10010000 1001 0011 10010011 1001
04/07/15 Ritula Thakur 165
ASCII to packed BCD conversionASCII to packed BCD conversion
Key ASCII Unpacked BCDKey ASCII Unpacked BCD Packed BCDPacked BCD
44 34 0000010034 00000100
77 37 00000111 01000111 or 47H37 00000111 01000111 or 47H
MOV A,#’4’ ;A=34H, hex for ASCII char 4
MOV R1,#’7’ ;R1=37H, hex for ASCII char 7
ANL A,#0FH ;mask upper nibble (A=04)
ANL R1,#0FH ;mask upper nibble (R1=07)
SWAP A ;A=40H
ORL A,R1 ;A=47H, packed BCD
04/07/15 Ritula Thakur 166
04/07/15 Ritula Thakur 167
Chapter 8Chapter 8
SINGLE-BIT INSTRUCTIONSSINGLE-BIT INSTRUCTIONS
AND PROGRAMMINGAND PROGRAMMING
OutlinesOutlines
List the 8051 Assembly language instructions for bit
manipulation
Code 8051 instructions for bit manipulation of ports
Explain which 8051 registers are bit-addressable
Describe which portions of the 8051 RAM are bit-
addressable
Discuss bit manipulation of the carry flag
Describe the carry flag bit-related instructions of the
8051
04/07/15 Ritula Thakur 169
Single-bit instructionsSingle-bit instructions
04/07/15 Ritula Thakur 170
I/O ports and bit-addressabilityI/O ports and bit-addressability
The 8051 has four I/O ports, each of which is 8 bits
04/07/15 Ritula Thakur 171
04/07/15 Ritula Thakur 172
04/07/15 Ritula Thakur 173
04/07/15 Ritula Thakur 174
04/07/15 Ritula Thakur 175
Checking an input bitChecking an input bit
JNB (jump if no bit) ; JB (jump if bit = 1)
04/07/15 Ritula Thakur 176
Registers and bit-addressabilityRegisters and bit-addressability
04/07/15 Ritula Thakur 177
04/07/15 Ritula Thakur 178
Figure 8-2. Bits of the PSW Register
04/07/15 Ritula Thakur 179
04/07/15 Ritula Thakur 180
Bit-addressable RAMBit-addressable RAM
04/07/15 Ritula Thakur 181
04/07/15 Ritula Thakur 182
04/07/15 Ritula Thakur 183
Single-bit operations with CYSingle-bit operations with CY
04/07/15 Ritula Thakur 184
04/07/15 Ritula Thakur 185
04/07/15 Ritula Thakur 186
04/07/15 Ritula Thakur 187
Instructions for reading input portInstructions for reading input port
READING INPUT PINS VS. PORT LATCHREADING INPUT PINS VS. PORT LATCH
In Reading a port:
1.Read the status of the input pin
2.Read the internal latch of the output port
04/07/15 Ritula Thakur 188
Reading latch for output portReading latch for output port
04/07/15 Ritula Thakur 189
8051 Timers8051 Timers
Basic Registers of the timer
Timer 0 registers
Timer 1 registers
Both the registers are 16 bits wide but can be
accessed as 8 bit registers separately.
04/07/15 Ritula Thakur 190
PROGRAMMING 8051 TIMERSPROGRAMMING 8051 TIMERS
Timer 0 registersTimer 0 registers
TL0 ( timer 0 low byte )
TH0 ( timer 0 high byte )
04/07/15 Ritula Thakur 191
Timer 1 registersTimer 1 registers
TL1 ( timer 1 low byte )
TH1 ( timer 1 high byte )
04/07/15 Ritula Thakur 192
04/07/15 Ritula Thakur
Timer Interrupt & OptimizeTimer Interrupt & Optimize
TMOD Register - Operation ControlTMOD Register - Operation Control
TIMER1 TIMER2
M1 M1M0GATE C/T GATE C/T M0
(MSB) (LSB)
GATE Gating Control
When Set Timer/Counter “x”is enabled
Only while “INTx”pin is high and “TRx” control pin is set
When Cleared Timer “x” is enabled
Whenever “TRx” control bit is set
C/T Timer or Counter Selector
Cleared for Timer operation (input from internal system clock).
Set for Counter operation (input from “Tx” input pin)
193
04/07/15 Ritula Thakur
Chap3. Timer Interrupt & OptimizeChap3. Timer Interrupt & Optimize
TMOD Register - Operating Mode Control (0 , 1, 2 )TMOD Register - Operating Mode Control (0 , 1, 2 )
TIMER1 TIMER2
GATE C/T GATE C/TM1 M1M0 M0
(MSB) (LSB)
8048 TIMER : ”TLx” serves as 5-bit prescaler.
16-bit Timer/Counter : “THx” and “TLx” are
cascaded
8-bit auto reload
“THx” hold a value which is to be
Reloaded into “TLx” each time it overflows
M1 M0 Function
0 0
0 1
1 0
194
Indicate which mode and which timer are
selected for each of the following:
MOV TMOD,#01H
MOV TMOD,#20H
TMOD=00000001, mode 1 of Timer 0
TMOD=00100000, mode 2 of Timer 1
04/07/15 Ritula Thakur 195
04/07/15 Ritula Thakur 196
Clock Source for timerClock Source for timer
The crystal frequency attached to the 8051
timer is the source of the clock for the timer.
The frequency for the timer is always 1/12th
the
frequency of the crystal attached to the 8051
04/07/15 Ritula Thakur 197
Mode 1 programmingMode 1 programming
1. It is a 16-bit timer; so it allows values of 0000 to FFFFH
to be loaded into the timer’s registers TL and TH
After TH and TL are loaded with a 16 bit initial value, the
timer must be started (SETB TR0 and SETB TR1)
It starts counting up until it reaches its limit of FFFFH.
When it rolls over from FFFFH to 0000, it sets high TF
(Timer flag)
Stop the timer (CLR TR0 & CLR TR1)
After the timer reaches its limit and rolls over, in order to
repeat the process TH and TL must be reloaded with the
original value, and TF must be reset to 0
04/07/15 Ritula Thakur 198
Mode 1 programmingMode 1 programming
1.Loaded value into TL and TH
2.”SETB TR0” for timer 0 ;”SETB TR1” for timer 1
3.If TF (timer flag) = high “CLR TR0” or “CLR TR1”
4.Reloaded TH and TL value, TF reset to 0
04/07/15 Ritula Thakur 199
Steps to program in mode 1Steps to program in mode 1
1.Load the TMOD value
2.Load registers TL and TH
3.Start the timer (SETB TR0 or SETB TR1)
4.Keep monitoring the timer flag (TF)
5.Stop the timer (CLR TR0 or CLR TR1)
6.Clear the TF flag
7.Go back to step 2
04/07/15 Ritula Thakur 200
Calculate Timer DelayCalculate Timer Delay
04/07/15 Ritula Thakur 201
04/07/15 Ritula Thakur 202
04/07/15 Ritula Thakur 203
04/07/15 Ritula Thakur 204
Finding values to be loaded into the timerFinding values to be loaded into the timer
Assuming XTAL =11.0592MHz from Example 9-10
1.Divide the desired time delay by 1.085μs
2.Perform 65536-n, where n is the decimal value we got in
Step 1
3.Convert the result of Step 2 to hex, where yyxx is the
initial hex value to be loaded into the timer’s registers
4.Set TL = xx and TH = yy
04/07/15 Ritula Thakur 205
04/07/15 Ritula Thakur 206
04/07/15 Ritula Thakur
Chap3. Timer Interrupt & OptimizeChap3. Timer Interrupt & Optimize
osc 12÷
1/ =TC CONTROL
TL1
(8BITS)
TH1
(8BITS)
TF1 INTERRUPT
GATE
PININT1
TR1
T1 PIN
0/ =TC
Timer/Counter 1 Mode 1:16-bit Counter
Timer Mode - Mode 1
207
Mode 0Mode 0
Like mode 1 except that it is a 13-bit timer
Mode 2 ProgrammingMode 2 Programming
1.Loaded value into TH (8-bit timer)
2.”SETB TR0” for timer 0 ;”SETB TR1” for timer 1
3.If TF (timer flag) = high “CLR TR0” or “CLR TR1”
4.Reloaded TL value kept by TH
04/07/15 Ritula Thakur 208
Steps to program in mode 2Steps to program in mode 2
1.Load the TMOD value
2.Load the TH registers
3.Start the timer
4.Keep monitoring the timer flag (TF)
5.Clear the TF flag
7.Go back to step 4
04/07/15 Ritula Thakur 209
04/07/15 Ritula Thakur 210
04/07/15 Ritula Thakur 211
8051 SERIAL COMMUNICATION8051 SERIAL COMMUNICATION
OutlinesOutlines
Contrast and compare serial versus parallel
communication
List the advantages of serial communication
over parallel
Explain serial communication protocol
Contrast synchronous versus asynchronous
communication
Contrast half-versus full-duplex transmission
04/07/15 Ritula Thakur 213
♦ Explain the process of data framingExplain the process of data framing
♦ Describe data transfer rate and bps rateDescribe data transfer rate and bps rate
♦ Define the RS232 standardDefine the RS232 standard
♦ Explain the use of the MAX232 andExplain the use of the MAX232 and
MAX233 chipsMAX233 chips
♦ Interface the 8051 with an RS232Interface the 8051 with an RS232
connectorconnector
♦ Discuss the baud rate of the 8051Discuss the baud rate of the 8051
♦ Describe serial communication features ofDescribe serial communication features of
the 8051the 8051
♦ Program the 8051 for serial dataProgram the 8051 for serial data
04/07/15 Ritula Thakur 214
Basics of serial communicationBasics of serial communication
04/07/15 Ritula Thakur 215
04/07/15 Ritula Thakur 216
Start and stop bitsStart and stop bits
04/07/15 Ritula Thakur 217
RS232 pinsRS232 pins
04/07/15 Ritula Thakur 218
Data communication classificationData communication classification
04/07/15 Ritula Thakur 219
RxD and TxD pins in the 8051RxD and TxD pins in the 8051
TxD pin 11 of the 8051 (P3.1)
RxD pin 10 of the 8051 (P3.0)
04/07/15 Ritula Thakur 220
MAX232MAX232
04/07/15 Ritula Thakur 221
MAX233MAX233
04/07/15 Ritula Thakur 222
8051 SERIAL COMMUNICATION8051 SERIAL COMMUNICATION
PROGRAMMINGPROGRAMMING
04/07/15 Ritula Thakur 223
Baud Rate in 8051Baud Rate in 8051
The baud rate in 8051 is programmable (done
with the help of timer 1)
Relation b/w crystal frequency and baud rate
8051 divides crystal frequency by 12 to get m/c
cycle frequency
8051’s serial commn UART crctry divides it by
32 once more
11.0592/12=921.6 kHz
921.6 kHz/32=28,800 Hz
04/07/15 Ritula Thakur 224
04/07/15 Ritula Thakur 225
04/07/15 Ritula Thakur 226
SBUF registerSBUF register
MOV SBUF,#’D’ ;load SBUF=44H, ASCII for ‘D’
MOV SBUF,A ;copy accumulator into SBUF
MOV A,SBUF ;copy SBUF into accumulator
04/07/15 Ritula Thakur 227
SCON (Serial control) registerSCON (Serial control) register
04/07/15 Ritula Thakur 228
SM0,SM1SM0,SM1
SM0 and SM1 are D7 and D6 of the SCON
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 3
04/07/15 Ritula Thakur 229
Programming the 8051 to transfer dataProgramming the 8051 to transfer data
seriallyserially
TMOD register is loaded with 20H to set the baud rate)
TH1 is loaded to set the baud rate for serial data transfer
SCON is loaded with 50H
TR1 is set to start the Timer 1
Character byte to be transferred is written into SBUF
register
TI flag is monitored to see if the character has been
transferred completely
TI is cleared by CLR TI
To transfer the next character, go to Step 6
04/07/15 Ritula Thakur 230
Programming the 8051 to transferProgramming the 8051 to transfer
data seriallydata serially
04/07/15 Ritula Thakur 231
04/07/15 Ritula Thakur 232
Programming the 8051 to receive dataProgramming the 8051 to receive data
seriallyserially
TMOD register is loaded with 20H to set the baud rate)
TH1 is loaded to set the baud rate for serial data transfer
SCON is loaded with 50H
TR1 is set to start the Timer 1
Character byte to be transferred is written into SBUF
register
RI flag is monitored to see if the character has been
transferred completely
RI is cleared by CLR TI
To receive the next character, go to Step 6
04/07/15 Ritula Thakur 233
Programming the 8051 to receiveProgramming the 8051 to receive
data seriallydata serially
04/07/15 Ritula Thakur 234
04/07/15 Ritula Thakur 235
04/07/15 Ritula Thakur 236
04/07/15 Ritula Thakur 237
Doubling the baud rate in theDoubling the baud rate in the
80518051
1. To use a higher frequency crystal
2. To change a bit in the PCON register
SMODSMOD ---- ---- ---- GF1GF1 GF0GF0 PDPD IDLIDL
D7 D0
MOV A,PCON ;place a copy of PCON in ACC
SETB ACC.7 ;make D7=1
MOV PCON,A ;now SMOD=1 without
;changing any other bits
04/07/15 Ritula Thakur 238
Baud rates for SMOD=0Baud rates for SMOD=0
Machine cycle freq. = 11.0592 MHz / 12 = 921.6 kHz
and
921.6 kHz / 32 = 28,800 Hz since SMOD = 0
04/07/15 Ritula Thakur 239
Baud rates for SMOD=1Baud rates for SMOD=1
Machine cycle freq. = 11.0592 MHz / 12 = 921.6 kHz
and
921.6 kHz / 16 = 57,600 Hz since SMOD = 1
04/07/15 Ritula Thakur 240
04/07/15 Ritula Thakur 241
04/07/15 Ritula Thakur 242
04/07/15 Ritula Thakur 243
Chapter 11Chapter 11
INTERRUPTS PROGRAMMINGINTERRUPTS PROGRAMMING
OutlinesOutlines
Contrast and compare interrupts versus polling
Explain the purpose of the ISR
List the 6 interrupts of the 8051
Explain the purpose of the interrupt vector
table
Enable or disable 8051 interrupts
Program the 8051 timers using interrupts
Describe the two external hardware interrupts
of the 8051
04/07/15 Ritula Thakur 245
♦ Contrast edge-triggered with level-triggeredContrast edge-triggered with level-triggered
interruptsinterrupts
♦ Program the 8051 for interrupt-based serialProgram the 8051 for interrupt-based serial
communicationcommunication
♦ Define the interrupt priority of the 8051Define the interrupt priority of the 8051
04/07/15 Ritula Thakur 246
Six interrupts in the 8051Six interrupts in the 8051
04/07/15 Ritula Thakur 247
Step in enabling an interruptStep in enabling an interrupt
04/07/15 Ritula Thakur 248
04/07/15 Ritula Thakur 249
PROGRAMMING TIMERPROGRAMMING TIMER
INTERRUPTSINTERRUPTS
04/07/15 Ritula Thakur 250
Roll-over timer flag andRoll-over timer flag and
interruptinterrupt
JNB TF, target
04/07/15 Ritula Thakur 251
04/07/15 Ritula Thakur 252
04/07/15 Ritula Thakur 253
04/07/15 Ritula Thakur 254
04/07/15 Ritula Thakur 255
Programming externalProgramming external
hardware interruptshardware interrupts
04/07/15 Ritula Thakur 256
04/07/15 Ritula Thakur 257
04/07/15 Ritula Thakur 258
Sampling the low level-Sampling the low level-
triggered interrupttriggered interrupt
04/07/15 Ritula Thakur 259
Edge-triggered interruptsEdge-triggered interrupts
04/07/15 Ritula Thakur 260
04/07/15 Ritula Thakur 261
04/07/15 Ritula Thakur 262
Sampling the edge-triggeredSampling the edge-triggered
interruptinterrupt
04/07/15 Ritula Thakur 263
RI and TI flags and interruptsRI and TI flags and interrupts
04/07/15 Ritula Thakur 264
Use of serial COM in the 8051Use of serial COM in the 8051
04/07/15 Ritula Thakur 265
04/07/15 Ritula Thakur 266
04/07/15 Ritula Thakur 267
Clearing RI and TI before theClearing RI and TI before the
RETI instructionRETI instruction
CLR TI ; CLR RI
04/07/15 Ritula Thakur 268
04/07/15 Ritula Thakur 269
04/07/15 Ritula Thakur 270
Interrupt priority upon resetInterrupt priority upon reset
04/07/15 Ritula Thakur 271
04/07/15 Ritula Thakur 272
04/07/15 Ritula Thakur 273
Setting interrupt priority with the IPSetting interrupt priority with the IP
registerregister
04/07/15 Ritula Thakur 274
04/07/15 Ritula Thakur 275

More Related Content

What's hot

Design Procedure for an Integrator
Design Procedure for an IntegratorDesign Procedure for an Integrator
D and T Flip Flop
D and T Flip FlopD and T Flip Flop
D and T Flip Flop
Dhrumil Panchal
 
T-states in microprocessor 8085
T-states in microprocessor 8085T-states in microprocessor 8085
T-states in microprocessor 8085yedles
 
8155 PPI
8155 PPI8155 PPI
8155 PPI
ShivamSood22
 
Behavioral modelling in VHDL
Behavioral modelling in VHDLBehavioral modelling in VHDL
Behavioral modelling in VHDL
Bhupendra Pratap Singh
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONS
Dr.YNM
 
Flipflop
FlipflopFlipflop
Flipflop
sohamdodia27
 
RF Circuit Design - [Ch4-2] LNA, PA, and Broadband Amplifier
RF Circuit Design - [Ch4-2] LNA, PA, and Broadband AmplifierRF Circuit Design - [Ch4-2] LNA, PA, and Broadband Amplifier
RF Circuit Design - [Ch4-2] LNA, PA, and Broadband Amplifier
Simen Li
 
JK flip flops
JK flip flopsJK flip flops
JK flip flops
Zakariae EL IDRISSI
 
Mini Project on 4 BIT SERIAL MULTIPLIER
Mini Project on 4 BIT SERIAL MULTIPLIERMini Project on 4 BIT SERIAL MULTIPLIER
Mini Project on 4 BIT SERIAL MULTIPLIER
j naga sai
 
8255 PPI (programmable Peripheral Interface) mode 0
8255 PPI (programmable Peripheral Interface) mode 08255 PPI (programmable Peripheral Interface) mode 0
8255 PPI (programmable Peripheral Interface) mode 0
ABHIMANYUJHA8
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
Archita Misra
 
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptxBUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
Ashish Sadavarti
 
verilog code for logic gates
verilog code for logic gatesverilog code for logic gates
verilog code for logic gates
Rakesh kumar jha
 
Analog Electronic Circuit Design (AECD) text book
Analog Electronic Circuit Design (AECD) text bookAnalog Electronic Circuit Design (AECD) text book
Analog Electronic Circuit Design (AECD) text book
ramanikumar
 
VLSI subsystem design processes and illustration
VLSI subsystem design processes and illustrationVLSI subsystem design processes and illustration
VLSI subsystem design processes and illustration
Vishal kakade
 
VHDL Part 4
VHDL Part 4VHDL Part 4
VHDL Part 4
Abhilash Nair
 

What's hot (20)

Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
 
Interfacing 8255
Interfacing 8255Interfacing 8255
Interfacing 8255
 
Design Procedure for an Integrator
Design Procedure for an IntegratorDesign Procedure for an Integrator
Design Procedure for an Integrator
 
D and T Flip Flop
D and T Flip FlopD and T Flip Flop
D and T Flip Flop
 
T-states in microprocessor 8085
T-states in microprocessor 8085T-states in microprocessor 8085
T-states in microprocessor 8085
 
8155 PPI
8155 PPI8155 PPI
8155 PPI
 
Behavioral modelling in VHDL
Behavioral modelling in VHDLBehavioral modelling in VHDL
Behavioral modelling in VHDL
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONS
 
Flipflop
FlipflopFlipflop
Flipflop
 
RF Circuit Design - [Ch4-2] LNA, PA, and Broadband Amplifier
RF Circuit Design - [Ch4-2] LNA, PA, and Broadband AmplifierRF Circuit Design - [Ch4-2] LNA, PA, and Broadband Amplifier
RF Circuit Design - [Ch4-2] LNA, PA, and Broadband Amplifier
 
JK flip flops
JK flip flopsJK flip flops
JK flip flops
 
Mini Project on 4 BIT SERIAL MULTIPLIER
Mini Project on 4 BIT SERIAL MULTIPLIERMini Project on 4 BIT SERIAL MULTIPLIER
Mini Project on 4 BIT SERIAL MULTIPLIER
 
8255 PPI (programmable Peripheral Interface) mode 0
8255 PPI (programmable Peripheral Interface) mode 08255 PPI (programmable Peripheral Interface) mode 0
8255 PPI (programmable Peripheral Interface) mode 0
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
 
Vlsi stick daigram (JCE)
Vlsi stick daigram (JCE)Vlsi stick daigram (JCE)
Vlsi stick daigram (JCE)
 
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptxBUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
 
verilog code for logic gates
verilog code for logic gatesverilog code for logic gates
verilog code for logic gates
 
Analog Electronic Circuit Design (AECD) text book
Analog Electronic Circuit Design (AECD) text bookAnalog Electronic Circuit Design (AECD) text book
Analog Electronic Circuit Design (AECD) text book
 
VLSI subsystem design processes and illustration
VLSI subsystem design processes and illustrationVLSI subsystem design processes and illustration
VLSI subsystem design processes and illustration
 
VHDL Part 4
VHDL Part 4VHDL Part 4
VHDL Part 4
 

Similar to 8051 Microcontroller

Emb day2 8051
Emb day2 8051Emb day2 8051
Emb day2 8051
shivamarya55
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontroller
Nitin Ahire
 
8051 microcontrolle rclass1
8051 microcontrolle rclass18051 microcontrolle rclass1
8051 microcontrolle rclass1
Nitin Ahire
 
8051 (microcontroller)class1
8051 (microcontroller)class18051 (microcontroller)class1
8051 (microcontroller)class1
Nitin Ahire
 
Embedded System
Embedded SystemEmbedded System
Embedded System
Richa Arora
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
Patruni Chidananda Sastry
 
8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
jhcid
 
Microcontroller 8051 basics (part I)
Microcontroller 8051 basics (part I)Microcontroller 8051 basics (part I)
Microcontroller 8051 basics (part I)
Nilesh Bhaskarrao Bahadure
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
Gaurav Verma
 
Unit -2 and 3 mekirirygiygyuguiguihiiqio
Unit -2 and 3 mekirirygiygyuguiguihiiqioUnit -2 and 3 mekirirygiygyuguiguihiiqio
Unit -2 and 3 mekirirygiygyuguiguihiiqio
Manikanta Reddy Sakam
 
MCUnit 4and 5_New.pptx
MCUnit 4and 5_New.pptxMCUnit 4and 5_New.pptx
MCUnit 4and 5_New.pptx
nandalalparthiban
 
B sc e5.2 mp unit 4 mc-8051
B sc e5.2 mp unit 4 mc-8051B sc e5.2 mp unit 4 mc-8051
B sc e5.2 mp unit 4 mc-8051
MahiboobAliMulla
 
Live B tech Projects & Industrial Training @Technogroovy
Live B tech Projects & Industrial Training @Technogroovy Live B tech Projects & Industrial Training @Technogroovy
Live B tech Projects & Industrial Training @Technogroovy
Technogroovy India
 
Microprocessor 8085 Basics
Microprocessor 8085 BasicsMicroprocessor 8085 Basics
Microprocessor 8085 Basics
Nilesh Bhaskarrao Bahadure
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
KalaiSelvan911913
 
module-2.pptx
module-2.pptxmodule-2.pptx
module-2.pptx
Ambika Naik
 
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp011347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01bvenkanna
 
Presentation On: "Micro-controller 8051 & Embedded System"
Presentation On: "Micro-controller 8051 & Embedded System"Presentation On: "Micro-controller 8051 & Embedded System"
Presentation On: "Micro-controller 8051 & Embedded System"
surabhii007
 

Similar to 8051 Microcontroller (20)

Emb day2 8051
Emb day2 8051Emb day2 8051
Emb day2 8051
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontroller
 
8051 microcontrolle rclass1
8051 microcontrolle rclass18051 microcontrolle rclass1
8051 microcontrolle rclass1
 
8051 (microcontroller)class1
8051 (microcontroller)class18051 (microcontroller)class1
8051 (microcontroller)class1
 
Microprocessor systems 8085(2)
Microprocessor systems 8085(2)Microprocessor systems 8085(2)
Microprocessor systems 8085(2)
 
Embedded System
Embedded SystemEmbedded System
Embedded System
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
 
Microcontroller 8051 basics (part I)
Microcontroller 8051 basics (part I)Microcontroller 8051 basics (part I)
Microcontroller 8051 basics (part I)
 
8051
80518051
8051
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
 
Unit -2 and 3 mekirirygiygyuguiguihiiqio
Unit -2 and 3 mekirirygiygyuguiguihiiqioUnit -2 and 3 mekirirygiygyuguiguihiiqio
Unit -2 and 3 mekirirygiygyuguiguihiiqio
 
MCUnit 4and 5_New.pptx
MCUnit 4and 5_New.pptxMCUnit 4and 5_New.pptx
MCUnit 4and 5_New.pptx
 
B sc e5.2 mp unit 4 mc-8051
B sc e5.2 mp unit 4 mc-8051B sc e5.2 mp unit 4 mc-8051
B sc e5.2 mp unit 4 mc-8051
 
Live B tech Projects & Industrial Training @Technogroovy
Live B tech Projects & Industrial Training @Technogroovy Live B tech Projects & Industrial Training @Technogroovy
Live B tech Projects & Industrial Training @Technogroovy
 
Microprocessor 8085 Basics
Microprocessor 8085 BasicsMicroprocessor 8085 Basics
Microprocessor 8085 Basics
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
 
module-2.pptx
module-2.pptxmodule-2.pptx
module-2.pptx
 
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp011347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
 
Presentation On: "Micro-controller 8051 & Embedded System"
Presentation On: "Micro-controller 8051 & Embedded System"Presentation On: "Micro-controller 8051 & Embedded System"
Presentation On: "Micro-controller 8051 & Embedded System"
 

Recently uploaded

在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
AkolbilaEmmanuel1
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 

Recently uploaded (20)

在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 

8051 Microcontroller

  • 2. Chapter 1Chapter 1 The 8051 MicrocontrollersThe 8051 Microcontrollers
  • 3. OutlinesOutlines Compare microprocessors & microcontrollers Advantages of microcontrollers Embedded systems Choose a microcontroller Speed, packaging, memory & cost per unit Various members of 8051 family Various manufacturers of 8051 04/07/15 Ritula Thakur 3
  • 5. Embedded Computing SystemsEmbedded Computing Systems Use a microprocessor or microcontroller to do one task only Printer PC used for any number of applications Word processor, print-server, bank teller terminal, video game player, network server, internet terminal PC contains or is connected to various embedded products Keyboard, printer, modem, disk controller, sound card, CD-ROM driver, mouse X86 PC embedded applications04/07/15 Ritula Thakur 5
  • 6. Embedded Products Using MicrocontrollersEmbedded Products Using Microcontrollers Home Appliances, intercom, telephones, security systems, garage door openers, answering machines, fax machines, home computers, TVs, cable TV tuner, VCR, camcorder, remote controls, video games, cellular phones, musical instruments, sewing machines, lighting control, paging, camera, pinball machines, toys, exercise equipment 04/07/15 Ritula Thakur 6
  • 7. Embedded Products Using MicrocontrollersEmbedded Products Using Microcontrollers Office Telephones, computers, security systems, fax machines, microwave, copier, laser printer, color printer, paging 04/07/15 Ritula Thakur 7
  • 8. Embedded Products Using MicrocontrollersEmbedded Products Using Microcontrollers Auto Trip computer, engine control, air bag, ABS, instrumentation, security system, transmission control, entertainment, climate control, cellular phone, keyless entry 04/07/15 Ritula Thakur 8
  • 9. Choosing A MicrocontrollerChoosing A Microcontroller Computing needs Speed, packaging, power consumption, RAM, ROM, I/O pins, timers, upgrade to high performance or low-power versions, cost Software development tools Assembler, debugger, C compiler, emulator, technical support Availability & source 04/07/15 Ritula Thakur 9
  • 10. Companies Producing 8051Companies Producing 8051 Table 1-2:Some Companies Producing a Member of the 8051 Family CompanyCompany Web SiteWeb Site IntelIntel www.intel.com/design/mcs51www.intel.com/design/mcs51 AtmelAtmel www.atmel.comwww.atmel.com Philips/SigneticsPhilips/Signetics www.semiconductors.philips.comwww.semiconductors.philips.com SiemensSiemens www.sci.siemens.comwww.sci.siemens.com Dallas SemiconductorDallas Semiconductor www.dalsemi.comwww.dalsemi.com 04/07/15 Ritula Thakur 10
  • 11. Inside 8051 MicrocontrollerInside 8051 Microcontroller Introduced by Intel in 1981 04/07/15 Ritula Thakur 11
  • 12. 8051 Family8051 Family Table 1-4:Comparison of 8051 Family Members FeatureFeature 80518051 80528052 80318031 ROM (on chip program space in bytes)ROM (on chip program space in bytes) 4K4K 8k8k 0k0k RAM (bytes)RAM (bytes) 128128 256256 128128 TimersTimers 22 33 22 I/O pinsI/O pins 3232 3232 3232 Serial portSerial port 11 11 11 Interrupt sourcesInterrupt sources 66 88 66 04/07/15 Ritula Thakur 12
  • 13. Various 8051 MicrocontrollersVarious 8051 Microcontrollers 8751 microcontroller UV-EPROM AT89C51 from Atmel Corporation Flash (erase before write) DS5000 from Dallas Semiconductor NV-RAM (changed one byte at a time), RTC (real- time clock) OTP (one-time-programmable) version of 8051 8051 family from Philips AD, DA, extended I/O, OTP and flash04/07/15 Ritula Thakur 13
  • 14. Chapter 2Chapter 2 8051 Assembly Language Programming8051 Assembly Language Programming
  • 15. OutlinesOutlines 8051 registers Manipulate data using registers & MOVE instructions Code simple assembly language instructions Assemble and run a program Sequence events upon power-up Examine programs in ROM codes ROM memory map Execution of instructions Data types PSW register RAM memory space Stack Register banks 04/07/15 Ritula Thakur 15
  • 16. 8051 Registers8051 Registers D7D7 D6D6 D5D5 D4D4 D3D3 D2D2 D1D1 D0D0 DPTR PC PC (Program counter) DPH DPL Figure2-1 (a): Some 8 bit Registers of the 8051 Figure2-1 (b): Some 8051 16 bit Registers 8 bit Registers R6R6 R5R5 R4R4 R3R3 R2R2 R1R1 R0R0 BB AA R7R7 04/07/15 Ritula Thakur 16
  • 17. MOV InstructionMOV Instruction MOV destination, source ; copy source to dest. MOV A,#55H ;load value 55H into reg. A MOV R0,A ;copy contents of A into R0 ;(now A=R0=55H) MOV R1,A ;copy contents of A into R1 ;(now A=R0=R1=55H) MOV R2,A ;copy contents of A into R2 ;(now A=R0=R1=R2=55H) MOV R3,#95H ;load value 95H into R3 ;(now R3=95H) MOV A,R3 ;copy contents of R3 into A ;now A=R3=95H 04/07/15 Ritula Thakur 17
  • 18. Notes on ProgrammingNotes on Programming Value (proceeded with #) can be loaded directly to registers A, B, or R0 – R7 MOV R5, #0F9H If values 0 to F moved into an 8-bit register, the rest assumed all zeros MOV A, #5 A too large value causes an error MOV A, #7F2H 04/07/15 Ritula Thakur 18
  • 19. ADD InstructionADD Instruction ADD A, source ;ADD the source operand ;to the accumulator MOV A, #25H ;load 25H into A MOV R2,#34H ;load 34H into R2 ADD A,R2 ;add R2 to accumulator ;(A = A + R2) 04/07/15 Ritula Thakur 19
  • 20. Structure of Assembly LanguageStructure of Assembly Language ORG 0H ;start (origin) at location 0 MOV R5,#25H ;load 25H into R5 MOV R7,#34H ;load 34H into R7 MOV A,#0 ;load 0 into A ADD A,R5 ;add contents of R5 to A ;now A = A + R5 ADD A,R7 ;add contents of R7 to A ;now A = A + R7 ADD A,#12H ;add to A value 12H ;now A = A + 12H HERE: SJMP HERE ;stay in this loop END ;end of asm source file Program 2-1:Sample of an Assembly Language Program 04/07/15 Ritula Thakur 20
  • 21. Steps to Create a ProgramSteps to Create a Program 04/07/15 Ritula Thakur 21
  • 22. 8051 Program Counter & ROM8051 Program Counter & ROM SpaceSpace 04/07/15 Ritula Thakur 22
  • 23. 8051 Program Counter & ROM8051 Program Counter & ROM SpaceSpace 04/07/15 Ritula Thakur 23
  • 24. 8051 Program Counter & ROM8051 Program Counter & ROM SpaceSpace 04/07/15 Ritula Thakur 24
  • 25. Execute a Program Byte by ByteExecute a Program Byte by Byte 1. PC=0000: opcode 7D fetched; 25 fetched; R5←25; PC+2 2. PC=0002: opcode 7F fetched; 34 fetched; R7←34; PC+2 3. PC=0004; opcode 74 fetched; 0 fetched; A←0; PC+2 4. PC=0006; opcode 2D fetched; A←A+R5; PC+1 5. (Similarly…) 04/07/15 Ritula Thakur 25
  • 26. 8051 On-Chip ROM Address Range8051 On-Chip ROM Address Range 04/07/15 Ritula Thakur 26
  • 27. Data Types & DirectivesData Types & Directives ORG 500H DATA1: DB 28 ;DECIMAL (1C in Hex) DATA2: DB 00110101B ;BINARY (35 in Hex) DATA3: DB 39H ;HEX ORG 510H DATA4: DB “2591” ; ASCII NUMBERS ORG 518H DATA6: DB “My name is Joe” ;ASCII CHARACTERS 04/07/15 Ritula Thakur 27
  • 28. PSW (Flag) RegisterPSW (Flag) Register 04/07/15 Ritula Thakur 28
  • 29. Instructions Affecting Flag BitsInstructions Affecting Flag Bits 04/07/15 Ritula Thakur 29
  • 30. ADD Instruction and PSWADD Instruction and PSW 04/07/15 Ritula Thakur 30
  • 31. ADD Instruction and PSWADD Instruction and PSW 04/07/15 Ritula Thakur 31
  • 32. ADD Instruction and PSWADD Instruction and PSW 04/07/15 Ritula Thakur 32
  • 33. 8051 RAM Allocation8051 RAM Allocation 04/07/15 Ritula Thakur 33
  • 34. 8051 Register Banks8051 Register Banks 04/07/15 Ritula Thakur 34
  • 35. Access RAM Locations Using Register NamesAccess RAM Locations Using Register Names 04/07/15 Ritula Thakur 35
  • 36. Access RAM Locations UsingAccess RAM Locations Using AddressesAddresses 04/07/15 Ritula Thakur 36
  • 37. Switch Register BanksSwitch Register Banks 04/07/15 Ritula Thakur 37
  • 38. Switch Register BanksSwitch Register Banks 04/07/15 Ritula Thakur 38
  • 39. Pushing onto StackPushing onto Stack 04/07/15 Ritula Thakur 39
  • 40. Popping from StackPopping from Stack 04/07/15 Ritula Thakur 40
  • 41. Stack & Bank 1 ConflictStack & Bank 1 Conflict 04/07/15 Ritula Thakur 41
  • 42. Stack & Bank 1 ConflictStack & Bank 1 Conflict 04/07/15 Ritula Thakur 42
  • 43. Chapter 3Chapter 3 JUMP, LOOP and CALL InstructionsJUMP, LOOP and CALL Instructions
  • 44. OutlinesOutlines Loop instructions Conditional jump instructions Conditions determining conditional jump Unconditional long & short jumps Calculate target addresses for jumps Subroutines Using stack in subroutines Crystal frequency vs. machine cycle Code programs to generate time delay 04/07/15 Ritula Thakur 44
  • 46. Loop inside a Loop (NestedLoop inside a Loop (Nested Loop)Loop) 04/07/15 Ritula Thakur 46
  • 47. 8051 Conditional Jump8051 Conditional Jump InstructionsInstructions 04/07/15 Ritula Thakur 47
  • 48. Conditional Jump ExampleConditional Jump Example 04/07/15 Ritula Thakur 48
  • 49. Conditional Jump ExampleConditional Jump Example 04/07/15 Ritula Thakur 49
  • 50. Unconditional Jump InstructionsUnconditional Jump Instructions All conditional jumps are short jumps Target address within -128 to +127 of PC LJMP (long jump): 3-byte instruction 2-byte target address: 0000 to FFFFH Original 8051 has only 4KB on-chip ROM SJMP (short jump): 2-byte instruction 1-byte relative address: -128 to +127 04/07/15 Ritula Thakur 50
  • 51. Calculating Short Jump AddressesCalculating Short Jump Addresses 04/07/15 Ritula Thakur 51
  • 52. Calculating Short Jump AddressesCalculating Short Jump Addresses 04/07/15 Ritula Thakur 52
  • 53. Call InstructionsCall Instructions LCALL (long call): 3-byte instruction 2-byte address Target address within 64K-byte range ACALL (absolute call): 2-byte instruction 11-bit address Target address within 2K-byte range 04/07/15 Ritula Thakur 53
  • 55. CALL Instruction & Role of StackCALL Instruction & Role of Stack 04/07/15 Ritula Thakur 55
  • 56. CALL Instruction & Role of StackCALL Instruction & Role of Stack 04/07/15 Ritula Thakur 56
  • 57. Using PUSH & POP in SubroutinesUsing PUSH & POP in Subroutines 04/07/15 Ritula Thakur 57
  • 58. Using PUSH & POP in SubroutinesUsing PUSH & POP in Subroutines 04/07/15 Ritula Thakur 58
  • 59. Using PUSH & POP in SubroutinesUsing PUSH & POP in Subroutines 04/07/15 Ritula Thakur 59
  • 62. ACALL (absolute call)ACALL (absolute call) 04/07/15 Ritula Thakur 62
  • 64. Time Delay Generation &Time Delay Generation & CalculationCalculation 1 instruction = n × machine cycle 1 machine cycle = 12 clock cycles 04/07/15 Ritula Thakur 64
  • 66. Delay Calculation ExampleDelay Calculation Example 04/07/15 Ritula Thakur 66
  • 67. Delay Calculation ExampleDelay Calculation Example 04/07/15 Ritula Thakur 67
  • 68. Increasing Delay Using NOPIncreasing Delay Using NOP 04/07/15 Ritula Thakur 68
  • 69. Large Delay Using Nested LoopLarge Delay Using Nested Loop 04/07/15 Ritula Thakur 69
  • 70. Chapter 4Chapter 4 I/O Port ProgrammingI/O Port Programming
  • 71. OutlinesOutlines 8051 pin functions 4 ports of 8051 Dual role of port 0 for data & address Code assembly language to use ports Use of port 3 for interrupt signals Code 8051 instructions for I/O handling Code bit-manipulation instructions 04/07/15 Ritula Thakur 71
  • 72. 8051 Pin Diagram8051 Pin Diagram 04/07/15 Ritula Thakur 72
  • 75. Machine & Clock CyclesMachine & Clock Cycles 04/07/15 Ritula Thakur 75
  • 76. RESET Value of RegistersRESET Value of Registers 04/07/15 Ritula Thakur 76
  • 79. Pins for External ROM/RAMPins for External ROM/RAM EA (external access) VCC: on-chip ROM GND: external ROM PSEN (program store enable) to OE (output enable) pin of ROM ALE (address latch enable) to G (enable) pin of 74LS373 See Chapter 14 04/07/15 Ritula Thakur 79
  • 80. Port 0: I/O, Open DrainPort 0: I/O, Open Drain Initially configured as output MOVMOV A,#55HA,#55H BACK:BACK: MOVMOV P0,AP0,A ACALLACALL DELAYDELAY CPLCPL AA SJMPSJMP BACKBACK 04/07/15 Ritula Thakur 80
  • 81. Port 0: I/O, Open DrainPort 0: I/O, Open Drain 04/07/15 Ritula Thakur 81
  • 82. Port 0 as Input: Write all 1sPort 0 as Input: Write all 1s Dual role of port 0 Can be configured as AD0 – AD7 MOV A,#0FFH ;A = FF hex MOV P0,A ;make P0 an input port ;by writing all 1s to it BACK: MOV A,P0 ;get data from P0 MOV P1,A ;send it to port 1 SJMP BACK ;keep doing it 04/07/15 Ritula Thakur 82
  • 83. Port 1: I/O, No Pull-up ResistorsPort 1: I/O, No Pull-up Resistors Initially configured as output MOV A,#55H BACK: MOV P1,A ACALL DELAY CPL A SJMP BACK MOV A,#0FFH ;A=FF hex MOV P1,A ;make P1 an input port ;by writing all 1s to it MOV A,P1 ;get data from P1 MOV R7,A ;save it in reg R7 ACALL DELAY ;wait MOV A,P1 ;get another data from P1 MOV R6,A ;save it in reg R6 ACALL DELAY ;wait MOV A,P1 ;get another data from P1 MOV R5,A ;save it in reg R5 04/07/15 Ritula Thakur 83
  • 84. Port 2: I/O, No Pull-up ResistorsPort 2: I/O, No Pull-up Resistors Initially configured as output MOV A,#55H BACK: MOV P2,A ACALL DELAY CPL A SJMP BACK MOV A,#0FFH ;A=FF hex MOV P2,A ;make P2 an input port by ;writing all 1s to it BACK: MOV A,P2 ;get data from P2 MOV P1,A ;send it to Port 1 SJMP BACK ;keep doing that ♦ Dual role of port 2: A8-A15Dual role of port 2: A8-A15 04/07/15 Ritula Thakur 84
  • 85. Port 3: I/O, No Pull-up ResistorsPort 3: I/O, No Pull-up Resistors 04/07/15 Ritula Thakur 85
  • 86. Different Ways of Accessing 8 bitsDifferent Ways of Accessing 8 bits BACK: MOV A,#55H MOV P1,A ACALL DELAY MOV A,#0AAH MOV P1,A ACALL DELAY SJMP BACK BACK:BACK: MOVMOV P1,#55HP1,#55H ACALLACALL DELAYDELAY MOVMOV P1,#0AAHP1,#0AAH ACALLACALL DELAYDELAY SJMPSJMP BACKBACK MOV P1,#55H ;P1=01010101 AGAIN: XLR P1,#0FFH ;EX-OR ;P1 with 1111 1111 ACALL DELAY SJMP AGAIN 04/07/15 Ritula Thakur 86
  • 87. Single-bit Addressability of PortsSingle-bit Addressability of Ports BACK: CPL P1.2 ;complement P1.2 only ACALL DELAY SJMP BACK ;another variation of the above program follows AGAIN: SETB P1.2 ;change only P1.2=high ACALL DELAY CLR P1.2 ;change only P1.2=low ACALL DELAY SJMP AGAIN 04/07/15 Ritula Thakur 87
  • 88. Single-bit Addressability of PortsSingle-bit Addressability of Ports 04/07/15 Ritula Thakur 88
  • 90. Chapter 5Chapter 5 Addressing ModesAddressing Modes
  • 91. OutlinesOutlines Five addressing modes of 8051 Code instructions using each addressing mode Access RAM using various addressing modes SFR addresses Access SFR Operate stack using direct addressing mode Code instructions to operate look-up table 04/07/15 Ritula Thakur 91
  • 92. Five Addressing ModesFive Addressing Modes Immediate Register Direct Register indirect Indexed 04/07/15 Ritula Thakur 92
  • 93. Immediate Addressing ModeImmediate Addressing Mode MOVMOV A,#25HA,#25H ;load 25H into A;load 25H into A MOVMOV R4,#62R4,#62 ;load the decimal value 62 into R4;load the decimal value 62 into R4 MOV B,#40HMOV B,#40H ;load 40H into B;load 40H into B MOVMOV DPTR,#4521HDPTR,#4521H ;DPTR=4521H;DPTR=4521H MOVMOV DPTR,#2550HDPTR,#2550H ;is the same as:;is the same as: MOVMOV DPL,#50HDPL,#50H MOVMOV DPH,#25HDPH,#25H 04/07/15 Ritula Thakur 93
  • 94. MOVMOV DPTR,#68975DPTR,#68975 ;illegal!! value > 65535 (FFFFH);illegal!! value > 65535 (FFFFH) COUNTCOUNT EQU 30EQU 30 …… …… MOVMOV R4,#COUNTR4,#COUNT ;R4=1E (30=1EH);R4=1E (30=1EH) MOVMOV DPTR,#MYDATADPTR,#MYDATA ;DPTR=200H;DPTR=200H ORGORG 200H200H MYDATA:MYDATA: DB “America”DB “America” 04/07/15 Ritula Thakur 94
  • 95. Register Addressing ModeRegister Addressing Mode MOVMOV A,R0A,R0 ;copy the contents of R0 into A;copy the contents of R0 into A MOVMOV R2,AR2,A ;copy the contents of A into R2;copy the contents of A into R2 ADDADD A,R5A,R5 ;add the contents of R5 to contents of A;add the contents of R5 to contents of A ADDADD A,R7A,R7 ;add the contents of R7 to contents of A;add the contents of R7 to contents of A MOVMOV R6,AR6,A ;save accumulator in R6;save accumulator in R6 MOVMOV DPTR,#25F5HDPTR,#25F5H MOVMOV R7,DPLR7,DPL MOVMOV R6,DPHR6,DPH 04/07/15 Ritula Thakur 95
  • 96. Direct Addressing ModeDirect Addressing Mode RAM addresses 00 to 7FH MOVMOV R0,40HR0,40H ;save content of RAM location 40H in R0;save content of RAM location 40H in R0 MOVMOV 56H,A56H,A ;save content of A in RAM location 56H;save content of A in RAM location 56H MOVMOV R4,7FHR4,7FH ;move contents of RAM location 7FH to;move contents of RAM location 7FH to R4R4 MOVMOV A,4A,4 ;is same as;is same as MOV A,R4MOV A,R4 ;which means copy R4 into A;which means copy R4 into A MOVMOV A,7A,7 ;is same as;is same as MOVMOV A,R7A,R7 ;which means copy R7 into A;which means copy R7 into A 04/07/15 Ritula Thakur 96
  • 97. MOVMOV A,2A,2 ;is the same as;is the same as MOVMOV A,R2A,R2 ;which means copy R2 into A;which means copy R2 into A MOVMOV A,0A,0 ;is the same as;is the same as MOVMOV A,R0A,R0 ;which means copy R0 into A;which means copy R0 into A MOVMOV R2,#5R2,#5 ;R2=05;R2=05 MOVMOV A,2A,2 ;copy R2 to A (A=R2=05);copy R2 to A (A=R2=05) MOVMOV B,2B,2 ;copy R2 to B (B=R2=05);copy R2 to B (B=R2=05) MOVMOV 7,27,2 ;copy R2 to R7;copy R2 to R7 ;since “MOV R7,R2” is invalid;since “MOV R7,R2” is invalid 04/07/15 Ritula Thakur 97
  • 98. SFR Registers & Their AddressesSFR Registers & Their Addresses MOVMOV 0E0H,#55H0E0H,#55H ;is the same as;is the same as MOVMOV A,#55HA,#55H ;which means load 55H into A (A=55H);which means load 55H into A (A=55H) MOVMOV 0F0H,#25H0F0H,#25H ;is the same as;is the same as MOV B,#25HMOV B,#25H ;which means load 25H into B (B=25H);which means load 25H into B (B=25H) MOVMOV 0E0H,R20E0H,R2 ;is the same as;is the same as MOVMOV A,R2A,R2 ;which means copy R2 into A;which means copy R2 into A MOVMOV 0F0H,R00F0H,R0 ;is the same as;is the same as MOVMOV B,R0B,R0 ;which means copy R0 into B;which means copy R0 into B 04/07/15 Ritula Thakur 98
  • 99. SFR Addresses ( 1 of 2 )SFR Addresses ( 1 of 2 ) 04/07/15 Ritula Thakur 99
  • 100. SFR Addresses ( 2 of 2 )SFR Addresses ( 2 of 2 ) 04/07/15 Ritula Thakur 100
  • 102. Stack and Direct Addressing ModeStack and Direct Addressing Mode Only direct addressing is allowed for stack 04/07/15 Ritula Thakur 102
  • 103. Register Indirect Addressing ModeRegister Indirect Addressing Mode Only R0 & R1 can be used MOVMOV A,@R0A,@R0 ;move contents of RAM location whose;move contents of RAM location whose ;address is held by R0 into A;address is held by R0 into A MOVMOV @R1,B@R1,B ;move contents of B into RAM location;move contents of B into RAM location ;whose address is held by R1;whose address is held by R1 04/07/15 Ritula Thakur 103
  • 104. Example ( 1 of 2 )Example ( 1 of 2 ) 04/07/15 Ritula Thakur 104
  • 105. Example ( 2 of 2 )Example ( 2 of 2 ) 04/07/15 Ritula Thakur 105
  • 106. Advantage of Register Indirect AddressingAdvantage of Register Indirect Addressing Looping not possible in direct addressing 04/07/15 Ritula Thakur 106
  • 108. Index Addressing Mode & On-chip ROMIndex Addressing Mode & On-chip ROM AccessAccess Limitation of register indirect addressing: 8-bit addresses (internal RAM) DPTR: 16 bits MOVC A, @A+DPTR ; “C” means program (code) space ROM 04/07/15 Ritula Thakur 108
  • 109. Example ( 1 of 2 )Example ( 1 of 2 ) 04/07/15 Ritula Thakur 109
  • 110. Example ( 2 of 2 )Example ( 2 of 2 ) 04/07/15 Ritula Thakur 110
  • 111. Example ( 1 of 3 )Example ( 1 of 3 ) 04/07/15 Ritula Thakur 111
  • 112. Example ( 2 of 3 )Example ( 2 of 3 ) 04/07/15 Ritula Thakur 112
  • 113. Example ( 3 of 3 )Example ( 3 of 3 ) 04/07/15 Ritula Thakur 113
  • 114. Look-up Table & IndexedLook-up Table & Indexed AddressingAddressing 04/07/15 Ritula Thakur 114
  • 116. Chapter 6Chapter 6 Arithmetic Instructions and ProgramsArithmetic Instructions and Programs
  • 117. OutlinesOutlines Range of numbers in 8051 unsigned data Addition & subtraction instructions for unsigned data BCD system of data representation Packed and unpacked BCD data Addition & subtraction on BCD data Range of numbers in 8051 signed data Signed data arithmetic instructions Carry & overflow problems & corrections 04/07/15 Ritula Thakur 117
  • 118. Addition of Unsigned NumbersAddition of Unsigned Numbers ADD A, source ; A = A + source 04/07/15 Ritula Thakur 118
  • 120. Addition of Individual BytesAddition of Individual Bytes 04/07/15 Ritula Thakur 120
  • 121. ADDC & Addition of 16-bitADDC & Addition of 16-bit NumbersNumbers 1 3C E7 3B 8D 78 74 + 04/07/15 Ritula Thakur 121
  • 122. BCD Number SystemBCD Number System Unpacked BCD: 1 byte Packed BCD: 4 bits 04/07/15 Ritula Thakur 122
  • 123. Adding BCD Numbers & DAAdding BCD Numbers & DA InstructionInstruction MOVMOV A,#17HA,#17H ADDADD A,#28HA,#28H MOVMOV A,#47HA,#47H ;A=47H first BCD operand;A=47H first BCD operand MOVMOV B,#25HB,#25H ;B=25 second BCD operand;B=25 second BCD operand ADDADD A,BA,B ;hex (binary) addition (A=6CH);hex (binary) addition (A=6CH) DADA AA ;adjust for BCD addition;adjust for BCD addition (A=72H)(A=72H) HEXHEX BCDBCD 2929 0010 10010010 1001 ++ 1818 ++0001 10000001 1000 4141 0100 00010100 0001 AC=1AC=1 ++ 66 ++ 01100110 4747 0100 01110100 0111 04/07/15 Ritula Thakur 123
  • 125. Subtraction of Unsigned NumbersSubtraction of Unsigned Numbers SUBB A, source ; A = A – source – CY SUBB when CY = 0 Take 2’s complement of subtraend (source) Add it to minuend Invert carry 04/07/15 Ritula Thakur 125
  • 126. Example (Positive Result)Example (Positive Result) 04/07/15 Ritula Thakur 126
  • 127. Example (Negative Result)Example (Negative Result) 04/07/15 Ritula Thakur 127
  • 128. SUBB When CY = 1SUBB When CY = 1 For multibyte numbers 04/07/15 Ritula Thakur 128
  • 129. Multiplication of UnsignedMultiplication of Unsigned NumbersNumbers MUL AB ; A × B, place 16-bit result in B and AMOVMOV A,#25HA,#25H ;load 25H to reg. A;load 25H to reg. A MOVMOV B,#65HB,#65H ;load 65H in reg. B;load 65H in reg. B MULMUL ABAB ;25H * 65H = E99 where;25H * 65H = E99 where ;B = 0EH and A = 99H;B = 0EH and A = 99H Table 6-1:Unsigned Multiplication Summary (MUL AB)Table 6-1:Unsigned Multiplication Summary (MUL AB) MultiplicationMultiplication Operand 1Operand 1 Operand 2Operand 2 ResultResult bytebyte ×× bytebyte AA BB A=low byte,A=low byte, B=high byteB=high byte 04/07/15 Ritula Thakur 129
  • 130. Division of Unsigned NumbersDivision of Unsigned Numbers DIV AB ; divide A by B MOVMOV A,#95HA,#95H ;load 95 into A;load 95 into A MOVMOV B,#10HB,#10H ;load 10 into B;load 10 into B DIVDIV ABAB ;now A = 09 (quotient) and;now A = 09 (quotient) and ;B = 05 (remainder);B = 05 (remainder) Table 6-2:Unsigned Division Summary (DIV AB)Table 6-2:Unsigned Division Summary (DIV AB) DivisionDivision NumeratorNumerator DenominatorDenominator QuotientQuotient RemainderRemainder byte / bytebyte / byte AA BB AA BB 04/07/15 Ritula Thakur 130
  • 131. Example ( 1 of 2 )Example ( 1 of 2 ) 04/07/15 Ritula Thakur 131
  • 132. Example ( 2 of 2 )Example ( 2 of 2 ) 04/07/15 Ritula Thakur 132
  • 133. Signed 8-bit OperandsSigned 8-bit Operands Covert to 2’s complement Write magnitude of number in 8-bit binary (no sign) Invert each bit Add 1 to it 04/07/15 Ritula Thakur 133
  • 137. Byte-sized Signed Numbers RangesByte-sized Signed Numbers Ranges DecimalDecimal BinaryBinary HexHex -128-128 1000 00001000 0000 8080 -127-127 1000 00011000 0001 8181 -126-126 1000 00101000 0010 8282 …….. …………………… .... -2-2 1111 11101111 1110 FEFE -1-1 1111 11111111 1111 FFFF 00 0000 00000000 0000 0000 +1+1 0000 00010000 0001 0101 +2+2 0000 00100000 0010 0202 …… …………………… ...... +127+127 0111 11110111 1111 7F7F 04/07/15 Ritula Thakur 137
  • 138. Overflow in Signed NumberOverflow in Signed Number OperationsOperations 04/07/15 Ritula Thakur 138
  • 139. When Is the OV Flag Set?When Is the OV Flag Set? Either: there is a carry from D6 to D7 but no carry out of D7 (CY = 0) Or: there is a carry from D7 out (CY = 1) but no carry from D6 to D7 04/07/15 Ritula Thakur 139
  • 143. Chapter 7Chapter 7 LOGIC INSTRUCTIONS ANDLOGIC INSTRUCTIONS AND PROGRAMSPROGRAMS
  • 144. OutlinesOutlines Define the truth tables for logic functions AND, OR, XOR Code 8051 Assembly language logic function instructions Use 8051 logic instructions for bit manipulation Use compare and jump instructions for program control Code 8051 rotate and swap instructions Code 8051 programs for ASCII and BCD data conversion 04/07/15 Ritula Thakur 144
  • 145. ANDAND XX YY X AND YX AND Y 00 00 00 00 11 00 11 00 00 11 11 11 ANL destination, source ;dest = dest AND source 04/07/15 Ritula Thakur 145
  • 146. OROR ORL destination, source ;dest = dest ORORL destination, source ;dest = dest OR sourcesourceXX YY X AND YX AND Y 00 00 00 00 11 11 11 00 11 11 11 11 04/07/15 Ritula Thakur 146
  • 147. XORXOR XRL destination, source ;dest = dest XORXRL destination, source ;dest = dest XOR sourcesourceXX YY X AND YX AND Y 00 00 00 00 11 11 11 00 11 11 11 00 XRL A,#04H ;EX-OR A with 0000 010004/07/15 Ritula Thakur 147
  • 150. CPL (complement accumulator)CPL (complement accumulator) MOVMOV A,#55HA,#55H CPLCPL AA ;now A=AAH;now A=AAH ;0101 0101(55H) becomes;0101 0101(55H) becomes ;1010 1010 (AAH);1010 1010 (AAH) 04/07/15 Ritula Thakur 150
  • 151. Compare instructionCompare instruction CJNE destination, source ,relative addressCJNE destination, source ,relative address 04/07/15 Ritula Thakur 151
  • 152. Table 7-1:Carry Flag Setting For CJNE InstructionTable 7-1:Carry Flag Setting For CJNE Instruction CompareCompare Carry FlagCarry Flag destination > sourcedestination > source CY = 0CY = 0 destination < sourcedestination < source CY = 1CY = 1 CJNE R5,#80,NOT_EQUAL ;check R5 for 80 …. ;R5=80 NOT_EQUAL: JNC NEXT ;jump if R5>80 …. ;R5<80 NEXT: …. 04/07/15 Ritula Thakur 152
  • 157. Rotating the bits of A right and leftRotating the bits of A right and left RRRR AA ;rotate right A;rotate right A MOV A,#36H ;A=0011 0110 RR A ;A=0001 1011 RR A ;A=1000 1101 RR A ;A=1100 0110 RR A ;A=0110 0011 RL A ;rotate left A 04/07/15 Ritula Thakur 157
  • 158. MOV A,#72H ;A=0111 0010 RL A ;A=1110 0100 RL A ;A=1100 1001 04/07/15 Ritula Thakur 158
  • 159. Rotating through the carryRotating through the carry RRCRRC AA ;rotate right through carry;rotate right through carry CLR C ;make CY=0 MOV A,#26H ;A=0010 0110 RRC A ;A=0001 0011 CY=0 RRC A ;A=0000 1001 CY=1 RRC A ;A=1000 0100 CY=1 RLC A ;rotate left through carry 04/07/15 Ritula Thakur 159
  • 160. SETB C ;make CY=1 MOV A,#15H ;A=0001 0101 RLC A ;A=0010 1010 CY=0 RLC A ;A=0101 0110 CY=0 RLC A ;A=1010 1100 CY=0 RLC A ;A=0101 1000 CY=1 04/07/15 Ritula Thakur 160
  • 163. RRC A ;first bit to carry MOV P1.3,C ;output carry as data bit RRC A ;second bit to carry MOV P1.3,C ;output carry as data bit RRC A ;third bit to carry MOV P1.3,C ;output carry as data bit ….. 04/07/15 Ritula Thakur 163
  • 164. BCD AND ASCII APPLICATIONBCD AND ASCII APPLICATION PROGRAMPROGRAM 04/07/15 Ritula Thakur 164
  • 165. Packed BCD to ASCII conversionPacked BCD to ASCII conversion Packed BCDPacked BCD Unpacked BCDUnpacked BCD ASCIIASCII 29H29H 02H & 09H02H & 09H 32H & 39H32H & 39H 0010 10010010 1001 0000 0010 &0000 0010 & 0011 0010 &0011 0010 & 0000 10010000 1001 0011 10010011 1001 04/07/15 Ritula Thakur 165
  • 166. ASCII to packed BCD conversionASCII to packed BCD conversion Key ASCII Unpacked BCDKey ASCII Unpacked BCD Packed BCDPacked BCD 44 34 0000010034 00000100 77 37 00000111 01000111 or 47H37 00000111 01000111 or 47H MOV A,#’4’ ;A=34H, hex for ASCII char 4 MOV R1,#’7’ ;R1=37H, hex for ASCII char 7 ANL A,#0FH ;mask upper nibble (A=04) ANL R1,#0FH ;mask upper nibble (R1=07) SWAP A ;A=40H ORL A,R1 ;A=47H, packed BCD 04/07/15 Ritula Thakur 166
  • 168. Chapter 8Chapter 8 SINGLE-BIT INSTRUCTIONSSINGLE-BIT INSTRUCTIONS AND PROGRAMMINGAND PROGRAMMING
  • 169. OutlinesOutlines List the 8051 Assembly language instructions for bit manipulation Code 8051 instructions for bit manipulation of ports Explain which 8051 registers are bit-addressable Describe which portions of the 8051 RAM are bit- addressable Discuss bit manipulation of the carry flag Describe the carry flag bit-related instructions of the 8051 04/07/15 Ritula Thakur 169
  • 171. I/O ports and bit-addressabilityI/O ports and bit-addressability The 8051 has four I/O ports, each of which is 8 bits 04/07/15 Ritula Thakur 171
  • 176. Checking an input bitChecking an input bit JNB (jump if no bit) ; JB (jump if bit = 1) 04/07/15 Ritula Thakur 176
  • 177. Registers and bit-addressabilityRegisters and bit-addressability 04/07/15 Ritula Thakur 177
  • 179. Figure 8-2. Bits of the PSW Register 04/07/15 Ritula Thakur 179
  • 184. Single-bit operations with CYSingle-bit operations with CY 04/07/15 Ritula Thakur 184
  • 188. Instructions for reading input portInstructions for reading input port READING INPUT PINS VS. PORT LATCHREADING INPUT PINS VS. PORT LATCH In Reading a port: 1.Read the status of the input pin 2.Read the internal latch of the output port 04/07/15 Ritula Thakur 188
  • 189. Reading latch for output portReading latch for output port 04/07/15 Ritula Thakur 189
  • 190. 8051 Timers8051 Timers Basic Registers of the timer Timer 0 registers Timer 1 registers Both the registers are 16 bits wide but can be accessed as 8 bit registers separately. 04/07/15 Ritula Thakur 190
  • 191. PROGRAMMING 8051 TIMERSPROGRAMMING 8051 TIMERS Timer 0 registersTimer 0 registers TL0 ( timer 0 low byte ) TH0 ( timer 0 high byte ) 04/07/15 Ritula Thakur 191
  • 192. Timer 1 registersTimer 1 registers TL1 ( timer 1 low byte ) TH1 ( timer 1 high byte ) 04/07/15 Ritula Thakur 192
  • 193. 04/07/15 Ritula Thakur Timer Interrupt & OptimizeTimer Interrupt & Optimize TMOD Register - Operation ControlTMOD Register - Operation Control TIMER1 TIMER2 M1 M1M0GATE C/T GATE C/T M0 (MSB) (LSB) GATE Gating Control When Set Timer/Counter “x”is enabled Only while “INTx”pin is high and “TRx” control pin is set When Cleared Timer “x” is enabled Whenever “TRx” control bit is set C/T Timer or Counter Selector Cleared for Timer operation (input from internal system clock). Set for Counter operation (input from “Tx” input pin) 193
  • 194. 04/07/15 Ritula Thakur Chap3. Timer Interrupt & OptimizeChap3. Timer Interrupt & Optimize TMOD Register - Operating Mode Control (0 , 1, 2 )TMOD Register - Operating Mode Control (0 , 1, 2 ) TIMER1 TIMER2 GATE C/T GATE C/TM1 M1M0 M0 (MSB) (LSB) 8048 TIMER : ”TLx” serves as 5-bit prescaler. 16-bit Timer/Counter : “THx” and “TLx” are cascaded 8-bit auto reload “THx” hold a value which is to be Reloaded into “TLx” each time it overflows M1 M0 Function 0 0 0 1 1 0 194
  • 195. Indicate which mode and which timer are selected for each of the following: MOV TMOD,#01H MOV TMOD,#20H TMOD=00000001, mode 1 of Timer 0 TMOD=00100000, mode 2 of Timer 1 04/07/15 Ritula Thakur 195
  • 197. Clock Source for timerClock Source for timer The crystal frequency attached to the 8051 timer is the source of the clock for the timer. The frequency for the timer is always 1/12th the frequency of the crystal attached to the 8051 04/07/15 Ritula Thakur 197
  • 198. Mode 1 programmingMode 1 programming 1. It is a 16-bit timer; so it allows values of 0000 to FFFFH to be loaded into the timer’s registers TL and TH After TH and TL are loaded with a 16 bit initial value, the timer must be started (SETB TR0 and SETB TR1) It starts counting up until it reaches its limit of FFFFH. When it rolls over from FFFFH to 0000, it sets high TF (Timer flag) Stop the timer (CLR TR0 & CLR TR1) After the timer reaches its limit and rolls over, in order to repeat the process TH and TL must be reloaded with the original value, and TF must be reset to 0 04/07/15 Ritula Thakur 198
  • 199. Mode 1 programmingMode 1 programming 1.Loaded value into TL and TH 2.”SETB TR0” for timer 0 ;”SETB TR1” for timer 1 3.If TF (timer flag) = high “CLR TR0” or “CLR TR1” 4.Reloaded TH and TL value, TF reset to 0 04/07/15 Ritula Thakur 199
  • 200. Steps to program in mode 1Steps to program in mode 1 1.Load the TMOD value 2.Load registers TL and TH 3.Start the timer (SETB TR0 or SETB TR1) 4.Keep monitoring the timer flag (TF) 5.Stop the timer (CLR TR0 or CLR TR1) 6.Clear the TF flag 7.Go back to step 2 04/07/15 Ritula Thakur 200
  • 201. Calculate Timer DelayCalculate Timer Delay 04/07/15 Ritula Thakur 201
  • 205. Finding values to be loaded into the timerFinding values to be loaded into the timer Assuming XTAL =11.0592MHz from Example 9-10 1.Divide the desired time delay by 1.085μs 2.Perform 65536-n, where n is the decimal value we got in Step 1 3.Convert the result of Step 2 to hex, where yyxx is the initial hex value to be loaded into the timer’s registers 4.Set TL = xx and TH = yy 04/07/15 Ritula Thakur 205
  • 207. 04/07/15 Ritula Thakur Chap3. Timer Interrupt & OptimizeChap3. Timer Interrupt & Optimize osc 12÷ 1/ =TC CONTROL TL1 (8BITS) TH1 (8BITS) TF1 INTERRUPT GATE PININT1 TR1 T1 PIN 0/ =TC Timer/Counter 1 Mode 1:16-bit Counter Timer Mode - Mode 1 207
  • 208. Mode 0Mode 0 Like mode 1 except that it is a 13-bit timer Mode 2 ProgrammingMode 2 Programming 1.Loaded value into TH (8-bit timer) 2.”SETB TR0” for timer 0 ;”SETB TR1” for timer 1 3.If TF (timer flag) = high “CLR TR0” or “CLR TR1” 4.Reloaded TL value kept by TH 04/07/15 Ritula Thakur 208
  • 209. Steps to program in mode 2Steps to program in mode 2 1.Load the TMOD value 2.Load the TH registers 3.Start the timer 4.Keep monitoring the timer flag (TF) 5.Clear the TF flag 7.Go back to step 4 04/07/15 Ritula Thakur 209
  • 212. 8051 SERIAL COMMUNICATION8051 SERIAL COMMUNICATION
  • 213. OutlinesOutlines Contrast and compare serial versus parallel communication List the advantages of serial communication over parallel Explain serial communication protocol Contrast synchronous versus asynchronous communication Contrast half-versus full-duplex transmission 04/07/15 Ritula Thakur 213
  • 214. ♦ Explain the process of data framingExplain the process of data framing ♦ Describe data transfer rate and bps rateDescribe data transfer rate and bps rate ♦ Define the RS232 standardDefine the RS232 standard ♦ Explain the use of the MAX232 andExplain the use of the MAX232 and MAX233 chipsMAX233 chips ♦ Interface the 8051 with an RS232Interface the 8051 with an RS232 connectorconnector ♦ Discuss the baud rate of the 8051Discuss the baud rate of the 8051 ♦ Describe serial communication features ofDescribe serial communication features of the 8051the 8051 ♦ Program the 8051 for serial dataProgram the 8051 for serial data 04/07/15 Ritula Thakur 214
  • 215. Basics of serial communicationBasics of serial communication 04/07/15 Ritula Thakur 215
  • 217. Start and stop bitsStart and stop bits 04/07/15 Ritula Thakur 217
  • 218. RS232 pinsRS232 pins 04/07/15 Ritula Thakur 218
  • 219. Data communication classificationData communication classification 04/07/15 Ritula Thakur 219
  • 220. RxD and TxD pins in the 8051RxD and TxD pins in the 8051 TxD pin 11 of the 8051 (P3.1) RxD pin 10 of the 8051 (P3.0) 04/07/15 Ritula Thakur 220
  • 223. 8051 SERIAL COMMUNICATION8051 SERIAL COMMUNICATION PROGRAMMINGPROGRAMMING 04/07/15 Ritula Thakur 223
  • 224. Baud Rate in 8051Baud Rate in 8051 The baud rate in 8051 is programmable (done with the help of timer 1) Relation b/w crystal frequency and baud rate 8051 divides crystal frequency by 12 to get m/c cycle frequency 8051’s serial commn UART crctry divides it by 32 once more 11.0592/12=921.6 kHz 921.6 kHz/32=28,800 Hz 04/07/15 Ritula Thakur 224
  • 227. SBUF registerSBUF register MOV SBUF,#’D’ ;load SBUF=44H, ASCII for ‘D’ MOV SBUF,A ;copy accumulator into SBUF MOV A,SBUF ;copy SBUF into accumulator 04/07/15 Ritula Thakur 227
  • 228. SCON (Serial control) registerSCON (Serial control) register 04/07/15 Ritula Thakur 228
  • 229. SM0,SM1SM0,SM1 SM0 and SM1 are D7 and D6 of the SCON 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 3 04/07/15 Ritula Thakur 229
  • 230. Programming the 8051 to transfer dataProgramming the 8051 to transfer data seriallyserially TMOD register is loaded with 20H to set the baud rate) TH1 is loaded to set the baud rate for serial data transfer SCON is loaded with 50H TR1 is set to start the Timer 1 Character byte to be transferred is written into SBUF register TI flag is monitored to see if the character has been transferred completely TI is cleared by CLR TI To transfer the next character, go to Step 6 04/07/15 Ritula Thakur 230
  • 231. Programming the 8051 to transferProgramming the 8051 to transfer data seriallydata serially 04/07/15 Ritula Thakur 231
  • 233. Programming the 8051 to receive dataProgramming the 8051 to receive data seriallyserially TMOD register is loaded with 20H to set the baud rate) TH1 is loaded to set the baud rate for serial data transfer SCON is loaded with 50H TR1 is set to start the Timer 1 Character byte to be transferred is written into SBUF register RI flag is monitored to see if the character has been transferred completely RI is cleared by CLR TI To receive the next character, go to Step 6 04/07/15 Ritula Thakur 233
  • 234. Programming the 8051 to receiveProgramming the 8051 to receive data seriallydata serially 04/07/15 Ritula Thakur 234
  • 238. Doubling the baud rate in theDoubling the baud rate in the 80518051 1. To use a higher frequency crystal 2. To change a bit in the PCON register SMODSMOD ---- ---- ---- GF1GF1 GF0GF0 PDPD IDLIDL D7 D0 MOV A,PCON ;place a copy of PCON in ACC SETB ACC.7 ;make D7=1 MOV PCON,A ;now SMOD=1 without ;changing any other bits 04/07/15 Ritula Thakur 238
  • 239. Baud rates for SMOD=0Baud rates for SMOD=0 Machine cycle freq. = 11.0592 MHz / 12 = 921.6 kHz and 921.6 kHz / 32 = 28,800 Hz since SMOD = 0 04/07/15 Ritula Thakur 239
  • 240. Baud rates for SMOD=1Baud rates for SMOD=1 Machine cycle freq. = 11.0592 MHz / 12 = 921.6 kHz and 921.6 kHz / 16 = 57,600 Hz since SMOD = 1 04/07/15 Ritula Thakur 240
  • 244. Chapter 11Chapter 11 INTERRUPTS PROGRAMMINGINTERRUPTS PROGRAMMING
  • 245. OutlinesOutlines Contrast and compare interrupts versus polling Explain the purpose of the ISR List the 6 interrupts of the 8051 Explain the purpose of the interrupt vector table Enable or disable 8051 interrupts Program the 8051 timers using interrupts Describe the two external hardware interrupts of the 8051 04/07/15 Ritula Thakur 245
  • 246. ♦ Contrast edge-triggered with level-triggeredContrast edge-triggered with level-triggered interruptsinterrupts ♦ Program the 8051 for interrupt-based serialProgram the 8051 for interrupt-based serial communicationcommunication ♦ Define the interrupt priority of the 8051Define the interrupt priority of the 8051 04/07/15 Ritula Thakur 246
  • 247. Six interrupts in the 8051Six interrupts in the 8051 04/07/15 Ritula Thakur 247
  • 248. Step in enabling an interruptStep in enabling an interrupt 04/07/15 Ritula Thakur 248
  • 251. Roll-over timer flag andRoll-over timer flag and interruptinterrupt JNB TF, target 04/07/15 Ritula Thakur 251
  • 256. Programming externalProgramming external hardware interruptshardware interrupts 04/07/15 Ritula Thakur 256
  • 259. Sampling the low level-Sampling the low level- triggered interrupttriggered interrupt 04/07/15 Ritula Thakur 259
  • 263. Sampling the edge-triggeredSampling the edge-triggered interruptinterrupt 04/07/15 Ritula Thakur 263
  • 264. RI and TI flags and interruptsRI and TI flags and interrupts 04/07/15 Ritula Thakur 264
  • 265. Use of serial COM in the 8051Use of serial COM in the 8051 04/07/15 Ritula Thakur 265
  • 268. Clearing RI and TI before theClearing RI and TI before the RETI instructionRETI instruction CLR TI ; CLR RI 04/07/15 Ritula Thakur 268
  • 271. Interrupt priority upon resetInterrupt priority upon reset 04/07/15 Ritula Thakur 271
  • 274. Setting interrupt priority with the IPSetting interrupt priority with the IP registerregister 04/07/15 Ritula Thakur 274