0% found this document useful (0 votes)
323 views30 pages

Cs3691 Embedded

The document discusses the architecture of the 8-bit 8051 microcontroller. It describes the main components of the 8051 architecture, including the CPU, memory (4KB ROM and 128B RAM), I/O ports, timers, interrupts, registers, buses, and addressing modes. The 8051 was designed by Intel in 1981 and is still widely used today due to its low cost and ease of programming. Its architecture includes all the major components needed for control applications.

Uploaded by

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

Cs3691 Embedded

The document discusses the architecture of the 8-bit 8051 microcontroller. It describes the main components of the 8051 architecture, including the CPU, memory (4KB ROM and 128B RAM), I/O ports, timers, interrupts, registers, buses, and addressing modes. The 8051 was designed by Intel in 1981 and is still widely used today due to its low cost and ease of programming. Its architecture includes all the major components needed for control applications.

Uploaded by

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

CS3691 EMBEDDED SYSTEMS AND IOT

UNIT-1

8-BIT EMBEDDED PROCESSOR

8-Bit Microcontroller – Architecture – Instruction Set and Programming – Programming Parallel


Ports – Timers and Serial Port – Interrupt Handling.

Difference between Microprocessor and Microcontroller

The following table highlights the differences between a microprocessor and a microcontroller −

Microcontroller Microprocessor

Microcontrollers are used to execute a single task within Microprocessors are used for big
an application. applications.

Its designing and hardware cost is


Its designing and hardware cost is low.
high.

Easy to replace. Not so easy to replace.

It is built with CMOS technology, which requires less Its power consumption is high because
power to operate. it has to control the entire system.

It doesn’t consist of RAM, ROM, I/O


It consists of CPU, RAM, ROM, I/O ports. ports. It uses its pins to interface to
peripheral devices.

Types of Microcontrollers

Microcontrollers are divided into various categories based on memory, architecture, bits and
instruction sets. Following is the list of their types −

Bit

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

 8-bit microcontroller − This type of microcontroller is 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 − This type of microcontroller is 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 − This type of microcontroller is generally 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 − This type of microcontroller is designed in such a


way that they do not have a program memory on the chip. Hence, it is named as external
memory microcontroller. For example: Intel 8031 microcontroller.
 Embedded memory microcontroller − This type of microcontroller is designed in such
a way that the microcontroller has 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.
 Measuring devices like Volt Meter.

CHAPTER-1:
Microcontrollers - 8051 Architecture

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.

Let us now discuss the architecture of 8051 Microcontroller.

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.

CPU (Central Processing Unit)

The CPU is the brain of any processing machine. It is the part that is responsible for managing
all the tasks of the microcontroller. The CPU is an independent unit. Users can not interfere with
the CPU controlling how it should function. It identifies the tasks present in the ROM and then
processes them. In the 8051 microcontroller architecture, the CPU is responsible for managing
registers. Registers are a type of memory in a computer. They can store and manipulate data.

Interrupts

In the 8051 microcontroller architecture, interrupts stop the microcontroller’s current task.
Interrupts are caused when some other program has a higher priority request for execution. When
an interrupt occurs, the ongoing task stops, the sub-routine for the interrupt is executed, and then
the previous job resumes.

Types of interrupts in 8051 Microcontroller

The following are the types of interrupts in the 8051 microcontroller architecture:

INT0 It is an external interrupt having code 0. External hardware cause this interrupt.

INT1 It is an external interrupt having code 1. External hardware cause this interrupt.
TF0 This is for timer 0 overflow interrupt.

TF1 This is for timer 1, overflow interrupt

RI/TI This is a serial communication interrupt.

Memory

The next part of the 8051 microcontroller architecture is the memory. For any data manipulation
to occur, we require a set of instructions. These programs need to be saved in memory. This
memory where the program resides in the controller's memory is called code memory or program
memory. It acts as ROM memory for the 8051 microcontroller architecture. In the 8051
microcontroller architecture, the microcontroller has 4KB ROM and 128 bytes of RAM.

Bus

