SlideShare a Scribd company logo
1 of 21
S. Y. B. Sc. (Computer Science)
SEM – III
Electronics Paper I
Microcontroller Architecture & Programming
Presentation
By
Mrs. Neeta Gatkal
Head, Department of Electronics
Pratibha College of Computer and Computer Studies,Chinchwad
Objectives
● To study the basics of 8051microcontroller
● To study the Programming of 8051
● To study the interfacing techniques of 8051
● To design different application circuits using 8051
Course Outcomes
1. To write programs for 8051 microcontroller
2. To interface I/O peripherals to 8051 microcontroller
3. To design small microcontroller based projects
UNIT- 2
Programming model of 8051
 Instruction classification and Instruction set
 Addressing Modes,(Immediate, register, direct, indirect and relative)
 assembler directives (ORG, END), features with examples
 I/O Bit & Byte programming using assembly language for LED and
seven segment display (SSD) interfacing
 Introduction to 8051 programming in C
Structure of the 8051 Microcontroller Instruction
● An 8051 Instruction consists of an Opcode (short of Operation – Code)
followed by Operand(s) of size Zero Byte, One Byte or Two Bytes.
● The Op-Code part of the instruction contains the Mnemonic, which specifies
the type of operation to be performed. All Mnemonics or the Opcode part of
the instruction are of One Byte size.
● An Assembly language instruction consists of four fields:
[label:] Mnemonic [operands] [;comment]
E.g MOV A,#55H ;load 55H into A
HERE: SJMP HERE
● Data transfer instructions.
● Arithmetic instructions
● Logical Instructions
● Program Branching Instructions
● Bit manipulation instructions
Types of Instructions in 8051 MC
Data Transfer Instructions
● The Data Transfer Instructions are associated with transfer with data between
registers or external program memory or external data memory. The
Mnemonics associated with Data Transfer are given below.
● MOV
● MOVC
● MOVX
● PUSHPOP
● XCH
● XCHD
unit5.pdf
Arithmetic Instructions
● Using Arithmetic Instructions, you can perform addition, subtraction,
multiplication and division. The arithmetic instructions also include
increment by one, decrement by one and a special instruction called Decimal
Adjust Accumulator.
● The arithmetic instructions has no knowledge about the data format i.e.
signed, unsigned, ASCII, BCD, etc. Also, the operations performed by the
arithmetic instructions affect flags like carry, overflow, zero, etc. in the PSW
Register.
● The Mnemonics associated with the Arithmetic Instructions of the 8051
Microcontroller Instruction Set are:
● ADD ADDC
● SUBB INC
● DEC MUL
● DIV DA A
● unit5.pdf
Logical Instructions
● The next group of instructions are the Logical Instructions, which perform
logical operations like AND, OR, XOR, NOT, Rotate, Clear and Swap.
Logical Instruction are performed on Bytes of data on a bit-by-bit basis.
Mnemonics associated with Logical Instructions are as follows:
ANL ORL
XRL CLR
CPL RL
RLC RR
RRC SWAP
unit5.pdf
Program Branching Instructions
● These instructions control the flow of program logic.
● All these instructions, except the NOP (No Operation) affect the Program
Counter (PC) in one way or other. Some of these instructions has decision
making capability before transferring control to other part of the program.
● The mnemonics of the Program Branching Instructions are as follows.
● LJMP AJMP
● SJMP JZ
● JNZ CJNE
● DJNZ NOP
● LCALL ACALL
● RET RETI
● JMP
unit5.pdf
Bit manipulation instructions
● As the name suggests, Boolean or Bit Manipulation Instructions will deal
with bit variables. We know that there is a special bit-addressable area in the
RAM and some of the Special Function Registers (SFRs) are also bit
addressable.
● The Mnemonics corresponding to the Boolean or Bit Manipulation
instructions are:
● CLR SETB
● MOV JC
● JNC JB
● JNB JBC
● ANL ORL
● CPL
unit5.pdf
ADDRESSING MODES
 The CPU can access data in various ways, which are
called addressing modes
 Immediate
 Register
 Direct
 Register indirect
 Indexed
IMMEDIATE ADDRESSING MODE
 The source operand is a constant
 The immediate data must be preceded by the pound sign, “#”
 Can load information into any registers, including 16-bit
DPTR register
 DPTR can also be accessed as two 8-bit registers, the high
byte DPH and low byte DPL
 We can also use immediate addressing mode to send data to
