0% found this document useful (0 votes)
77 views

Module 5

A microcontroller is a small, low-cost microcomputer designed to perform specific tasks in embedded systems. It contains a processor, memory like RAM and ROM, and peripherals like timers, counters, and serial ports integrated onto a single chip. Microcontrollers are categorized based on their memory configuration, bit size, instruction set, and other factors. Common examples include 8-bit, 16-bit, and 32-bit microcontrollers. Microcontrollers are widely used in devices that require automated control functions like appliances, medical devices, and more.

Uploaded by

Chippy T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Module 5

A microcontroller is a small, low-cost microcomputer designed to perform specific tasks in embedded systems. It contains a processor, memory like RAM and ROM, and peripherals like timers, counters, and serial ports integrated onto a single chip. Microcontrollers are categorized based on their memory configuration, bit size, instruction set, and other factors. Common examples include 8-bit, 16-bit, and 32-bit microcontrollers. Microcontrollers are widely used in devices that require automated control functions like appliances, medical devices, and more.

Uploaded by

Chippy T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 142

Microcomputer

A microcomputer is a complete computer on a small scale,


designed for use by one person at a time.
eg:Modern desktop computers,laptops, tablet PCs, and many
types of handheld devices, including mobile phones, pocket
calculators,, may all be considered examples of microcomputers
Microcontroller
● A microcontroller is a small and low-cost microcomputer, which is designed
to perform the specific tasks of embedded systems like displaying
microwave’s information, receiving remote signals, etc.
The general microcontroller consists of the processor, the memory (RAM, ROM,
EPROM), Serial ports, peripherals (timers, counters), etc.
Difference between Microprocessor and Microcontroller
Types of Microcontrollers

Microcontrollers are divided into various categories based on memory,


architecture, bits and instruction sets
Bit

Based on bit configuration, the microcontroller is further divided into three


categories.

● 8-bit microcontroller − used to execute arithmetic and logical operations


like addition, subtraction, multiplication division, etc. For example, Intel
8031 and 8051 are 8 bits microcontroller.
● 16-bit microcontroller − used to perform arithmetic and logical
operations where higher accuracy and performance is required. For
example, Intel 8096 is a 16-bit microcontroller.

● 32-bit microcontroller − used in automatically controlled appliances


like automatic operational machines, medical appliances, etc.
Memory

Based on the memory configuration, the microcontroller is further divided into


two categories.

● External memory microcontroller − they do not have a program memory


on the chip. For example: Intel 8031 microcontroller.
● Embedded memory microcontroller − all programs and data memory,
counters and timers, interrupts, I/O ports are embedded on the chip. For
example: Intel 8051 microcontroller.
Instruction Set

Based on the instruction set configuration, the microcontroller is further divided


into two categories.

● CISC − CISC stands for complex instruction set computer. It allows the
user to insert a single instruction as an alternative to many simple
instructions.
● RISC − RISC stands for Reduced Instruction Set Computers. It reduces
the operational time by shortening the clock cycle per instruction.
Applications of Microcontrollers

Microcontrollers are widely used in various different devices such as −

● Light sensing and controlling devices like LED.


● Temperature sensing and controlling devices like microwave oven,
chimneys.
● Fire detection and safety devices like Fire alarm.
Microcontrollers - 8051 Architecture
Basic components present internally inside 8051 Microcontroller architecture are:
● CPU (Central Processing Unit): It synchronizes and manages all processes that are
carried out in microcontroller.
● It interprets the program stored in ROM and carries out from storage and then
performs it projected duty.
● CPU manage the different types of registers available in 8051 microcontroller

Interrupts: Interrupts is a sub-routine call that given by the microcontroller when some
other program with high priority is request for acquiring the system buses.
Interrupts provide a method to postpone or delay the current process, performs a sub-
routine task and then restart the standard program again.
Types of interrupt in 8051 Microcontroller:
Let's see the five sources of interrupts in 8051 Microcontroller:

● Timer 0 overflow interrupt - TF0


● Timer 1 overflow interrupt - TF1
● External hardware interrupt - INT0
● External hardware interrupt - INT1
● Serial communication interrupt - RI/TI(receiver interrupt/transfer interrupt)
Memory:
● Microcontroller required memory for storage of data and operands for the short
duration.
● In microcontroller 8051 there is code or program memory of 4 KB that is it has 4
KB ROM and it also comprise of data memory (RAM) of 128 bytes.
Bus :
● Bus is a group of wires which uses as a communication canal or acts as means of
data transfer.
● The different bus configuration includes 8, 16 or more cables. Therefore, a bus
can bear 8 bits, 16 bits all together.
Types of buses in 8051 Microcontroller:
Let's see the two types of bus used in 8051 microcontroller:

● 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.
● 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.
Oscillator:
● As the microcontroller is digital circuit therefore it needs timer for their operation.
● To perform timer operation inside microcontroller it required externally connected
or on-chip oscillator.
● Microcontroller is used inside an embedded system for managing the function of
devices.
● Therefore, 8051 uses the two 16 bit counters and timers.
● For the operation of this timers and counters the oscillator is used inside
microcontroller.
Special function registers
there are certain registers 🡪they meant for certain specific operations. These
registers are called special function registers(SFRs)
Applications of 8051 microcontroller
• Energy Management:
• Touch screens:
• Automobiles:
• Medical Devices:
• Medical Devices:
Register Organization
● The register is the main part of the
microcontrollers and processors
● provide a fast way to collect and store data.
● Microcontrollers contain several types of registers that can be
classified according to their content or instructions that operate in
them.
Types of Registers

The 8051 microcontroller contains mainly two types of registers:

● General-purpose registers (Byte addressable registers)


● Special function registers (Bit addressable registers)
● The 8051 microcontroller consists of 256 bytes of RAM,
● such as 128 bytes for general purpose and 128 bytes for special function
registers (SFR) memory.
● The memory which is used for general purpose is called as RAM,
● and the memory used for SFR contains all the peripheral related registers
like Accumulator, ‘B’ register, Timers or Counters, and interrupt related
registers.
General Purpose Registers
● The general-purpose memory is called as the RAM of the 8051 microcontrollers,
which is divided into 3 areas such as

Banks

bit-addressable area

scratch-pad area.

The banks contain different general-purpose registers such as R0-R7, and all such
registers are byte-addressable registers that store or remove only 1-byte of data.
Banks and Registers

The B0, B1, B2, and B3 stand for banks, and each bank contains eight general-

purpose registers ranging from ‘R0’ to ‘R7’. All these registers are byte-addressable.

Data transfer between general-purpose registers to general-purpose registers is not

possible. These banks are selected by the Program Status Word (PSW) register.
PSW (Program Status Word) Register

● The PSW register is a bit and byte-addressable register.

● This register reflects the status of the operation that is carried out in the

controller.

● The PSW register determines bank selection by an RS1 and RS0, as

shown below. The physical address of the PSW starts from D0h and the

individual bits are accessed with D0h to D7h.


Carry Flag (C): The Address of the Carry flag is D7. This carry flag is
affected when the bit is generated from the 7th position.
When C=0 carry resets
C=1 carry sets
Auxillary Flag(AC): The address of the auxiliary carry is D5. This
auxiliary carry is affected when a bit is generated from the 3rd position to
the 4th position.
AC=0 auxiliary is reset
AC=1 auxiliary is set
Overflow Flag (OV): When a bit is generated from the 6th position to the 7th

position, then the overflow flag is affected.

OV=0 overflow flag resets

OV=1 overflow flag sets

Parity Flag (P): The address of the parity flag is D0. While performing
arithmetic operations, if the result is 1, then the parity flag is set – otherwise,
reset.
RS1 and RS0

