0% found this document useful (0 votes)
43 views35 pages

Esad File

The document is a lab file for a Bachelor of Technology in Electronics and Communication, detailing experiments related to the 8051 microcontroller. It covers the history, architecture, advantages, and disadvantages of the 8051 microcontroller, along with practical programming examples using Keil uVision 5. The document includes specific experiments aimed at performing arithmetic operations and sending ASCII values using the microcontroller.

Uploaded by

avengeradi15
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)
43 views35 pages

Esad File

The document is a lab file for a Bachelor of Technology in Electronics and Communication, detailing experiments related to the 8051 microcontroller. It covers the history, architecture, advantages, and disadvantages of the 8051 microcontroller, along with practical programming examples using Keil uVision 5. The document includes specific experiments aimed at performing arithmetic operations and sending ASCII values using the microcontroller.

Uploaded by

avengeradi15
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/ 35

BACHELOR OF TECHNOLOGY

IN
ELECTRONICS AND COMMUNICATION

ESAD LAB FILE


NAME:ASHISH RATURI
SEMESTER: SIXTH
ROLL NO.: 06713202822
SUBMITTED TO : DR. GAGANDEEP KAUR
INDEX
EXPERIMENT-1

AIM:
Introduction to 8051 Microcontroller.

APPARATUS USED:
In lab we have used ANSHUMAN 8051 MICROCONTROLLER KIT

THEORY:
History:

The history of microcontrollers is intertwined with the development of


microprocessors, but with a key difference.

While microprocessors are the brains of computers, microcontrollers are like


miniaturized computers designed for specific tasks.

Here is the timeline of some key milestones:

Early 1970s: The race is on! Around the same time Intel created the first
microprocessor, the 4-bit Intel 4004, engineers at Texas Instruments were
working on a similar concept.

1971: Credit for the first true microcontroller often goes to Texas Instruments"
Gary Boone and Michael Cochran, who developed the TMS 1000. This 4-bit
microcontroller contained all the essential components (CPU, memory,
input/output) on a single chip.

Mid-1970s: Japanese electronics manufacturers jump in, developing


microcontrollers specifically for automobiles, like engine control and in-car
entertainment systems.

1977: Intel responds to the popularity of the TMS 1000 with the Intel 8048,
another single-chip design that combined RAM and ROM with a
microprocessor. This chip found its way into millions of PC keyboards.

Since then, microcontrollers have continued to evolve:

Increasing Complexity: Bit size grew from 4-bit to 8-bit, 16-bit, 32-bit and
beyond, enabling more complex tasks.
Re-programmability: Early microcontrollers required specialized equipment for
programming. The introduction of erasable programmable memory (like flash
memory) allowed for easier updates and development.

Wider Applications: Microcontrollers are now embedded in countless devices,


from appliances and toys to medical equipment and industrial automation.

Today, microcontrollers are ubiquitous, silently running the background


operations in a vast array of technologies.

Difference between Microcontroller and Microprocessor:

Functionality:

Microprocessor (µP): The brains of a computer system. It handles the central


processing tasks and requires additional components like memory and
input/output (I/O) interfaces to function. They are more general-purpose.
Microcontroller (µC): Self-contained mini-computer on a single chip. It
integrates the CPU, memory (RAM and ROM), and I/O peripherals all together.

Microcontrollers are designed for specific tasks and are more application-
specific.

Complexity:

Microprocessor: More complex architecture with higher clock speeds and


larger memory capacities. This makes them suitable for demanding
computational tasks.

Microcontroller: Simpler design with lower clock speeds and limited memory.
This keeps them cost-effective and efficient for embedded systems.

Applications:

Microprocessor: Found in personal computers, servers, smartphones, and


other general-purpose computing devices.

Microcontroller: Widely used in embedded systems like washing machines,


thermostats, drones, toys, and many more.

Analogy:

Think of a microprocessor as a powerful, expandable desktop computer.

A microcontroller is like a small, efficient single-board computer designed for a


specific purpose.

Introduction to 8051 Microcontroller:

The 8051 microcontroller is a Harvard architecture 8-bit microcontroller. It has


a RISC (Reduced Instruction Set Computing) architecture. It features a single
accumulator, 16-bit program counter, and 8-bit data bus. It has 4KB of on-chip
program memory (ROM). It also haves 128 bytes of on-chip data memory
(RAM) with a built-in memory controller. It has four 8-bit I/O ports that can be
programmed to be input or output. It also has two 16-bit timers/counters, a
serial communication port, and an interrupt controller. The architecture
supports direct addressing, register indirect addressing, and immediate
addressing modes. Many manufacturers produce 8051 microcontrollers. Their
variations are increased memory, additional peripherals, and improved clock
speeds.

