SlideShare a Scribd company logo
1 of 34
8051 Microcontroller and Interfacing Experiments
Introduction to 8051 Microcontroller
INTRODUCTION
A microcontroller is a small computer on a single integrated circuit containing a
processor core, memory, and programmable input/output peripherals. Microcontrollers are
designed for embedded applications, in contrast to the microprocessors used in personal
computers or other general purpose applications. But their presence is unnoticed at most of the
places like
• At supermarkets in Cash Registers, Weighing Scales, etc.
• At home in Ovens, Washing Machines, Alarm Clocks, etc.
• At play in Toys, VCRs, Stereo Equipment, etc.
• At office in Typewriters, Photocopiers, Elevators, etc.
• In industry in Industrial Automation, safety systems, etc.
• On roads in Cars, Traffic Signals, etc.
What inside them makes these machines smart? The answer is microcontroller.
Creating applications for the microcontrollers is different than any other development job
in electronics and computing. Before selecting a particular device for an application, it is
important to understand what the different options and features are and what they can mean with
regard to developing the application.
The reminder of the book will go through different types of programming and interfacing
techniques of microcontroller, mainly 8051 based microcontrollers, in detail.
COMPARING MICROPROCESSOR AND MICROCONTROLLER
• Microprocessor is a single chip CPU, microcontroller contains, a CPU and much of the
remaining circuitry of a complete microcomputer system in a single chip.
• Microcontroller includes RAM, ROM, serial and parallel interface, timer, interrupt
schedule circuitry (in addition to CPU) in a single chip.
 RAM is smaller than that of even an ordinary microcomputer, but enough for its
applications.
 Interrupt system is an important feature, as microcontrollers have to respond to
