0% found this document useful (0 votes)
79 views116 pages

MC Lab-Record Final - Watermark-1

The document provides an introduction to the 8051 microcontroller. It discusses that microcontrollers were developed to be smaller, faster and more reliable than microprocessors. It then describes some key features of the 8051 microcontroller, including that it is an 8-bit microcontroller introduced in 1980 by Intel, it has 4KB of ROM, 128 bytes of RAM, 32 I/O lines across four ports, timers, interrupts and serial communication. It also summarizes the architecture of the 8051 including its memory systems, registers and pinout.

Uploaded by

Mohamed Saleel
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)
79 views116 pages

MC Lab-Record Final - Watermark-1

The document provides an introduction to the 8051 microcontroller. It discusses that microcontrollers were developed to be smaller, faster and more reliable than microprocessors. It then describes some key features of the 8051 microcontroller, including that it is an 8-bit microcontroller introduced in 1980 by Intel, it has 4KB of ROM, 128 bytes of RAM, 32 I/O lines across four ports, timers, interrupts and serial communication. It also summarizes the architecture of the 8051 including its memory systems, registers and pinout.

Uploaded by

Mohamed Saleel
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/ 116

Dept.

Of Electronics Engineering Microcontroller and Applications Lab

INTRODUCTION TO 8051 MICROCONTROLLER

Earlier to Microcontrollers, Microprocessors were greatly used for each and every purpose.
Microprocessors were containing ALU, general purpose register, stack pointer, program counter,
clock counter and so many other features which the today’s Microcontroller also possesses. But the
difference between them exists with respect to the number of instructions, access times, size,
reliability, PCB size and so on. Microprocessor contains large instruction set called as CISC
processor whereas Microcontroller contains a smaller number of instructions and is called as RISC
processor. The access time is less in case of microcontrollers compared to microprocessors and
the PCB size reduces in case of microcontrollers.
The 8051 family was introduced in the early 1980s by Intel. Since its introduction, the 8051
has been one of the most popular microcontrollers and has been second- sourced by many
manufacturers. The 8051 currently has many different versions and some types include on-chip
analogue-to-digital converters, a considerably large size of program and data memories. The two
other members of these 8051 families are-
 8052-This microcontroller has 3 timers & 256 bytes of RAM. Additionally, it has all the
features of the traditional 8051 microcontroller. 8051 microcontroller is a subset of 8052
microcontroller.
 8031 - This microcontroller is ROM less, other than that it has all the features of a traditional
 8051 microcontrollers. For execution an external ROM of size 64K bytes can be added to its
chip.8051 microcontroller brings into play 2 different sorts of memory such as - NV-
RAM, UV - EPROM and Flash. 8051 is the basic microcontroller to learn embedded systems
projects.
There are many versions of microcontrollers 8051, 80528751, AT8951 from Atmel
Corporation and many more. In this manual we will study about the 8051 architectures, its features,
programming and interfacing. MCS 8051 is an 8-bit single chip microcontroller with many built-in
functions and is the core for all MCS-51 devices. It was developed using N-type Metal-Oxide-
Semiconductor (NMOS) technology and later it came to be identified by a letter C in their names
e.g., 80C51 which was developed with Complementary Metal-Oxide-Semiconductor (CMOS)
technology which consumes less power than NMOS and made it better compatible for battery-
powered applications.

SSM Polytechnic College, Tirur 1|Page


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 2|Page


Dept. Of Electronics Engineering Microcontroller and Applications Lab

ARCHITECHURE OF 8051 MICRO-CONTROLLERS


The Intel MCS-51 (commonly referred to as 8051) is a Harvard architecture, single chip
microcontroller (μC) series which was developed by Intel in 1980 for use in embedded systems. The
8051 architecture provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer, etc.) in a
single package.
FEATURES OF 8051
 8051 microcontroller is an eight-bit microcontroller.
 Operates with single Power Supply +5V.
 Itis available in 40 pin D I P (Dual Inline Package).
 It has 4kb of ROM (on- chip programmable space) and 128 bytes of RAM space which is
inbuilt, if desired 64KB of external memory can be interfaced with the microcontroller.
 128 bytes of On-Chip Data Memory (Internal RAM):
 Four Register Banks, each containing 8 registers (R0 to R7) [Total 32 reg]
 16-bytes of bit addressable memory.
 80 bytes of general-purpose data memory (Scratch Pad Area).
 Special Function Registers (SFR) to configure/operate microcontroller.
 There are four parallel 8 bits ports which are easily programmable as well as addressable.
32 bit bi-directional I/O Lines (4 ports P0 to P3).
 An on- chip crystal oscillator is integrated in the microcontroller which has crystal
frequency of 12MHz.
 In the microcontroller there is a serial input/output port which has 2 pins. Full duplex
UART (Universal Asynchronous Receiver/Transmitter).
 Two timers of 16 bits (T0 and T1) are also incorporated in it; these timers can be
employed as timer for iinternal functioning as well as counter for external functioning.
 The microcontroller comprises of 5 interrupt sources namely-Serial Port Interrupt, Timer
Interrupt 1, External Interrupt 0, Timer Interrupt 0, External Interrupt 1.
 The programming mode of this micro-controller includes GPRs (general purpose
registers), SFRs (special function registers) and SPRs (special purpose registers).
 16-bit program counter (PC) and 16-bit data pointer (DPTR).
 8-bit program status word (PSW), 8-bit stack pointer (SP).

SSM Polytechnic College, Tirur 3|Page


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 4|Page


Dept. Of Electronics Engineering Microcontroller and Applications Lab

PIN DIAGRAM OF 8051 MICRO-CONTROLLER

Pins 1-8: Port 1 Each of these pins can be configured as an input or an output.
Pin 9: RS A logic one on this pin disables the microcontroller and clears the contents of most
registers. In other words, the positive voltage on this pin resets the microcontroller. By applying
logic zero to this pin, the program starts execution from the beginning.
Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general input or output. Besides,
all of them have alternative functions:
Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication
output.
Pin 11: TXD Serial asynchronous communication output or Serial synchronous communication
clock output.
Pin 12: INT0 Interrupt 0 inputs.
Pin 13: INT1 Interrupt 1 input.
Pin 14: T0 Counter 0 clock input.
Pin 15: T1 Counter 1 clock input.
Pin 16: WR Write to external (additional) RAM.
Pin 17: RD Read from external RAM.
Pin 18, 19: X2, X1 Internal oscillator input and output. A quartz crystal which specifies operating
frequency is usually connected to these pins. Instead of it, miniature ceramics resonators can also
be used for frequency stability. Later versions of microcontrollers operate at a frequency of 0 Hz
up to over 50 Hz.
Pin 20: GND Ground.
Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are configured
as general inputs/outputs. In case external memory is used, the higher address byte, i.e., addresses
A8-A15 will appear on this port. Even though memory with capacity of 64Kb is not used, which
means that not all eight port bits are used for its addressing, the rest of them are not available as
inputs/outputs.
Pin 29: PSEN If external ROM is used for storing program, then a logic zero (0) appears on it
every time the microcontroller reads a byte from memory.
Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower address
byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the
external register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the state of P0 and

