Microcontroller 8051 - Introduction
Microcontroller 8051 - Introduction
UNIT 4: MICROCONTROLLER
1. Architecture of 8051
8051 microcontroller is designed by Intel in 1981. It is an 8-bit microcontroller. It is built with 40 pins
DIP (dual inline package), 4kb of ROM storage and 128 bytes of RAM storage, 2 16-bit timers. It
consists of are four parallel 8-bit ports, which are programmable as well as addressable as per the
requirement. An on-chip crystal oscillator is integrated in the microcontroller having crystal frequency of
12 MHz.
In the following diagram, the system bus connects all the support devices to the CPU. The system bus
consists of an 8-bit data bus, a 16-bit address bus and bus control signals. All other devices like program
memory, ports, data memory, serial interface, interrupt control, timers, and the CPU are all interfaced
together through the system bus.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 1 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as input or output. Hence,
total 32 input/output pins allow the microcontroller to be connected with the peripheral devices.
Pin configuration, i.e. the pin can be configured as 1 for input and 0 for output as per the logic
state.
o Input/Output (I/O) pin − All the circuits within the microcontroller must be connected
to one of its pins except P0 port because it does not have pull-up resistors built-in.
o Input pin − Logic 1 is applied to a bit of the P register. The output FE transistor is
turned off and the other pin remains connected to the power supply voltage over a pull-
up resistor of high resistance.
Port 0 − The P0 (zero) port is characterized by two functions −
o When the external memory is used then the lower address byte (addresses A0A7) is
applied on it, else all bits of this port are configured as input/output.
o When P0 port is configured as an output then other ports consisting of pins with built-in
pull-up resistor connected by its end to 5V power supply, the pins of this port have this
resistor left out.
Input Configuration
If any pin of this port is configured as an input, then it acts as if it “floats”, i.e. the input has unlimited
input resistance and in-determined potential.
Output Configuration
When the pin is configured as an output, then it acts as an “open drain”. By applying logic 0 to a port bit,
the appropriate pin will be connected to ground (0V), and applying logic 1, the external output will keep
on “floating”.
In order to apply logic 1 (5V) on this output pin, it is necessary to build an external pullup resistor.
Port 1: P1 is a true I/O port as it doesn’t have any alternative functions as in P0, but this port can be
configured as general I/O only. It has a built-in pull-up resistor and is completely compatible with TTL
circuits.
Port 2: P2 is similar to P0 when the external memory is used. Pins of this port occupy addresses intended
for the external memory chip. This port can be used for higher address byte with addresses A8-A15.
When no memory is added then this port can be used as a general input/output port similar to Port 1.
Port 3: In this port, functions are similar to other ports except that the logic 1 must be applied to
appropriate bit of the P3 register.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 2 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
Pins Current Limitations
When pins are configured as an output (i.e. logic 0), then the single port pins can receive a
current of 10mA.
When these pins are configured as inputs (i.e. logic 1), then built-in pull-up resistors provide very
weak current, but can activate up to 4 TTL inputs of LS series.
If all 8 bits of a port are active, then the total current must be limited to 15mA (port P0: 26mA).
If all ports (32 bits) are active, then the total maximum current must be limited to 71mA.
Interrupts are the events that temporarily suspend the main program, pass the control to the external
sources and execute their task. It then passes the control to the main program where it had left off.
8051 has 5 interrupt signals, i.e. INT0, TFO, INT1, TF1, RI/TI. Each interrupt can be enabled or
disabled by setting bits of the IE register and the whole interrupt system can be disabled by clearing the
EA bit of the same register.
IE (Interrupt Enable) Register
This register is responsible for enabling and disabling the interrupt. EA register is set to one for enabling
interrupts and set to 0 for disabling the interrupts. Its bit sequence and their meanings are shown in the
following figure.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 3 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
PS IP.4 It defines the serial port interrupt priority level.
Out of these 128 Memory Locations (80H to FFH), there are only 21 locations that are actually assigned
to SFRs. Each SFR has one Byte Address and also a unique name which specifies its purpose.
Since the SFRs are a part of the Internal RAM Structure, you can access SFRs as if you access the
Internal RAM. The main difference is the address space: first 128 Bytes (00H to 7FH) is for regular
Internal RAM and next 128 Bytes (80H to FFH) is for SFRs.
TIP: As only 21 of the possible 128 SFR memory locations are assigned, it is recommended that the
remaining registers or memory locations are not accessed during programming.
A or ACC
B
DPL
DPH
IE
IP
P0
P1
P2
P3
PCON
PSW
SCON
SBUF
SP
TMOD
TCON
TL0
TH0
TL1
TH1
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 4 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
Categories of 8051 Microcontroller Special Function Registers
All the 21 8051 Microcontroller Special Function Registers (SFRs) along with their functions and Internal
RAM Address is given in the following table.
There are many ways to categorize these 21 Special Function Registers but I find the following way as an
appropriate one. The 21 Special Function Registers of 8051 Microcontroller are categorized in to seven
groups. They are:
Pointer Registers: DPTR (Data Pointer – DPL, DPH) and SP (Stack Pointer)
I/O Port Latches: P0 (Port 0), P1 (Port 1), P2 (Port 2) and P3 (Port 3)
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 5 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
A or Accumulator (ACC)
The Accumulator or Register A is the most important and most used 8051 Microcontroller SFRs. The
Register A is located at the address E0H in the SFR memory space. The Accumulator is used to hold the
data for almost all the ALU Operations.
The name “Accumulator” came from the fact this register is used to accumulate (or store) the result of all
Arithmetic and most of the Logical Operations.
B (Register B)
The B Register is used along with the ACC in Multiplication and Division operations. These two
operations are performed on data that are stored only in Registers A and B. During Multiplication
Operation, one of the operand (multiplier or multiplicand) is stores in B Register and also the higher byte
of the result.
In case of Division Operation, the B Register holds the divisor and also the remainder of the result. It can
also be used as a General Purpose Register for normal operations and is often used as an Auxiliary
Register by Programmers to store temporary results.
The PSW or Program Status Word Register is also called as Flag Register and is one of the important
SFRs. The PSW Register consists of Flag Bits, which help the programmer in checking the condition of
the result and also make decisions.
Flags are 1-bit storage elements that store and indicate the nature of the result that is generated by
execution of certain instructions. The following image shows the contents of the PSW Register.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 6 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
Pointer Registers
Data Pointer (DPTR – DPL and DPH)
The Data Pointer is a 16-bit Register and is physically the combination of DPL (Data Pointer Low) and
DPH (Data Pointer High) SFRs. The Data Pointer can be used as a single 16-bit register (as DPTR) or
two 8-bit registers (as DPL and DPH).
DPTR doesn’t have a physical Memory Address but the DPL (Lower Byte of DPTR) and DPH (Higher
Byte of DPTR) have separate addresses in the SFR Memory Space. DPL = 82H and DPH = 83H.
The DPTR Register is used by the programmer addressing external memory (Program – ROM or Data –
RAM).
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 7 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
SP or Stack Pointer points out to the top of the Stack and it indicates the next data to be accessed. Stack
Pointer can be accesses using PUSH, POP, CALL and RET Instructions. The Stack Pointer is an 8-bit
register and upon reset, the Stack Pointer is initialized with 07H.
When writing a new data byte into the stack, the SP (Stack Pointer) is automatically incremented by 1 and
the new data is written at an address SP+1. When reading data from stack, the data is retrieved from the
Address in SP and after that the SP is decremented by 1 (SP-1).
Each bit in these SFRs corresponds to one physical Pin in the 8051 Microcontroller. All these Port
Registers are both Bit Addressable and Byte Addressable. Writing 1 or 0 on a Port Register Bit will
reflect as an appropriate voltage (5V and 0V) on the corresponding Pin.
If a Port Bit is SET (declared as 1), the corresponding Port Pin will be configured as Input and similarly if
a Port Bit is CLEARED (declared as 0), the corresponding Port Pin is configured as Output. Upon reset,
all the Port Bits are SET (1) and hence, all the Port Pins are configured as Inputs.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 8 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
The PCON or Power Control register, as the name suggests is used to control the 8051 Microcontroller’s
Power Modes and is located at 87H of the SFR Memory Space. Using two bits in the PCON Register, the
microcontroller can be set to Idle Mode and Power Down Mode.
During Idle Mode, the Microcontroller will stop the Clock Signal to the ALU (CPU) but it is given to
other peripherals like Timer, Serial, Interrupts, etc. In order to terminate the Idle Mode, you have to use
an Interrupt or Hardware Reset.
In the Power Down Mode, the oscillator will be stopped and the power will be reduced to 2V. To
terminate the Power Down Mode, you have to use the Hardware Reset.
Apart from these two, the PCON Register can also be used for few additional purposes. The SMOD Bit in
the PCON Register is used to control the Baud Rate of the Serial Port.
There are two general purpose Flag Bits in the PCON Register, which can be used by the programmer
during execution.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 9 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
The Serial Control or SCON SFR is used to control the 8051 Microcontroller’s Serial Port. It is located as
an address of 98H. Using SCON, you can control the Operation Modes of the Serial Port, Baud Rate of
the Serial Port and Send or Receive Data using Serial Port.
SCON Register also consists of bits that are automatically SET when a byte of data is transmitted or
received.
Timer Control or TCON Register is used to start or stop the Timers of 8051 Microcontroller. It also
contains bits to indicate if the Timers has overflowed. The TCON SFR also consists of Interrupt related
bits.
The TMOD or Timer Mode register or SFR is used to set the Operating Modes of the Timers T0 and T1.
The lower four bits are used to configure Timer0 and the higher four bits are used to configure Timer1.
The Gatex bit is used to operate the Timerx with respect to the INTx pin or regardless of the INTx pin.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 10 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
GATE1 = 0 ==> Timer1 is operates irrespective of INT1 pin.
The C/Tx bit is used selects the source of pulses for the Timer to count.
C/T1 = 1 ==> Timer1 counts pulses from Pin T1 (P3.5) (Counter Mode)
C/T1 = 0 ==> Timer1 counts pulses from internal oscillator (Timer Mode)
C/T0 = 1 ==> Timer0 counts pulses from Pin T0 (P3.4) (Counter Mode)
C/T0 = 0 ==> Timer0 counts pulses from internal oscillator (Timer Mode)
IE (Interrupt Enable)
The IE or Interrupt Enable Register is used to enable or disable individual interrupts. If a bit is SET, the
corresponding interrupt is enabled and if the bit is cleared, the interrupt is disabled. The Bit7 of the IE
register i.e. EA bit is used to enable or disable all the interrupts.
IP (Interrupt Priority)
The IP or Interrupt Priority Register is used to set the priority of the interrupt as High or Low. If a bit is
CLEARED, the corresponding interrupt is assigned low priority and if the bit is SET, the interrupt is
assigned high priority.
The Serial Buffer or SBUF register is used to hold the serial data while transmission or reception.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 11 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
The Timer 0 consists of two SFRs: TL0 and TH0. The TL0 is the lower byte and the TH0 is the higher
byte and together they form a 16-bit Timer0 Register.
The TL1 and TH1 are the lower and higher bytes of the Timer 0.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 12 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
Just as our sentences are made of words, a Microcontroller’s (for that matter, any computer) program is
made of Instructions. Instructions written in a program tell the Microcontroller which operation to carry
out.
An Instruction Set is unique to a family of computers. This tutorial introduces the 8051 Microcontroller
Instruction Set also called as the MCS-51 Instruction Set.
As the 8051 family of Microcontrollers are 8-bit processors, the 8051 Microcontroller Instruction Set is
optimized for 8-bit control applications. As a typical 8-bit processor, the 8051 Microcontroller
instructions have 8-bit Opcodes. As a result, the 8051 Microcontroller instruction set can have up to 2 8 =
256 Instructions.
The following table shows the 8051 Instruction Groups and Instructions in each group. There are 49
Instruction Mnemonics in the 8051 Microcontroller Instruction Set and these 49 Mnemonics are divided
into five groups.
DATA PROGRAM
ARITHMETIC LOGICAL BOOLEAN
TRANSFER BRANCHING
DA A RR JBC NOP
CPL RET
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 13 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
RETI
JMP
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.
Coming to the Operand part of the instruction, it defines the data being processed by the instructions. The
operand can be any of the following:
No Operand
Data value
I/O Port
Memory Location
CPU register
A simple instruction consists of just the opcode. Other instructions may include one or more operands.
Instruction can be one-byte instruction, which contains only opcode, or two-byte instructions, where the
second byte is the operand or three byte instructions, where the operand makes up the second and third
byte.
Based on the operation they perform, all the instructions in the 8051 Microcontroller Instruction Set are
divided into five groups. They are:
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
PUSH
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 14 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
POP
XCH
XCHD
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 Mnemonics associated with the Arithmetic Instructions of the 8051 Microcontroller Instruction Set
are:
ADD
ADDC
SUBB
INC
DEC
MUL
DIV
DA A
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.
All the possible Mnemonics associated with Arithmetic Instructions are mentioned in the following table.
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.
ANL
ORL
XRL
CLR
CPL
RL
RLC
RR
RRC
SWAP
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.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 15 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
The Mnemonics corresponding to the Boolean or Bit Manipulation instructions are:
CLR
SETB
MOV
JC
JNC
JB
JNB
JBC
ANL
ORL
CPL
These instructions can perform set, clear, and, or, complement etc. at bit level.
The last group of instructions in the 8051 Microcontroller Instruction Set are the Program Branching
Instructions. These instructions control the flow of program logic. The mnemonics of the Program
Branching Instructions are as follows.
LJMP
AJMP
SJMP
JZ
JNZ
CJNE
DJNZ
NOP
LCALL
ACALL
RET
RETI
JMP
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.
In this tutorial, we have seen the introduction to the 8051 Microcontroller Instruction Set, Addressing
Modes in 8051 Microcontroller and different types of instructions in the Instruction Set of the 8051
Microcontroller.
Immediate Addressing
Register Addressing
Direct Addressing
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 16 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
Register – Indirect Addressing
Indexed Addressing
Immediate Addressing
In Immediate Addressing mode, the operand, which follows the Opcode, is a constant data of either 8 or
16 bits. The name Immediate Addressing came from the fact that the constant data to be stored in the
memory immediately follows the Opcode.
The constant value to be stored is specified in the instruction itself rather than taking from a register. The
destination register to which the constant data must be copied should be the same size as the operand
mentioned in the instruction.
Here, the Accumulator is loaded with 30 (hexadecimal). The # in the operand indicates that it is a data
and not the address of a Register.
Immediate Addressing is very fast as the data to be loaded is given in the instruction itself.
Register Addressing
In the 8051 Microcontroller Memory Organization Tutorial, we have seen the organization of RAM and
four banks of Working Registers with eight Registers in each bank.
In Register Addressing mode, one of the eight registers (R0 – R7) is specified as Operand in the
Instruction.
It is important to select the appropriate Bank with the help of PSW Register. Let us see a example of
Register Addressing assuming that Bank0 is selected.
Example: MOV A, R5
Here, the 8-bit content of the Register R5 of Bank0 is moved to the Accumulator.
Direct Addressing
In Direct Addressing Mode, the address of the data is specified as the Operand in the instruction. Using
Direct Addressing Mode, we can access any register or on-chip variable. This includes general purpose
RAM, SFRs, I/O Ports, Control registers.
Here, the data in the RAM location 47H is moved to the Accumulator.
In the Indirect Addressing Mode or Register Indirect Addressing Mode, the address of the Operand is
specified as the content of a Register. This will be clearer with an example.
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 17 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
Example: MOV A, @R1
The @ symbol indicates that the addressing mode is indirect. If the contents of R1 is 56H, for example,
then the operand is in the internal RAM location 56H. If the contents of the RAM location 56H is 24H,
then 24H is moved into accumulator.
Only R0 and R1 are allowed in Indirect Addressing Mode. These register in the indirect addressing mode
are called as Pointer registers.
With Indexed Addressing Mode, the effective address of the Operand is the sum of a base register and an
offset register. The Base Register can be either Data Pointer (DPTR) or Program Counter (PC) while the
Offset register is the Accumulator (A).
In Indexed Addressing Mode, only MOVC and JMP instructions can be used. Indexed Addressing Mode
is useful when retrieving data from look-up tables.
Here, the address for the operand is the sum of contents of DPTR and Accumulator.
Assembler Directives
Instruction Set
Addressing Modes
Assembler Directives:
The assembling directives give the directions to the CPU. The 8051 microcontroller consists of various
kinds of assembly directives to give the direction to the control unit. The most useful directives are 8051
programming, such as:
ORG
DB
EQU
END
ORG(origin): This directive indicates the start of the program. This is used to set the register address
during assembly. For example; ORG 0000h tells the compiler all subsequent code starting at address
0000h.
Syntax: ORG 0000h
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 18 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
DB(define byte): The define byte is used to allow a string of bytes. For example, print the “EDGEFX”
wherein each character is taken by the address and finally prints the “string” by the DB directly with
double quotes.
Syntax:
ORG 0000h
MOV a, #00h
————-
————-
DB”EDGEFX”
EQU (equivalent): The equivalent directive is used to equate address of the variable.
Syntax:
reg equ,09h
—————–
—————–
MOV reg,#2h
END:The END directive is used to indicate the end of the program.
Syntax:
reg equ,09h
—————–
—————–
MOV reg,#2h
END
Addressing Modes:
The way of accessing data is called addressing mode. The CPU can access the data in different ways by
using addressing modes. The 8051 microcontroller consists of five addressing modes such as:
Immediate Addressing Mode
Register Addressing Mode
Direct Addressing Mode
Indirect Addressing Mode
Base Index Addressing Mode
Immediate Addressing Mode:
In this addressing mode, the source must be a value that can be followed by the ‘#’ and destination must
be SFR registers, general purpose registers and address. It is used for immediately storing the value in the
memory registers.
Syntax:
MOV A, #20h //A is an accumulator register, 20 is stored in the A//
MOV R0,#15 // R0 is a general purpose register; 15 is stored in the R0 register//
MOV P0, #07h //P0 is a SFR register;07 is stored in the P0//
MOV 20h,#05h //20h is the address of the register; 05 stored in the 20h//
Ex:
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 19 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
MOV R0, #1
MOV R0, #20 //R0 <—R0[15]+20, the final value is stored in R0//
EX:
MOV R0, #02h
MOV A, #30h
ADD R0, A //R0<—R0+A, the final value is stored in the R0 register//
Syntax:
MOV A,20h // 20h is an address; A is a register//
MOV 00h, 07h // both are addressed of the GPS registers//
Ex:
MOV 07h,#01h
MOV A, #08h
ADD A,07h //A<—A+07h the final value is stored in A//
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 20 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
In this addressing mode, the source or destination (or destination or source) must be a indirect address,
but not a value. This addressing mode supports the pointer concept. The pointer is a variable that is used
to store the address of the other variable. This pointer concept is only used for R0 and R1 registers.
Syntax:
MOVR0, #01h //01 value is stored in the R0 register, R0 address is 08h//
MOV R1, #08h//R1 is the pointer variable that stores address (08h) of R0 //
MOV 20h,@R1 //01 value is stored in the 20h address of the GP register//
Addition
Multiplication
Subtraction
Division
Addition:
ORG 0000h
MOV R0, #03H // move the value 3 to the register R0//
MOV A, #05H // move the value 5 to accumulator A//
Add A, 00H // addA value with R0 value and stores the result inA//
END
Multiplication:
ORG 0000h
MOV R0, #03H // move the value 3 to the register R0//
MOV A, #05H // move the value 5 to accumulator A//
MUL A, 03H // Multiplied result is stored in the Accumulator A //
END
Subtraction:
ORG 0000h
MOV R0, #03H // move the value 3 to register R0//
MOV A, #05H // move the value 5 to accumulator A//
SUBB A, 03H // Result value is stored in the Accumulator A //
END
Division:
ORG 0000h
MOV R0, #03H // move the value 3 to register R0//
MOV A, #15H // move the value 5 to accumulator A//
DIV A, 03H // final value is stored in the Accumulator A //
END
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 21 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
Conditional Instructions
The CPU executes the instructions based on the condition by checking the single bit status or byte status.
The 8051 microcontroller consists of various conditional instructions such as:
JB —>Jump below
JNB —> Jump if not below
JC —> Jump if Carry
JNC —>Jump if not Carry
JZ —>Jump if Zero
JNZ —> Jump if not Zero
Call and Jump Instructions: The call and jump instructions are used to avoid the code replication of the
program. When some specific code used more than once in different places in the program, if we
mention specific name to code then we could use that name anywhere in the program without entering a
code for every time. This reduces the complexity of the program. The 8051 programming consists of call
and jump instructions such as LCALL, SJMP.
Shifting Operators
The shift operators are used for sending and receiving the data efficiently. The
8051 microcontroller consist four shift operators:
RR —> Rotate Right
RRC —>Rotate Right through carry
RL —> Rotate Left
RLC —>Rotate Left through carry
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 22 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
Rotate Right (RR):
In this shifting operation, the MSB becomes LSB and all bits shift towards right side bit-by-bit, serially.
Syntax:
MOV A, #25h
RR A
Syntax:
MOV A, #25h
RL A
Syntax:
MOV A, #27h
RRC A
Syntax:
MOV A, #27h
RLC A
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 23 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
Timer/Counter calculations and program using 8051 microcontroller
Serial Communication calculations and program using 8051 microcontroller
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 24 of 25
EC 1601 – Microprocessors and Microcontrollers Department of CSE 2022-2023
3. WAP to count the 250 pulses using mode0 count0
Syntax:
ORG 0000H
MOV TMOD, #50H //select the counter//
MOV TH0, #15 //move the counting pulses higher bit//
MOV TH1, #9FH //move the counting pulses, lower bit//
SET TR0 //ON the timer//
JNB $ //decrement the count value till zero//
CLR TF0 //clear the counter, flag bit//
CLR TR0 //stop the timer//
END
St. Joseph’s College of Engineering & St. Joseph’s Institute of Technology Page 25 of 25