control oriented devices in real time.
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
1
8051 Microcontroller and Interfacing Experiments
• Microprocessors are most commonly used as the CPU in microcomputer systems.
Microcontrollers are used in small, minimum component designs performing control-
oriented activities.
• Microprocessor instruction sets are processing intensive, implying powerful addressing
modes with instructions catering to large volumes of data. Their instructions operate on
nibbles, bytes, etc. Microcontrollers have instruction sets catering to the control of inputs
and outputs. Their instructions operate also on a single bit. E.g., a motor may be turned
ON and OFF by a 1-bit output port.
FEATURES OF 8051 MICROCONTROLLER
The Intel 8051 microcontroller is one of the most popular general purpose
microcontrollers in use today. The microcontroller 8051 is 8-bit microcontroller which includes:
CPU (Central Processing Unit), RAM (Random Access Memory), EPROM/PROM/ROM
(Erasable programmable Read Only Memory), I/O (input/output) – serial and parallel, timers,
interrupt controllers.
Figure1: Block Diagram of 8051 Microcontroller
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
2
8051 Microcontroller and Interfacing Experiments
By only including the features specific to the task (control), cost is relatively low. A
typical microcontroller has bit manipulation instructions, easy and direct access to I/O
(input/output), and quick and efficient interrupt processing. Figure1 shows the block diagram of
a typical microcontroller.
Basic features
• 8-bit CPU with register A and B.
• 8-bit data bus.
• 16-bit address bus.
• 32 general purpose registers each of 8 bits.
• 16 bit timers (usually 2, but may have more, or less).
• Bit as well as byte addressable RAM area of 16 bytes.
• Four 8-bit ports, (short models have two 8-bit ports).
• 16-bit program counter and data pointer.
• 8-bit stack pointer and 8-bit PSW (Program Status Word).
• Internal ROM (4kB) and RAM (128 Bytes).
• Serial data communication.
• Five Interrupt Sources (2 internal and 3 external interrupts).
Basic pins
• Figure2 shows the pin diagram of 8051 micro controller.
• PIN 9: PIN 9 is the reset pin which is used reset the microcontroller’s internal registers
and ports upon starting up. (Pin should be held high for 2 machine cycles.).
• PINS 18 & 19: The 8051 has a built-in oscillator amplifier hence we need to only
connect a crystal at these pins to provide clock pulses to the circuit.
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
3
8051 Microcontroller and Interfacing Experiments
• PIN 40 and 20: Pins 40 and 20 are VCC and ground respectively. The 8051 chip needs
+5V 500mA to function properly, although there are lower powered versions like the
Atmel 2051 which is a scaled down version of the 8051 which runs on +3V.
• PINS 29, 30 & 31: As described in the features of the 8051, this chip contains a built-in
flash memory. In order to program this we need to supply a voltage of +12V at pin 31. If
external memory is connected then PIN 31, also called EA/VPP, should be connected to
ground to indicate the presence of external memory. PIN 30 is called ALE (address latch
enable), which is used when multiple memory chips are connected to the controller and
only one of them needs to be selected. We will deal with this in depth in the later
chapters. PIN 29 is called PSEN. This is "program select enable". In order to use the
external memory it is required to provide the low voltage (0) on both PSEN and EA pins.
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
4
8051 Microcontroller and Interfacing Experiments
Figure2: Pin Diagram of 8051 microcontroller
Port Pins
There are four 8-bit ports: P0, P1, P2 and P3.
•
• PORT P1 (Pins 1 to 8): The port P1 is a general purpose input/output port which can be
used for a variety of interfacing tasks. The other ports P0, P2 and P3 have dual roles or
additional functions associated with them based upon the context of their usage.
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
5
8051 Microcontroller and Interfacing Experiments
• PORT P3 (Pins 10 to 17): PORT P3 acts as a normal IO port, but Port P3 has additional
functions such as, serial transmit and receive pins, 2 external interrupt pins, 2 external
counter inputs, read and write pins for memory access.
• PORT P2 (pins 21 to 28): PORT P2 can also be used as a general purpose 8 bit port
when no external memory is present, but if external memory access is required then
PORT P2 will act as an address bus in conjunction with PORT P0 to access external
memory. PORT P2 acts as A8-A15, as can be seen from fig 1.1
• PORT P0 (pins 32 to 39) PORT P0 can be used as a general purpose 8 bit port when no
external memory is present, but if external memory access is required then PORT P0 acts
as a multiplexed address and data bus that can be used to access external memory in
conjunction with PORT P2. P0 acts as AD0-AD7, as can be seen from Figure2.
Data and Program Memory
The 8051 Microprocessor can be programmed in PL/M, 8051 Assembly, C and a number
of other high-level languages. Many compilers even have support for compiling C++ for an
8051. Program memory in the 8051 is read-only, while the data memory is considered to be
read/write accessible. When stored on EEPROM or Flash, the program memory can be rewritten
when the microcontroller is in the special programmer circuit. Program memory in the 8051 is
read-only, while the data memory is considered to be read/write accessible. When stored on
EEPROM or Flash, the program memory can be rewritten when the microcontroller is in the
special programmer circuit.
Program Start Address
The 8051 starts executing program instructions from address 0x00 in the program
memory.
Direct Memory
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
6
8051 Microcontroller and Interfacing Experiments
The 8051 has 256 bytes of internal addressable RAM, although only the first 128 bytes
are available for general use by the programmer. The first 128 bytes of RAM (from 0x00 to
0x7F) are called the Direct Memory, and can be used to store data.
Special Function Register (SFR)
The Special Function Register (SFR) is the upper area of addressable memory, from
address 0x80 to 0xFF. A, B, PSW, DPTR are called SFR. This area of memory cannot be used
for data or program storage, but is instead a series of memory-mapped ports and registers. All
port input and output can therefore be performed by memory mov operations on specified
addresses in the SFR. Also, different status registers are mapped into the SFR, for use in
checking the status of the 8051, and changing some operational parameters of the 8051.
General Purpose Registers
The 8051 has 4 selectable banks of 8 addressable 8-bit registers, R0 to R7. This means
that there are essentially 32 available general purpose registers, although only 8 (one bank) can
be directly accessed at a time. To access the other banks, we need to change the current bank
number in the flag status register.
A and B Registers
The A register is located in the SFR memory location 0xE0. The A register works in a
similar fashion to the AX register of x86 processors. The A register is called the accumulator,
and by default it receives the result of all arithmetic operations. The B register is used in a
similar manner, except that it can receive the extended answers from the multiply and divide
operations. When not being used for multiplication and Division, the B register is available as an
extra general-purpose register.
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
7
8051 Microcontroller and Interfacing Experiments
Programming with P89V51RD2
INTRODUCTION
The P89V51RD2 is an 80C51 microcontroller with 64kB Flash and 1024 bytes of data
RAM. A key feature of the P89V51RD2 is its X2 mode option. The design engineer can choose
to run the application with the conventional 80C51 clock rate (12 clocks per machine cycle) or
select the X2 mode (6 clocks per machine cycle) to achieve twice the throughput at the same
clock frequency. Another way to benefit from this feature is to keep the same performance by
reducing the clock frequency by half, thus dramatically reducing the EMI.
The Flash program memory supports both parallel programming and in serial In-System
Programming (ISP). Parallel programming mode offers gang-programming at high speed,
reducing programming costs and time to market. ISP allows a device to be reprogrammed in the
end product under software control. The capability to field/update the application firmware
makes a wide range of applications possible.
The P89V51RD2 is also In-Application Programmable (IAP), allowing the Flash
program memory to be reconfigured even while the application is running. Figure3 shows the
photograph picture of 8051 development board.
Figure3: 8051 Development Board
The hardware required to develop projects is 8051 development board and it has the
following features:
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
8
8051 Microcontroller and Interfacing Experiments
• P89V51RD2BN 40 Pin DIP.
• Both Manual and Power on Reset.
• 16 x 2 Alphanumeric LCD and trimmer for contrast Control.
• 8channel analog input using ADC0809.
• 4 x 4 hexadecimal keyboard.
• RS 232 serial interface.
• On board EEPROM using 24C02.
• On board RTC using DS1307.
• Multiplexed four common anode seven segment displays.
• 8 Led indication panel for checking the port operation.
• 1channel relay drive.
• 8channel uln2803 drive that can be used to drive stepper motor or 8 relays.
Features of P89V51RD2
• 80C51 Central Processing Unit 5V Operating voltage from 0 to 40MHz.
• 64 KB of on-chip Flash program memory.
• ISP (In-System Programming).
• IAP (In-Application Programming).
• Enhanced UART.
• PCA (Programmable Counter Array) with PWM and Capture/Compare functions.
• Four 8-bit I/O ports with three high-current Port 1 pins (16mA each).
• Three 16-bit timers/counters Programmable Watchdog timer (WDT).
• Eight interrupt sources with four priority levels Second DPTR register.
• Low EMI mode (ALE inhibit).
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
9
8051 Microcontroller and Interfacing Experiments
• TTL and CMOS compatible logic levels.
Software’s required to develop projects
1. Keil IDE(Integrated Development Environment)
An integrated development environment (IDE) also known as integrated design
environment or integrated debugging environment is a software application that provides
comprehensive facilities to computer programmers for software development. An IDE
normally consists of:
• Source code editor.
• Compiler and/or an interpreter.
• Build automation tools.
• Debugger.
Installing keil software
• Open My Computer
• Within the my computer window, open the CD Drive, 8051
DEVELOPMENT BOARD CDDATACOMPILERSkeil
• In this directory keil setup file contains, double click on the file and follow the
instructions.
• After installation, if it prompts you to reboot the computer, do it.
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
10
8051 Microcontroller and Interfacing Experiments
2. Flash Magic Programmer
Flash Magic provides a Windows based user interface that is easy and intuitive,
which connects to the target via serial line. Flash Magic is a free, powerful, feature-rich
Windows application that allows easy programming of Philips FLASH Microcontrollers.
Installing flash magic software
• Follow the same instructions as guided in the previous section, except locate
the setup file at 8051 DEVELOPMENT BOARDDATAPROGRAMMER
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
11
8051 Microcontroller and Interfacing Experiments
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
12
8051 Microcontroller and Interfacing Experiments
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
13
8051 Microcontroller and Interfacing Experiments
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
14
8051 Microcontroller and Interfacing Experiments
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
15
8051 Microcontroller and Interfacing Experiments
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
16
8051 Microcontroller and Interfacing Experiments
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
17
8051 Microcontroller and Interfacing Experiments
Lab experiments on P89V51RD2
Experiment No. 1
Aim:
To construct an 8-bit binary counter using P89V51RD2 and LEDs, that displays binary
count from 0 to 255.
Schematic Diagram:
Algorithm:
1. Connect LEDs to the port1 as shown in the schematic diagram. In the
schematic it is shown that four LEDs are connected. But to display binary
counter from 0 to 255 user should connect 8 LEDs.
2. Configure port1 as output port.
3. Initialize a variable to 0, equate it to port1 and send it to port1.
4. Increment the value and send it to port1 until it reaches 255.
5. Write the program in Keil software by using embedded-C language.
6. Generate the .hex file and transfer the .hex file from PC to the target board by
using flash magic.
Source Code:
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
18
8051 Microcontroller and Interfacing Experiments
Lab experiments on P89V51RD2
Experiment No. 1
Aim:
To construct an 8-bit binary counter using P89V51RD2 and LEDs, that displays binary
count from 0 to 255.
Schematic Diagram:
Algorithm:
1. Connect LEDs to the port1 as shown in the schematic diagram. In the
schematic it is shown that four LEDs are connected. But to display binary
counter from 0 to 255 user should connect 8 LEDs.
2. Configure port1 as output port.
3. Initialize a variable to 0, equate it to port1 and send it to port1.
4. Increment the value and send it to port1 until it reaches 255.
5. Write the program in Keil software by using embedded-C language.
6. Generate the .hex file and transfer the .hex file from PC to the target board by
using flash magic.
Source Code:
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
19
8051 Microcontroller and Interfacing Experiments
/* -----------------------------------------------------------------------
binarycounter.c : Demonstration of interfacing of LEDs
Designed for 89c51 running at 11.0592Mhz
LED binary counter at rate of 1Hz with crystal of 11.0592Mhz
compile the program in Keil uVision Compiler.
Operation : when MCU power up LED binary counter runs at frequency of 1Hz.
Feedback appreciated: researchermouli@gmail.com
-----------------------------------------------------------------------------*/
//includes definition of 89c51
#include <at89x51.h>
void Delay(unsigned int time);
void main(void)
{
int i;
while(1)
for(i=0;i<=255;i++)
{
P1 = i; // Turn on leds
Delay(500); // delay for 500msec = 0.5 sec
}
}
// program routines
void Delay(unsigned int time)
{
unsigned char pause; // Declare variable pause as unsigned char
while( time > 0) // loop until time is greater than zero
{
pause = 150; // Initialize pause to 150 (decimal value)
while(pause--); // Decrement pause until it becomes zero
time--; // Decrement time and loop back until time
} // value becomes zero
} // End of Delay function
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
20
8051 Microcontroller and Interfacing Experiments
Experiment No. 2
Aim:
To interface a seven segment display (SSD) with P89V51RD2, that displays hexadecimal
numbers from 0 to F.
Seven segment display:
This version is a common anode version. That means that the positive leg of each LED is
connected to a common point which is pin 3 in this case. Each LED has a negative leg that is
connected to one of the pins of the device. To make it work you need to connect pin 3 to 5
volts. Then to make each segment light up, connect the ground pin for that led to ground. A
resistor is required to limit the current. Rather than using a resistor from each LED to ground,
you can just use one resistor from Vcc to pin 3 to limit the current. The following table shows
how to form the numbers 0 to 9 and the letters A, b, C, d, E, and F. '0' means that pin is
connected to ground. '1' means that pin is connected to Vcc.
To Display a (P0.1) b (P0.0) c (P0.6) d (P0.5) e (P0.4) f (P0.2) g (P0.3)
0 0 0 0 0 0 0 1
1 1 0 0 1 1 1 1
2 0 0 1 0 0 1 0
3 0 0 0 0 1 1 0
4 1 0 0 1 1 0 0
5 0 1 0 0 1 0 0
6 0 1 0 0 0 0 0
7 0 0 0 1 1 1 1
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
21
8051 Microcontroller and Interfacing Experiments
8 0 0 0 0 0 0 0
9 0 0 0 1 1 0 0
A 0 0 0 1 0 0 0
b 1 1 0 0 0 0 0
C 0 1 1 0 0 0 1
d 1 0 0 0 0 1 0
E 0 1 1 0 0 0 0
F 0 1 1 1 0 0 0
Schematic Diagram of the experiment:
Algorithm:
1. Connect SSD to the port0 as shown in the schematic diagram.
2. Configure port0 as output port.
3. Send the codes shown in table to port0 one by one.
4. Write the program in Keil software by using embedded-C language.
5. Generate the .hex file and transfer the .hex file from computer to the target
board by using flash magic.
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
22
8051 Microcontroller and Interfacing Experiments
Source Code:
/* -----------------------------------------------------------------------
ssd.c : Demonstration of interfacing of SSD
Designed for microcontroller running at 11.0592Mhz
SSD displays at rate of 1Hz with crystal of 11.0592Mhz
compile the program in Keil uVision Compiler.
Operation : when MCU power up SSD runs at frequency of 1Hz.
Feedback appreciated: researchermouli@gmail.com
-----------------------------------------------------------------------------*/
//includes definition of 89c51
#include<at89x51.h>
void Delay(unsigned int);
void main(void)
{
unsigned int r ,codes[]= {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x83,0xf8,
0x80,0x98,0x88,0x80,0xc6, 0xc0, 0x86, 0x8e };
P0=0;
while(1)
{
for(r=0; r<=15; r++)
{
P0 = codes[r]; Delay(500);
}
}
}
// program routines
void Delay(unsigned int time)
{
unsigned char pause; // Declare variable pause as unsigned char
while( time > 0) // loop until time is greater than zero
{
pause = 150; // Initialize pause to 150 (decimal value)
while(pause--); // Decrement pause until it becomes zero
time--; // Decrement time and loop back until time
} // value becomes zero
} // End of Delay function
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
23
8051 Microcontroller and Interfacing Experiments
Experiment No. 3
Aim:
To establish serial communication between P89V51RD2 and PC by programming the
serial port of microcontroller.
Schematic Diagram:
Description of MAX232:
The P89V51RD2 has two pins that are used specifically for transferring and receiving
data serially. These two pins are called TxD and RxD and are part of the port3 group (P3.0 and
P3.1). Pin 11 of the controller i.e. P3.1 is assigned to TxD and pin 10 i.e. P3.0 is designated as
RxD. These pins are TTL compatible; therefore, they require a line driver to make them RS232
compatible. One such line driver is MAX232 chip
Since RS232 is not compatible with today’s microprocessors and microcontrollers, we
need a line driver (voltage converter) to convert RS232’s signals to TTL voltage levels that will
be acceptable to the controller TxD and RxD pins. One example of such a converter is MAX232
chip that converts RS232 voltage levels to TTL voltage levels, and vice versa. The circuit
diagram of interfacing P89V51RD2 and MAX 232 is shown in Schematic diagram.
Algorithm:
1. Initialize TMOD = 0X20 for Timer 1, 8-bit auto reload mode.
2. Store TH1 = 0xFD to set 9600 baud rate.
3. Load SCON = 0X50 and TR1 = 1 to start timer.
4. Transfer the data serially using SBUF register.
5. Write the program in Keil software by using embedded-C language.
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
24
8051 Microcontroller and Interfacing Experiments
6. Generate the .hex file and transfer the .hex file from computer to the target
board by using flash magic.
Source Code:
/*-----------------------------------------------------------------------------
serial coomunication.c : Demonstration of serial communication - A ECHO program
Designed for P89V51RD2 running at 11.0592Mhz
communication between PC and microcontroller.
RS232 serial specification
9600 baud rate
8-bit
1- start bit
1-stop bit
parity none
compile the program in Keil uVision Compiler.
Note: Hyper Terminal / Terminal v1.9b software for communication
operation: receives data from PC (or any serial device) and transmitt
same data back to PC- A ECHO program
feedback appreciated: researchermouli@gmail.com
------------------------------------------------------------------------------*/
#include<at89x51.h> //Includes definition of 89c51
//DEFINE CONSTANT
#define Baud_rate 0xFD // BAUD RATE 9600
//DEFINE PROTOTYPES
void main(void);
void SerialInitialize(void);
void SendByteSerially(unsigned char ascii);
unsigned char ReceiveByteSerially(void);
//FUNCTIONS
void main(void)
{
unsigned char serialdata;
SerialInitialize(); // CALL ROUTINE TO INITIALIZE SERIAL PORT
while(1) // INFINITE LOOP
{
serialdata = ReceiveByteSerially();//RECEIVE DATA FROM SERIAL PORT (PC)
SendByteSerially(serialdata); // SEND DATA BACK TO PC
}
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
25
8051 Microcontroller and Interfacing Experiments
} // END OF MAIN FUNCTION
void SerialInitialize(void) // INITIALIZE SERIAL PORT
{
TMOD = 0X20; // Timer 1 IN MODE 2 -AUTO RELOAD RATE
SCON = 0x50; // SERIAL MODE 1, 8-DATA BIT 1-START BIT, 1-STOP BIT
TH1 = Baud_rate; // LOAD BAUDRATE TO TIMER
REGISTER
TR1 = 1; // START TIMER
}
void SendByteSerially(unsigned char serialdata)
{
SBUF = serialdata; // LOAD DATA TO SERIAL BUFFER REGISTER
while(TI == 0); // WAIT UNTIL TRANSMISSION TO COMPLETE
TI = 0; // CLEAR TRANSMISSION INTERRUPT FLAG
}
unsigned char ReceiveByteSerially(void)
{
while(RI == 0); // WAIT UNTIL DATA IS RECEIVED
RI = 0; // CLEAR FLAG
return SBUF; // RETURN SERIAL DATA
} // END OF PROGRAM
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
26
8051 Microcontroller and Interfacing Experiments
Experiment No. 4
Aim:
To interface a 16X2 Liquid Crystal Display (LCD) with P89V51RD2.
Schematic Diagram:
Pin Symbol Function
1 Vss Ground
2 Vdd Supply Voltage
3 Vo Contrast Setting
4 RS Register Select
5 R/W Read/Write Select
6 En Chip Enable Signal
7-14 DB0-DB7 Data Lines
15 A/Vee Gnd for the backlight
16 K Vcc for backlight
The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines. The number on
data lines depends on the mode of operation. If operated in 8-bit mode then 8 data lines + 3
control lines i.e. total 11 lines are required. And if operated in 4-bit mode then 4 data lines + 3
control lines i.e. 7 lines are required. How do we decide which mode to use? It’s simple if you
have sufficient data lines you can go for 8 bit mode & if there is a time constrain i.e. display
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
27
8051 Microcontroller and Interfacing Experiments
should be faster then we have to use 8-bit mode because basically 4-bit mode takes twice
as more time as compared to 8-bit mode.
When RS is low (0), the data is to be treated as a command. When RS is high (1), the data
being sent is considered as text data which should be displayed on the screen.
When R/W is low (0), the information on the data bus is being written to the LCD. When
RW is high (1), the program is effectively reading from the LCD. Most of the times there is no
need to read from the LCD so this line can directly be connected to Gnd thus saving one
controller line.
The ENABLE pin is used to latch the data present on the data pins. A HIGH - LOW
signal is required to latch the data. The LCD interprets and executes our command at the instant
the EN line is brought low. If you never bring EN low, your instruction will never be executed.
Display Data Ram (DDRAM) stores the display data. So when we have to display a
character on LCD we basically write it into DDRAM. For a 2x16 LCD the DDRAM address for
first line is from 80h to 8fh & for second line is 0c0h to 0cfh. So if we want to display 'H' on the
7th
position of the first line then we will write it at location 87h.
Now as you have noticed two types of data is given to the LCD data to be displayed,
command or special instruction.
Source Code:
#include <AT89X51.H>
#define LCD P1
sbit sw=P2^7;
sbit rs=P2^0;
sbit en=P2^1;
void lcdcmd(unsigned char);
void lcd_data(unsigned char);
void lcd_data_string(unsigned char *);
void init_lcd();
//void ser_str(unsigned char* );
//void ser_data(unsigned char )
void delay(unsigned int );
void main()
{
init_lcd();
sw=1;
while(1)
{
lcd_data_string(" ESSENCE TRAINING PROGRAM FOR SKU ");
//ser_str("n anticlockwise r ");
delay(900);
}
}
void init_lcd(void)
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
28
8051 Microcontroller and Interfacing Experiments
{
lcdcmd(0X38);
delay(500);
lcdcmd(0X0E);
delay(500);
lcdcmd(0X01);
delay(500);
lcdcmd(0X06);
delay(500);
/*lcdcmd(0X80);
delay(500);*/
}
void lcdcmd(unsigned char a)
{
LCD=a;
rs=0;
en=1;
delay(500);
en=0;
}
void lcd_data(unsigned char a)
{
LCD=a;
rs=1;
en=1;
delay(500);
en=0;
//return(0);
}
void delay(unsigned int j)
{
unsigned int i;
for(i=0;i<j;i++);
}
void lcd_data_string(unsigned char *p)
{
while(*p!='0')
{
lcd_data(*p++);
}
}
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
29
8051 Microcontroller and Interfacing Experiments
Experiment No. 5
Aim:
Interface 12V DC Electro Mechanical Relay (EMR) with P89V51RD2 using 8051
development board.
Electro Mechanical Relay (EMR):
A relay is an electrically controllable switch widely used in industrial controls,
automobiles and appliances. It allows the isolation of two separate sections of a system with two
different sources. One such relay is called Electro Mechanical Relay or Electro Magnetic
Relay. The EMRs have three components: the coil, spring and contacts. When current flows
through the coil, a magnetic field is created around the coil (the coil is energized), which causes
the armature to be attracted to the coil. The armature contact acts like a switch and closes or
opens the circuit.
The contacts normally open (NO) or normally close (NC). In the NC type, the contacts
are closed when the coil is not energized. In the NO, the contacts are open when the coil is not
energized. There can one or more contacts. For example, we can have SPST (Single pole, single
through), SPDT (Single pole, double through) and DPDT (Double pole, double through) relays.
Relay diagram shows all types of relay internal diagram.
Relay Diagrams:
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
30
8051 Microcontroller and Interfacing Experiments
Schematic Diagram:
Algorithm:
1. Connect the relay to microcontroller as shown in the schematic.
a. Relay coil needs around 10mA to be energized; the
microcontroller pin can provide a maximum of 1-2mA
current.
b. For this reason we place a driver such as a power transistor
or ULN2803 between microcontroller and relay.
2. Control the P1.0 pin by switching it with some delay.
3. Write the program in Keil software by using embedded-C language.
4. Generate .hex file and transfer the .hex file from computer to the target
board by using flash magic.
Source Code:
/* -----------------------------------------------------------------------
relay.c : Demonstration of interfacing an Relay
Designed for 89c51 running at 11.0592Mhz
Controlling a port pin (turn on and off) at rate of 1Hz with crystal of 11.0592Mhz
compile the program in Keil uVision Compiler.
Operation : when MCU power up port pin on/off continuously at frequency of 1Hz.
Feedback appreciated: researchermouli@gmail.com
-----------------------------------------------------------------------------*/
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
31
8051 Microcontroller and Interfacing Experiments
//INCLUDES DEFINITION OF 89C51
#include<at89x51.h>
//CONSTANT DEFINES
#define INPUT_PIN 1 // define 1 as INPUT_PIN
#define LOW 0
#define HIGH 1
//PINS DEFINE
#define RELAY_PIN P1_0 // define port P1_0 as RELAY i.e connect RELAY to P1_0
//DEFINE MACROS
#define RELAYOn() RELAY_PIN = LOW
#define RELAYOff() RELAY_PIN = HIGH
//FUNCTIONS PROTOYPES
void Delay(unsigned int time);
//main function begins
void main(void)
{
RELAY_PIN = INPUT_PIN;
while(1) // loop forever
{
RELAYOn(); // Turn on relay
Delay(500); // delay for 500msec = 0.5 sec
RELAYOff(); // Turn off relay
Delay(500); // delay for 500msec = 0.5 sec
} // end of while loop
}
// end of main function
// PROGRAM ROUTINES
void Delay(unsigned int time)
{
unsigned char pause; // Declare variable pause as unsigned char
while( time > 0) // loop until time is greater than zero
{
pause = 150; // Initialize pause to 150 (decimal value)
while(pause--); // Decrement pause until it becomes zero
time--; // Decrement time and loop back until time
} // value becomes zero
} // End of Delay function
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
32
8051 Microcontroller and Interfacing Experiments
Experiment No. 6
Aim:
To interface stepper motor with P89V51RD2 using 8051 development board.
Schematic Diagram:
1. Stepper motor unlike DC motor rotates in steps.
2. Stepper motor has 4 coils which forms the stator and a central rotor.
3. Rotation depends on excitation of stator coils.
step coil A coil B coil C coil D
1 0 0 0 1
2 1 0 0 0
3 0 1 0 0
4 0 0 0 1
Anyone of these values forms the initial value. To get 360o revolution 48 steps are required.
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
33
8051 Microcontroller and Interfacing Experiments
Step angle= 360o
/48 = 7.5o
.
Algorithm:
1. Configure P1 as output.
2. Apply the initial excitation of 11 to motor coils through P1.
3. For clockwise motion -Rotate right once the excitation and repeat step 2.
4. For anticlockwise motion -Rotate left once the excitation and repeat step 2.
Source Code:
#include<reg51.h>
void Delay(unsigned int);
void main(void)
{
unsigned int r, rotation, codes[4]= {0x11,0x44,0x22,0x88};
while(1)
{
for(rotation=0; rotation<5; rotation++)
{
for(r=0; r<=3; r++)
{
P2 = codes[r];
Delay(500);
}
}
}
}
void Delay(unsigned int time)
{
unsigned char pause;
while( time > 0)
{
pause = 52;
while(pause--);
time--;
}
}
By
C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur.
Mobile: +919963719606, email: researchermouli@gmail.com
34