BASIC ARCHITECTURE of 8051 MICROCONTROLLER:

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

2. 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:

INTO It is an external interrupt having code 0. External hardware causes this


interrupt.

INTI It is an external interrupt having code 1. External hardware causes this


interrupt.

TFO This is for timer 0 overflow interrupt.

TF1 This is for timer 1, overflow interrupt

RI/TI This is a serial communication interrupt.

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

4. 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:

a. Address Bus: The address bus in the 8051 microcontroller architecture is 16


bits. This bus transfers data from the CPU to the memory.

b. Data Bus: In 8051 microcontroller architecture, the data bus is 8 bits. It helps
in carrying the data from one place to another.
5. 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.

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

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

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

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

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

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

a. Immediate Addressing Mode

b. Register Addressing Mode

c. Register Indirect Addressing Mode

d. Implied Addressing Mode

e. Direct Addressing Mode

f. Indexed Addressing Mode

8051 Pin Diagram:


The 8051 microcontroller is a popular microcontroller in embedded systems. It
has 40 pins, each of which has a specific purpose. An explanation of the 8051
pin diagram is provided below:

Port PO(Pins 32-39)

An 8-bit bidirectional I/O port is port 0.

It can be applied to operations involving input and output.

A different name for it is the "low-order" address bus.

Port P1 (Pins 1-8)

Another 8-bit bidirectional I/O port is Port 1, which is.

It can be applied to operations involving input and output.

A different use for it is to offer a collection of all-purpose I/O pins or external


interrupt pins.

Port P2 (Pins 2-28)

An 8-bit bidirectional I/O port is known as Port 2.

It can be applied to operations involving input and output.

Additionally, it functions as the high-order address bus for accessing external


memory.

Port 3 (P3) (Pins 10-17)

A bidirectional 8-bit I/O port with additional specific functionality is port 3.

It contains two external interrupt pins (INTO, INTI) that can cause hardware
interruptions from outside the device.
TXD and RXD, two additional pins, are provided for serial communication.

ALE (Address Latch Enable) (Pin 30):

A memory read/write operation uses ALE to latch the address of external


memory devices.

It is a pulse signal produced by the 8051 to let other devices know that the data
on the address bus is legitimate.

EA/VPP (External Access/Programming Enable) (Pin 31)

EA/VPP is used for two different functions depending on its logic level.

When connected to VCC (5V), it enables the 8051 to fetch code from external
memory.

When connected to VPP (12V), it enables programming of the 8051's ROM.

PSEN (Program Store Enable) (Pin 29)

PSEN is used to indicate that external program memory is being accessed.

When activated, it informs the external ROM that the 8051 is fetching
instructions.

RST (Reset) (Pin 9):

RST is an active-low reset input.

When pulled low, it resets the microcontroller, initializing it to its starting state.

XTALI and XTAL2 (Pins 18 and 19)

These are the connections for an external crystal oscillator or resonator.

They are used to provide the clock signal for the microcontroller.
VCC and GND (Pins 20 and 40)

VCC is the supply voltage pin (typically +5V).

GND is the ground reference pin.

Advantages of 8051 Microcontroller Architecture:

The 8051 microcontroller architecture offers several advantages, making it


popular in embedded systems:

Wide Availability: It's one of the most widely used microcontrollers, with
numerous variants and extensive support available.

Low Cost: The 8051 is cost-effective for a wide range of applications, making it
a go-to choice for budget-sensitive projects.

Simple Architecture: Its straightforward architecture is easy to understand and


program, ideal for beginners and complex projects alike.
Power Efficiency: It is designed for low power consumption, extending the
battery life of portable devices.

Versatile I/O Operations: Provides a variety of built-in I/O operations, including


timers, serial communication, and interrupt handling, facilitating diverse
applications.

Embedded C Compatibility: It supports programming in Embedded C, a popular


language for microcontroller programming, alongside assembly language.

Disadvantages of 8051 Microcontroller Architecture:

The 8051 microcontroller architecture, while widely used, has several


disadvantages:

Limited Memory: The standard 8051 comes with only 4KB of ROM and 128
bytes of RAM, which may not suffice for more complex applications.

Single Accumulator: Reliance on a single accumulator for operations can lead to


bottlenecks in processing and increased instruction execution time.

No Power Management: Older 8051 models lack advanced power management


features, leading to higher power consumption compared to modern
microcontrollers.

Slower Speed: Compared to contemporary microcontrollers, the 8051's clock


speed is relatively slow, affecting performance in time-sensitive applications.

Fewer I/O Ports: With only four 8-bit I/O ports, the 8051 provides limited direct
interface capabilities for peripherals and sensors.

No In-built ADCs: Absence of built-in Analog-to-Digital Converters (ADCs)