SSM Polytechnic College, Tirur 5|Page


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 6|Page


Dept. Of Electronics Engineering Microcontroller and Applications Lab

uses it as a memory chip address. Immediately after that, the ALU pin is returned its previous logic
state and P0 is now used as a Data Bus. As seen, port data multiplexing is performed by means
of only one additional (and cheap) integrated circuit. In other words, this port is used for both data
and address transmission.
Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and address transmission
with no regard to whether there is internal memory or not. It means that even there is a program
written to the microcontroller, it will not be executed. Instead, the program written to external
ROM will be executed. By applying logic one to the EA pin, the microcontroller will use both
memories, first internal then external (if exists).
Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as general
inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven
high (1) or as data output (Data Bus) when the ALE pin is driven low (0).
Pin 40: VCC +5V power supply.

SSM Polytechnic College, Tirur 7|Page


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 8|Page


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.1 Date: …. /..…/…..


GETTING STARTED WITH KEIL µVision 5
AIM
To Study about how to build an Assembly language program for8051 microcontrollers using
KEIL µVision 5.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Keil µVision 5 IDE software
PROCEDURE:
Step 01: Open KEIL µVision 5
Step 02: Go to Project >> New µVision Project

Step 03: Create a new project folder. Right Click on Mouse >>New >> Folder.

SSM Polytechnic College, Tirur 9|Page


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 10 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Step 04: Rename the folder as Project name and open.

Step 05: Open the folder and chose project name and save.

SSM Polytechnic College, Tirur 11 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 12 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Step 06: Chose Microcontroller as “AT89S51” and click OK. Apopup window will open.
Just click NO

Step 07: Go to Files and click on new.

A new text window will open.

SSM Polytechnic College, Tirur 13 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 14 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Step 08: Write your program on Text Window

Step 09: Press CTRL + S keys to save the file. A window willopen. Save the file as
ADDITION.ASM/.A/.S/.M

After saving file, the window name will change to given nameand the text will be in colored
format.

SSM Polytechnic College, Tirur 15 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 16 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Step 10: Go to View click on Project window

The project window will open.

SSM Polytechnic College, Tirur 17 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 18 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Step 11: Click on the “+” Near to Target 1 folder. It will


show another folder “Source Group 1”

Step 12: Double click on “Source Group 1” Folder. A windowwill appear. Select the file
that you saved as .ASM/.A/.S/.S and click Add. Then close the window.

Step 13: Pres F7 Key to build the program. After successfulbuild, you can see the output
window like below.

SSM Polytechnic College, Tirur 19 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 20 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Step 14: Go to Debug >> Start Stop Debug session. A popupwindow will open. Just
click on OK

Then the debug window will open like below, click “OK”

SSM Polytechnic College, Tirur 21 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 22 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Step 15: Press F11 key to check the step-by-step register/Memory changes while running
of program

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 23 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 24 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.2 Date: …. /..…/…..


ARITHMETIC OPERATIONS USING 8051
AIM
To perform the arithmetic operations using 8051 microcontroller.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Keil µVision 5 IDE software
PRINCIPLE
Arithmetic instructions perform several basic operations such as addition, subtraction,
division, multiplication etc. After execution, the result is stored in the first operand.
Addition

The instruction ADD is used to add two operands. The destination operand is always in
register A while the source operand can be a register, immediate data, or in memory. Remember that
memory-to-memory arithmetic operations are never allowed in 8051 Assembly language. The
instruction could change any of the AF, CF, or P bits of the flag register, depending on the operands
involved. The effect of the ADD instruction on the overflow flag is discussed in Section 6.3 since it
is used mainly in signed number operations.
In this group, we have instructions to
i. Add the contents of A with immediate data with or without carry.
i. ADD A, #45H
ii. ADDC A, #OB4H
ii. Add the contents of A with register Rn with or without carry.
i. ADD A, R5
ii. ADDC A, R2
iii. Add the contents of A with contents of memory with or without carry using direct and
indirect addressing
i. ADD A, 51H
ii. ADDC A, 75H
iii. ADD A, @R1
iv. ADDC A, @R0
CY AC and OV flags will be affected by this operation.

SSM Polytechnic College, Tirur 25 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 26 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Subtraction

In many microprocessors there a^e two different instructions for subtraction: SUB and
SUBB (subtract with borrow). In the 8051 we have only SUBB. If the C Y = 0 after the execution
of SUBB, the result is positive; if C Y = 1, the result is negative and the destination has the 2′s
complement of the result
In the arithmetic group, we have instructions to
i. Subtract the contents of A with immediate data with or without carry.
i. SUBB A, #45H
ii. SUBB A, #OB4H
ii. Subtract the contents of A with register Rn with or without carry.
i. SUBB A, R5
ii. SUBB A, R2
iii. Subtract the contents of A with contents of memory with or without carry using direct
and indirect addressing
i. SUBB A, 51H
ii. SUBB A, 75H
iii. SUBB A, @R1
iv. SUBB A, @R0

Multiplication

In multiplying or dividing two numbers in the 8051, the use of registers A and B is required
since the multiplication and division instructions work only with these two registers.
This instruction multiplies two 8 bit unsigned numbers which are stored in A and B register.
After multiplication the lower byte of the result will be stored in accumulator and higher byte of
result will be stored in B register.

E.g. MOV A, #45H ; [A]=45H


MOV B, #0F5H ; [B]=F5H
MUL AB ; [A] x [B] = 45 x F5 = 4209
; [A]=09H, [B]=42H

SSM Polytechnic College, Tirur 27 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 28 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Division

This instruction divides the 8-bit unsigned number which is stored in A by the 8 bit unsigned
number which is stored in B register. After division the result will be stored in accumulator and
remainder will be stored in B register.

E.g. MOV A, #45H ; [A]=0E8H


MOV B, #0F5H ; [B]=1BH
DIV AB ; [A] / [B] = E8 /1B = 08 H with remainder 10H
; [A] = 08H, [B]=10H
Increment
Increments the operand by one.

INC A INC Rn INC DIRECT INC @Ri INC DPTR

INC increments the value of source by 1. If the initial value of register is FFh, incrementing
the value will cause it to reset to 0. The Carry Flag is not set when the value "rolls over" from 255
to 0.
In the case of "INC DPTR", the value two-byte unsigned integer value of DPTR is
incremented. If the initial value of DPTR is FFFF h, incrementing the value will cause it to reset to
0.

Decrement:

Decrements the operand by one.

DEC A DEC Rn DEC DIRECT DEC @Ri

DEC decrements the value of source by 1. If the initial value of is 0, decrementing the value
will cause it to reset to FF h. The Carry Flag is not set when the value "rolls over" from 0 to FF h.