8051 ports
MoV A,#25H ;load 25H into A
MOV R4,#62 ;load 62 into R4
MOV B,#40H ;load 40H into B
MOV DPTR,#4521H ; DPTR=4512H
MOV DPL,#21H ;This is the same
MOV DPH,#45H ;as above
REGISTER ADDRESSING MODE
 Use registers to hold the data to be manipulated
 The source and destination registers must match
in size
 MOV DPTR,A will give an error
 The movement of data between Rn registers is not
allowed
 MOV R4,R7 isinvalid
MOV A,R0
MOV R2,A
ADD A,R5
ADD A,R7
MOV R6,A
;copy contents of R0 into A
;copy contents of A into R2
;add contents of R5 to A
;add contents of R7 to A
;save accumulator in R6
MOV DPTR,#25F5H
MOV R7,DPL
MOV R6,DPH
Direct Addressing Mode
 It is most often used the direct addressing mode to access
RAM locations 30 – 7FH
 The entire 128 bytes of RAM can be accessed.
 The register bank locations are accessed by the register names
MOV A,4
MOV A,R4
;is same as
;which means copy R4 into A
 Contrast this with immediate addressing mode
 There is no “#” sign in the operand
MOV R0,40H
MOV 56H,A
;save content of 40H in R0
;save content of A in 56H
Register Indirect Addressing Mode
 A register is used as a pointer to the data
 Only register R0 and R1 are used for this purpose
 R2 – R7 cannot be used to hold the address of an operand located in
RAM
 When R0 and R1 hold the addresses of RAM locations, they must be preceded
by the “@” sign
MOV A,@R0
MOV @R1,B
;move contents of RAM whose
;address is held by R0 into A
;move contents of B into RAM
;whose address is held by R1
 R0 and R1 are the only registers that can be used for pointers in register indirect
addressing mode
 Since R0 and R1 are 8 bits wide, their use is limited to access any information in
the internal RAM
 Whether accessing externally connected RAM or on-chip ROM, we need 16-bit
pointer
 In such case, the DPTR register is used
IndexAddressing Mode
 Indexed addressing mode is widely used in accessing data
elements of look-up table entries located in the program
ROM
 The instruction used for this purpose is
● MOVC A,@A+DPTR
 Use instruction MOVC, “C” means code
 The contents of A are added to the 16-bit register DPTR to
form the 16-bit address of the needed data
Assembler Directives
 DB(define byte) : The DB directive is the most widely
used data directive in the assembler
 It is used to define the 8-bit data
 When DBis used to define data, the numbers can be in decimal, binary,
hex, ASCII format.
ORG 500H
DATA1: DB
DATA2: DB
DATA3: DB
28
00110101B
39H
;DECIMAL (1C in Hex)
;BINARY (35 in Hex)
;HEX
;ASCII NUMBERS
ORG
DATA4: DB
ORG
510H
“2591”
518H
DATA6: DB “My name is Joe”
;ASCII CHARACTERS
The “D” after the decimal
number is optional, but using
“B” (binary) and “H”
(hexadecimal) for the others is
required
The Assembler will
convert the numbers
into hex
Place ASCII in quotation marks
The Assembler will assign ASCII
code for the numbers or characters
Define ASCII strings larger
than two characters
 ORG(origin)
 The ORGdirective is used to indicate the beginning of the address
 The number that comes after ORGcan be either in hex and decimal
 If the number is not followed by H, it is decimal and the assembler will
convert it to hex
 END
 This indicates to the assembler the end of the source (asm) file
 The ENDdirective is the last line of an 8051 program
 Mean that in the code anything after the END directive is ignored by the
assembler
 EQU(equate)
 This is used to define a constant without occupying a memory location
 The EQU directive does not set aside storage for a data item but associates
a constant value with a data label
 When the label appears in the program, its constant value will be
substituted for the label
I/O Bit & Byte programming
 Instructions that are used for signal-bit operations are as following
Single-Bit Instructions
Instruction Function
SETB bit Set the bit (bit = 1)
CLR bit Clear the bit (bit = 0)
CPL bit Complement the bit (bit = NOT bit)
JB bit, target Jump to target if bit = 1 (jump if bit)
JNB bit, target Jump to target if bit = 0 (jump if no bit)
JBC bit, target Jump to target if bit = 1,
clear bit (jump if bit, then
clear)
 The JNB and JB instructions are widely used single-bit operations