More Related Content

What's hot

Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerMujahid Hussain
 
Overview of microcontroller and microprocessor
Overview of microcontroller and microprocessor Overview of microcontroller and microprocessor
Overview of microcontroller and microprocessor Mrunal Deshkar
 
INTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERINTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERAnkita Jaiswal
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerGaurav Verma
 
Project Report on Embedded Systems
Project Report on Embedded Systems Project Report on Embedded Systems
Project Report on Embedded Systems Suhani Singh
 
Introduction to arduino ppt main
Introduction to  arduino ppt mainIntroduction to  arduino ppt main
Introduction to arduino ppt maineddy royappa
 
microcontroller basics
microcontroller basicsmicrocontroller basics
microcontroller basicssagar Ramdev
 
Introduction to Arduino.pptx
Introduction to Arduino.pptxIntroduction to Arduino.pptx
Introduction to Arduino.pptxAkshat Bijronia
 
Embedded Systems Training Report
Embedded Systems Training ReportEmbedded Systems Training Report
Embedded Systems Training ReportAkhil Garg
 
Key board interfacing with 8051
Key board interfacing with 8051Key board interfacing with 8051
Key board interfacing with 8051DominicHendry
 
8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directivesSARITHA REDDY
 
Counter digital electronics
Counter digital electronics Counter digital electronics
Counter digital electronics Sooraj Maurya
 