A bus is a group of wires. Communication within the microcontroller happens through this bus.
There are either 8 or 16 or more wires in the bus. If the 8051 microcontroller architecture has 8
wires, it can carry 8 bits of data. If the 8051 microcontroller architecture has 16 wires, it can
carry 16 bits of data.

Types of Buses

Address Bus-

The address bus in the 8051 microcontroller architecture is 16 bits. This bus transfers data from
the CPU to the memory.

Data Bus-

In 8051 microcontroller architecture, the data bus is 8 bits. It helps in carrying the data from one
place to another.

Oscillators

The microcontroller requires a clock to perform operations. In the 8051 microcontroller


architecture, we have an oscillator that functions as a clock for the CPU.

Input/Output Ports

A microcontroller controls small operations for a system. It is embedded in the systems. We


might sometimes need to connect the microcontroller to other devices. In the 8051
microcontroller architecture, we have 4 input/output ports. We connect other input/output
peripherals using these ports.

Timers/Counters
In the 8051 microcontroller architecture, we have two timers. They are each 16 bits. We have the
timers to generate gaps between two events. The two timers generate two delays(gaps), and the
suitable one is chosen.

Data Types

In 8051, there is only one data type of 8 bits, from the MSB (most significant bit) D7 to the LSB
(least significant bit) D0. With an 8-bit data type, any data type larger than 8-bit must be broken
into 8-bit chunks by the programmer before it is processed.

Stack

The stack is a section of RAM used by the CPU to store information such as data or memory
address on a temporary basis. The CPU needs this storage area considering the limited number of
registers. There are registers inside the CPU to point to the stack. A Stack Pointer register is
used to access the stack. This stack pointer is 8 bits wide. The operation of storing the data in a
stack is known as PUSH and getting it back into a CPU register is known as POP.

Registers

Registers are memory storage devices used in the CPU to temporarily store information. This
information could be data to be processed or, an address pointing to the data to be fetched. The
most widely used registers of the 8051 are

A (accumulator)

B register

R0-R7

DPTR (Data Pointer)

PC (Program Counter)

Stack Pointer (SP)

All these registers are of 8 bits, except DPTR and PC.

Addressing modes

Addressing modes in the 8051 microcontrollers are a way of specifying the location of an
operand in memory. The addressing mode affects the number of bytes that the instruction takes
up in the memory and the speed at which it is executed. We choose different addressing modes
according to specific applications.

There are six different types of Addressing Modes.


1. Immediate Addressing Mode
2. Register Addressing Mode
3. Register Indirect Addressing Mode
4. Implied Addressing Mode
5. Direct Addressing Mode
6. Indexed Addressing Mode

Features of 8051 Microcontroller Architecture

Following are some of the features of the 8051 Microcontroller:

 Supports direct addressing, registers indirect addressing, and immediate addressing


modes.
 Multiple variants with different enhancements and modifications.
 Relatively easy to program.
 Widely used and supported by many manufacturers and third-party tools.
 Suitable for a wide range of applications. It includes industrial control systems, robotics,
automotive systems, and consumer electronics.

Applications of 8051 Microcontroller Architecture

Some of the applications of the 8051 microcontrollers are as follows:

 The 8051 microcontrollers are used in light sensing and controlling devices.
 The microcontroller is used in fire-sensing devices.
 It is also present in automobile and defence applications.
 It is also used in a voltmeter.
8051 Pin Diagram

 Pins 1 to 8 − These pins are known as Port 1. This port doesn’t serve any other
functions. It is internally pulled up, bi-directional I/O port.

 Pin 9 − It is a RESET pin, which is used to reset the microcontroller to its initial values.

 Pins 10 to 17 − These pins are known as Port 3. This port serves some functions like
interrupts, timer input, control signals, serial communication signals RxD and TxD, etc.
 Pins 18 & 19 − These pins are used for interfacing an external crystal to get the system
clock.

 Pin 20 − This pin provides the power supply to the circuit.

 Pins 21 to 28 − These pins are known as Port 2. It serves as I/O port. Higher order
address bus signals are also multiplexed using this port.

 Pin 29 − This is PSEN pin which stands for Program Store Enable. It is used to read a
signal from the external program memory.

 Pin 30 − This is EA pin which stands for External Access input. It is used to