SSM Polytechnic College, Tirur 29 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 30 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running
program.

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 31 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 32 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.3 Date: …. /..…/…..


LOGIC OPERATIONS USING 8051
AIM
To perform the logic operations using the 8051- microcontroller.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Keil µVision 5 IDE software
PRINCIPLE

Logical AND

ANL destination, source:

ANL does a bitwise "AND" operation between source and destination, leaving the resulting
value in destination. The value in source is not affected. "AND" instruction logically AND the bits
of source and destination.

ANL A,#DATA ANL A, Rn


ANL A,DIRECT ANL A,@Ri
ANL DIRECT,A ANL DIRECT, #DATA

Logical OR

ORL destination, source:

ORL does a bitwise "OR" operation between source and destination, leaving the resulting
value in destination. The value in source is not affected. " OR " instruction logically OR the bits of
source and destination.

ORL A,#DATA ORL A, Rn


ORL A,DIRECT ORL A,@Ri
ORL DIRECT,A ORL DIRECT, #DATA

SSM Polytechnic College, Tirur 33 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 34 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Logical Ex-OR
XRL destination, source:

XRL does a bitwise "EX-OR" operation between source and destination, leaving the
resulting value in destination. The value in source is not affected. " XRL " instruction logically
EX-OR the bits of source and destination.

XRL A,#DATA XRL A,Rn


XRL A,DIRECT XRL A,@Ri
XRL DIRECT,A XRL DIRECT, #DATA
Logical NOT

CPL complements operand, leaving the result in operand. If operand is a single bit, then the
state of the bit will be reversed. If operand is the Accumulator, then all the bits in the Accumulator
will be reversed.
CPL A CPL C CPL bit address

SWAP Instruction
SWAP A
Swap the upper nibble and lower nibble of A.

PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”

SSM Polytechnic College, Tirur 35 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 36 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

8. Press F11 Key to check the step-by-step register/memory changes while running
program.

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 37 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 38 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.4 Date: …. /..…/…..


BCD TO ASCII CONVERSION USING 8051
AIM
To perform the BCD to ASCII Code conversion using 8051- microcontroller.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Keil µVision 5 IDE software
PRINCIPLE
Many newer microcontrollers have a real-time clock (RTC) where the time and
date are kept even when the power is off. Very often the RTC provides the time and
date in packed BCD. However, to display them they must be converted to ASCII.
ASCII numbers
In computers, all the information is represented in 0s and 1s, binary pattern must assign
letters and other symbols or characters. Standard representation of this pattern was established in
1960 who names as ASCII which is stands for American Standard Code for Information Interchange.
The great advantage of this system is that it is used by most of the computers therefore information
is shared with other computers easily. ASCII code assign binary pattern from 0 to 9 in all alphabets
of English both in uppercase and lower case. ASCII system needs seven bits to represent a code.
On ASCII keyboards, when the key “0″ is activated, “011 0000″ (30H) is provided to the
computer. Similarly, 31H (011 0001) is provided for the key “1″, and so on, as shown in Table

SSM Polytechnic College, Tirur 39 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 40 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

It must be noted that although ASCII is standard in the United States (and many other
countries), BCD numbers are universal. Since the keyboard, printers, and monitors all use ASCII,
data should get converted from ASCII to BCD, and vice versa.

Packed BCD to ASCII conversion

Many systems have what is called a real-time clock (RTC). The RTC provides the time of
day (hour, minute, second) and the date (year, month, day) continuously, regardless of whether the
power is on or off (see Chapter 16). However, this data is provided in packed BCD. For this data to
be displayed on a device such as an LCD, or to be printed by the printer, it must be in ASCII format.
To convert packed BCD to ASCII, it must first be converted to unpacked BCD. Then the
unpacked BCD is tagged with Oil 0000 (30H). The following demonstrates converting from packed
BCD to ASCII.

Instructions Used
RR A
This instruction is rotate right the accumulator. Its operation is illustrated below. Each bit is
shifted one location to the right, with bit 0 going to bit 7.

RL A
Rotate left the accumulator. Each bit is shifted one location to the left, with bit 7 going to bit 0

SSM Polytechnic College, Tirur 41 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 42 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

RRC A
Rotate right through the carry. Each bit is shifted one location to the right, with bit 0 going
into the carry bit in the PSW, while the carry was at goes into bit 7

RLC A
Rotate left through the carry. Each bit is shifted one location to the left, with bit 7 going into
the carry bit in the PSW, while the carry goes into bit 0.

PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running program.

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 43 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 44 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.5 Date: …. /..…/…..


ASCII TO BCD CONVERSION USING 8051
AIM
To perform the ASCII to BCD Code Conversion using 8051- microcontroller...
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Keil µVision 5 IDE software
PRINCIPLE
ASCII to Packed BCD Conversion:
This is the reverse process of the packed BCD to ASCII. First, we need to convert ASCII
into unpacked BCD and then unpacked is converted into packed BCD.
To convert ASCII to packed BCD, it is first converted to unpacked BCD (to get rid of the
3), and then combined to make packed BCD.
Example 1:
For 4 and 7 the keyboard gives 34 and 37, respectively. The goal is to produce 47H
or “0100 0111″.

Example 2:

ASCII Unpacked BCD Packed BCD

37H & 38H 07H & 08H 78H


0011 0111 & 0011 1000 0000 0111 & 0000 1000 0111 1000

39H & 31H 09H & 01H 91H


0011 1001 & 0011 0001 0000 1001 & 0000 0001 1001 0001

SSM Polytechnic College, Tirur 45 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 46 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running
program
RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 47 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 48 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.6 Date: …. /..…/…..


PORT PROGRAMMING TO INTERFACE LED
AIM
To apply the concept of port programming to interface LED using 8051- microcontroller.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Keil µVision 5 IDE software
PRINCIPLE
In the 8051 there are a total of four ports for I/O operations. The four ports PO, Pi, P2, and
P3 each use 8 pins, making them 8-bit ports. All the ports upon RESET are configured as inputs,
ready to be used as input ports. When the first 0 is written to a port, it becomes an output. To
reconfigure it as an input, a 1 must be sent to the port. To use any of these ports as an input port, it
must be programmed
Port 0 (Pin No 32 - Pin No 39):
Port 0 contains 8 pins. It can be used as input or output. In general, we connect P0 with 10K-
ohm pull-up resistors for using it as an input or output port being an open drain.
It is also referred as AD0-AD7, which allowing it to be used as both address and data transfer
port. When we want to excess the external ROM, then P0 is used as both Data and Address Bus.
Address Latch Enable (ALE) Pin no 31 indicates if PO is used as address or data. When ALE=0
then it provides data D0-D7. When ALE=1 then it provides address A0-A7.
Port 1 (Pin No 1-Pin No 8):
It is also an 8-bit Port and can be worked as either input or output. It doesn't require external
connected pull-up resistors because they are already present internally. Upon reset, Port 1 worked
as an input port.
If port 1 is configured as an output port, then to use port 1 as input port again, we write 1 to
all bits of port 1
Port 2 (Pin No 21-Pin No 28):
Port 2 uses a total of 8 pins and it can also be used as input and output operation. Same as
Port 1, P2 also not require external pull- up resistors. Port 2 can be used along with P0 to provide
16-bit address for an external memory. Therefore, it is designated as (A0-A7).