80486 microprocessor
80486 microprocessor80486 microprocessor
80486 microprocessorMihika Shah
 
Sensor interfacing in 8051
Sensor interfacing in 8051Sensor interfacing in 8051
Sensor interfacing in 8051Irfan Ahmad
 
microcontroller vs microprocessor
microcontroller vs microprocessormicrocontroller vs microprocessor
microcontroller vs microprocessorsobhadevi
 

What's hot (20)

Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
Overview of microcontroller and microprocessor
Overview of microcontroller and microprocessor Overview of microcontroller and microprocessor
Overview of microcontroller and microprocessor
 
INTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERINTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLER
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
 
Serial Communication in 8051
Serial Communication in 8051Serial Communication in 8051
Serial Communication in 8051
 
Project Report on Embedded Systems
Project Report on Embedded Systems Project Report on Embedded Systems
Project Report on Embedded Systems
 
Introduction to arduino ppt main
Introduction to  arduino ppt mainIntroduction to  arduino ppt main
Introduction to arduino ppt main
 
microcontroller basics
microcontroller basicsmicrocontroller basics
microcontroller basics
 
Introduction to Arduino.pptx
Introduction to Arduino.pptxIntroduction to Arduino.pptx
Introduction to Arduino.pptx
 
Embedded Systems Training Report
Embedded Systems Training ReportEmbedded Systems Training Report
Embedded Systems Training Report
 
Arduino & NodeMcu
Arduino & NodeMcuArduino & NodeMcu
Arduino & NodeMcu
 
Key board interfacing with 8051
Key board interfacing with 8051Key board interfacing with 8051
Key board interfacing with 8051
 
8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directives
 
Counter digital electronics
Counter digital electronics Counter digital electronics
Counter digital electronics
 
80486 microprocessor
80486 microprocessor80486 microprocessor
80486 microprocessor
 
Arduino uno
Arduino unoArduino uno
Arduino uno
 
Sensor interfacing in 8051
Sensor interfacing in 8051Sensor interfacing in 8051
Sensor interfacing in 8051
 
Arduino presentation
Arduino presentationArduino presentation
Arduino presentation
 
Introduction to Microcontroller
Introduction to MicrocontrollerIntroduction to Microcontroller
Introduction to Microcontroller
 
microcontroller vs microprocessor
microcontroller vs microprocessormicrocontroller vs microprocessor
microcontroller vs microprocessor
 

Similar to 8051 dev board guide

Study of 8051 microcontroller
Study of 8051 microcontrollerStudy of 8051 microcontroller
Study of 8051 microcontroller918007165995
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller nitugatkal
 
EMBEDDED SYSTEMS AND IOT lab manual for enginnering students
EMBEDDED SYSTEMS AND IOT lab manual for enginnering studentsEMBEDDED SYSTEMS AND IOT lab manual for enginnering students
EMBEDDED SYSTEMS AND IOT lab manual for enginnering studentseceprinter6
 
8051 Architecture and PIN Configuration.pdf
8051 Architecture and PIN Configuration.pdf8051 Architecture and PIN Configuration.pdf
8051 Architecture and PIN Configuration.pdfSrikrishna Thota
 