The RS1 and RS0, the bits in the PSW register, are used to select different memory
locations (bank0 to bank4) in the RAM.
Special Function Registers (SFR)

● Special function registers are upper RAM

in the 8051 microcontrollers.

● These registers contain all peripherally related registers like P0, P1,

P2, P3, timers or counters, serial port, and interrupts-related

registers.

● The SFR register is implemented by bit-address registers and byte-

address registers.
Accumulator

● The accumulator which is also known as ACC or A is a bit as well as a

byte-addressable register by an address of the accumulator.

● If you want to use a bit-addressable register, you can use a single bit of

the register

● you can use an 8-bit of the accumulator as a byte-addressable register.

The accumulator holds the results of most Arithmetic and logical

operations.
B-Register

The B-register is a bit and byte-addressable register. You can access 1-bit or

all 8-bits. The B register is only used for multiplication and division operations.

Port Registers

The 8051 microcontroller consists of 4-input and output ports (P0, P1, P2, and

P3) or 32-I/O pins.


Counters and registers

● The timers are used to generate time delay .

● The counters are used to count the number of external events.

● The 8051 microcontroller consists of two 16-bit timers and counters such

as timer 0 and timer 1.

● Both the timers consist of a 16-bit register in which the lower byte is

stored in the TL and the higher byte is stored in the TH.

● The Timer can be used as a counter as well as for timing operation that
Types of Shift Register

● Shift registers are mainly used for the storage of digital data.

● The shift registers are bit-addressable registers that store only one bit of

data.

● The shift registers are mainly used for serial communication.


These are classified into 4- types:

● Serial in Serial out (SISO)


● Serial in Parallel Out (SIPO)
● Parallel in Serial out (PISO)
● Parallel in Parallel Out (PIPO)

These are all different types of registers in an 8051 microcontroller.


8051 Memory Organization/MEMORY ADDRESSING/IO ADDRESSING
● The 8051 microcontroller's memory is divided into Program
Memory and Data Memory.
● Program Memory (ROM) is used for permanent saving
program being executed,
● while Data Memory (RAM) is used for temporarily storing and
keeping intermediate results and variables.
Program Memory (ROM)
● Program Memory (ROM) is used for permanent saving program
(CODE) being executed.
● The memory is read only.
● program memory may also used to store a constant variables.
● The 8051 executes programs stored in program memory only.

8051 memory organization allows external program memory to be


added.
Internal Data Memory
● Up to 256 bytes of internal data memory are available.
● Locations available to the user occupy addressing space from 0 to 7Fh,

● i.e. first 128 registers and this part of RAM is divided in several blocks.
● The first 128 bytes of internal data memory are both directly and
indirectly addressable.

● The upper 128 bytes of data memory (from 0x80 to 0xFF) can be
addressed only indirectly.
IO ADDRESSING

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

● Each port has 8 pins. Thus the four ports jointly comprise 32 pins.
● All ports are bidirectional.
● We can modify their functions using software and hardware that they
connect to.
● 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.
Port 0
● Port 0 of the 8051 has two main functions: To be used as a simple
input-output port and to access external memory in conjunction
with Port 2.

Port 1
● It has only one function – to act as an Input-Output port.

Port 2

● Its main functions are kind of similar to those of Port 0. It can be used
as an input-output port. And can access external memory in
conjunction with Port 0.
Port 3
Just like Port 2, Port 3 can function as an input-output port.

RXD: this is used for a serial input port


TXD: this is used for serial output port
INT0: this used for an external interrupt 0
INT1: this used for external interrupt 1
T0: Timer 0 external input
T1: Timer 1 external input
WR: external data memory write strobe
RD: external data memory Read strobe
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.
IP (Interrupt Priority) Register

We can change the priority levels of the interrupts by changing the corresponding
bit in the Interrupt Priority (IP) register .

A low priority interrupt can only be interrupted by the high priority interrupt, but
not interrupted by another low priority interrupt.