SSM Polytechnic College, Tirur 49 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 50 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

If Port 2 is configured as an output port, then for using it as an input port again we write 1 to
all bits of port 2.
Port 3 (Pin No 10-Pin No 17):
Port 3 is also of 8 bits and it can be used as Input/output. This port provides some important
signals.
P3.1 and P3.0 are RxD (Receiver) and TxD (Transmitter) respectively and it is collectively
used for serial communication. P3.3 and P3.2 pins are used as external interrupts. P3.5 and P3.4 are
used as timers T1 and T0 respectively. P3.6 and P3.7 are Write (WR) and Read (RD) pins.
Port 3 table showing an individual pin function:

Pin Function P3 Bit

10 Receiver (RxD) P3.0

11 Transmitter (TxD) P3.1<

12 Complement of INT 0 P3.2<

13 INT 1 P3.3<

14 Timer 0(TO) P3.4<

15 Timer 1(T1) P3.5<

16 Write (WR) P3.6<

17 Complement of read (RD) P3.7<

I/O Ports and Bit Addressability:


It is a mostly used feature of 8051 while writing code for 8051. Sometimes there is a need to
use only 1 or 2 bits of the port instead of using entire 8-bits. 8051 microcontroller provides the
feature to use each bit of the ports.
While using a port in a single-bit manner, we provide the syntax "SETB X.Y", where X is
the port number varies from 0 to 3, and Y is a bit number varies from 0 to 7.
For example: - "SETB P1.3" sets high bit 3 of port 1.

SSM Polytechnic College, Tirur 51 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 52 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Software delay routine in 8051


In an 8051 microcontroller, it requires 12 cycles of the processor clock for
executing a single instruction cycle. For an 8051-microcontroller clocked by a
12MHz crystal, the time taken for executing one instruction cycle is 1µS and it is
according to the equation, Time for 1 instruction cycle= 12 /12MHz = 1µS. The
shortest instructions will execute in 1µS and other instructions will take 2 or more
micro seconds depending up on the size of the instruction. Thus, a time delay of any
magnitude can be generated by looping suitable instructions a required number of
times. Anyway, keep one thing in mind that software delay is not very accurate
because we cannot exactly predict how much time it takes for executing a single
instruction. Generally, an instruction will be executed in the theoretical amount of
time but sometimes it may advance or retard due to other reasons. Therefore, it is
better to use 8051 Timer for generating delay in time critical applications. However,
software delay routines are very easy to develop and well enough for less critical and
simple applications.
Program to delay 1mS
DELAY: MOV R6, #250D
MOV R7, #250D
LABEL1: DJNZ R6, LABEL1
LABEL2: DJNZ R7, LABEL2
RET
Program to delay 1 second
DELAY1: MOV R5, #250D
LABEL: ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
DJNZ R5, LABEL
RET

SSM Polytechnic College, Tirur 53 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 54 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

DELAY: MOV R6, #250D


MOV R7, #250D
LOOP1: DJNZ R6, LOOP1
LOOP2: DJNZ R7, LOOP1
RET

PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running
program

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 55 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 56 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.7 Date: …. /..…/…..


INTERFACE LCD DISPLAY WITH 8051
AIM
To demonstrate the interfacing of LCD Display with the 8051- microcontroller.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Proteus 8 Professional Software.
PRINCIPLE

Display units are the most important output devices in embedded projects and electronics
products. 16x2 LCD is one of the most used display unit. 16x2 LCD means that there are two rows
in which 16 characters can be displayed per line, and each character takes 5X7 matrix space on LCD.
A 16×2 LCD means it can display 16 characters per line and there are 2 such lines. In this
LCD each character is displayed in a 5×7-pixel matrix. This LCD has two registers, namely,
Command and Data. The command register stores the command instructions given to the LCD. A
command is an instruction given to LCD to do a predefined task like initializing it, clearing its
screen, setting the cursor position, controlling display, etc. The data register stores the data to be
displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.

Category Pin NO. Pin Name Function

Power Pins 1 VSS Ground Pin, connected to Ground


2 VDD or Vcc Voltage Pin +5V
Contrast Pin 3 V0 or VEE Contrast Setting, connected to Vcc thorough a
variable resistor.
4 RS Register Select Pin, RS=0 Command mode,
Control Pins
5 RW Read/ Write pin, RW=0 Write mode,
6 E Enable, a high to low pulse need to enable the LCD
Data Pins 7-14 D0-D7 Data Pins, Stores the Data to be displayed on LCD
or the command instructions
Backlight 15 LED+ or A To power the Backlight +5V
Pins
16 LED- or K Backlight Ground

SSM Polytechnic College, Tirur 57 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 58 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

The LCD display module requires 3 control lines as well as either 4 or 8 I/O lines for the data bus.
The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus. If a 4-
bit data bus is used the LCD will require a total of 7 data lines (3 control lines plus the 4 lines for
the data bus). If an 8-bit data bus is used the LCD will require a total of 11 data lines (3 control lines
plus the 8 lines for the data bus).

The three control lines are referred to as EN, RS, and RW.

EN:-The EN line is called “Enable.” This control line is used to tell the LCD that you are sending it
data. To send data to the LCD, your program should make sure this line is low (0) and then set the
other two control lines and/or put data on the data bus. When the other lines are completely ready,
bring EN high (1) and wait for the minimum amount of time required by the LCD datasheet (this
varies from LCD to LCD), and end by bringing it low (0) again.

RS:-The RS line is the “Register Select” line. When RS is low (0), the data is to be treated as a
command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1),
the data being sent is text data which should be displayed on the screen. For example, to display the
letter “T” on the screen you would set RS high.

RW:-The RW line is the “Read/Write” control line. When RW is low (0), the information on the
data bus is being written to the LCD. When RW is high (1), the program is effectively querying (or
reading) the LCD. Only one instruction (“Get LCD status”) is a read command. All others are write
commands–so RW will almost always be LOW.

DB0 – DB7:- Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation
selected by the user). In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2,
DB3, DB4, DB5, DB6, and DB7.

There are some preset command instructions in LCD, to prepare the LCD (in lcd_init()
function). Some important command instructions are given below:

SSM Polytechnic College, Tirur 59 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 60 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 61 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 62 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
11. After successful build operation, Go to Debug → Start VSM Debugging.
12. Click on Play Button on the bottom left to start simulation

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 63 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 64 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.8 Date: …. /..…/…..