Mnemonic Examples Description
MOV A,PX MOV A,P2 Bring into A the data at P2 pins
JNB PX.Y, .. JNB P2.1,TARGET Jump if pin P2.1 is low
JB PX.Y, .. JB P1.3,TARGET Jump if pin P1.3 is high
MOV C,PX.Y MOV C,P2.4 Copy status of pin P2.4 to CY
Example 4-3
Write a program to perform the following:
(a) Keep monitoring the P1.2 bit until it becomes high
(b) When P1.2 becomes high, write value 45H to port 0
(c) Send a high-to-low (H-to-L) pulse to P2.3
Solution:
SETB
MOV
P1.2
A,#45H
;make P1.2 an input
;A=45H
AGAIN: JNB P1.2,AGAIN ; get out when P1.2=1
MOV P0,A ;issue A to P0
SETB P2.3 ;make P2.3 high
CLR P2.3 ;make P2.3 low for H-to-L

More Related Content

What's hot

8051 addressing modes
 8051 addressing modes 8051 addressing modes
8051 addressing modes
ghoshshweta
 
Basic programming of 8085
Basic programming of 8085 Basic programming of 8085
Basic programming of 8085
vijaydeepakg
 
Computer archi&mp
Computer archi&mpComputer archi&mp
Computer archi&mp
MSc CST
 

What's hot (20)

8051 addressing modes & instruction set
8051 addressing modes & instruction set8051 addressing modes & instruction set
8051 addressing modes & instruction set
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing Modes
 
8085 instruction-set new
8085 instruction-set new8085 instruction-set new
8085 instruction-set new
 
Addressing modes 8085
Addressing modes 8085Addressing modes 8085
Addressing modes 8085
 
Unit 5 assembly language programming
Unit 5   assembly language programmingUnit 5   assembly language programming
Unit 5 assembly language programming
 
8051 Assembly Language Programming
8051 Assembly Language Programming8051 Assembly Language Programming
8051 Assembly Language Programming
 
Assembly language i
Assembly language iAssembly language i
Assembly language i
 
8051 addressing modes
 8051 addressing modes 8051 addressing modes
8051 addressing modes
 
Basic programming of 8085
Basic programming of 8085 Basic programming of 8085
Basic programming of 8085
 
microprocessor
   microprocessor   microprocessor
microprocessor
 
8051 addressing modes
8051 addressing modes8051 addressing modes
8051 addressing modes
 
8085 instruction set and Programming
8085 instruction set and Programming 8085 instruction set and Programming
8085 instruction set and Programming
 
Computer archi&mp
Computer archi&mpComputer archi&mp
Computer archi&mp
 
Malp edusat
Malp edusatMalp edusat
Malp edusat
 
ARITHMETIC OPERATIONS IN 8085 MICROPROCESSOR
ARITHMETIC OPERATIONS IN 8085 MICROPROCESSORARITHMETIC OPERATIONS IN 8085 MICROPROCESSOR
ARITHMETIC OPERATIONS IN 8085 MICROPROCESSOR
 
Addressing modes of 8085 by Er. Swapnil V. Kaware
Addressing modes of 8085 by Er. Swapnil V. KawareAddressing modes of 8085 by Er. Swapnil V. Kaware
Addressing modes of 8085 by Er. Swapnil V. Kaware
 
8051 addressing modes
8051 addressing modes8051 addressing modes
8051 addressing modes
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Addressing Modes
Addressing ModesAddressing Modes
Addressing Modes
 
Unit ii microcontrollers final
Unit ii microcontrollers finalUnit ii microcontrollers final
Unit ii microcontrollers final
 

Similar to 8051 microcontroller

microprocessor and microcontroller notes ppt
microprocessor and microcontroller notes pptmicroprocessor and microcontroller notes ppt
microprocessor and microcontroller notes ppt
mananjain543
 

Similar to 8051 microcontroller (20)

12 mt06ped008
12 mt06ped008 12 mt06ped008
12 mt06ped008
 
Unit -2 and 3 mekirirygiygyuguiguihiiqio
Unit -2 and 3 mekirirygiygyuguiguihiiqioUnit -2 and 3 mekirirygiygyuguiguihiiqio
Unit -2 and 3 mekirirygiygyuguiguihiiqio
 
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdfIntel8086_Flags_Addr_Modes_sample_pgms.pdf
Intel8086_Flags_Addr_Modes_sample_pgms.pdf
 
Lecture 4 (8051 instruction set) rv01
Lecture 4 (8051 instruction set) rv01Lecture 4 (8051 instruction set) rv01
Lecture 4 (8051 instruction set) rv01
 