Microcontroller (1).pptx
Microcontroller (1).pptxMicrocontroller (1).pptx
Microcontroller (1).pptxITPradiptaRoy
 
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT III The 8051 Microcontrollers
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT III  The 8051 MicrocontrollersSYBSC IT SEM IV EMBEDDED SYSTEMS UNIT III  The 8051 Microcontrollers
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT III The 8051 MicrocontrollersArti Parab Academics
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051guest70d48b1
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontrollerSouvik Dutta
 
Ashish microcontroller 8051
Ashish microcontroller 8051Ashish microcontroller 8051
Ashish microcontroller 8051ASHISH RAJ
 
Microcontroller (8051) by K. Vijay Kumar
Microcontroller (8051) by K. Vijay KumarMicrocontroller (8051) by K. Vijay Kumar
Microcontroller (8051) by K. Vijay KumarVijay Kumar
 
8051 Microcontroller Tutorial and Architecture with Applications
8051 Microcontroller Tutorial and Architecture with Applications8051 Microcontroller Tutorial and Architecture with Applications
8051 Microcontroller Tutorial and Architecture with Applicationselprocus
 
4th yr dmumicrocontroller1
4th yr dmumicrocontroller14th yr dmumicrocontroller1
4th yr dmumicrocontroller1haymanotyehuala
 
8051 microcontroller Microcontroller _2024.pptx
8051 microcontroller Microcontroller _2024.pptx8051 microcontroller Microcontroller _2024.pptx
8051 microcontroller Microcontroller _2024.pptxrohithansaliya2
 
Unit1 5-mpi-lecture-notes
Unit1 5-mpi-lecture-notesUnit1 5-mpi-lecture-notes
Unit1 5-mpi-lecture-notesPrabhu Mali
 

Similar to 8051 dev board guide (20)

Study of 8051 microcontroller
Study of 8051 microcontrollerStudy of 8051 microcontroller
Study of 8051 microcontroller
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
 
EMBEDDED SYSTEMS AND IOT lab manual for enginnering students
EMBEDDED SYSTEMS AND IOT lab manual for enginnering studentsEMBEDDED SYSTEMS AND IOT lab manual for enginnering students
EMBEDDED SYSTEMS AND IOT lab manual for enginnering students
 
8051 Architecture and PIN Configuration.pdf
8051 Architecture and PIN Configuration.pdf8051 Architecture and PIN Configuration.pdf
8051 Architecture and PIN Configuration.pdf
 
Microcontroller (1).pptx
Microcontroller (1).pptxMicrocontroller (1).pptx
Microcontroller (1).pptx
 
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT III The 8051 Microcontrollers
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT III  The 8051 MicrocontrollersSYBSC IT SEM IV EMBEDDED SYSTEMS UNIT III  The 8051 Microcontrollers
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT III The 8051 Microcontrollers
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
Micro controller
Micro controllerMicro controller
Micro controller
 
002079
002079002079
002079
 
Ashish microcontroller 8051
Ashish microcontroller 8051Ashish microcontroller 8051
Ashish microcontroller 8051
 
Microcontroller (8051) by K. Vijay Kumar
Microcontroller (8051) by K. Vijay KumarMicrocontroller (8051) by K. Vijay Kumar
Microcontroller (8051) by K. Vijay Kumar
 
Unit 4
Unit 4Unit 4
Unit 4
 
8051 Microcontroller Tutorial and Architecture with Applications
8051 Microcontroller Tutorial and Architecture with Applications8051 Microcontroller Tutorial and Architecture with Applications
8051 Microcontroller Tutorial and Architecture with Applications
 
4th yr dmumicrocontroller1
4th yr dmumicrocontroller14th yr dmumicrocontroller1
4th yr dmumicrocontroller1
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
 
89s52 2
89s52 289s52 2
89s52 2
 
8051 microcontroller Microcontroller _2024.pptx
8051 microcontroller Microcontroller _2024.pptx8051 microcontroller Microcontroller _2024.pptx
8051 microcontroller Microcontroller _2024.pptx
 
Unit1 5-mpi-lecture-notes
Unit1 5-mpi-lecture-notesUnit1 5-mpi-lecture-notes
Unit1 5-mpi-lecture-notes
 
MICROCONTROLLER 8051
MICROCONTROLLER 8051MICROCONTROLLER 8051
MICROCONTROLLER 8051
 

More from Murali Krishna

Fpga based implementation of a position estimator for controlling
Fpga based implementation of a position estimator for controllingFpga based implementation of a position estimator for controlling
Fpga based implementation of a position estimator for controllingMurali Krishna
 
8085 microprocessor ramesh gaonkar
8085 microprocessor   ramesh gaonkar8085 microprocessor   ramesh gaonkar
8085 microprocessor ramesh gaonkarMurali Krishna
 
Modulation & d emodul tion
Modulation & d emodul tionModulation & d emodul tion
Modulation & d emodul tionMurali Krishna
 

More from Murali Krishna (6)

Fpga based implementation of a position estimator for controlling
Fpga based implementation of a position estimator for controllingFpga based implementation of a position estimator for controlling
Fpga based implementation of a position estimator for controlling
 
Radix8
Radix8Radix8
Radix8
 
8086 labmanual
8086 labmanual8086 labmanual
8086 labmanual
 
8085 microprocessor ramesh gaonkar
8085 microprocessor   ramesh gaonkar8085 microprocessor   ramesh gaonkar
8085 microprocessor ramesh gaonkar
 
Satelite comm
Satelite commSatelite comm
Satelite comm
 
Modulation & d emodul tion
Modulation & d emodul tionModulation & d emodul tion
Modulation & d emodul tion
 

Recently uploaded

Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 

Recently uploaded (20)

Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 