KEYBOARD INTERFACING USING 8051
AIM
To make use of keyboard read function to interface matrix keyboard with 8051 MC.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Proteus 8 Professional Software.
PRINCIPLE
Keyboards and LCDs are the most widely used input/output devices of the 8051. They are
used to take inputs in the form of numbers and alphabets, and feed the same into system for further
processing.
Matrix keypad consists of set of Push buttons, which are interconnected.
There are 4 push buttons in each of four rows. In first row, one terminal of all the
four push buttons is connected together and another terminal of 4 push buttons are
representing each of 4 columns, same goes for each row. So, we are getting 8
terminals to connect with a microcontroller.

Interfacing the keyboard to the 8051


At the lowest level, keyboards are organized in a matrix of rows and columns. The CPU
accesses both rows and columns through ports; therefore, with two 8-bit ports, an 8 x 8 matrix of
keys can be connected to a microprocessor. When a key is pressed, a row and a column make a
contact; otherwise, there is no connection between rows and columns.

SSM Polytechnic College, Tirur 65 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 66 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Scanning and identifying the key


The Figure given above shows a 4 x 4 matrix connected to two ports. The rows are connected
to an output port and the columns are connected to an input port. If no key has been pressed, reading
the input port will yield 1 s for all columns since they are all connected to high (Vcc). If all the rows
are grounded and a key is pressed, one of the columns will have 0 since the key pressed provides
the path to ground. It is the function of the microcontroller to scan the keyboard continuously to
detect and identify the key pressed.
Grounding rows and reading the columns
To detect a pressed key, the microcontroller goes through the following four major
stages:
1. To make sure that the preceding key has been released, 0 s are output to all rows at once, and
the columns are read and checked repeatedly until all the columns are high. When all columns
are found to be high, the program waits for a short amount of time before it goes to the next
stage of waiting for a key to be pressed.
2. To see if any key is pressed, the columns are scanned over and over in an infinite loop until
one of them has a 0 on it. Remember that the output latches connected to rows still have their
initial zeros (provided in stage 1), making them grounded. After the key press detection, the
microcontroller waits 20 ms for the bounce and then scans the columns again. This serves
two functions: (a) it ensures that the first key press detection was not an erroneous one due
to a spike noise, and (b) the 20-ms delay prevents the same key press from being interpreted
as a multiple key press. If after the 20Tins delay the key is still pressed, it goes to the next

SSM Polytechnic College, Tirur 67 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 68 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

3. stage to detect which row it belongs to; otherwise, it goes back into the loop to detect a real
key press.
4. To detect which row the key press belongs to, the microcontroller grounds one row at a time,
reading the columns each time. If it finds that all columns are high, this means that the key
press cannot belong to that row; therefore, it grounds the next row and continues until it finds
the row the key press belongs to. Upon finding the row that the key press belongs to, it sets
up the starting address for the look-up table holding the scan codes (or the ASCII value) for
that row and goes to the next stage to identify the key.
5. To identify the key press, the microcontroller rotates the column bits, one bit at a time, into
the carry flag and checks to see if it is low. Upon finding the zero, it pulls out the ASCII code
for that key from the look-up table; otherwise, it increments the pointer to point to the next
element of the look-up table.
PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
11. After successful build operation, Go to Debug → Start VSM Debugging.
12. Click on Play Button on the bottom left to start simulation

SSM Polytechnic College, Tirur 69 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 70 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 71 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 72 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.9 Date: …. /..…/…..


TIMER OPERATION USING 8051
AIM
To toggle LED at specific interval using the concept of Timer in 8051- microcontroller.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Proteus 8 Professional Software.
PRINCIPLE
In Intel 8051, there are two 16-bit timer registers. These registers are known as Timer0
andTimer1. The timer registers can be used in two modes. These modes are Timer mode and the
Counter mode. The only difference between these two modes is the source for incrementing the
timer registers.
Timer Mode
In the timer mode, the internal machine cycles are counted. So this register is incremented
in each machine cycle. So, when the clock frequency is 12MHz, then the timer register is
incremented in each millisecond. In this mode it ignores the external timer input pin.
Counter Mode
In the counter mode, the external events are counted. In this mode, the timer register is
incremented for each 1 to 0 transition of the external input pin. This type of transitions is treated as
events. The external input pins are sampled once in each machine cycle, and to determine the 1or 0
transitions, another machine cycle will be needed.
Basic registers of the timer

1.Timer Registers
It is a16 bit register and can be accessed as 8 bit registers say Timer High(THx) and Timer
Low (TLx),These registers can be accessed as any other registers like A,B,R0 etc.,

SSM Polytechnic College, Tirur 73 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 74 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

2. TMOD (Timer Mode) Register


TMOD Register is an 8-bit register used to control the mode of operation of both timers. The
high four bits (bits 4 through 7) relate to Timer 1whereas the low four bits (bits 0 through 3) perform
the exact same functions, but for timer 0. In each case, the lower two bits are used to set the timer
mode and upper two bits to specify the operation as shown in Figure.

In upper or lower 4 bits, first bit is a GATE bit. Every timer has a means of starting and
stopping. Some timers do this by software, some by hardware, and some have both software and
hardware controls. The hardware way of starting and stopping the timer by an external source is
achieved by making GATE=1 in the TMOD register and if GATE=0 then we do start and stop the
timers by programming.
The second bit is C/T bit and is used to decide whether a timer is used as a time delay
generator or an event counter. If this bit is 0 then it is used as a timer and if it is 1 then it is used as
a counter.
In upper or lower 4 bits, the last bits third and fourth are known as M1 and M0 respectively. These
are used to select the timer mode.

Bit 7,3 – GATE:

1 = Enable Timer/Counter only when the INT0/INT1 pin is high and TR0/TR1 is set.

0 = Enable Timer/Counter when TR0/TR1 is set.

Bit 6,2 - C/ (Counter/Timer): Timer or Counter select bit

1 = Use as Counter

0 = Use as Timer

Bit 5:4 & 1:0 - M1:M0: Timer/Counter mode select bit

These are Timer/Counter mode select bit as per the below table

SSM Polytechnic College, Tirur 75 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 76 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

M1 M0 Mode Operation

0 0 0 (13-bit timer mode) 13-bit timer/counter, 8-bit of THx & 5-bit of TLx

0 1 1 (16-bit timer mode) 16-bit timer/counter, THx cascaded with TLx

2 (8-bit auto-reload 8-bit timer/counter (auto-reload mode), TLx


1 0 reload with the value held by THx each time TLx
mode) overflow

Split the 16-bit timer into two 8-bit timers i.e.


1 1 3 (split timer mode) THx and TLx like two 8-bit timer

TCON Register
TCON is an 8-bit control register and contains a timer and interrupt flags.

MODES OF OPERATION:

Mode 0
Mode 0 is a 13-bit timer mode for which 8-bit of THx and 5-bit of TLx (as Prescaler) are
used. The 13- bit counter can hold values between 0000 to 1FFFH in TH-TL. Therefore, when the
timer reaches its maximum of 1FFH, it rolls over to 0000, and TF is raised. It is mostly used for
interfacing possible with old MCS-48 family microcontrollers.
Steps to program in mode 0