necessitates external components for analog signal processing, increasing
complexity and cost.

Benefits of the 8051 Microcontroller:


Simple and Cost-Effective: The 8051's architecture is straightforward, making it
easy to learn and use. This also translates to lower production costs, ideal for
applications where budget is a major concern.

Versatile Instruction Set: The 8051 packs a powerful instruction set for an 8-bit
microcontroller. It supports a variety of arithmetic, logical, and branching
operations, allowing you to tackle a wide range of tasks within its processing
capabilities.

Wide Availability and Strong Community Support: The 8051 has been around
for a long time and remains a popular choice. This translates to easy
availability, a wealth of documentation and tutorials, and a strong community
of developers you can tap into for help.

Low Power Consumption: While not the most power-efficient microcontroller


on the market, the 8051 consumes less power than some of its counterparts,
making it suitable for battery-powered applications to an extent.

Limitations of the 8051 Microcontroller:

Limited Processing Power: Being an 8-bit microcontroller, the 8051 is inherently


less powerful than its 16, 32, or 64-bit counterparts. This limits its ability to
handle complex calculations or data processing tasks.

Limited Memory: Both program memory (ROM) and data memory (RAM) are
constrained in the 8051. This can restrict the size and complexity of programs
you can develop for it.

Limited On-Chip Peripherals: The 8051 has a basic set of built-in peripherals like
timers and serial ports. For more advanced functionalities, you might need
external components, increasing design complexity.
EXPERIMENT -2

AIM:
Write a program to perform addition and subtraction of two numbers.

SOTWARE USED:
Keil u vision 5

PROGRAM
#include <reg51.h>

void main(void)
{
unsigned char a, b, c, m, n, o, p, q, r, x, y, z;

a=0x03;
b=0x05;
c=a+ b; // perform addition
m=0x0a;
n=0x04;
o=m-n ; // perform subtraction

P0=c;
P1=o;
}
OUTPUT
EXPERIMENT -3
AIM:
Write a program to perform multiplication and division of two numbers.

SOTWARE USED:
Keil u vision 5

PROGRAM
#include <reg51.h>

void main(void)
{
unsigned char a, b, c, m, n, o, p, q, r, x, y, z;
p=0x04;
q=0x06;
r=p/q;

x=0x02;
y=0x04;
z=x*y;

P2=r;//perform division
P3=z;//perform multiplication

OUTPUT
EXPERIMENT-4
AIM:
Write an 8051 C program to send hex values for ASCII characters of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E to Pl.

SOFTWARE USED:
Keil uVision5

PROGRAM CODE

#include<reg51.h>

void main(void)

unsigned char mynum[] = "0123456789ABCDE";

unsigned char z;

for(z=0; z <= 15; z++)

P1 = mynum[z];

OUTPUT:
EXPERIMENT - 5
AIM:

Write a Program to find factorial of a number.

Software Required:

Keil uVision5

Code:

//factorial of a number

#include <reg51.h>

unsigned int factorial(unsigned int n){

unsigned int result = 1;

while(n>1){

result *=n;

n-;

return result;

void main(void) {

unsigned int num = 7;

unsigned int result;

result = factorial(num);

P1 = result;

while(1);}
OUTPUT
EXPERIMENT-6
AIM:

Write a C program to toggle bits of P1 ports continuously with a 250 ms.

Software Required:

Keil uVision5

PROGRAM CODE

#include <reg51.h>

void MSDelay(unsigned int); //delay routine definition

void main()

while(1) //repeat forever

P1 = 0x55;

MSDelay(1000);

P1 = 0xaa;

MSDelay(1000);

//delay routine implimentation

void MSDelay(unsigned int itime)

unsigned int i, j;
for(i=0; i < itime; i++)

for(j=0;j<1275; j++);
}

OUTPUT:
EXPERIMENT - 7

AIM:

Write an 8051 C program to get byte of data from P1, wait ½ second (i.e 500ms) and then
send it to P2.

SOFTWARE USED:

Keil uVision5.

PROGRAM CODE:

#include <reg51.h>

void MSDelay(unsigned int);

void main()

unsigned char mybyte;

P10x45; // input port pl

while(1)

mybyte P1; //get a byte from pl

MSDelay(500); //wait for 1 sec

P2mybyte; // sending to p2

void MSDelay(unsigned int itime)

unsigned int i, j;
for(i=0; i<itime; i++)

for(j=0; j <1275; j++);


}

OUTPUT:
EXPERIMENT-8
AIM:

Write an 8051 C program to send the two messages "first name" and "last name" to the
serial port. If SW-0, send first name else if SW-1, send last name.

SOFTWARE USED:

Keil uVision5.

PROGRAM CODE:

#include <reg51.>

unsigned char SW;

void main(void)

unsigned char z,

unsigned char first_name[] = "NEW";

unsigned char last_name[] = "USER";

TMOD=0x20;

TH1 = 0xfd;

SCON = 0x50;

TRI=1;

if (SW==0)

for(z=0; z < 3; z++) {

SBUF=first_name[z];
while(T1==0)

TI=0;

else
{

for(z=0; z <4; z++)


{

SBUF=last_name[z].

while(TI==0);

TI=0;

}
}
}

OUTPUT:
EXPERIMENT -9
AIM:

To use Embest IDE for ARM and ARM Software Emulator.

SOFTWARE USED:

Embest IDE.

THEORY:

Embest IDE is an Integrated Development Environment for software cross- development.


The EmbestIDE is an application that provides a simple and versatile graphical user interface
and tools for developing embedded software. It is an Integrated Development Environment
(IDE) that facilitates managing and building projects, establishing and managing host-target
communication, running and debugging applications. It provides an efficient way for
developing embedded applications. EmbestIDE comprises the following elements (Figure 1-
1):

An integrated source-code editor.

A project management facility.

Integrated C and ASM compilers and linker. Z

a source-level debugger.

an integrated development environment.

an ARM simulator

EmbestIDE uses host-target cross model for developing embedded applications. EmbestIDE
runs on a host computer. Your target board is connected to the host computer through
debug device (BDM/JTAG Emulator). You can edit and build your projects on the host, and
create a target executable file with EmbestIDE. Download the target file to the target, and
then use EmbestIDE debugger to debug it through the communication of debug device
connected between the host computer and the target board. Figure1-2 illustrates the host-
target cross model with EmbestIDE.

When you use EmbestIDE for ARM, a debug device-Embest JTAG Emulator is provided. See
appendix A "JTAG Emulator Connection" for detail describe about Embest JTAG Emulator.
Simple Example

This section shows users step by step how to create, compile and debug a simple project.
The project described below is to create a random number. The project demo locates at
Examples\arm\explasm under EmbestIDE installing directory. The files to be used are:

Random.s Assemble file of random number function

Randtest Main program file

Create a Project

1) Creating Project

