0% found this document useful (0 votes)
66 views33 pages

Embedded Systems - 8051 Microcontroller

The document discusses the 8051 microcontroller. It provides a brief history, describing how the 8051 was introduced by Intel in 1981 as an 8-bit microcontroller with RAM, ROM, timers, ports, and other features on a single chip. It discusses other members of the 8051 family like the 8052 and 8031. It includes sections on the features, block diagram, ports and their functions, addressing modes, and hardware connection of the 8051 microcontroller pins.

Uploaded by

Aarti Dhotre
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)
66 views33 pages

Embedded Systems - 8051 Microcontroller

The document discusses the 8051 microcontroller. It provides a brief history, describing how the 8051 was introduced by Intel in 1981 as an 8-bit microcontroller with RAM, ROM, timers, ports, and other features on a single chip. It discusses other members of the 8051 family like the 8052 and 8031. It includes sections on the features, block diagram, ports and their functions, addressing modes, and hardware connection of the 8051 microcontroller pins.

Uploaded by

Aarti Dhotre
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/ 33

Embedded Systems - 8051

Microcontroller
Embedded Systems - 8051 Microcontroller
Brief History of 8051

The first microprocessor 4004 was invented by Intel


Corporation. 8085 and 8086 microprocessors were also invented
by Intel. In 1981, Intel introduced an 8-bit microcontroller called
the 8051. It was referred as system on a chip because it had 128
bytes of RAM, 4K byte of on-chip ROM, two timers, one serial
port, and 4 ports (8-bit wide), all on a single chip. When it
became widely popular, Intel allowed other manufacturers to
make and market different flavors of 8051 with its code
compatible with 8051. It means that if you write your program for
one flavor of 8051, it will run on other flavors too, regardless of
the manufacturer. This has led to several versions with different
speeds and amounts of on-chip RAM.
8051 Family Members

8052 microcontroller − 8052 has all the standard features of the


8051 microcontroller as well as an extra 128 bytes of RAM and an
extra timer. It also has 8K bytes of on-chip program ROM instead
of 4K bytes.

8031 microcontroller − It is another member of the 8051 family.


This chip is often referred to as a ROM-less 8051, since it has 0K
byte of on-chip ROM. You must add external ROM to it in order to
use it, which contains the program to be fetched and executed.
This program can be as large as 64K bytes. But in the process of
adding external ROM to the 8031, it lost 2 ports out of 4 ports. To
solve this problem, we can add an external I/O to the 8031
Comparison between 8051 Family Members
The following table compares the features available in 8051, 8052, and 8031.
Features of 8051 Microcontroller

An 8051 microcontroller comes bundled with the following features −


•4K bytes on-chip program memory (ROM)
•128 bytes on-chip data memory (RAM)
•4 register banks
•128 user defined software flags
•8-bit bidirectional data bus
•16-bit unidirectional address bus
•32 general purpose registers each of 8-bit
•16 bit Timers (usually 2, but may have more or less)
•3 internal and 2 external Interrupts
•Four 8-bit ports
•16-bit program counter and data pointer
•8051 may also have a number of special features such as UARTs, ADC, Op-amp, etc
Block Diagram of 8051 Microcontroller
The following illustration shows the block diagram of an 8051 microcontroller −
CPU (Central Processor Unit):
As you may be familiar that Central Processor Unit or CPU is the mind of any
processing machine. It scrutinizes and manages all processes that are carried
out in the Microcontroller. 

The characteristic of 8051 Interrupt is extremely constructive as it aids in


emergency cases. Interrupts provides us a method to postpone or delay the
current process, carry out a sub-routine task and then all over again restart
standard program implementation.

The memory which is used to store the program of the microcontroller is


known as code memory or Program memory of applications. It is known as
ROM memory of  microcontroller also requires a memory to store data or
operands temporarily of the micro controller. The data memory of the 8051 is
used to store data temporarily for operation is known RAM memory. 8051
microcontroller  has 4K of code memory or program memory,that  has 4KB
ROM and also 128 bytes of data memory of RAM
BUS
Basically Bus is a collection of wires which work as a communication channel
or medium for transfer of Data.
Address Bus: Microcontroller 8051 has a 16 bit address bus for
transferring the data. It is used to address memory locations and to
transfer the address from CPU to Memory of the microcontroller. 
Data Bus: Microcontroller 8051 has 8 bits of  the data bus, which is used
to carry data of particular applications.

Oscillators
As we know microcontroller is a digital circuit device hence it requires clock
for operation. 8051 has an on chip  oscillators which work as clock source for
CPU. The output pulse of oscillator are stable therefore it enables
synchronized work of all parts of 8051 microcontroller.

Input/Output Port
The microcontroller 8051 has 4 input, output ports to connect it to the other
peripheral.
I/O Ports and their Functions