1. Load TMOD register value i.e. TMOD = 0x00 for Timer0/1 mode0 (13-bit timer mode).
2. Load calculated THx value i.e. here TH0 = 0xE3.
3. Load calculated TLx value i.e. here TL0 = 0x14.
4. Start the timer by setting a TRx bit. i.e. here TR0 = 1.
5. Poll TFx flag till it does not get set.
6. Stop the timer by clearing TRx bit. i.e. here TR0 = 0.
7. Clear timer flag TFx bit i.e. here TF0 = 0.
8. Repeat from step 1 to 7 for the delay again.

SSM Polytechnic College, Tirur 77 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 78 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Mode 1:
It is a 16-bit timer; therefore it allows values from 0000 to FFFFH to be loaded into the
timer’s registers TL and TH .
Steps to program in mode 1:
1. Load the TMOD value register with mode and timer0 or 1.
2. Load registers TLx and THx with initial count corresponding to delay.
3. Start the timer.
4. Continuously monitor the timer flag (TFx) with the “JNB TFx,target” instruction to see
if it is raised, if it is raised (TFx=1) then get out of the loop.
5. Stop the timer.
6. Clear the TFx flag for the next round.
7. Go back to Step 2 to load THx and TLx again.

Mode2 (8-bit auto-reload timer mode)

In 8051 mcu mode 2 is an 8-bit auto-reload timer mode. In this mode, we have to load the
THx-8-bit value only. when the Timer gets started, the THx value gets automatically loaded into the
TLx and TLx starts counting from that value. After the value of TLx overflows from the 0xFF to
0x0, the TFx flag gets set and again value from the THx gets automatically loaded into the TLx
register.
Steps to program in mode 1:
1. Select timer in TMOD register indicating which timer (timer 0 or timer 1) is to be used,
and the timer mode (mode 2) to be selected
2. THx register loaded with initial count value
3. Start timer
4. Continuously monitoring the timer flag (TFx) with the JNB TFx,target instruction to see
whether TFx is ‘1’ (high) . Get out of the loop when TF goes high
5. Clear the TFx flag
6. Go back to Step4, since mode 2 is auto-reload

SSM Polytechnic College, Tirur 79 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 80 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
11. After successful build operation, Go to Debug → Start VSM Debugging.
12. Click on Play Button on the bottom left to start simulation

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 81 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 82 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.10 Date: …. /..…/…..


INTERFACE DC MOTOR WITH 8051
AIM
To interface DC Motor with 8051- microcontroller.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Proteus 8 Professional Software.
PRINCIPLE
Interfacing with 8051 microcontroller can be defined as transferring data from interfacing
peripherals such as sensors, motors, machines, circuit components, and so on to 8051
microcontroller and vice versa. By interfacing with 8051, we can have ease of control over complex
circuit components or devices. The 8051 microcontroller is frequently used in electronics projects
for controlling several operations.
Generally, several electronics devices or peripherals are interfaced with 8051 which are
termed as interfacing devices. For example, 7 segment display interfacing with 8051, LCD display
interfacing with 8051, Matrix keypad interfacing with 8051, interfacing DS1307 RTC with 8051
microcontroller, interfacing 8051 with servo motor, interfacing DC motor with 8051, 8051
microcontroller interfacing with ADC, and so on.

Interfacing DC Motor with 8051 Microcontroller

The main purpose of DC interfacing with 8051 microcontroller is for controlling the speed
of the motor. The DC motor is an electrical machine with a rotating part termed as a rotor which has
to be controlled. Speed or direction of rotation of DC motor can be controlled using programming
techniques which can be achieved by interfacing with 8051 microcontrollers.

SSM Polytechnic College, Tirur 83 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 84 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Motor Driver

The maximum output current of microcontroller pin is 15mA at 5V. But the power
requirements of most of DC motors is out of reach of the microcontroller and even the back emf
(electro motive force) which is produced by the motor may damage the microcontroller. Hence, it is
not good to interface DC motor directly to the controller. So, we use motor driver circuit in between
a DC motor and the microcontroller.
There are various types of driver ICs among which L293D is typically used for interfacing
DC motor with 8051. L293 is an IC with 16 pins which are represented in the figure below.

This L293 IC is having ratings of 600mA per channel and DC supply voltage in the range of 4.5V
to 36V. These ICs can be protected from inductive spikes by connecting higher speed clamp diodes
internally. This 16 pin L293D IC can be used for controlling the direction of two DC motors. The
IC L293D works based on the H-bridge concept. The voltage can be made to flow in either direction
using this circuit (H-bridge) such that by changing the voltage direction the motor direction can be
changed.
Pin description:
 VSS pin is used to provide input voltage to L293D. For 8051 interface, 5v is given to it.

 The motor supply is given to VS pin of the L293D. It depends upon motor requirement.
 EN1 is used to enable input pair 1 (IN1, IN2, for OUT1, OUT2) and EN2 is used to
enable input pair 2 (IN3, IN4, for OUT3, OUT4). EN is connected to 5V for to enable
any input.
 Direction of motor 1 is controlled through input pins logic. IN1 and IN2 control motor
connected output OUT1 and OUT2.

SSM Polytechnic College, Tirur 85 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 86 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

 Direction of motor 2 is controlled through input pins logic. IN3 and IN4 control motor
connected output OUT3 and OUT4.
 All GND pins should be connected to ground.

CONNECTIONS:
 P2 of 8051 microcontroller is used as output port and it gives inputs to the motor driver
IC. Its lower four pins are connected to drive two DC motors.
 P0 is used as input port. 2 Buttons are connected to its lower two pins so that whenever
we can manually start and stop the motors.
 Motor 1 is connected between OUT1 and OUT2 of L293D. Motor 2 is connected
between OUT3 and OUT4 of L293D.
 12V battery is used to give input to the VS for motors.
 5V battery is used to give input to VSS for motor driver IC.

PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
11. After successful build operation, Go to Debug → Start VSM Debugging.
12. Click on Play Button on the bottom left to start simulation

SSM Polytechnic College, Tirur 87 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 88 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 89 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 90 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.11 Date: …. /..…/…..


INTERFACE ADC WITH 8051
AIM
To interface ADC with 8051- microprocessor.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Proteus 8 Professional Software.
PRINCIPLE
The data we process in a microcontroller normally deals with digital signals. But there may
a situation where we have to deal with external inputs such as analog signals. All most all the input
signals from physical sensors are of analog signals. In such cases, we can interface the
microcontroller with an external device such as an ADC0808 to convert the analog signal to a digital
signal. Because our microcontrollers can only understand 0 and 1. 8051 doesn’t have an internal
module so we will go for an external ADC, which is ADC0804.
ADC 0804.

ADC0804 is an 8-bit successive approximation analogue to digital converter from National