Select File > New Workspace menu, Give a project name and specify project directory as
shown Rantest has been used as a project name, and project directory has been specified as
D:\EmbestIDE\Example\arm250\explasm\, D:\EmbestIDE is default installing directory of
EmbestIDE unless noted.

After clicking OK, two files will be created in the project directory.
Dac.ews workspace file
Dac.pjf Project file.

After the project has been created,files pane will appear in Embest IDE workspace window
as shown.
2) Add Source Files

Choose Project Source Files folder in rantest workspace window. Click Project > Add To
Project> Files to add source files. You can also right click Project Source Files folder to add
source files as shown below

You can add the source files in the pop up dialog box. To select source files, press CTRL key
and hold, click source files of random.s and randtest.c in Project directory, See Figure below
3.1.1 Project Settings

Above Figure shows Workspace Window

After creating a project, you need to configure the project. The project settings include CPU
settings, emulator settings, debug settings, directory settings, compiler settings, assembler
settings and linker settings. The project settings is a critical step to entire software
development.

Click Project > Settings, Project Settings dialog box pops up, then Choose randtest files in the

dialog.

1) CPU Settings

Select Processor pane from Project Settings dialog box. Define CPU module as ARM7, CPU
family and CPU member as ARM7 too. Switch Endian to little endian. Build tools are GNU
tools for ARM.
After build tool has been set, Project Setting dialog will show the pane of this build tool

2) Emulator Settings

Select Remote pane from Project Settings dialog. Define Remote Device as jtagarm7.
Because of Embest Eimulator for ARM does not support to change the working speed, don't
worry about the setting of Speed item. When wing Embest

PowerICE for ARM, select the valid work speed: Full Speed(120Kbyte/). High Speed. Medium
Speed, Low Speed. Communication port with remote device is PARALLEL. Communication
channel is LPT1 as shown on Figure

3) Debug Settings

Select Debug pane from Project Settings dialog. Select General from Category, Set symbol
file as

/debug/rantest.elf and Action after connected as None. See Figure


Select download from category set Download file as/debug/rantest.elf.set Download verify
option on set download file to address 0x20000000

Execute program starting from download address.


Set memory map to use map file, and set target memory map file as

$(EMBEST_IDE)\targets\at91\targets\eb-40.map.

4. Compiler Settings

5. Assembler settings
Select assembler pane from project settings dialog, set object files location as/debug and
other as default.
6 LINKER SETTINGS

Select linker pane from project settings dialog Select general from category set objects files
location as debug and other as default.

You might also like