The four ports P0, P1, P2, and P3, each use 8 pins, making them 8-bit ports. Upon RESET,
all the ports are configured as inputs, ready to be used as input ports. When the first 0 is
written to a port, it becomes an output. To reconfigure it as an input, a 1 must be sent to
a port.

Port 0 (Pin No 32 – Pin No 39)


It has 8 pins (32 to 39). It can be used for input or output. Unlike P1, P2, and P3 ports,
we normally connect P0 to 10K-ohm pull-up resistors to use it as an input or output port
being an open drain.

Port 0 is also designated as AD0–AD7, as it can be used for both data and address
handling. While connecting an 8051 to external memory, Port 0 can provide both
address and data. In case of 8031 (i.e. ROMless Chip), when we need to access the
external ROM, then P0 will be used for both Address and Data Bus. ALE (Pin no 31)
indicates if P0 has address or data. When ALE = 0, it provides data D0-D7, but when ALE
= 1, it has address A0-A7.
Port 1 (Pin 1 through 8)
It is an 8-bit port (pin 1 through 8) and can be used either as input or output. It
doesn't require pull-up resistors because they are already connected internally.
Upon reset, Port 1 is configured as an input port. To configure it as an output
port , Port bits must be set i.e. a high bit must be sent to all ports pins.

Port 2 (Pins 21 through 28)


Port 2 occupies a total of 8 pins (pins 21 through 28) and can be used for both
input and output operations. Just as P1 (Port 1), P2 also doesn't require external
Pull-up resistors because they are already connected internally. It must be used
along with P0 to provide the 16-bit address for the external memory.

Besides working as I/O, Port P2 is also used to provide 16-bit address bus for
external memory along with Port 0. When the 8051 is connected to an external
memory, it provides path for upper 8-bits of 16-bits address, and it cannot be
used as I/O. Upon reset, Port 2 is configured as an input port.
Port 3 (Pins 10 through 17)

•It is also of 8 bits and can be used as Input/Output. This port provides some
extremely important signals.
•P3.0 and P3.1 are RxD (Receiver) and TxD (Transmitter) respectively and are
collectively used for Serial Communication.
•P3.2 and P3.3 pins are used for external interrupts.
•P3.4 and P3.5 are used for timers T0 and T1 respectively.
•P3.6 and P3.7 are Write (WR) and Read (RD) pins. These are active low pins,
means they will be active when 0 is given to them and these are used to provide
Read and Write operations to External ROM in 8031 based systems.
In 8051, I/O operations are done using four ports and 40 pins. The following pin
diagram shows the details of the 40 pins. I/O operation port reserves 32 pins
where each port has 8 pins. The other 8 pins are designated as Vcc, GND, XTAL1,
XTAL2, RST, EA (bar), ALE/PROG (bar), and PSEN (bar).
It is a 40 Pin PDIP (Plastic Dual Inline Package)
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.
Addressing Modes in 8085

These are the instructions used to transfer the data from one register to another register,
from the memory to the register, and from the register to the memory without any
alteration in the content. Some addressing modes are-

Immediate mode: In immediate addressing the operand is specified in the instruction


itself. In this mode the data is 8 bits or 16 bits long and data is the part of instruction.

Example:  MOV AL, 35H (move the data 35H into AL register)

Register mode: In register addressing the operand is placed in one of 8 bit or 16 bit
general purpose registers. The data is in the register that is specified by the instruction.
Example: MOV AX,CX (move the contents of CX register to AX register)

Register Indirect mode: In this addressing the operand’s offset is placed in any one of
the registers BX,BP,SI,DI as specified in the instruction. The effective address of the
data is in the base register or an index register that is specified by the instruction.

MOV AX, [BX](move the contents of memory location s addressed by


the register BX to the register AX)
Hardware Connection of Pins
Vcc − Pin 40 provides supply to the Chip and it is +5 V.
Gnd − Pin 20 provides ground for the Reference.

XTAL1, XTAL2 (Pin no 18 & Pin no 19) − 8051 has on-chip oscillator but
requires external clock to run it. A quartz crystal is connected between the
XTAL1 & XTAL2 pin of the chip. 8051 IC is available in various speeds and it all
depends on this Quartz crystal, for example, a 20 MHz microcontroller
requires a crystal with a frequency no more than 20 MHz.

RST (Pin No. 9) − It is an Input pin and active High pin. Upon applying a high
pulse on this pin, that is 1, the microcontroller will reset and terminate all
activities. This process is known as Power-On Reset.
EA or External Access (Pin No. 31) − It is an input pin. This pin is an active low
pin; upon applying a low pulse, it gets activated. In case of microcontroller
(8051/52) having on-chip ROM, the EA (bar) pin is connected to Vcc.