semiconductors. The features of ADC0804 are differential analogue voltage inputs, 0-5V input
voltage range, no zero adjustment, built in clock generator, reference voltage can be externally
adjusted to convert smaller analogue voltage span to 8-bit resolution etc.
The pin out diagram of ADC0804 is shown in the figure below.

SSM Polytechnic College, Tirur 91 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 92 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Pin
Pin Name Description
Number
Chip select is used if more than 1 ADC module is
1 Chip Select (CS)
used. By default, grounded
Read pin must be grounded to read the Analog
2 Read (RD)
value
Write pin should be pulsed high to start data
3 Write (WR)
conversion
An external clock can be connected here, else
4 CLK IN
RC can be used for accessing the internal clock
5 Interrupt (INTR) Goes high for interrupt request.
Differential Analog input +. Connect to ADC
6 Vin (+)
input
7 Vin (-) Differential Analog input -. Connect to ground
Analog Ground pin connected to the ground of
8 Ground
the circuit
9 Vref/2 Reference voltage for ADC conversion.
Digital Ground pin connected to the ground of
10 Ground
the circuit
Seven output Data bit pins from which output is
11 to 18 Data bit 0 to bit 7
obtained
RC timing resistor input pin for internal clock
19 CLK R
gen
20 Vcc Powers the ADC module, use +5V

Steps for converting the analogue input and reading the output from ADC0804.

 Make CS=0 and send a low to high pulse to WR pin to start the conversion.
 Now keep checking the INTR pin. INTR will be 1 if conversion is not finished and
INTR will be 0 if conversion is finished.
 If conversion is not finished (INTR=1), poll until it is finished.
 If conversion is finished (INTR=0), go to the next step.
 Make CS=0 and send a high to low pulse to RD pin to read the data from the ADC.

SSM Polytechnic College, Tirur 93 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 94 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.
11. After successful build operation, Go to Debug → Start VSM Debugging.
12. Click on Play Button on the bottom left to start simulation

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 95 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 96 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.12 Date: …. /..…/…..


INTERFACE STEPPER MOTOR WITH 8051
AIM
To interface Stepper Motor with 8051-microcontroller.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Proteus 8 Professional Software.
PRINCIPLE
Stepper motor is a Brushless DC electric motor that divides the complete rotation into very
small angles called steps. Usually, each step moves 1.8 degrees and therefore a total of 200 steps for
a rotor to finish a single rotation. Unlike normal dc motors, it contains multiple Stator magnets used
to trigger each step. Apart from 1.8 degrees, stepper motors with step angle 30, 15.5, 2.5, 2 and 0.9
are available. The highest resolution variant, with a 0.9-degree step angle, takes 400 steps for a
complete rotation. The article discusses the details of stepper motor operation and interfacing of
stepper motor with 8051 microcontrollers.

Working of Stepper motor


A stepper motor has a rotating part called a rotor and a static part termed Stator. The Stator and rotor
have magnetic poles and by energizing the Stator poles, the rotor moves in order to align with the
stator. A rotor is a central gear-shaped piece of iron. Stator is a set of toothed electromagnets
arranged around the central gear.

SSM Polytechnic College, Tirur 97 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 98 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

When the phase winding of the stepper motor is provided with a current, corresponding
magnetic flux will be developed in the stator in the direction perpendicular to the direction of the
current flow. When one electromagnet is energized with the help of an external driver circuit or a
microcontroller, the rotor shaft turns in such a way that it aligns itself with the stator in a position
that minimizes the flux opposition. And when the next electromagnet is turned on and the first is
turned off, the gear rotates slightly to align with the next one. From there the process is repeated.
Each of those rotations is called a “step”, with an integer number of steps making a full rotation. In
that way, the motor can be turned by a precise angle.
Coils should be energised in a particular sequence to make the rotator rotate. On the basis of
this “sequence” we can divide the working method of Unipolar stepper motor in three modes: Wave
drive mode, full step drive mode and half step drive mode.
Wave drive mode:

In this mode one coil is energised at a time, all four coils are energised one after another. It
produces less torque in compare with Full step drive mode but power consumption is less. Following
is the table for producing this mode using microcontroller, means we need to give Logic 1 to the
coils in the sequential manner.

Steps A B C D

1 1 0 0 0

2 0 1 0 0

3 0 0 1 0

4 0 0 0 1

Full Drive mode: In this, two coil are energised at the same time producing high torque.
Power consumption is higher. We need to give Logic 1 to two coils at the same time, then to the
next two coils and so on.

SSM Polytechnic College, Tirur 99 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 100 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Steps A B C D

1 1 1 0 0

2 0 1 1 0

3 0 0 1 1

4 1 0 0 1

Half Drive mode:


In this mode one and two coils are energised alternatively, means firstly one coil is energised
then two coils are energised then again one coil is energised then again two, and so on. This is
combination of full and wave drive mode, and used to increase the angular rotation of the motor.

Steps A B C D
1 1 0 0 0
2 1 1 0 0
3 0 1 0 0
4 0 1 1 0
5 0 0 1 0
6 0 0 1 1
7 0 0 0 1
8 1 0 0 1

Interfacing Stepper Motor with 8051 Microcontroller


Interfacing with 8051 is very easy we just need to give the 0 and 1 to the four wires of stepper
motor according to the above tables depending on which mode we want to run the stepper motor.
And rest two wires should be connected to a proper 12v supply (depending on the stepper motor).
Here we have used the unipolar stepper motor. We have connected four ends of the coils to the first
four pins of port 2 of 8051 through the ULN2003A.

SSM Polytechnic College, Tirur 101 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 102 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

8051 doesn’t provide enough current to drive the coils so we need to use a current driver IC
that is ULN2003A. ULN2003A is the array of seven NPN Darlington transistor pairs. Darlington
pair is constructed by connecting two bipolar transistors to achieve high current amplification. In
ULN2003A, 7 pins are input pins and 7 pins are output pins, two pins are for Vcc (power supply)
and Ground. Here we are using four input and four output pins. We can also use L293D IC in place
of ULN2003A for current amplification.
PROCEDURE
1. Click on the desktop icon of Proteus 8 and Open the Home page of Proteus 8
2. Now, click on "New Project" option and in which you have to name the project and choose
the directory to save the project.
3. The Next step is to select the Schematic layout from the categories and 'Default' will be A4
size.
4. In next step, you can also create PCB layout in the next step by selecting it and choosing
the required layout. You can also select 'Do not create PCB layout' option, if you don't want
any PCB design of your schematic circuit.
5. Now, you have to choose the installed compiler and the microcontroller you are going to
use. Now, you can see the three tabs: - Schematic capture, PCB layout, and Source code.
6. Click On P (Pick from Libraries)
7. Add all the required components
8. Place the components on the workspace and wire up the circuit.
9. Write program on “Source Code” window.
10. Press F7 to build the program.

SSM Polytechnic College, Tirur 103 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 104 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

11. After successful build operation, Go to Debug → Start VSM Debugging.