● If two interrupts of different priority levels are received simultaneously,


the request of higher priority level is served.
● If the requests of the same priority levels are received simultaneously,
then the internal polling sequence determines which request is to be
serviced.
TCON Register

TCON register specifies the type of external interrupt to the microcontroller.


Stack and its Operations
(MODULE 3 STACK STRUCTURE EXPLANATION & DIAGRAM)

The stack is a section of a RAM used by the CPU to store information such as data or
memory address on temporary basis. The CPU needs this storage area considering
limited number of registers.
How Stacks are Accessed

● As the stack is a section of a RAM, there are registers inside the CPU to point to
it.
● The register used to access the stack is known as the stack pointer register.
● The stack pointer in the 8051 is 8-bits wide, and it can take a value of 00 to
FFH.
● When the 8051 is initialized, the SP register contains the value 07H.
● This means that the RAM location 08 is the first location used for the stack.
● The storing operation of a CPU register in the stack is known as a PUSH,
and getting the contents from the stack back into a CPU register is called a
POP.
Pushing into the Stack

● In the 8051, the stack pointer (SP) points to the last used location of the
stack.
● When data is pushed onto the stack, the stack pointer (SP) is incremented by
1.
● When PUSH is executed, the contents of the register are saved on the stack
and SP is incremented by 1.
● To push the registers onto the stack, we must use their RAM addresses. For
example, the instruction "PUSH 1" pushes register R1 onto the stack.
Popping from the Stack

Popping the contents of the stack back into a given register is the opposite to the
process of pushing.

With every pop operation, the top byte of the stack is copied to the register
specified by the instruction and the stack pointer is decremented once.
Immediate addressing mode:

● In this type of addressing mode, directly data is given to instruction to


perform operation.
● special character ‘#’ is used to differentiate data from addresses.
● MOV A , #16H ; this instruction means move data ( 16H ) to register A
● MOV DPTR #2000H
● This type of addressing mode , processors immediately can fetch data
( operand ), so this is known as immediate addressing mode.
Register addressing mode:

● In this type of addressing mode, instead of giving the data directly, the register
name is given.
● Data from one register is moved to other register
● Generally the data is stored in general purpose registers, thus it is named as
register addressing mode.

MOV R1 , A ;

it means access to the data is moved from register A to register R1. However the data
is not removed from A register, it is just copied.
Direct addressing mode:

In this type, the address of the data location is given in the instruction , This operation
is only for internal RAM and SFRs because it provides an address of only 8-bit.

MOV A , 25H ; data from 25H location is given to register A.

Here # is not used, because it is an address.

MOV 30H , A ; move A register data to 30H location.

MOV 15H , 25H ; move data from 25H location to location 15H .
Indirect register addressing mode:
This addressing mode is for both internal RAM and external RAM.
Indirect addressing mode in internal RAM:
MOV A , @R0 ;
This means copying the data from the location stored in R0.
R0 has data 10, which is address of 23.
It means copy 23 to register A
Indirect addressing mode in external RAM:
MOVX A , @DPTR ; for external RAM, MOVX is used.
DPTR is a 16-bit address register, but the data in it is 8-bit only
Absolute addressing mode in 8051

● The Absolute addressing mode in 8051 is used with absolute jump


(AJMP) and absolute call (ACALL) instructions.
● AJMP and ACALL instructions are 2 bytes instructions.
● The absolute addressing allows jumping or branching within the 2K
program memory space starting from 0800H to 0FFFH.
Long addressing mode in 8051
● The long addressing mode in 8051 is used with long jump (LJMP) and
long call (LCALL) instructions.
● LJMP and LCALL are 3 bytes instructions. The destination memory
address is 16 bits address so that jump can be made within 64K bytes
memory space.
Bit inherent addressing mode in 8051
In Bit inherent addressing mode in 8051, is implied in the opcode of the
instruction. The example of bit inherent addressing mode is show below

