8051 Microcontroller

Post on 18-Jul-2015

187 views 19 download

Tags:

Transcript of 8051 Microcontroller

Micro-Controller 8051Micro-Controller 8051

OverviewOverview

Ritula Thakur

NITTTR

Chapter 1Chapter 1The 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 8031 8031 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 28051 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 banks04/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 R2ADD 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 0MOV R5,#25H ;load 25H into R5MOV R7,#34H ;load 34H into R7MOV A,#0 ;load 0 into AADD A,R5 ;add contents of R5 to A

;now A = A + R5ADD A,R7 ;add contents of R7 to A

;now A = A + R7ADD A,#12H ;add to A value 12H

;now A = A + 12HHERE: 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 & ROM 8051 Program Counter & ROM SpaceSpace

04/07/15 Ritula Thakur 22

8051 Program Counter & ROM 8051 Program Counter & ROM SpaceSpace

04/07/15 Ritula Thakur 23

8051 Program Counter & ROM 8051 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 500HDATA1: DB 28 ;DECIMAL (1C in Hex)

DATA2: DB 00110101B ;BINARY (35 in Hex)

DATA3: DB 39H ;HEX

ORG 510HDATA4: DB “2591” ; ASCII NUMBERS

ORG 518HDATA6: 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 Using Access 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 3JUMP, 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 delay04/07/15 Ritula Thakur 44

LoopingLooping

04/07/15 Ritula Thakur 45

Loop inside a Loop (Nested Loop inside a Loop (Nested Loop)Loop)

04/07/15 Ritula Thakur 46

8051 Conditional Jump 8051 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 4I/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: MOV MOV 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 fromP1

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 R504/07/15 Ritula Thakur 83

Port 2: I/O, No Pull-up ResistorsPort 2: I/O, No Pull-up Resistors

� Initially configured as outputMOV A,#55H

BACK: MOV P2,AACALL DELAYCPL ASJMP BACK

MOV A,#0FFH ;A=FF hexMOV P2,A ;make P2 an input port by

;writing all 1s to itBACK: MOV A,P2 ;get data from P2

MOV P1,A ;send it to Port 1SJMP BACK ;keep doing that

♦ Dual role of port 2: A8-A15Dual role of port 2: A8-A1504/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=01010101AGAIN: 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 5Addressing 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 table04/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

MOV MOV 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 30 EQU 30

…… … …

MOV MOV R4,#COUNT R4,#COUNT ;R4=1E (30=1EH) ;R4=1E (30=1EH)

MOV MOV DPTR,#MYDATA DPTR,#MYDATA ;DPTR=200H;DPTR=200H

ORGORG 200H 200H

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 ROM Index 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 & Indexed Look-up Table & Indexed AddressingAddressing

04/07/15 Ritula Thakur 114

ExampleExample

04/07/15 Ritula Thakur 115

Chapter 6Chapter 6Arithmetic 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-bit ADDC & Addition of 16-bit NumbersNumbers

13C E73B 8D78 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 & DA Adding 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 operandMOVMOV 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

++ 6 6 + + 0110 0110

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 Unsigned Multiplication 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

byte byte ×× 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 Number Overflow 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 7LOGIC INSTRUCTIONS AND LOGIC 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 OR ORL 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 XOR XRL 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 0110RR A ;A=0001 1011RR A ;A=1000 1101RR A ;A=1100 0110RR A ;A=0110 0011

RL A ;rotate left A

04/07/15 Ritula Thakur 157

MOV A,#72H ;A=0111 0010RL A ;A=1110 0100RL A ;A=1100 1001

04/07/15 Ritula Thakur 158

Rotating through the carryRotating through the carry

RRCRRC A A ;rotate right through carry;rotate right through carry

CLR C ;make CY=0MOV A,#26H ;A=0010 0110RRC A ;A=0001 0011 CY=0RRC A ;A=0000 1001 CY=1RRC A ;A=1000 0100 CY=1

RLC A ;rotate left through carry

04/07/15 Ritula Thakur 159

SETB C ;make CY=1MOV A,#15H ;A=0001 0101RLC A ;A=0010 1010 CY=0RLC A ;A=0101 0110 CY=0RLC A ;A=1010 1100 CY=0RLC 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 carryMOV P1.3,C ;output carry as data bitRRC A ;second bit to carryMOV P1.3,C ;output carry as data bitRRC A ;third bit to carryMOV P1.3,C ;output carry as data bit…..

04/07/15 Ritula Thakur 163

BCD AND ASCII APPLICATION BCD 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 00000100 34 00000100

77 37 00000111 01000111 or 47H 37 00000111 01000111 or 47H

MOV A,#’4’ ;A=34H, hex for ASCII char 4MOV R1,#’7’ ;R1=37H, hex for ASCII char 7ANL A,#0FH ;mask upper nibble (A=04)ANL R1,#0FH ;mask upper nibble (R1=07)SWAP A ;A=40HORL A,R1 ;A=47H, packed BCD

04/07/15 Ritula Thakur 166

04/07/15 Ritula Thakur 167

Chapter 8Chapter 8SINGLE-BIT INSTRUCTIONS SINGLE-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 pin2.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 registersTL0 ( timer 0 low byte )TH0 ( timer 0 high byte )

04/07/15 Ritula Thakur 191

Timer 1 registersTimer 1 registersTL1 ( 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 cascaded8-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 programming1.Loaded value into TL and TH2.”SETB TR0” for timer 0 ;”SETB TR1” for timer 13.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 11.Load the TMOD value2.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 flag7.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 timerAssuming XTAL =11.0592MHz from Example 9-10

1.Divide the desired time delay by 1.085μs2.Perform 65536-n, where n is the decimal value we got in Step 13.Convert the result of Step 2 to hex, where yyxx is the initial hex value to be loaded into the timer’s registers4.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 13.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 21.Load the TMOD value2.Load the TH registers 3.Start the timer4.Keep monitoring the timer flag (TF)5.Clear the TF flag7.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 and Explain the use of the MAX232 and

MAX233 chipsMAX233 chips♦ Interface the 8051 with an RS232 Interface the 8051 with an RS232

connectorconnector♦ Discuss the baud rate of the 8051Discuss the baud rate of the 8051♦ Describe serial communication features of Describe serial communication features of

the 8051the 8051♦ Program the 8051 for serial data Program the 8051 for serial data

communicationcommunication

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 COMMUNICATION 8051 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 data Programming 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 transfer Programming the 8051 to transfer data seriallydata serially

04/07/15 Ritula Thakur 231

04/07/15 Ritula Thakur 232

Programming the 8051 to receive data Programming 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 receive Programming 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 the Doubling the baud rate in the 80518051

1. To use a higher frequency crystal2. To change a bit in the PCON register

SMODSMOD ---- ---- ---- GF1GF1 GF0GF0 PDPD IDLIDL

D7 D0

MOV A,PCON ;place a copy of PCON in ACCSETB 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 kHzand921.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 kHzand921.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 11INTERRUPTS 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 805104/07/15 Ritula Thakur 245

♦ Contrast edge-triggered with level-triggered Contrast edge-triggered with level-triggered interruptsinterrupts

♦ Program the 8051 for interrupt-based serial Program 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 TIMER PROGRAMMING TIMER INTERRUPTSINTERRUPTS

04/07/15 Ritula Thakur 250

Roll-over timer flag and Roll-over timer flag and interruptinterruptJNB 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 external Programming 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-triggered Sampling 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 the Clearing RI and TI before the RETI instructionRETI instructionCLR 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 IP Setting interrupt priority with the IP registerregister

04/07/15 Ritula Thakur 274

04/07/15 Ritula Thakur 275