enable/disable the external memory interfacing.

 Pin 31 − This is ALE pin which stands for Address Latch Enable. It is used to
demultiplex the address-data signal of port.

 Pins 32 to 39 − These pins are known as Port 0. It serves as I/O port. Lower order
address and data bus signals are multiplexed using this port.

 Pin 40 − This pin is used to provide power supply to the circuit.

CHAPTER-2:
Instruction Set and Programming
INSTRUCTION SET OF 8051
The process of writing program for the microcontroller mainly consists of giving
instructions (commands) in the specific order in which they should be executed in order to
carry out a specific task. As electronics cannot “understand” what for example an
instruction “if the push button is pressed- turn the light on” means, then a certain number
of simpler and precisely defined orders that decoder can recognise must be used. All
commands are known as INSTRUCTION SET. All microcontrollers compatibile with the
8051 have in total of 255 instructions, i.e. 255 different words available for program
writing.

At first sight, it is imposing number of odd signs that must be known by heart.
However, It is not so complicated as it looks like. Many instructions are considered to
be “different”, even though they perform the same operation, so there are only 111
truly different commands. For example: ADD A,R0, ADD A,R1, ... ADD A,R7 are
instructions that perform the same operation (additon of the accumulator and register).
Since there are 8 such registers, each instruction is counted separately. Taking into
account that all instructions perform only 53 operations (addition, subtraction, copy
etc.) and most of them are rarely used in practice, there are actually 20 -30
abbreviations to be learned, which is acceptable.
3.1 Types of instructions
Depending on operation they perform, all instructions are divided in several groups:
1.Arithmetic Instructions
2.Branch Instructions
3.Data Transfer Instructions
4.Logic Instructions
5.Bit-oriented Instructions

The first part of each instruction, called MNEMONIC refers to the operation an
instruction performs (copy, addition, logic operation etc.). Mnemonics are
abbreviations of the name of operation being executed.

For example:
INC R1 - Means: Increment register R1 (increment register R1);
LJMP LAB5 - Means: Long Jump LAB5 (long jump to the address marked as LAB5);
JNZ LOOP - Means: Jump if Not Zero LOOP (if the number in the accumulator is
not 0, jump to the address marked as LOOP);

The other part of instruction, called OPERAND is separated from mnemonic by at


least one whitespace and defines data being processed by instructions. Some of the
instructions have no operand, while some of them have one, two or three. If there is
more than one operand in an instruction, they are separated by a comma.

For example:
RET - return from a subroutine;
JZ TEMP - if the number in the accumulator is not 0, jump to the address marked as
TEMP;
ADD A,R3 - add R3 and accumulator;
CJNE A,#20,LOOP - compare accumulator with 20. If they are not equal, jump to the
address marked as LOOP;

1.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.

2. 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 wit h the next
instruction

3.Data Transfer Instructions

Data transfer instructions move the content of one register to another. The register
the content of which is moved remains unchanged. If they have the suffix “X”
(MOVX), the data is exchanged with external memory.

4. Logic Instructions
Logic instructions perform logic operations upon corresponding bits of two registers.
After execution, the result is stored in the first operand.
5. Bit-oriented Instructions
Similar to logic instructions, bit-oriented instructions perform logic operations. The
difference is that these are performed upon single bits.

ARITHMETIC INSTRUCTIONS

ADD A,Rn
Adds the register to the accumulator

ADD A,direct
Adds the direct byte to the accumulator

ADD A,@Ri
Adds the indirect RAM to the accumulator

ADD A,#data
Adds the immediate data to the accumulator

ADDC A,Rn
Adds the register to the accumulator with a carry flag

ADDC A,direct
Adds the direct byte to the accumulator with a carry flag

ADDC A,@Ri
Adds the indirect RAM to the accumulator with a carry flag

ADDC A,#data
Adds the immediate data to the accumulator with a carry flag

SUBB A,Rn
Subtracts the register from the accumulator with a borrow
SUBB A,direct
Subtracts the direct byte from the accumulator with a borrow

SUBB A,@Ri
Subtracts the indirect RAM from the accumulator with a borrow

SUBB A,#data
Subtracts the immediate data from the accumulator with a borrow

