Professional Documents
Culture Documents
MPMC-Unit-2 NOTES
MPMC-Unit-2 NOTES
MICROCONTROLLERS
Microprocessors
CPU for Computers
No RAM,ROM,I/O on CPU chip It self
Example: Intel's x86, Motorola’s 680x0
What is Microcontroller?
Micro Controller
• Speed
• Packaging
• Power consumption
I/O PORTS:
The 8051 has four important ports. Port 0, Port 1, Port 2 and Port 3. These ports
allow the microcontroller to connect with the outside world. The four ports of 8051
microcontrollers have certain specific functions and corresponding features. In this
post, we will take a gander at the purpose of each of these ports.
Each port has 8 pins. Thus the four ports jointly comprise 32 pins.
All ports are bidirectional.
They are constructed with a D type output latch. They have output drivers and
input buffers.
We can modify their functions using software and hardware that they connect to.
All the ports are configured as input ports on Reset.
To configure ports as an input port 1 must be written to that port
To configure it as an output port 0 must be written to it.
o In the 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. Interrupt is a sub-routine call that given by the microcontroller
Dilshad SK CMR Technical Campus
when some other program with high priority is request for acquiring the system
buses the n interrupts occurs in current running program. Address Bus 8051
microcontrollers is consisting of 16 bit address bus. It is generally be used for
transferring the data from Central Processing Unit to Memory.
o Data bus: 8051 microcontroller is consisting of 8 bits data bus. It is generally be
used for transferring the data from one peripherals position to other peripherals.
A or ACC
B
DPL
DPH
IE
IP
P0
P1
P2
P3
PCON
PSW
SCON
SBUF
All the 21 8051 Microcontroller Special Function Registers (SFRs) along with their functions and
Internal RAM Address is given in the following table.
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)
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.
A value stored in the Stack Pointer points to the first free stack address and permits stack
availability.
Stack pushes increment the value in the Stack Pointer by 1. Likewise, stack pops decrement
its value by 1. Upon any reset and power-on, the value 7 is stored in the Stack Pointer, which
means that the space of RAM reserved for the stack starts at this location. If another value is
written to this register, the entire Stack is moved to the new memory location.
1 = Timer1 overflow occurred (i.e. Timer1 goes to its max and roll over back to zero).
It is cleared through software. In the Timer1 overflow interrupt service routine, this bit will get cleared
automatically while exiting from ISR.
1 = Timer1 start.
0 = Timer1 stop.
1 = Timer0 overflow occurred (i.e. Timer0 goes to its max and roll over back to zero).
It is cleared through software. In the Timer0 overflow interrupt service routine, this bit will get cleared
1 = Timer0 start.
0 = Timer0 stop.
TMOD (Timer Mode register): 8-bit register used to select timer mode. There are 4 modes in
which timer can be loaded.
TH0/TL0->Timer 0 16 bit register (byte addressable only) 8 bits can be send at a time.
TH1/TL1-> Timer 1 16 bit register (byte addressable only) 8 bits can be send at a time.
TMOD register is an 8-bit register used to set timer mode of timer0 and timer1 .
Its lower 4 bits are used for Timer0 and the upper 4 bits are used for Timer1
Bit 7,3 – GATE:
1 = Enable Timer/Counter only when the INT0/INT1 pin is high and TR0/TR1 is set.
MOVA, R5;
MOVR2, #45H;
MOVR0, A;
3. Direct Addressing Mode
In the Direct Addressing Mode, the source or destination address is specified by using 8-bit data in the
instruction. Only the internal data memory can be used in this mode. Here some of the examples of
direct Addressing Mode.
MOV80H, R6;
MOVR2, 45H;
MOVR0, 05H;
In this mode, the source or destination address is given in the register. By using register indirect
addressing mode, the internal or external addresses can be accessed. The R0 and R1 are used for
8-bit addresses, and DPTR is used for 16-bit addresses, no other registers can be used for
addressing purposes. Let us see some examples of this mode.
MOV0E5H, @R0;
MOV@R1, 80H
In the instructions, the @ symbol is used for register indirect addressing. In the first instruction, it
is showing that theR0 register is used.
5. Indexed addressing mode: In the indexed addressing mode, the source memory can only
be accessed from program memory only. The destination operand is always the register A.
These are some examples of Indexed addressing mode.
MOVCA, @A+PC;
MOVCA, @A+DPTR;
In the implied addressing mode, there will be a single operand. These types of instruction can work on
specific registers only. These types of instructions are also known as register specific instruction. Here
are some examples of Implied Addressing Mode.
RLA
SWAPA;
These are 1- byte instruction. The first one is used to rotate the A register content to the Left. The
second one is used to swap the nibbles in A.
The instructions of 8051 Microcontroller can be classified into five different groups. These groups are
like below
ADDCA, direct Adds the direct byte to the accumulator with a carry flag
ADDCA,@Ri Adds the indirect RAMto the accumulator with a carry flag
ADDCA, data Adds the immediate data to the accumulator with a carry flag
SUBBA, direct Subtracts the direct byte from the accumulator with a borrow
SUBBA,#data Subtracts the immediate data from the accumulator with a borrow
INC A Increments the accumulator by 1
DIV AB Divides A by B
BranchInstructions
Mnemonic Description
ACALLaddr11 Absolute subroutine call
LCALLaddr16 Long Subroutine call
RET Returns from subroutine
RETI Returns from interrupt subroutine
AJMPaddr11 Absolute jump
LJMPaddr16 Long jump
Short jump ( from – 128 to +127 locations relative to the following
SJMPrel
instruction)
JBCbit,rel Jump if direct bit is set and clears bit. Short jump.
Compares immediate data to the register and jumps if notequal. Short jump.
CJNERn,#data,rel
DJNZRn,rel Decrements register and jumps if not 0. Short jump.
NOP No operation
Bit-oriented/Processing Instructions:
Mnemonic Description