Bit direct addressing mode in 8051


Bit direct addressing mode in 8051,the direct address of the bit is specified in
the instruction. The example of Bit direct addressing mode is shown below
​INSTRUCTION SET OF 8051
Types of instructions
Depending on operation they perform, all instructions are divided in several
groups:
● Arithmetic Instructions
● Branch Instructions
● Data Transfer Instructions
● Logical Instructions
● Boolean instructions
Arithmetic instructions
Arithmetic instructions perform several basic operations such as addition,
subtraction, division, multiplication etc.
After execution, the result is stored in the first operand.
For example:
ADD A,R1 - The result of addition (A+R1) will be stored in the
accumulator.
Control transfer (BRANCH INSTRUCTIONS)
Branch Instructions

There are two kinds of branch instructions:

Unconditional jump instructions: upon their execution a jump to a new location


from where the program continues execution is executed.

Conditional jump instructions: a jump to a new program location is executed


only if a specified condition is met. Otherwise, the program normally proceeds with
the next instruction
ACALL addr11 - Absolute subroutine call
addr11: Subroutine address
Description: Instruction unconditionally calls a subroutine located at the specified
code address

AJMP addr11 - Absoulte jump


addr11: Jump address
Description: Program continues execution after executing a jump to the specified
address.
CJNE A,direct,rel - Compares direct byte to the accumulator and jumps if
not equal
A: accumulator
Direct: arbitrary register with address 0-255 (0-FFh)

Description: Instruction first compares the number in the accumulator with the
directly addressed byte. If they are equal, the program proceeds with execution.
Otherwise, a jump to the specified address will be executed.
CJNE A,#data,rel - Compares immediate data to the accumulator and jumps
if not equal
A: accumulator
Data: constant in the range of 0-255 (0-FFh)

Description: Instruction first compares the number in the accumulator with the
immediate data. If they are equal, the program proceeds with execution.
Otherwise, a jump to the specified address will be executed.
CJNE Rn,#data,rel - Compares immediate data to the register Rn and jumps
if not equal
Rn: Any R register (R0-R7)
Data: Constant in the range of 0 - 255 (0-FFh)

Description: Instruction first compares immediate data to the register Rn. If they
are equal, the program proceeds with execution. Otherwise, a jump to the
specified address will be executed.
CJNE @Ri,#data,rel - Compares immediate data to indirectly addressed
register and jumps if not equal
Ri: Register R0 or R1
Data: Constant in the range of 0 - 255 (0-FFh)
Description: This instruction first compares immediate data to indirectly
addressed register. If they are equal, the program proceeds with execution.
Otherwise, a jump to the specified address in the program will be executed.
DJNZ Rn,rel - Decrements the Rn register by 1 and jumps if not 0
Rn: any R register (R0-R7)
addr: jump address

Description: This instruction first decrements the value in the Rn register. If the result
is 0, the program proceeds with execution. Otherwise, a jump to the specified address
in the program will be executed.

JB bit,rel - Jump if direct bit is set


addr: Jump address
Bit: any bit of RAM
Description: If the bit is set, a jump to the specified address will be executed.
Otherwise, if the value of bit is 0, the program proceeds with the next instruction.
JC rel - Jump if carry flag is set
addr: Jump address
Description: Instruction first checks if the carry flag is set. If set, a jump to the specified
address is executed. Otherwise, the program proceeds with the next instruction. This is
a short jump instruction

JBC bit,rel - Jump if direct bit is set


Bit: any bit of RAM
addr: Jump Address
Description: This instruction first checks if the bit is set. If set, a jump to the specified
address is executed and the bit is cleared. Otherwise, the program proceeds with the
first following instruction.
JNB bit,rel - Jump if direct bit is not set
addr: Jump address
Bit: any bit of RAM
Description: If the bit is cleared, a jump to the specified address will be executed.
Otherwise, if the bit value is 1, the program proceeds with the first following instruction.