INC A
Increments the accumulator by 1

INC Rn
Increments the register by 1

INC Rx
Increments the direct byte by 1

INC @Ri
Increments the indirect RAM by 1

DEC A
Decrements the accumulator by 1

DEC Rn
Decrements the register by 1

DEC Rx
Decrements the direct byte by 1

DEC @Ri
Decrements the indirect RAM by 1

INC DPTR
Increments the Data Pointer by 1

MUL AB
Multiplies A and B

DIV AB
Divides A by B

DA A
Decimal adjustment of the accumulator according to BCD code

BRANCH INSTRUCTIONS

ACALL addr11
Absolute subroutine call

LCALL addr16
Long subroutine call

RET
Returns from subroutine

RETI
Returns from interrupt subroutine

AJMP addr11
Absolute jump

LJMP addr16
Long jump

SJMP rel
Short jump (from –128 to +127 locations relative to the following instruction)

JC rel
Jump if carry flag is set. Short jump.

JNC rel
Jump if carry flag is not set. Short jump.

JB bit,rel
Jump if direct bit is set. Short jump.

JBC bit,rel
Jump if direct bit is set and clears bit. Short jump.

JMP @A+DPTR
Jump indirect relative to the DPTR

JZ rel
Jump if the accumulator is zero. Short jump.

JNZ rel
Jump if the accumulator is not zero. Short jump.

CJNE A,direct,rel
Compares direct byte to the accumulator and jumps if not equal. Short jump.

CJNE A,#data,rel
Compares immediate data to the accumulator and jumps if not equal. Short jump.

CJNE Rn,#data,rel
Compares immediate data to the register and jumps if not equal. Short jump.

CJNE @Ri,#data,rel
Compares immediate data to indirect register and jumps if not equal. Short jump.

DJNZ Rn,rel
Decrements register and jumps if not 0. Short jump.

DJNZ Rx,rel
Decrements direct byte and jump if not 0. Short jump.

NOP
No operation

DATA TRANSFER INSTRUCTIONS

MOV A,Rn
Moves the register to the accumulator

MOV A,direct
Moves the direct byte to the accumulator

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

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

MOV Rn,A
Moves the accumulator to the register

MOV Rn,direct
Moves the direct byte to the register
MOV Rn,#data
Moves the immediate data to the register

MOV direct,A
Moves the accumulator to the direct byte

MOV direct,Rn
Moves the register to the direct byte

MOV direct,direct
Moves the direct byte to the direct byte

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

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

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

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

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

MOV DPTR,#data
Moves a 16-bit data to the data pointer

MOVC A,@A+DPTR
Moves the code byte relative to the DPTR to the accumulator (address=A+DPTR)

MOVC A,@A+PC
Moves the code byte relative to the PC to the accumulator (address=A+PC)

MOVX A,@Ri
Moves the external RAM (8-bit address) to the accumulator

MOVX A,@DPTR
Moves the external RAM (16-bit address) to the accumulator