13229286.ppt
13229286.ppt13229286.ppt
13229286.ppt
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
instructions set of 8051.pdf
instructions set of 8051.pdfinstructions set of 8051.pdf
instructions set of 8051.pdf
 
Microprocessor system - summarize
Microprocessor system - summarizeMicroprocessor system - summarize
Microprocessor system - summarize
 
microprocessor and microcontroller notes ppt
microprocessor and microcontroller notes pptmicroprocessor and microcontroller notes ppt
microprocessor and microcontroller notes ppt
 
5th unit Microprocessor 8085
5th unit Microprocessor 80855th unit Microprocessor 8085
5th unit Microprocessor 8085
 
8051d
8051d8051d
8051d
 
8051 data type and directives
8051 data type and directives8051 data type and directives
8051 data type and directives
 
8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directives
 
module-3.pptx
module-3.pptxmodule-3.pptx
module-3.pptx
 
The 8051 microcontroller
The 8051 microcontrollerThe 8051 microcontroller
The 8051 microcontroller
 
Pdemodule 4
Pdemodule 4Pdemodule 4
Pdemodule 4
 
Unit 2 Instruction set.pdf
Unit 2 Instruction set.pdfUnit 2 Instruction set.pdf
Unit 2 Instruction set.pdf
 
addressingmodes8051.ppt
addressingmodes8051.pptaddressingmodes8051.ppt
addressingmodes8051.ppt
 
Computer architecture 3
Computer architecture 3Computer architecture 3
Computer architecture 3
 
Uc 2(vii)
Uc 2(vii)Uc 2(vii)
Uc 2(vii)
 

Recently uploaded

Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
Areesha Ahmad
 
Conjugation, transduction and transformation
Conjugation, transduction and transformationConjugation, transduction and transformation
Conjugation, transduction and transformation
Areesha Ahmad
 
POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.
Silpa
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
seri bangash
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Sérgio Sacani
 
Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.
Silpa
 

Recently uploaded (20)

GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
Stages in the normal growth curve
Stages in the normal growth curveStages in the normal growth curve
Stages in the normal growth curve
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
 
An introduction on sequence tagged site mapping
An introduction on sequence tagged site mappingAn introduction on sequence tagged site mapping
An introduction on sequence tagged site mapping
 
Use of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptxUse of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptx
 
Conjugation, transduction and transformation
Conjugation, transduction and transformationConjugation, transduction and transformation
Conjugation, transduction and transformation
 
POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.POGONATUM : morphology, anatomy, reproduction etc.
POGONATUM : morphology, anatomy, reproduction etc.
 
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICEPATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
 
Exploring Criminology and Criminal Behaviour.pdf
Exploring Criminology and Criminal Behaviour.pdfExploring Criminology and Criminal Behaviour.pdf
Exploring Criminology and Criminal Behaviour.pdf
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
 
Selaginella: features, morphology ,anatomy and reproduction.
Selaginella: features, morphology ,anatomy and reproduction.Selaginella: features, morphology ,anatomy and reproduction.
Selaginella: features, morphology ,anatomy and reproduction.
 
module for grade 9 for distance learning
module for grade 9 for distance learningmodule for grade 9 for distance learning
module for grade 9 for distance learning
 
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
 
Zoology 5th semester notes( Sumit_yadav).pdf
Zoology 5th semester notes( Sumit_yadav).pdfZoology 5th semester notes( Sumit_yadav).pdf
Zoology 5th semester notes( Sumit_yadav).pdf
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
 
Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.
 
Factory Acceptance Test( FAT).pptx .
Factory Acceptance Test( FAT).pptx       .Factory Acceptance Test( FAT).pptx       .
Factory Acceptance Test( FAT).pptx .
 
Velocity and Acceleration PowerPoint.ppt
Velocity and Acceleration PowerPoint.pptVelocity and Acceleration PowerPoint.ppt
Velocity and Acceleration PowerPoint.ppt
 
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
 