JMP @A+DPTR - Jump indirect relative to the DPTR


A: accumulator
DPTR: Data Pointer
Description: This instruction causes a jump to the address calculated by adding value
stored in the accumulator to the 16-bit number in the DPTR Register.
JNZ rel - Jump if accumulator is not zero
addr: Jump Address

Description: This instruction checks if the value stored in the accumulator is 0. If not, a
jump to the specified address will be executed. Otherwise, the program proceeds with
the first following instruction

JNC rel - Jump if carry flag is not set


addr: Jump Address

Description: This instruction first checks whether the carry flag is set. If not, a jump to
the specified address will be executed. Otherwise, the program proceeds with the first
following instruction.
LCALL addr16 - Long subroutine call
addr16: Subroutine Address
Description: This instruction unconditionally calls a subroutine located at the specified
address.

JZ rel - Jump if accumulator is zero


addr: Jump Address
Description: The instruction checks whether the value stored in the accumulator is 0. If yes,
a jump to the specified address will be executed. Otherwise, the program proceeds with the
following instruction.

LJMP addr16 - Long jump


addr16: jump address
Description: Instruction causes a jump to the specified 16-bit address.
RET - Return from subroutine
Description: This instruction ends every subroutine. After execution, the program
proceeds with the instruction following an ACALL or LCALL.

SJMP rel - Short Jump (relative address)


addr: Jump Address
Description: Instruction enables jump to the new address
DATA TRANSFER INSTRUCTIONS
Data transfer instructions

This instructions are used to copy the content of source operand to Destination
operand

MOV A,Rn - Moves the Rn register to the accumulator


The instruction moves the Rn register to the accumulator.

MOV A,@Ri - Moves the indirect RAM to the accumulator


Description: Instruction moves the indirectly addressed register of RAM to the
accumulator. The register address is stored in the Ri register (R0 or R1). The result is
stored in the accumulator.
MOV A,direct - Moves the direct byte to the accumulator
Description: Instruction moves the direct byte to the accumulator.

MOV Rn,A - Moves the accumulator to the Rn register


Desription: Instruction moves the accumulator to the Rn register.

MOV A,#data - Moves the immediate data to the accumulator


Desription: Instruction moves the immediate data to the accumulator.
MOV Rn,#data - Moves the immediate data to the Rn register
Description: Instruction moves the immediate data to the Rn register.

MOV Rn,direct - Moves the direct byte to the Rn register


Description: Instruction moves the direct byte to the Rn register.

MOV direct,Rn - Moves the Rn register to the direct


Description: Instruction moves the Rn register to the direct.
MOV direct,A - Moves the accumulator to the direct
Description: Instruction moves the accumulator to the direct .

MOV direct,@Ri - Moves the indirect RAM to the direct


Description: Instruction moves the indirectly adressed register of RAM to the direct .

MOV direct1,direct2 - Moves the direct byte to the direct


Description: Instruction moves the direct byte to another direct .
MOV @Ri,A - Moves the accumulator to the indirect RAM
Description: Instruction moves the accumulator to the indirectly addressed register
of RAM.

MOV direct,#data - Moves the immediate data to the direct


Description: Instruction moves the immediate data to the direct.

MOV @Ri,#data - Moves the immediate data to the indirect RAM


Description: Instruction moves the immediate data to the idirectly addressed
register of RAM.
MOV @Ri,direct - Moves the direct byte to the indirect RAM
Description: Instruction moves the direct byte to a register the address of which is
stored in the Ri register (R0 or R1).

MOVC A,@A+DPTR - Moves the code byte relative to the DPTR to the
accumulator
Description: Instruction first adds the 16-bit DPTR register to the accumulator. The
result of addition is then used as a memory address from which the 8-bit data is moved
to the accumulator.
LOGIC INSTRUCTIONS
Boolean instructions/bit oriented instructions
Bit instructions
8051 programs

You might also like