MOVX @Ri,A
Moves the accumulator to the external RAM (8-bit address
MOVX @DPTR,A
Moves the accumulator to the external RAM (16-bit address)

PUSH direct
Pushes the direct byte onto the stack

POP direct
Pops the direct byte from the stack

XCH A,Rn
Exchanges the register with the accumulator

XCH A,direct
Exchanges the direct byte with the accumulator

XCH A,@Ri
Exchanges the indirect RAM with the accumulator

XCHD A,@Ri
Exchanges the low-order nibble indirect RAM with the accumulator

RETI
Returns from interrupt subroutine

LOGIC INSTRUCTIONS

ANL A,Rn
AND register to accumulator

ANL A,direct
AND direct byte to accumulator

ANL A,@Ri
AND indirect RAM to accumulator

ANL A,#data
AND immediate data to accumulator

ANL direct,A
AND accumulator to direct byte

ANL direct,#data
AND immediate data to direct register
ORL A,Rn
OR register to accumulator

ORL A,direct
OR direct byte to accumulator

ORL A,@Ri
OR indirect RAM to accumulator

ORL direct,A
OR accumulator to direct byte

ORL direct,#data
OR immediate data to direct byte

XRL A,Rn
Exclusive OR register to accumulator

XRL A,direct
Exclusive OR direct byte to accumulator

XRL A,@Ri
Exclusive OR indirect RAM to accumulator

XRL A,#data
Exclusive OR immediate data to accumulator

XRL direct,A
Exclusive OR accumulator to direct byte

XORL direct,#data
Exclusive OR immediate data to direct byte

CLR A
Clears the accumulator

CPL A
Complements the accumulator (1=0, 0=1)

SWAP A
Swaps nibbles within the accumulator

RL A
Rotates bits in the accumulator left

RLC A
Rotates bits in the accumulator left through carry

RR A
Rotates bits in the accumulator right

RRC A
Rotates bits in the accumulator right through carry

CJNE @Ri,#data,rel
Compares immediate data to indirect register and jumps if not equa l. Short jump.

BIT-ORIENTED INSTRUCTIONS

CLR C
Clears the carry flag

CLR bit
Clears the direct bit

SETB C
Sets the carry flag

SETB bit
Sets the direct bit

CPL C
Complements the carry flag

CPL bit
Complements the direct bit

ANL C,bit
AND direct bit to the carry flag

ANL C,/bit
AND complements of direct bit to the carry flag

ORL C,bit
OR direct bit to the carry flag
ORL C,/bit
OR complements of direct bit to the carry flag

MOV C,bit
Moves the direct bit to the carry flag

MOV bit,C
Moves the carry flag to the direct bit

Description of all 8051 instructions


Here is a list of the operands and their meanings:

 A - accumulator;
Rn - is one of working registers (R0-R7) in the currently active RAM memory
bank;
 Direct - is any 8-bit address register of RAM. It can be any general-purpose
register or a SFR (I/O port, control register etc.);
 @Ri - is indirect internal or external RAM location addressed by register R0 or
R1;
 #data - is an 8-bit constant included in instruction (0-255);
 #data16 - is a 16-bit constant included as bytes 2 and 3 in instruction (0-65535);
 addr16 - is a 16-bit address. May be anywhere within 64KB of program memory;
 addr11 - is an 11-bit address. May be within the same 2KB page of program
memory as the first byte of the following instruction;
 rel - is the address of a close memory location (from -128 to +127 relative to the
first byte of the following instruction). On the basis of it, assembler computes the
value to add or subtract from the number currently stored in the progr am counter;
 bit - is any bit-addressable I/O pin, control or status bit; and
 C - is carry flag of the status register (register PSW).

Alphabetical List of Instructions

 ACALL - Absolute Call


 ADD, ADDC - Add Accumulator (With Carry)
 AJMP - Absolute Jump
 ANL - Bitwise AND
 CJNE - Compare and Jump if Not Equal
 CLR - Clear Register
 CPL - Complement Register
 DA - Decimal Adjust
 DEC - Decrement Register
 DIV - Divide Accumulator by B
 DJNZ - Decrement Register and Jump if Not Zero
 INC - Increment Register
 JB - Jump if Bit Set
 JBC - Jump if Bit Set and Clear Bit
 JC - Jump if Carry Set
 JMP - Jump to Address
 JNB - Jump if Bit Not Set
 JNC - Jump if Carry Not Set
 JNZ - Jump if Accumulator Not Zero
 JZ - Jump if Accumulator Zero
 LCALL - Long Call
 LJMP - Long Jump
 MOV - Move Memory
 MOVC - Move Code Memory
 MOVX - Move Extended Memory
 MUL - Multiply Accumulator by B
 NOP - No Operation
 ORL - Bitwise OR
 POP - Pop Value From Stack
 PUSH - Push Value Onto Stack
 RET - Return From Subroutine
 RETI - Return From Interrupt
 RL - Rotate Accumulator Left
 RLC - Rotate Accumulator Left Through Carry
 RR - Rotate Accumulator Right
 RRC - Rotate Accumulator Right Through Carry
 SETB - Set Bit
 SJMP - Short Jump
 SUBB - Subtract From Accumulator With Borrow
 SWAP - Swap Accumulator Nibbles
 XCH - Exchange Bytes
 XCHD - Exchange Digits
 XRL - Bitwise Exclusive OR
 Undefined - Undefined Instruction

8051 Microcontroller

The 8051 microcontroller is a tiny computer developed by Intel in the 1980s. It is used in many
electronic systems like cars, medical devices, etc. It has two memory spaces, one for program
memory and the other for data memory. The program counter can access up to 64K of program
memory, while the data memory has 128 bytes of internal RAM and up to 64K of external RAM.
The microcontroller has four functional blocks: the CPU, memory, input/output ports, and serial
communication interface. It comes with many built-in tools that can be used to interface with
other devices, making it an excellent choice for many embedded system applications.
8051 Microcontroller Architecture

The 8051 Microcontroller Architecture consists of the following major components:

 Interrupt control: It supports five interrupt sources, which can interrupt the normal program
execution to handle specific events.

 Central Processing Unit (CPU): This is the brain of the microcontroller, which is responsible
for executing instructions and performing arithmetic and logical operations. The 8051 CPU
consists of an ALU, accumulator, registers, and a program counter.

 Oscillator: It requires an external oscillator to provide a clock signal to the microcontroller

 Bus control: The 8051 microcontroller includes a bus controller that manages data transfer
between the CPU and peripheral devices, such as memory or input/output devices.

 4k byte ROM: The 8051 microcontroller architecture includes a 4 kilobyte (4k) read-only
memory (ROM) for storing the program instructions that are executed by the CPU.

 128-byte RAM: The 8051 microcontroller also has a 128-byte random-access memory (RAM)
for storing data that is used by the program instructions during runtime.

 Input/Output Ports: They have four 8-bit input/output (I/O) ports that can be configured as
either input or output.

 Timers and Counters: They have two 16-bit timers/counters that can be used for a variety of
tasks such as measuring time intervals, generating PWM signals, and counting external events.

 Serial Communication Interface(SCI): It has a built-in serial port that can be used for
asynchronous serial communication.
8051 Pin Diagram

The 8051 microcontroller has a total of 40 pins arranged in four groups, namely Port 0, Port 1,
Port 2, and Port 3. Here’s a brief explanation of each group:

 Port 0: Pins 32-39 are designated as Port 0 and are used for both input and output operations.
Port 0 can also be used for external memory interfacing.

 Port 1: Pins 1-8 are designated as Port 1 and are used for both input and output operations. Port
1 also has built-in pull-up resistors that can be activated by writing a 1 to the corresponding bit.

 Port 2: Pins 21-28 are designated as Port 2 and are used for both input and output operations.
Port 2 can also be used for external memory interfacing, and some of its pins have alternate
functions, such as being used as a serial communication interface.

 Port 3: Pins 10-17 are designated as Port 3 and are used for both input and output operations.
Port 3 can also be used for external memory interfacing, and some of its pins have alternate
functions, such as being used as a timer/counter input.

 Vcc: This pin is used to supply power to the microcontroller and is typically connected to a +5V
power source.

 GND: This pin is used as the ground reference for the microcontroller and is typically connected
to the ground.

 XTAL1 and XTAL2: These pins are used to connect an external crystal oscillator that provides
the clock signal for the microcontroller.

 Reset: This pin is used to reset the microcontroller and is typically connected to a push-button
switch.

 ALE: This pin is used as the Address Latch Enable signal and is used to latch the address from
the program counter onto the external memory bus.

 PSEN: This pin is used as the Program Store Enable signal and is used to select the external
ROM for program execution.

 EA: This pin is used to enable/disable external memory interfacing. If this pin is connected to
Vcc, the microcontroller will fetch the program from the external memory. if it is connected to
GND, the microcontroller will fetch the program from the internal ROM.
Application for 8051 Microcontroller Architecture

The 8051 microcontroller architecture has various applications, including:

 It is commonly used in embedded systems, such as in home appliances, security systems, and
industrial automation systems.

 This is used in automotive applications, such as in engine control units, airbag control units, and
anti-lock braking systems.

 It is used in medical devices, such as heart rate monitors, blood pressure monitors, and insulin
pumps.

 It is used in robotics applications, such as in controlling robot arms and movements.

 They are used in various consumer electronics products, such as in remote controls, digital
cameras, and smart home devices.

 This is used in communication systems, such as modems, routers, and switches.

 These are used in security systems, such as access control systems and alarm systems.
Advantages for 8051 Microcontroller Architecture

Here, the advantages of the 8051 microcontroller architecture include:

 It is a cheaper option, which makes it a popular choice for low-cost applications.

 Designed to consume very low power for applications.

 8051 Microcontroller Architecture is known for its high reliability.

 It is easy to program, has a simple instruction set, and has easy-to-use development tools.

 It can be used in a wide variety of applications.

Disadvantages of 8051 Microcontroller Architecture

Here, are the disadvantages of 8051 Microcontroller Architecture:

 It has limited processing power compared to microcontrollers

 Memory is limited for applications it requires a lot of data storage.

 It highly requires advanced peripherals such as USB or Ethernet connectivity.

 The instruction set makes it challenging to program and optimize code.

 The development tools are not as advanced, and it is difficult to develop and debug code.

CHAPTER-3
Programming Parallel Ports – Timers and Serial Port
1. Serial Port: A serial port is an interface that is used for connecting the serial lines to
attain the serial communication. These ports can dock a 9-pin D-shaped connector that
connects to the transmission line, is called DB-9 connectors. Serial communication gained
by single wire and only the single stream of data is transferred from one end to other.
Therefore, like parallel transmission, in serial transmission data speed mismatch is not a
problem. The length of the wire can be increased as needed. The transmission speed of
serial port is comparatively low as compared to parallel port transmission speed. Serial
ports are typically implemented in the modems, connecting devices, controllers, mouse and
also in security cameras. DB-9 pin connector diagram is given below.
2. Parallel Port: Unlike serial port, a parallel port can move a set of 8 bits at a time on
eight different wires. That’s why it is faster in comparison to the serial communication.
Unlike serial port, It uses a 25 pin connector that is called DB-25 connector. To eliminate
crosstalk and errors, all bitstreams need to transfer data at the same speed in parallel
communication. But, that is impractical. Therefore, for this reason, transmission lines are
preferred to be short in parallel communication. Parallel ports are typically implemented in
zip-drives, printers, hard drives, CD-ROM drives, etc. DB-25 pin connector diagram is
given below.

Difference between Serial port and Parallel Ports:

S.NO Serial Port Parallel Port

Serial port is used to achieve serial While parallel port is used to achieve
1.
transmission. parallel transmission.

The transmission speed of serial port is While transmission speed of parallel


2. comparatively low as compared to parallel port is higher than serial port
port transmission speed. transmission speed.

While in parallel port communication


In serial port communication less number
3. more number of wires are used as
of wires are used.
compared to serial port.

A serial port is capable of delivering the While a parallel port is capable of


4.
single stream of data. delivering multiple streams of data.

Serial port send a bit after another byte at While parallel ports send multiple bits
5.
a time. at once.

While in a parallel port, female ports


6. In a serial port, male ports are involved.
are involved.
S.NO Serial Port Parallel Port

Serial ports are typically implemented in Parallel ports are typically implemented
7. modems, connecting devices, security in zip-drives, printers, hard drives, CD-
cameras and controllers. ROM drives, etc.

CHAPTER-4
Microcontrollers - 8051 Interrupts
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.

It disables all interrupts. When EA = 0 no interrupt will be


EA IE.7
acknowledged and EA = 1 enables the interrupt individually.

- IE.6 Reserved for future use.

- IE.5 Reserved for future use.

ES IE.4 Enables/disables serial port interrupt.

ET1 IE.3 Enables/disables timer1 overflow interrupt.

EX1 IE.2 Enables/disables external interrupt1.


ET0 IE.1 Enables/disables timer0 overflow interrupt.

EX0 IE.0 Enables/disables external interrupt0.

IP (Interrupt Priority) Register

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

 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.

- IP.6 Reserved for future use.

- IP.5 Reserved for future use.

PS IP.4 It defines the serial port interrupt priority level.

PT1 IP.3 It defines the timer interrupt of 1 priority.

PX1 IP.2 It defines the external interrupt priority level.

PT0 IP.1 It defines the timer0 interrupt priority level.

PX0 IP.0 It defines the external interrupt of 0 priority level.

TCON Register

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


Interrupt programming in 8051
1. Timer Interrupt Programming: In microcontroller Timer 1 and Timer 0 interrupts are
generated by time register bits TF0 AND TF1. This timer interrupts programming by C
code involves:
o Selecting the configuration of TMOD register and their mode of operation.
o Enables the IE registers and corresponding timer bits in it.
o Choose and load the initial values of TLx and THx by using appropriate mode of
operation.
o Set the timer run bit for starting the timer.
o Write the subroutine for a timer and clears the value of TRx at the end of the
subroutine.

Let's see the timer interrupt programming using Timer0 model for blinking
LED using interrupt method:

1. #include< reg51 .h>


2. sbit Blink Led = P2^0; // LED is connected to port 2 Zeroth pin
3. void timer0_ISR (void) interrupt 1 //interrupt no. 1 for Timer0
4. {
5. Blink Led=~Blink Led; // Blink LED on interrupt
6. TH0=0xFC; // loading initial values to timer
7. TL0=0x66;
8. }
9. void main()
10. {
11. TMOD=0x0l; // mode 1 of Timer0
12. TH0 = 0xFC: // initial value is loaded to timer
13. TL0 = 0x66:
14. ET0 =1; // enable timer 0 interrupt
15. TR0 = 1; // start timer
16. while (1); // do nothing
17. }
2. External Hardware Interrupt Programming

Microcontroller 8051 is consisting of two external hardware interrupts: INT0 and


INT1 as discussed above. These interrupts are enabled at pin 3.2 and pin 3.3. It
can be level triggered or edge triggered. In level triggering, low signal at pin 3.2
enables the interrupt, while at pin 3.2 high to low transition enables the edge
triggered interrupt.

Let us see the programmable feature of 8051 microcontroller are:

o Enables the equivalent bit of external interrupt in Interrupt Enable (IE) register.
o If it is level triggering, then write subroutine appropriate to this interrupt, or else
enable the bit in TCON register corresponding to the edge triggered interrupt.

Consider the edge triggered external hardware interrupt programming is:-

1. void main()
2. {
3. IT0 = 1; // Configure interrupt 0 for falling edge on INT0
4. EXO = 1; // Enabling the EX0 interrupt
5. EA =1; // Enabling the global interrupt flag
6. }
7. void ISR_ex0(void) interrupt 0
8. {
9. <body of interrupt>
10. }
2. Serial Communication Interrupt Programming It is used when there is a need to send
or receive data. Since one interrupt bit is used for both Transfer Interrupt (TI) and
Receiver Interrupt (RI) flags, Interrupt Service Routine (ISR) must examine these flags for
knowing the actual interrupt. By the logical OR operation of RI and TI flags causes the
interrupt and it is clear by the software alone. Consider the steps involved in serial
communication interrupt programming are:-
o Configure the Interrupt Enable register for enabling serial interrupt.
o Configure the SCON register for performing transferring and receiving operation.
o Write a subroutine for given interrupt with appropriate function.

Let's see the program for sending 'E' through serial port with 9600 baud
rate using Serial Interrupt:

1. void main()
2. {
3. TMOD = 0x20:
4. TH1= 0xFD; // baud rate for 9600 bps
5. SCON = 0x50;
6. TR1=1;
7. EA=l;
8. whlle(l);
9. }
10. void ISR_Serial(void) interrupt 4
11. {
12. if(TI==l)
13. {
14. SBUF= ?E?;
15. TI=0;
16. }
17. else
18. RI =0;
19. }

Embedded C Programming with Keil


Language
2. Embedded C is most popular programming language in software field for
developing electronic gadgets. Each processor used in electronic system is
associated with embedded software.
3. Embedded C programming plays a key role in performing specific function by the
processor. In day-to-day life we used many electronic devices such as mobile
phone, washing machine, digital camera, etc. These all device working is based on
microcontroller that are programmed by embedded C.
4. Let's see the block diagram representation of embedded system programming:
5.
6. The Embedded C code written in above block diagram is used for blinking the
LED connected with Port0 of microcontroller.

You might also like