8051 dev board guide

  • 1. 8051 Microcontroller and Interfacing Experiments Introduction to 8051 Microcontroller INTRODUCTION A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications. But their presence is unnoticed at most of the places like • At supermarkets in Cash Registers, Weighing Scales, etc. • At home in Ovens, Washing Machines, Alarm Clocks, etc. • At play in Toys, VCRs, Stereo Equipment, etc. • At office in Typewriters, Photocopiers, Elevators, etc. • In industry in Industrial Automation, safety systems, etc. • On roads in Cars, Traffic Signals, etc. What inside them makes these machines smart? The answer is microcontroller. Creating applications for the microcontrollers is different than any other development job in electronics and computing. Before selecting a particular device for an application, it is important to understand what the different options and features are and what they can mean with regard to developing the application. The reminder of the book will go through different types of programming and interfacing techniques of microcontroller, mainly 8051 based microcontrollers, in detail. COMPARING MICROPROCESSOR AND MICROCONTROLLER • Microprocessor is a single chip CPU, microcontroller contains, a CPU and much of the remaining circuitry of a complete microcomputer system in a single chip. • Microcontroller includes RAM, ROM, serial and parallel interface, timer, interrupt schedule circuitry (in addition to CPU) in a single chip.  RAM is smaller than that of even an ordinary microcomputer, but enough for its applications.  Interrupt system is an important feature, as microcontrollers have to respond to control oriented devices in real time. By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 1
  • 2. 8051 Microcontroller and Interfacing Experiments • Microprocessors are most commonly used as the CPU in microcomputer systems. Microcontrollers are used in small, minimum component designs performing control- oriented activities. • Microprocessor instruction sets are processing intensive, implying powerful addressing modes with instructions catering to large volumes of data. Their instructions operate on nibbles, bytes, etc. Microcontrollers have instruction sets catering to the control of inputs and outputs. Their instructions operate also on a single bit. E.g., a motor may be turned ON and OFF by a 1-bit output port. FEATURES OF 8051 MICROCONTROLLER The Intel 8051 microcontroller is one of the most popular general purpose microcontrollers in use today. The microcontroller 8051 is 8-bit microcontroller which includes: CPU (Central Processing Unit), RAM (Random Access Memory), EPROM/PROM/ROM (Erasable programmable Read Only Memory), I/O (input/output) – serial and parallel, timers, interrupt controllers. Figure1: Block Diagram of 8051 Microcontroller By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 2
  • 3. 8051 Microcontroller and Interfacing Experiments By only including the features specific to the task (control), cost is relatively low. A typical microcontroller has bit manipulation instructions, easy and direct access to I/O (input/output), and quick and efficient interrupt processing. Figure1 shows the block diagram of a typical microcontroller. Basic features • 8-bit CPU with register A and B. • 8-bit data bus. • 16-bit address bus. • 32 general purpose registers each of 8 bits. • 16 bit timers (usually 2, but may have more, or less). • Bit as well as byte addressable RAM area of 16 bytes. • Four 8-bit ports, (short models have two 8-bit ports). • 16-bit program counter and data pointer. • 8-bit stack pointer and 8-bit PSW (Program Status Word). • Internal ROM (4kB) and RAM (128 Bytes). • Serial data communication. • Five Interrupt Sources (2 internal and 3 external interrupts). Basic pins • Figure2 shows the pin diagram of 8051 micro controller. • PIN 9: PIN 9 is the reset pin which is used reset the microcontroller’s internal registers and ports upon starting up. (Pin should be held high for 2 machine cycles.). • PINS 18 & 19: The 8051 has a built-in oscillator amplifier hence we need to only connect a crystal at these pins to provide clock pulses to the circuit. By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 3
  • 4. 8051 Microcontroller and Interfacing Experiments • PIN 40 and 20: Pins 40 and 20 are VCC and ground respectively. The 8051 chip needs +5V 500mA to function properly, although there are lower powered versions like the Atmel 2051 which is a scaled down version of the 8051 which runs on +3V. • PINS 29, 30 & 31: As described in the features of the 8051, this chip contains a built-in flash memory. In order to program this we need to supply a voltage of +12V at pin 31. If external memory is connected then PIN 31, also called EA/VPP, should be connected to ground to indicate the presence of external memory. PIN 30 is called ALE (address latch enable), which is used when multiple memory chips are connected to the controller and only one of them needs to be selected. We will deal with this in depth in the later chapters. PIN 29 is called PSEN. This is "program select enable". In order to use the external memory it is required to provide the low voltage (0) on both PSEN and EA pins. By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 4
  • 5. 8051 Microcontroller and Interfacing Experiments Figure2: Pin Diagram of 8051 microcontroller Port Pins There are four 8-bit ports: P0, P1, P2 and P3. • • PORT P1 (Pins 1 to 8): The port P1 is a general purpose input/output port which can be used for a variety of interfacing tasks. The other ports P0, P2 and P3 have dual roles or additional functions associated with them based upon the context of their usage. By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 5
  • 6. 8051 Microcontroller and Interfacing Experiments • PORT P3 (Pins 10 to 17): PORT P3 acts as a normal IO port, but Port P3 has additional functions such as, serial transmit and receive pins, 2 external interrupt pins, 2 external counter inputs, read and write pins for memory access. • PORT P2 (pins 21 to 28): PORT P2 can also be used as a general purpose 8 bit port when no external memory is present, but if external memory access is required then PORT P2 will act as an address bus in conjunction with PORT P0 to access external memory. PORT P2 acts as A8-A15, as can be seen from fig 1.1 • PORT P0 (pins 32 to 39) PORT P0 can be used as a general purpose 8 bit port when no external memory is present, but if external memory access is required then PORT P0 acts as a multiplexed address and data bus that can be used to access external memory in conjunction with PORT P2. P0 acts as AD0-AD7, as can be seen from Figure2. Data and Program Memory The 8051 Microprocessor can be programmed in PL/M, 8051 Assembly, C and a number of other high-level languages. Many compilers even have support for compiling C++ for an 8051. Program memory in the 8051 is read-only, while the data memory is considered to be read/write accessible. When stored on EEPROM or Flash, the program memory can be rewritten when the microcontroller is in the special programmer circuit. Program memory in the 8051 is read-only, while the data memory is considered to be read/write accessible. When stored on EEPROM or Flash, the program memory can be rewritten when the microcontroller is in the special programmer circuit. Program Start Address The 8051 starts executing program instructions from address 0x00 in the program memory. Direct Memory By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 6
  • 7. 8051 Microcontroller and Interfacing Experiments The 8051 has 256 bytes of internal addressable RAM, although only the first 128 bytes are available for general use by the programmer. The first 128 bytes of RAM (from 0x00 to 0x7F) are called the Direct Memory, and can be used to store data. Special Function Register (SFR) The Special Function Register (SFR) is the upper area of addressable memory, from address 0x80 to 0xFF. A, B, PSW, DPTR are called SFR. This area of memory cannot be used for data or program storage, but is instead a series of memory-mapped ports and registers. All port input and output can therefore be performed by memory mov operations on specified addresses in the SFR. Also, different status registers are mapped into the SFR, for use in checking the status of the 8051, and changing some operational parameters of the 8051. General Purpose Registers The 8051 has 4 selectable banks of 8 addressable 8-bit registers, R0 to R7. This means that there are essentially 32 available general purpose registers, although only 8 (one bank) can be directly accessed at a time. To access the other banks, we need to change the current bank number in the flag status register. A and B Registers The A register is located in the SFR memory location 0xE0. The A register works in a similar fashion to the AX register of x86 processors. The A register is called the accumulator, and by default it receives the result of all arithmetic operations. The B register is used in a similar manner, except that it can receive the extended answers from the multiply and divide operations. When not being used for multiplication and Division, the B register is available as an extra general-purpose register. By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 7
  • 8. 8051 Microcontroller and Interfacing Experiments Programming with P89V51RD2 INTRODUCTION The P89V51RD2 is an 80C51 microcontroller with 64kB Flash and 1024 bytes of data RAM. A key feature of the P89V51RD2 is its X2 mode option. The design engineer can choose to run the application with the conventional 80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per machine cycle) to achieve twice the throughput at the same clock frequency. Another way to benefit from this feature is to keep the same performance by reducing the clock frequency by half, thus dramatically reducing the EMI. The Flash program memory supports both parallel programming and in serial In-System Programming (ISP). Parallel programming mode offers gang-programming at high speed, reducing programming costs and time to market. ISP allows a device to be reprogrammed in the end product under software control. The capability to field/update the application firmware makes a wide range of applications possible. The P89V51RD2 is also In-Application Programmable (IAP), allowing the Flash program memory to be reconfigured even while the application is running. Figure3 shows the photograph picture of 8051 development board. Figure3: 8051 Development Board The hardware required to develop projects is 8051 development board and it has the following features: By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 8
  • 9. 8051 Microcontroller and Interfacing Experiments • P89V51RD2BN 40 Pin DIP. • Both Manual and Power on Reset. • 16 x 2 Alphanumeric LCD and trimmer for contrast Control. • 8channel analog input using ADC0809. • 4 x 4 hexadecimal keyboard. • RS 232 serial interface. • On board EEPROM using 24C02. • On board RTC using DS1307. • Multiplexed four common anode seven segment displays. • 8 Led indication panel for checking the port operation. • 1channel relay drive. • 8channel uln2803 drive that can be used to drive stepper motor or 8 relays. Features of P89V51RD2 • 80C51 Central Processing Unit 5V Operating voltage from 0 to 40MHz. • 64 KB of on-chip Flash program memory. • ISP (In-System Programming). • IAP (In-Application Programming). • Enhanced UART. • PCA (Programmable Counter Array) with PWM and Capture/Compare functions. • Four 8-bit I/O ports with three high-current Port 1 pins (16mA each). • Three 16-bit timers/counters Programmable Watchdog timer (WDT). • Eight interrupt sources with four priority levels Second DPTR register. • Low EMI mode (ALE inhibit). By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 9
  • 10. 8051 Microcontroller and Interfacing Experiments • TTL and CMOS compatible logic levels. Software’s required to develop projects 1. Keil IDE(Integrated Development Environment) An integrated development environment (IDE) also known as integrated design environment or integrated debugging environment is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: • Source code editor. • Compiler and/or an interpreter. • Build automation tools. • Debugger. Installing keil software • Open My Computer • Within the my computer window, open the CD Drive, 8051 DEVELOPMENT BOARD CDDATACOMPILERSkeil • In this directory keil setup file contains, double click on the file and follow the instructions. • After installation, if it prompts you to reboot the computer, do it. By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 10
  • 11. 8051 Microcontroller and Interfacing Experiments 2. Flash Magic Programmer Flash Magic provides a Windows based user interface that is easy and intuitive, which connects to the target via serial line. Flash Magic is a free, powerful, feature-rich Windows application that allows easy programming of Philips FLASH Microcontrollers. Installing flash magic software • Follow the same instructions as guided in the previous section, except locate the setup file at 8051 DEVELOPMENT BOARDDATAPROGRAMMER By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 11
  • 12. 8051 Microcontroller and Interfacing Experiments By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 12
  • 13. 8051 Microcontroller and Interfacing Experiments By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 13
  • 14. 8051 Microcontroller and Interfacing Experiments By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 14
  • 15. 8051 Microcontroller and Interfacing Experiments By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 15
  • 16. 8051 Microcontroller and Interfacing Experiments By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 16
  • 17. 8051 Microcontroller and Interfacing Experiments By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 17
  • 18. 8051 Microcontroller and Interfacing Experiments Lab experiments on P89V51RD2 Experiment No. 1 Aim: To construct an 8-bit binary counter using P89V51RD2 and LEDs, that displays binary count from 0 to 255. Schematic Diagram: Algorithm: 1. Connect LEDs to the port1 as shown in the schematic diagram. In the schematic it is shown that four LEDs are connected. But to display binary counter from 0 to 255 user should connect 8 LEDs. 2. Configure port1 as output port. 3. Initialize a variable to 0, equate it to port1 and send it to port1. 4. Increment the value and send it to port1 until it reaches 255. 5. Write the program in Keil software by using embedded-C language. 6. Generate the .hex file and transfer the .hex file from PC to the target board by using flash magic. Source Code: By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 18
  • 19. 8051 Microcontroller and Interfacing Experiments Lab experiments on P89V51RD2 Experiment No. 1 Aim: To construct an 8-bit binary counter using P89V51RD2 and LEDs, that displays binary count from 0 to 255. Schematic Diagram: Algorithm: 1. Connect LEDs to the port1 as shown in the schematic diagram. In the schematic it is shown that four LEDs are connected. But to display binary counter from 0 to 255 user should connect 8 LEDs. 2. Configure port1 as output port. 3. Initialize a variable to 0, equate it to port1 and send it to port1. 4. Increment the value and send it to port1 until it reaches 255. 5. Write the program in Keil software by using embedded-C language. 6. Generate the .hex file and transfer the .hex file from PC to the target board by using flash magic. Source Code: By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 19
  • 20. 8051 Microcontroller and Interfacing Experiments /* ----------------------------------------------------------------------- binarycounter.c : Demonstration of interfacing of LEDs Designed for 89c51 running at 11.0592Mhz LED binary counter at rate of 1Hz with crystal of 11.0592Mhz compile the program in Keil uVision Compiler. Operation : when MCU power up LED binary counter runs at frequency of 1Hz. Feedback appreciated: researchermouli@gmail.com -----------------------------------------------------------------------------*/ //includes definition of 89c51 #include <at89x51.h> void Delay(unsigned int time); void main(void) { int i; while(1) for(i=0;i<=255;i++) { P1 = i; // Turn on leds Delay(500); // delay for 500msec = 0.5 sec } } // program routines void Delay(unsigned int time) { unsigned char pause; // Declare variable pause as unsigned char while( time > 0) // loop until time is greater than zero { pause = 150; // Initialize pause to 150 (decimal value) while(pause--); // Decrement pause until it becomes zero time--; // Decrement time and loop back until time } // value becomes zero } // End of Delay function By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 20
  • 21. 8051 Microcontroller and Interfacing Experiments Experiment No. 2 Aim: To interface a seven segment display (SSD) with P89V51RD2, that displays hexadecimal numbers from 0 to F. Seven segment display: This version is a common anode version. That means that the positive leg of each LED is connected to a common point which is pin 3 in this case. Each LED has a negative leg that is connected to one of the pins of the device. To make it work you need to connect pin 3 to 5 volts. Then to make each segment light up, connect the ground pin for that led to ground. A resistor is required to limit the current. Rather than using a resistor from each LED to ground, you can just use one resistor from Vcc to pin 3 to limit the current. The following table shows how to form the numbers 0 to 9 and the letters A, b, C, d, E, and F. '0' means that pin is connected to ground. '1' means that pin is connected to Vcc. To Display a (P0.1) b (P0.0) c (P0.6) d (P0.5) e (P0.4) f (P0.2) g (P0.3) 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 1 2 0 0 1 0 0 1 0 3 0 0 0 0 1 1 0 4 1 0 0 1 1 0 0 5 0 1 0 0 1 0 0 6 0 1 0 0 0 0 0 7 0 0 0 1 1 1 1 By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 21
  • 22. 8051 Microcontroller and Interfacing Experiments 8 0 0 0 0 0 0 0 9 0 0 0 1 1 0 0 A 0 0 0 1 0 0 0 b 1 1 0 0 0 0 0 C 0 1 1 0 0 0 1 d 1 0 0 0 0 1 0 E 0 1 1 0 0 0 0 F 0 1 1 1 0 0 0 Schematic Diagram of the experiment: Algorithm: 1. Connect SSD to the port0 as shown in the schematic diagram. 2. Configure port0 as output port. 3. Send the codes shown in table to port0 one by one. 4. Write the program in Keil software by using embedded-C language. 5. Generate the .hex file and transfer the .hex file from computer to the target board by using flash magic. By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 22
  • 23. 8051 Microcontroller and Interfacing Experiments Source Code: /* ----------------------------------------------------------------------- ssd.c : Demonstration of interfacing of SSD Designed for microcontroller running at 11.0592Mhz SSD displays at rate of 1Hz with crystal of 11.0592Mhz compile the program in Keil uVision Compiler. Operation : when MCU power up SSD runs at frequency of 1Hz. Feedback appreciated: researchermouli@gmail.com -----------------------------------------------------------------------------*/ //includes definition of 89c51 #include<at89x51.h> void Delay(unsigned int); void main(void) { unsigned int r ,codes[]= {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x83,0xf8, 0x80,0x98,0x88,0x80,0xc6, 0xc0, 0x86, 0x8e }; P0=0; while(1) { for(r=0; r<=15; r++) { P0 = codes[r]; Delay(500); } } } // program routines void Delay(unsigned int time) { unsigned char pause; // Declare variable pause as unsigned char while( time > 0) // loop until time is greater than zero { pause = 150; // Initialize pause to 150 (decimal value) while(pause--); // Decrement pause until it becomes zero time--; // Decrement time and loop back until time } // value becomes zero } // End of Delay function By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 23
  • 24. 8051 Microcontroller and Interfacing Experiments Experiment No. 3 Aim: To establish serial communication between P89V51RD2 and PC by programming the serial port of microcontroller. Schematic Diagram: Description of MAX232: The P89V51RD2 has two pins that are used specifically for transferring and receiving data serially. These two pins are called TxD and RxD and are part of the port3 group (P3.0 and P3.1). Pin 11 of the controller i.e. P3.1 is assigned to TxD and pin 10 i.e. P3.0 is designated as RxD. These pins are TTL compatible; therefore, they require a line driver to make them RS232 compatible. One such line driver is MAX232 chip Since RS232 is not compatible with today’s microprocessors and microcontrollers, we need a line driver (voltage converter) to convert RS232’s signals to TTL voltage levels that will be acceptable to the controller TxD and RxD pins. One example of such a converter is MAX232 chip that converts RS232 voltage levels to TTL voltage levels, and vice versa. The circuit diagram of interfacing P89V51RD2 and MAX 232 is shown in Schematic diagram. Algorithm: 1. Initialize TMOD = 0X20 for Timer 1, 8-bit auto reload mode. 2. Store TH1 = 0xFD to set 9600 baud rate. 3. Load SCON = 0X50 and TR1 = 1 to start timer. 4. Transfer the data serially using SBUF register. 5. Write the program in Keil software by using embedded-C language. By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 24
  • 25. 8051 Microcontroller and Interfacing Experiments 6. Generate the .hex file and transfer the .hex file from computer to the target board by using flash magic. Source Code: /*----------------------------------------------------------------------------- serial coomunication.c : Demonstration of serial communication - A ECHO program Designed for P89V51RD2 running at 11.0592Mhz communication between PC and microcontroller. RS232 serial specification 9600 baud rate 8-bit 1- start bit 1-stop bit parity none compile the program in Keil uVision Compiler. Note: Hyper Terminal / Terminal v1.9b software for communication operation: receives data from PC (or any serial device) and transmitt same data back to PC- A ECHO program feedback appreciated: researchermouli@gmail.com ------------------------------------------------------------------------------*/ #include<at89x51.h> //Includes definition of 89c51 //DEFINE CONSTANT #define Baud_rate 0xFD // BAUD RATE 9600 //DEFINE PROTOTYPES void main(void); void SerialInitialize(void); void SendByteSerially(unsigned char ascii); unsigned char ReceiveByteSerially(void); //FUNCTIONS void main(void) { unsigned char serialdata; SerialInitialize(); // CALL ROUTINE TO INITIALIZE SERIAL PORT while(1) // INFINITE LOOP { serialdata = ReceiveByteSerially();//RECEIVE DATA FROM SERIAL PORT (PC) SendByteSerially(serialdata); // SEND DATA BACK TO PC } By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 25
  • 26. 8051 Microcontroller and Interfacing Experiments } // END OF MAIN FUNCTION void SerialInitialize(void) // INITIALIZE SERIAL PORT { TMOD = 0X20; // Timer 1 IN MODE 2 -AUTO RELOAD RATE SCON = 0x50; // SERIAL MODE 1, 8-DATA BIT 1-START BIT, 1-STOP BIT TH1 = Baud_rate; // LOAD BAUDRATE TO TIMER REGISTER TR1 = 1; // START TIMER } void SendByteSerially(unsigned char serialdata) { SBUF = serialdata; // LOAD DATA TO SERIAL BUFFER REGISTER while(TI == 0); // WAIT UNTIL TRANSMISSION TO COMPLETE TI = 0; // CLEAR TRANSMISSION INTERRUPT FLAG } unsigned char ReceiveByteSerially(void) { while(RI == 0); // WAIT UNTIL DATA IS RECEIVED RI = 0; // CLEAR FLAG return SBUF; // RETURN SERIAL DATA } // END OF PROGRAM By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 26
  • 27. 8051 Microcontroller and Interfacing Experiments Experiment No. 4 Aim: To interface a 16X2 Liquid Crystal Display (LCD) with P89V51RD2. Schematic Diagram: Pin Symbol Function 1 Vss Ground 2 Vdd Supply Voltage 3 Vo Contrast Setting 4 RS Register Select 5 R/W Read/Write Select 6 En Chip Enable Signal 7-14 DB0-DB7 Data Lines 15 A/Vee Gnd for the backlight 16 K Vcc for backlight The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines. The number on data lines depends on the mode of operation. If operated in 8-bit mode then 8 data lines + 3 control lines i.e. total 11 lines are required. And if operated in 4-bit mode then 4 data lines + 3 control lines i.e. 7 lines are required. How do we decide which mode to use? It’s simple if you have sufficient data lines you can go for 8 bit mode & if there is a time constrain i.e. display By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 27
  • 28. 8051 Microcontroller and Interfacing Experiments should be faster then we have to use 8-bit mode because basically 4-bit mode takes twice as more time as compared to 8-bit mode. When RS is low (0), the data is to be treated as a command. When RS is high (1), the data being sent is considered as text data which should be displayed on the screen. When R/W is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively reading from the LCD. Most of the times there is no need to read from the LCD so this line can directly be connected to Gnd thus saving one controller line. The ENABLE pin is used to latch the data present on the data pins. A HIGH - LOW signal is required to latch the data. The LCD interprets and executes our command at the instant the EN line is brought low. If you never bring EN low, your instruction will never be executed. Display Data Ram (DDRAM) stores the display data. So when we have to display a character on LCD we basically write it into DDRAM. For a 2x16 LCD the DDRAM address for first line is from 80h to 8fh & for second line is 0c0h to 0cfh. So if we want to display 'H' on the 7th position of the first line then we will write it at location 87h. Now as you have noticed two types of data is given to the LCD data to be displayed, command or special instruction. Source Code: #include <AT89X51.H> #define LCD P1 sbit sw=P2^7; sbit rs=P2^0; sbit en=P2^1; void lcdcmd(unsigned char); void lcd_data(unsigned char); void lcd_data_string(unsigned char *); void init_lcd(); //void ser_str(unsigned char* ); //void ser_data(unsigned char ) void delay(unsigned int ); void main() { init_lcd(); sw=1; while(1) { lcd_data_string(" ESSENCE TRAINING PROGRAM FOR SKU "); //ser_str("n anticlockwise r "); delay(900); } } void init_lcd(void) By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 28
  • 29. 8051 Microcontroller and Interfacing Experiments { lcdcmd(0X38); delay(500); lcdcmd(0X0E); delay(500); lcdcmd(0X01); delay(500); lcdcmd(0X06); delay(500); /*lcdcmd(0X80); delay(500);*/ } void lcdcmd(unsigned char a) { LCD=a; rs=0; en=1; delay(500); en=0; } void lcd_data(unsigned char a) { LCD=a; rs=1; en=1; delay(500); en=0; //return(0); } void delay(unsigned int j) { unsigned int i; for(i=0;i<j;i++); } void lcd_data_string(unsigned char *p) { while(*p!='0') { lcd_data(*p++); } } By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 29
  • 30. 8051 Microcontroller and Interfacing Experiments Experiment No. 5 Aim: Interface 12V DC Electro Mechanical Relay (EMR) with P89V51RD2 using 8051 development board. Electro Mechanical Relay (EMR): A relay is an electrically controllable switch widely used in industrial controls, automobiles and appliances. It allows the isolation of two separate sections of a system with two different sources. One such relay is called Electro Mechanical Relay or Electro Magnetic Relay. The EMRs have three components: the coil, spring and contacts. When current flows through the coil, a magnetic field is created around the coil (the coil is energized), which causes the armature to be attracted to the coil. The armature contact acts like a switch and closes or opens the circuit. The contacts normally open (NO) or normally close (NC). In the NC type, the contacts are closed when the coil is not energized. In the NO, the contacts are open when the coil is not energized. There can one or more contacts. For example, we can have SPST (Single pole, single through), SPDT (Single pole, double through) and DPDT (Double pole, double through) relays. Relay diagram shows all types of relay internal diagram. Relay Diagrams: By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 30
  • 31. 8051 Microcontroller and Interfacing Experiments Schematic Diagram: Algorithm: 1. Connect the relay to microcontroller as shown in the schematic. a. Relay coil needs around 10mA to be energized; the microcontroller pin can provide a maximum of 1-2mA current. b. For this reason we place a driver such as a power transistor or ULN2803 between microcontroller and relay. 2. Control the P1.0 pin by switching it with some delay. 3. Write the program in Keil software by using embedded-C language. 4. Generate .hex file and transfer the .hex file from computer to the target board by using flash magic. Source Code: /* ----------------------------------------------------------------------- relay.c : Demonstration of interfacing an Relay Designed for 89c51 running at 11.0592Mhz Controlling a port pin (turn on and off) at rate of 1Hz with crystal of 11.0592Mhz compile the program in Keil uVision Compiler. Operation : when MCU power up port pin on/off continuously at frequency of 1Hz. Feedback appreciated: researchermouli@gmail.com -----------------------------------------------------------------------------*/ By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 31
  • 32. 8051 Microcontroller and Interfacing Experiments //INCLUDES DEFINITION OF 89C51 #include<at89x51.h> //CONSTANT DEFINES #define INPUT_PIN 1 // define 1 as INPUT_PIN #define LOW 0 #define HIGH 1 //PINS DEFINE #define RELAY_PIN P1_0 // define port P1_0 as RELAY i.e connect RELAY to P1_0 //DEFINE MACROS #define RELAYOn() RELAY_PIN = LOW #define RELAYOff() RELAY_PIN = HIGH //FUNCTIONS PROTOYPES void Delay(unsigned int time); //main function begins void main(void) { RELAY_PIN = INPUT_PIN; while(1) // loop forever { RELAYOn(); // Turn on relay Delay(500); // delay for 500msec = 0.5 sec RELAYOff(); // Turn off relay Delay(500); // delay for 500msec = 0.5 sec } // end of while loop } // end of main function // PROGRAM ROUTINES void Delay(unsigned int time) { unsigned char pause; // Declare variable pause as unsigned char while( time > 0) // loop until time is greater than zero { pause = 150; // Initialize pause to 150 (decimal value) while(pause--); // Decrement pause until it becomes zero time--; // Decrement time and loop back until time } // value becomes zero } // End of Delay function By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 32
  • 33. 8051 Microcontroller and Interfacing Experiments Experiment No. 6 Aim: To interface stepper motor with P89V51RD2 using 8051 development board. Schematic Diagram: 1. Stepper motor unlike DC motor rotates in steps. 2. Stepper motor has 4 coils which forms the stator and a central rotor. 3. Rotation depends on excitation of stator coils. step coil A coil B coil C coil D 1 0 0 0 1 2 1 0 0 0 3 0 1 0 0 4 0 0 0 1 Anyone of these values forms the initial value. To get 360o revolution 48 steps are required. By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 33
  • 34. 8051 Microcontroller and Interfacing Experiments Step angle= 360o /48 = 7.5o . Algorithm: 1. Configure P1 as output. 2. Apply the initial excitation of 11 to motor coils through P1. 3. For clockwise motion -Rotate right once the excitation and repeat step 2. 4. For anticlockwise motion -Rotate left once the excitation and repeat step 2. Source Code: #include<reg51.h> void Delay(unsigned int); void main(void) { unsigned int r, rotation, codes[4]= {0x11,0x44,0x22,0x88}; while(1) { for(rotation=0; rotation<5; rotation++) { for(r=0; r<=3; r++) { P2 = codes[r]; Delay(500); } } } } void Delay(unsigned int time) { unsigned char pause; while( time > 0) { pause = 52; while(pause--); time--; } } By C. Chandra Mouli, Research Scholar, Department of Instrumentation, Sri Krishnadevaraya University, Anantapur. Mobile: +919963719606, email: researchermouli@gmail.com 34