8051 microcontroller

  • 1. S. Y. B. Sc. (Computer Science) SEM – III Electronics Paper I Microcontroller Architecture & Programming Presentation By Mrs. Neeta Gatkal Head, Department of Electronics Pratibha College of Computer and Computer Studies,Chinchwad
  • 2. Objectives ● To study the basics of 8051microcontroller ● To study the Programming of 8051 ● To study the interfacing techniques of 8051 ● To design different application circuits using 8051
  • 3. Course Outcomes 1. To write programs for 8051 microcontroller 2. To interface I/O peripherals to 8051 microcontroller 3. To design small microcontroller based projects
  • 4. UNIT- 2 Programming model of 8051  Instruction classification and Instruction set  Addressing Modes,(Immediate, register, direct, indirect and relative)  assembler directives (ORG, END), features with examples  I/O Bit & Byte programming using assembly language for LED and seven segment display (SSD) interfacing  Introduction to 8051 programming in C
  • 5. Structure of the 8051 Microcontroller Instruction ● An 8051 Instruction consists of an Opcode (short of Operation – Code) followed by Operand(s) of size Zero Byte, One Byte or Two Bytes. ● The Op-Code part of the instruction contains the Mnemonic, which specifies the type of operation to be performed. All Mnemonics or the Opcode part of the instruction are of One Byte size. ● An Assembly language instruction consists of four fields: [label:] Mnemonic [operands] [;comment] E.g MOV A,#55H ;load 55H into A HERE: SJMP HERE
  • 6. ● Data transfer instructions. ● Arithmetic instructions ● Logical Instructions ● Program Branching Instructions ● Bit manipulation instructions Types of Instructions in 8051 MC
  • 7. Data Transfer Instructions ● The Data Transfer Instructions are associated with transfer with data between registers or external program memory or external data memory. The Mnemonics associated with Data Transfer are given below. ● MOV ● MOVC ● MOVX ● PUSHPOP ● XCH ● XCHD unit5.pdf
  • 8. Arithmetic Instructions ● Using Arithmetic Instructions, you can perform addition, subtraction, multiplication and division. The arithmetic instructions also include increment by one, decrement by one and a special instruction called Decimal Adjust Accumulator. ● The arithmetic instructions has no knowledge about the data format i.e. signed, unsigned, ASCII, BCD, etc. Also, the operations performed by the arithmetic instructions affect flags like carry, overflow, zero, etc. in the PSW Register. ● The Mnemonics associated with the Arithmetic Instructions of the 8051 Microcontroller Instruction Set are: ● ADD ADDC ● SUBB INC ● DEC MUL ● DIV DA A ● unit5.pdf
  • 9. Logical Instructions ● The next group of instructions are the Logical Instructions, which perform logical operations like AND, OR, XOR, NOT, Rotate, Clear and Swap. Logical Instruction are performed on Bytes of data on a bit-by-bit basis. Mnemonics associated with Logical Instructions are as follows: ANL ORL XRL CLR CPL RL RLC RR RRC SWAP unit5.pdf
  • 10. Program Branching Instructions ● These instructions control the flow of program logic. ● All these instructions, except the NOP (No Operation) affect the Program Counter (PC) in one way or other. Some of these instructions has decision making capability before transferring control to other part of the program. ● The mnemonics of the Program Branching Instructions are as follows. ● LJMP AJMP ● SJMP JZ ● JNZ CJNE ● DJNZ NOP ● LCALL ACALL ● RET RETI ● JMP unit5.pdf
  • 11. Bit manipulation instructions ● As the name suggests, Boolean or Bit Manipulation Instructions will deal with bit variables. We know that there is a special bit-addressable area in the RAM and some of the Special Function Registers (SFRs) are also bit addressable. ● The Mnemonics corresponding to the Boolean or Bit Manipulation instructions are: ● CLR SETB ● MOV JC ● JNC JB ● JNB JBC ● ANL ORL ● CPL unit5.pdf
  • 12. ADDRESSING MODES  The CPU can access data in various ways, which are called addressing modes  Immediate  Register  Direct  Register indirect  Indexed
  • 13. IMMEDIATE ADDRESSING MODE  The source operand is a constant  The immediate data must be preceded by the pound sign, “#”  Can load information into any registers, including 16-bit DPTR register  DPTR can also be accessed as two 8-bit registers, the high byte DPH and low byte DPL  We can also use immediate addressing mode to send data to 8051 ports MoV A,#25H ;load 25H into A MOV R4,#62 ;load 62 into R4 MOV B,#40H ;load 40H into B MOV DPTR,#4521H ; DPTR=4512H MOV DPL,#21H ;This is the same MOV DPH,#45H ;as above
  • 14. REGISTER ADDRESSING MODE  Use registers to hold the data to be manipulated  The source and destination registers must match in size  MOV DPTR,A will give an error  The movement of data between Rn registers is not allowed  MOV R4,R7 isinvalid MOV A,R0 MOV R2,A ADD A,R5 ADD A,R7 MOV R6,A ;copy contents of R0 into A ;copy contents of A into R2 ;add contents of R5 to A ;add contents of R7 to A ;save accumulator in R6 MOV DPTR,#25F5H MOV R7,DPL MOV R6,DPH
  • 15. Direct Addressing Mode  It is most often used the direct addressing mode to access RAM locations 30 – 7FH  The entire 128 bytes of RAM can be accessed.  The register bank locations are accessed by the register names MOV A,4 MOV A,R4 ;is same as ;which means copy R4 into A  Contrast this with immediate addressing mode  There is no “#” sign in the operand MOV R0,40H MOV 56H,A ;save content of 40H in R0 ;save content of A in 56H
  • 16. Register Indirect Addressing Mode  A register is used as a pointer to the data  Only register R0 and R1 are used for this purpose  R2 – R7 cannot be used to hold the address of an operand located in RAM  When R0 and R1 hold the addresses of RAM locations, they must be preceded by the “@” sign MOV A,@R0 MOV @R1,B ;move contents of RAM whose ;address is held by R0 into A ;move contents of B into RAM ;whose address is held by R1  R0 and R1 are the only registers that can be used for pointers in register indirect addressing mode  Since R0 and R1 are 8 bits wide, their use is limited to access any information in the internal RAM  Whether accessing externally connected RAM or on-chip ROM, we need 16-bit pointer  In such case, the DPTR register is used
  • 17. IndexAddressing Mode  Indexed addressing mode is widely used in accessing data elements of look-up table entries located in the program ROM  The instruction used for this purpose is ● MOVC A,@A+DPTR  Use instruction MOVC, “C” means code  The contents of A are added to the 16-bit register DPTR to form the 16-bit address of the needed data
  • 18. Assembler Directives  DB(define byte) : The DB directive is the most widely used data directive in the assembler  It is used to define the 8-bit data  When DBis used to define data, the numbers can be in decimal, binary, hex, ASCII format. ORG 500H DATA1: DB DATA2: DB DATA3: DB 28 00110101B 39H ;DECIMAL (1C in Hex) ;BINARY (35 in Hex) ;HEX ;ASCII NUMBERS ORG DATA4: DB ORG 510H “2591” 518H DATA6: DB “My name is Joe” ;ASCII CHARACTERS The “D” after the decimal number is optional, but using “B” (binary) and “H” (hexadecimal) for the others is required The Assembler will convert the numbers into hex Place ASCII in quotation marks The Assembler will assign ASCII code for the numbers or characters Define ASCII strings larger than two characters
  • 19.  ORG(origin)  The ORGdirective is used to indicate the beginning of the address  The number that comes after ORGcan be either in hex and decimal  If the number is not followed by H, it is decimal and the assembler will convert it to hex  END  This indicates to the assembler the end of the source (asm) file  The ENDdirective is the last line of an 8051 program  Mean that in the code anything after the END directive is ignored by the assembler  EQU(equate)  This is used to define a constant without occupying a memory location  The EQU directive does not set aside storage for a data item but associates a constant value with a data label  When the label appears in the program, its constant value will be substituted for the label
  • 20. I/O Bit & Byte programming  Instructions that are used for signal-bit operations are as following Single-Bit Instructions Instruction Function SETB bit Set the bit (bit = 1) CLR bit Clear the bit (bit = 0) CPL bit Complement the bit (bit = NOT bit) JB bit, target Jump to target if bit = 1 (jump if bit) JNB bit, target Jump to target if bit = 0 (jump if no bit) JBC bit, target Jump to target if bit = 1, clear bit (jump if bit, then clear)  The JNB and JB instructions are widely used single-bit operations Mnemonic Examples Description MOV A,PX MOV A,P2 Bring into A the data at P2 pins JNB PX.Y, .. JNB P2.1,TARGET Jump if pin P2.1 is low JB PX.Y, .. JB P1.3,TARGET Jump if pin P1.3 is high MOV C,PX.Y MOV C,P2.4 Copy status of pin P2.4 to CY
  • 21. Example 4-3 Write a program to perform the following: (a) Keep monitoring the P1.2 bit until it becomes high (b) When P1.2 becomes high, write value 45H to port 0 (c) Send a high-to-low (H-to-L) pulse to P2.3 Solution: SETB MOV P1.2 A,#45H ;make P1.2 an input ;A=45H AGAIN: JNB P1.2,AGAIN ; get out when P1.2=1 MOV P0,A ;issue A to P0 SETB P2.3 ;make P2.3 high CLR P2.3 ;make P2.3 low for H-to-L