12. Click on Play Button on the bottom left to start simulation

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 105 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 106 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Experiment No.13 Date: …. /..…/…..


DATA TRANSFER USING
SERIAL COMMUNICATION IN 8051 MC
AIM
To transmit data from 8051 microcontroller using Serial Communication.
EQUIPMENTS & SOFTWARE REQUIRED:
1. Desktop/Laptop computer with windows operating system.
2. Keil µVision 5 IDE software
PRINCIPLE
The 8051 microcontroller is parallel device that transfers eight bits of data simultaneously
over eight data lines to parallel I/O devices. Parallel data transfer over a long is very expensive.
Hence, a serial communication is widely used in long distance communication. In serial data
communication, 8-bit data is converted to serial bits using a parallel in serial out shift register and
then it is transmitted over a single data line. The data byte is always transmitted with least significant
bit first.
Communication Links
1. Simplex communication link: In simplex transmission, the line is dedicated for transmission.
The transmitter sends and the receiver receives the data.

2. Half duplex communication link: In half duplex, the communication link can be used for
either transmission or reception. Data is transmitted in only one direction at a time.

3. Full duplex communication link: If the data is transmitted in both ways at the same time, it
is a full duplex i.e., transmission and reception can proceed simultaneously. This
communication link requires two wires for data, one for transmission and one for reception.

SSM Polytechnic College, Tirur 107 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 108 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

Types of Serial communication:


Serial data communication uses two types of communication.
 Synchronous serial data communication:
In this transmitter and receiver are synchronized. It uses a common clock to synchronize the
receiver and the transmitter. First the synch character is sent and then the data is transmitted. This
format is generally used for high-speed transmission. In Synchronous serial data communication, a
block of data is transmitted at a time.
2. Asynchronous Serial data transmission:
In this, different clock sources are used for transmitter and receiver. In this mode, data is
transmitted with start and stop bits. A transmission begins with start bit, followed by data and then
stop bit. For error checking purpose parity bit is included just prior to stop bit. In Asynchronous
serial data communication, a single byte is transmitted at a time.
Baud rate:
The rate at which the data is transmitted is called baud or transfer rate. The baud
rate is the reciprocal of the time to send one bit. In asynchronous transmission, baud
rate is not equal to number of bits per second. This is because; each byte is preceded
by a start bit and followed by parity and stop bit. For example, in synchronous
transmission, if data is transmitted with 9600 baud, it means that 9600 bits are
transmitted in one second. For bit transmission time = 1 second/ 9600 = 0.104 ms.
Division factor to achieve different baud rates

Baud Rate TH1 (Hex)


9600 FD
4800 FA
2400 F4
1200 E8

SSM Polytechnic College, Tirur 109 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 110 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

8051 Serial Communication

The 8051 supports a full duplex serial port. Three special function registers support serial
communication.
1. SBUF Register: Serial Buffer (SBUF) register is an 8-bit register. It has separate SBUF
registers for data transmission and for data reception. For a byte of data to be transferred via the
TXD line, it must be placed in SBUF register. Similarly, SBUF holds the 8-bit data received by the
RXD pin and read to accept the received data.

2. SCON register: The contents of the Serial Control (SCON) register are shown below.
This register contains mode selection bits, serial port interrupt bit (TI and RI) and also the ninth data
bit for transmission and reception (TB8 and RB8).

Bit 7:6 - SM0:SM1: Serial Mode Specifier

Mode SM0 SM1 Mode

0 0 0 1/12 of Osc frequency shift register mode fixed baud rate

1 0 1 8-bit UART with timer 1 determined baud rate

2 1 0 9-bit UART with 1/32 of Osc fixed baud rate

3 1 1 9-bit UART with timer 1 determined baud rate

Normally mode-1 (SM0 =0, SM1=1) is used with 8 data bits, 1 start bit, and 1 stop bit.
Bit 5 - SM2: for Multiprocessor Communication
This bit enables a multiprocessor communication feature in mode 2 & 3.
Bit 4 - REN: Receive Enable
1 = Receive enable
0 = Receive disable
Bit 3 - TB8: 9th Transmit Bit

SSM Polytechnic College, Tirur 111 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 112 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

This is the 9th bit which is to be transmitted in mode 2 & 3 (9-bit mode)
Bit 2 - RB8: 9th Receive Bit
This is the 9th received bit in mode 2 & 3 (9-bit mode), whereas in mode 1 if SM2
= 0 then RB8 hold the stop bit that received
Bit 1 - TI: Transmit Interrupt Flag
This bit indicates the transmission is complete and gets set after transmitting the
byte from the buffer. Normally TI (Transmit Interrupt Flag) is set by hardware at
the end of the 8th bit in mode 0 and at the beginning of stop bit in other modes.
Bit 0 – RI: Receive Interrupt Flag
This bit indicates reception is complete and gets set after receiving the complete
byte in the buffer. Normally RI (Receive Interrupt Flag) is set by hardware in
receiving mode at the end of the 8th bit in mode 0 and at the stop bit receive time
in other modes.
3. PCON register: The SMOD bit (bit 7) of PCON register controls the baud rate in
asynchronous mode transmission.

SMOD => Double Baud rate when Serial port is used in mode 1,2 or 3.
GF1 => General purpose flag bit.
GF0 => General purpose flag bit.
PD =>Power down. Activates power down operation.
IDL =>Ideal mode. Activates ideal mode operation.
— => Reserved

8051 Microcontroller Programming steps


1. Configure Timer 1 in auto-reload mode.
2. Load TH1 with value as per required baud rate e.g. for 9600 baud rate load 0xFD. ( 3 in
decimal)
3. Load SCON with serial mode and control bits. e.g. for mode 1 and enable reception, load
0x50.
4. Start timer1 by setting TR1 bit to 1.

SSM Polytechnic College, Tirur 113 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 114 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

5. Load transmitting data in the SBUF register.


6. Wait until loaded data is completely transmitted by polling the TI flag.
7. When the TI flag is set, clear it, and repeat from step 5 to transmit more data.

PROCEDURE
1. Open Keil Micro vision
2. Go to Project → New Project.
3. Write program on text window
4. Press CNTRL+S to save as ALP.ASM
5. Double click on “Source Group 1” Folder. A windowwill appear. Select the file that
you saved as .ASM and click Add.
6. Press F7 to build the program. After successful build operation, get the output window.
7. Go to Debug → Start/Stop Debug session. A pop-up window will open. Just click on
“OK”
8. Press F11 Key to check the step-by-step register/memory changes while running
program.
9. Press F5 Key to run the program and view the serial data transfer on “View ”→“Serial
Window” → “UART #1”.

RESULT
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….
…………………………………………………………………………………………………………….

FACULTY INCHARGE

…………………………..

SSM Polytechnic College, Tirur 115 | P a g e


Dept. Of Electronics Engineering Microcontroller and Applications Lab

SSM Polytechnic College, Tirur 116 | P a g e

You might also like