PSEN or Program store Enable (Pin No 29) − This is also an active low pin, i.e., it
gets activated after applying a low pulse. It is an output pin and used along with
the EA pin in 8031 based (i.e. ROMLESS) Systems to allow storage of program
code in external ROM.

ALE or (Address Latch Enable) − This is an Output Pin and is active high. It is
especially used for 8031 IC to connect it to the external memory. It can be used
while deciding whether P0 pins will be used as Address bus or Data bus.
Embedded Programming

Salient features of the language

•C language is a software designed with different


keywords, data types, variables, constants, etc.
•Embedded C is a generic term given to a
programming language written in C, which is
associated with a particular hardware architecture.
•Embedded C is an extension to the C language with
some additional header files. These header files may
change from controller to controller.
•The microcontroller 8051 #include<reg51.h> is
used.
  Differences between C and Embedded C
                                                                                                                                                              
The basic additional features of the embedded software

Data types
The data type refers to an extensive system for declaring
variables of different types like integer, character, float, etc. The
embedded C software uses four data types that are used to store
data in the memory.

The ‘char’ is used to store any single character; ‘int’ is used to


store integer value, and ‘float’ is used to store any precision
floating point value.

The size and range of different data types on a 32-bit machine is


given in the following table. The size and range may vary on
machines with different word sizes.
Datatype

Keywords
There are certain words that are reserved for doing specific
tasks. These words are known as keywords. They are standard
and predefined in the Embedded C.
Keywords are always written in lowercase. These keywords must
be defined before writing the main program. The basic keywords
of an embedded software are given below:
Keywords
sbit: This data type is used in case of accessing a single bit of SFR
register.
Syntax: sbit variable name = SFR bit ;
Ex: sbit a=P2^1;
Explanation: If we assign p2.1 as ‘a’ variable, then we can use ‘a’
instead of p2.1 anywhere in the program, which reduces the
complexity of the program.
Bit: This data type is used for accessing the bit addressable
memory of RAM (20h-2fh).
Syntax: bit variable name;
Ex: bit c;
Explanation: It is a bit sequence setting in a small data area that
is used by a program to remember something.

SFR: This data type is used for accessing a SFR register by


another name. All the SFR registers must be declared with
capital letters.

Syntax: SFR variable name = SFR address of SFR register;


Ex: SFR port0=0x80;
Explanation: If we assign 0x80 as ‘port0’, then we can use 0x80
instead of port0 anywhere in the program, which reduces the
complexity of the program.
SFR Register: The SFR stands for ‘Special Function Register’.
Microcontroller 8051 has 256 bytes of RAM memory. This RAM is
divided into two parts: the first part of 128 bytes is used for data
storage, and the other of 128 bytes is used for SFR registers. All
peripheral devices like I/O ports, timers and counters are stored
in the SFR register, and each element has a unique address.
The Structure of an Embedded C Program

comments
preprocessor directives
global variables
main() function
{
local variables
statements
…………..
…………..
}
fun(1)
{
local variables
statements
…………..
…………..
}
Comments: In embedded C programming language, we can place
comments in our code which helps the reader to understand the
code easily.
C=a+b; /* add two variables whose value is stored in another
variable C*/

Preprocessor directives: All the functions of the embedded C


software are included in the preprocessor library like
“#includes<reg51.h>, #defines”. These functions are executed at
the time of running the program.
Global variable
A global variable is a variable that is declared before the main
function, and can be accessed on any function in the program.
.

 
Local variable

A                                                                                                 
local variable is a variable declared within a function, and it is
. valid only to be used within that function

Main () function
The execution of a program starts with the main function. Every program
uses only one main () function
Advantages of embedded C program
•Its takes less time to develop application program.
•It reduces complexity of the program.
•It is easy to verify and understand.
•It is portable in nature from one controller to another.
(1)LED BLINKING

#include<reg51.h>
void main(void)
{
unsigned int i;
P1=0xff;
while(1)
{
P1=0x00;
for(i=0;i<500;i++);
P1=0xff;
for(i=0;i<500;i++);
}
}
(2) LED BLINKING
#include<reg51.h>
sbit a=P1^2;
void main(void)
{
unsigned int i;
unsigned char x;
a=0x00;
while(1)
{
a=0x01;
for(i=0;i<255;i++);
a=0x00;
for(i=0;i<255;i++);
}
}
3. Binary counter
#include<reg51.h>
void delay(int time); // delay() function prototype, this function generates
//delay = (time x
1msec)
// For example delay(500). Generates delay of (500 x 1msec) = 500msec
void main()
{
P1 = 00000000; // Initialize Port 1 as Output Port
while(1)
{
P1++; // Increment Port 1 (Binary Counter)
delay(100);
} // i.e. 1000 x 1msec = 1sec.
}
void delay(int time)
{
int i,j;
for(i=0;i<=time;i++)
for(j=0;j<=23;j++);
}

You might also like