You are on page 1of 26

JAIDEV EDUCATION SOCIETY’S

J D COLLEGE OF ENGINEERING AND MANAGEMENT


KATOL ROAD, NAGPUR
An Autonomous Institute, with NAAC "A" Grade
Website: www.jdcoem.ac.in E-mail: info@jdcoem.ac.in

Department of Electronics and Telecommunication


Engineering
“Rectifying Ideas, Amplifying Knowledge”
2021-22 (OddSem)

VISION MISSION
1. To provide quality teaching learning process through well-
developed educational environment and dedicated faculties.
“To be a Department providing high quality & globally
2. To produce competent technocrats of high standards
competent knowledge of concurrent technologies in the field of
satisfying the needs of all stakeholders.
Electronics and Telecommunication.”

LAB FILE

Subject: Microcontroller and Applications Lab (ET5L002)

Third Year B.Tech. – V Semester [Branch: Electronics & Telecommunication]

Subject Teacher
Prof. Avinash K. Ikhar
(Assistant Professor)

At: Khandala, Post: Valni, Katol Road Road, Nagpur– 441501 ( M.S.)
Affiliated to Dr. BabasahebAmbedkar Technological University, Lonere
Prerequisites: Basic knowledge of Microprocessor and microcontroller programming.

Course Objectives:

1. To perform a practical based on microcontroller based system.


2. To study assembly language programming skills.
3. Interface different peripherals with microcontroller with its use.

Course Outcomes:
At the end of the laboratory work, students will demonstrate the ability to:
1. The concept of Assembly languages structure and programming.
2. Interface various peripherals with 8051 microcontroller.
3. Simulate the programs on different software platforms.

List of Experiments:

1. Write and execute an assembly language program to perform addition & subtraction on 8
bit / 16 bit number for 8051using Keiluvision 4 / WIN8051 IDE.
2. Write and execute an assembly language program to perform Multiplication & Division on 8
bit / 16 bit number for 8051using Keiluvision 4 / WIN8051 IDE.
3. Write and execute 8051 assembly language program to find smallest byte in a string of bytes.
4. Write and execute 8051 assembly language program to exchange two data strings.
5. Write and execute 8051 assembly language program to generate square wave of 1 KHz (and
any other frequency) on one of the pin of output port
6. Design & implementation of LED & Switch interfacing with 8051.
7. Design & implementation of 7 segment display interfacing with 8051.
8. Design & implementation of 16 x 2 LCD interfacing with 8051.
9. Design & implementation of DC Motor interfacing with 8051.
10. Design & implementation of Stepper Motor interfacing with 8051.
11. Design & implementation of 4 x 4 matrix keyboard interfacing with PIC Microcontroller.
12. Interfacing of 8051 Microcontroller with various display devices.
13. Interfacing of 8051 Microcontroller with ADC and DAC.
14. Interfacing of 8051 Microcontroller with DC motor.
15. To study the serial port communication with 8051 microcontroller.
Introduction to Microcontroller 8051

The most universally employed set of microcontrollers come from the 8051 family. 8051
Microcontrollers persist to be an ideal choice for a huge group of hobbyists and experts. In
the course of 8051, the humankind became eyewitness to the most ground- breaking set of
microcontrollers. The original 8051 microcontroller was initially invented by Intel. The two
other members of this 8051 family 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 microcontroller. 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.

FEATURES OF 8051
8051 microcontroller is an eight bit microcontroller launched It is available in 40 pin DIP
(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. There are four parallel 8 bits ports which are easily programmable as well
as addressable. 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. Two timers of 16 bits are also incorporated in it; these timers can be
employed as timer for internal functioning as well as counter for external functioning.
The microcontroller comprise 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).
INTERNAL ARCHITECHURE OF 8051 MICRO-CONTROLLER

1. ALU
All arithmetic and logical functions are carried out by the ALU. Addition, subtraction with
carry, and multiplication come under arithmetic operations. Logical AND, OR and exclusive
OR (XOR) come under logical operations.
2. Program Counter (PC)
A program counter is a 16-bit register and it has no internal address. The basic function of
program counter is to fetch from memory the address of the next instruction to be
executed.
The PC holds the address of the next instruction residing in memory and when a command
isencountered, it produces that instruction. This way the PC increments automatically,
holding the address of the next instruction.

3. Registers
Registers are usually known as data storage devices. 8051 microcontroller has 2 registers,
namely Register A and Register B. Register A serves as an accumulator while Register B
functions as a general purpose register. These registers are used to store the output of
mathematical and logical instructions. The operations of addition, subtraction,
multiplication and division are carried out by Register A. Register B is usually unused and
comes into picture only when multiplication and division functions are carried out by
Register A. Register A also involved in data transfers between the microcontroller and
external memory.

PIN DIAGRAM OF 8051 MICRO-CONTROLLER


PINOUT DESCRIPTION

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 input.
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 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.
Introduction to Microcontroller Lab
Microcontroller Lab is mainly used with 15EE52 course. The Lab has following equipments.
Software tools used
1. KeiluVision4

2. Flash Magic
3. WIN8051 IDE

Application of Microcontroller in Day to Day Life Devices:


 Light sensing & controlling devices
 Temperature sensing and controlling devices
 Fire detection & safety devices
 Industrial instrumentation devices
 Process control devices

Application of microcontroller in Industrial Control Devices:


 Industrial instrumentation devices
 Process control devices
Experiment No. 0 Simulator and Programmer for 8051

A simulator is software to mimic a microcontroller operation with a Personal Computer.


This helps in running the assembly language program off-line and debug for errors. This is
also a powerful learning tool before actually working with a Microcontroller.
A programmer is a hardware used to transfer the machine code to the internal program
memory of a microcontroller.

In this section we will see a typical Simulator and a Programmer used for Atmel AT89C51.

Working with Win8051 Simulator

Win 8051 is a simulator for 8051 microcontroller to write and edit the code in assembly
language, compile it and also to run the code. Output of the assembly language program can
be verified using simulator.

Steps to Use WIN8051

 After installing the software Win8051, open 8051 IDE.


 Towritetheassemblycodeintheeditor,goto:FileNew
 After writing the assembly code in the editor, assemble the code (Assemble)
 Checkfor the errors in the output window View Output
 Once the error free code was made, simulate the code.SimulateStart Simulator
 Simulator options are
1. Step into - Each time only one instruction will be executed (single step
mode).
2. Continue - To run the whole code at once.
 Additional things:
1. To view RAM, program memory, SFRs, and External memory use the option
VIEW.
2. To set break points in the code (where simulation stops at that point)

Simulate Toggle Break Point

 To stop the simulation Simulate Stop

After checking the code in the simulator, the code (file with .HEX extension in  Intel HEX
format) is loaded into Atmel 89C51 microcontroller using Universal SP3 Programmer.
Although a separate 8051 assembly can be used at times assemble and generate Hex
code for a assembly language program, Win8051 simulator can perform that task
here.
Programming with Universal SuperPro III Programmer:
SuperProIII (SP3) Programmer is manufactured by XELTEK. This is a universal
programmer that can be used to program a host of Microcontrollers and EPROMs. This is
connected to PC by the parallel port. A software "SP3.EXE" is executed by the PC to
establish a communication with the programmer. Hex files can be downloaded from the PC
to an EPROM or the program memory of a microcontroller located in ZIF socket on the
programmer.

Fig 1   A view of SuperPro III Universal Programmer

The programmer is used to load HEX code into the microcontroller (Atmel 89C51 in the present case).
Steps:
 Run SP3.exe
 Selecting the device to be programmed.
Device Select by Device select AT89C51, type MPU/MCU Select
 Loading file in to the buffer.
File Load Select FILE_NAME.HEX to be loaded check INTEL file format OK
 To edit or to view the file to be loaded
Buffer Edit
(HEX code with corresponding memory location addresses to be loaded into will appear on the
screen)
 To load the program in to the microcontroller
Device Run
(Place the microcontroller in the slot provided in the Universal SP3 programmer)
o Select Blank check OK
o If blank check is failed, Select option EraseOK
If blank check is a success, proceed to next step.
o Select Program OK
o Select Blank check OK (it must fail which implies HEX code is programmed in to the
microcontroller)
 Remove microcontroller from the slot.
 Exit SP3.exe
File Quit
8051 Program to Add two 8 Bit numbers
https://www.tutorialspoint.com/8051-program-to-add-two-8-bit-numbers

Intel 8051 is an 8-bit microcontroller. It has many powerful instructions and IO accessing
techniques. In this section, we will see one of the simplest program using 8051.

Here we will add two8-bit numbers using this microcontroller. The register
A(Accumulator) is used as one operand in the operations. There are seven registers R0 –
R7 in different register banks. We can use any of them as the second operand.

We are taking two number 5FH and D8H at location 20H and 21H, After adding them, the
result will be stored at location 30H and 31H.  

Address Value
20H 5FH
21H D8H
. .
. .
30H 00H
31H 00H

PROGRAM:
MOV R0,#20H;set source address 20H to R0
MOV R1,#30H;set destination address 30H to R1
MOV A,@R0; take the value from source to register A
MOV R5,A; Move the value from A to R5
MOV R4,#00H; Clear register R4 to store carry
INC R0; Point to the next location
MOV A,@R0; take the value from source to register A
ADD A,R5;Add R5 with A and store to register A
JNC SAVE
INC R4; Increment R4 to get carry
MOV B,R4;Get carry to register B
MOV @R1,B; Store the carry first
INC R1; Increase R1 to point to the next address
SAVE: MOV @R1,A;Store the result
HALT: SJMP HALT ;Stop the program

So by adding 5FH + D8H, the result will be 0137H. The 01H will be stored
at 30H, and 37 is stored at 31H.
Output
Address Value
20H 5FH / 10
21H D8H / 20
. .
. .
30H 01H
31H 37H
8051 Program to Subtract two 8 Bit
numbers
Here we will see how to subtract two 8-bit numbers using this microcontroller. The
register A(Accumulator) is used as one operand in the operations. There are seven
registers R0 – R7 in different register banks. We can use any of them as the second
operand.

We are taking two number73H and BDH at location 20H and 21H, After subtracting the
result will be stored at location 30H and 31H

Address Value
20H 73H
21H BDH
. .
. .
30H 00H
31H 00H

PROGRAM:
MOV R0,#20H;set source address 20H to R0
MOV R1,#30H;set destination address 30H to R1

MOV A,@R0;take the value from source to register A


MOV R5,A; Move the value from A to R5
MOV R4,#00H; Clear register R4 to store borrow

INC R0; Point to the next location


MOV A,@R0; take the value from source to register A
MOV R3,A; store second byte
MOV A,R5;get back the first operand
SUBB A,R3; Subtract R3 from A
JNC SAVE
INC R4; Increment R4 to get borrow
MOV B,R4;Get borrow to register B
MOV @R1,B; Store the borrow first
INC R1; Increase R1 to point to the next address

SAVE: MOV @R1,A; Store the result


HALT: SJMP HALT ;Stop the program
So by subtracting 73H –BDH, the result will be B6H. At location 30H, we will get 01H.
This indicates that the result is negative. The get the actual value from result B6H, we
have to perform 2’s complement operation. After performing 2’s Complement, the
result will be -4AH.

Output
Address Value
20H 73H
21H BDH
. .
. .
30H 01H
31H B6H
8051 Program to Multiply two 8 Bit
numbers
https://www.tutorialspoint.com/8051-program-to-multiply-two-8-bit-
numbers

To multiply two 8-bit numbers using this 8051 microcontroller. The register A and B will
be used for multiplication. No other registers can be used for multiplication. The result of
the multiplication may exceed the 8-bit size. So the higher order byte is stored at register B,
and lower order byte will be in the Accumulator A after multiplication.

We are taking two number FFH and FFH at location 20H and 21H, After multiplying the
result will be stored at location 30H and 31H.  

Address Value
20H FFH
21H FFH
. .
. .
30H 00H B
31H 00H A

PROGRAM
MOV R0, #20H;set source address 20H to R0
MOV R1, #30H;set destination address 30H to R1

        MOV A, @R0;take the first operand from source to register A


        INCR0; Point to the next location
        MOV B,@R0;take the second operand from source to register B

        MUL AB ;Multiply A and B

        MOV @R1, B; Store higher order byte to 30H


        INC R1; Increase R1 to point to the next location
        MOV @R1, A;Store lower order byte to 31H
HALT:   SJMP HALT ; Stop the program

8051 provides MULAB instruction. By using this instruction, the multiplication can be


done. In some other microprocessors like8085, there was no MUL instruction. In that
microprocessor, we need to use repetitive ADD operations to get the result of the
multiplication. 
When the result is below255, the overflow flag OV is low, otherwise, it is 1.

Output
Address Value
20H FFH
21H FFH
. .
. .
30H FE H
31H 01 H
8051 Program to Divide two 8 Bit
numbers
https://www.tutorialspoint.com/8051-program-to-divide-two-8-bit-
numbers

The divide operation to divide two 8-bit numbers using this 8051 microcontroller. The
register A and B will be used in this operation. No other registers can be used for division.
The result of the division has two parts. The quotient part and the remainder part. Register
A will hold Quotient, and register B will hold Remainder.

We are taking two number0EH and 03H at location 20H and 21H, After dividing the result
will be stored at location 30H and 31H.

Address Value
20H 0E H A
21H 03H B
. .
. .
30H 00 HQ A
31H 00 H R  B

Program
MOV R0,#20H;set source address 20H to R0
MOV R1,#30H;set destination address 30H to R1

MOV A,@R0;take the first operand from source to register A


INC R0;Point to the next location
MOV B,@R0; take the second operand from source to register B

DIV AB ;Divide A by B

MOV @R1,A;StoreQuotient to 30H


INC R1;Increase R1 to point to the next location
MOV @R1,B;StoreRemainder to 31H
HALT:   SJMP HALT ;Stop the program

8051 provides DIVAB instruction. By using this instruction, the division can be done. In
some other microprocessors like 8085, there was no DIV instruction. In that
microprocessor, we need to use repetitive Subtraction operations to get the result of the
division. 

When the denominator is00H, the overflow flag OV will be 1. otherwise it is 0 for the
division.
Output
Address Value
20H 0E H
21H 03H
. .
. .
30H 04 H Q  A
31H 02 H R B
Blinking of LED using AT89C51
Aim:
To blink an LED connected to one of the port pin (say P 1.0) continuously.
Components/Software:
1. 2. Atmel 89C51 micro controller
3. 8051 simulator - win8051
4. Universal SP3 Programmer
5. Software to load the code into Universal SP3 Programmer
6. Computer System with Windows 98 or later operating system and RS 232 Cable
7. +5V D.C Power Supply
8. Resistors-8.2k-1,1k-1
9. Capacitors-30pF-2, 10uF-1
10. 10MHz crystal
11. LED-1
12. SPST switches-1

Theory :

A light-emitting diode (LED) is a semiconductor device or simply a PN junction diode that emits
visible light when an electric current passes through it in the forward direction. The amount of
light output is directly proportional to the forward current till a certain value of current.

How Light Emitting Diode (LED) works?

Light Emitting Diode (LED) works only in forward bias condition. When Light Emitting Diode
(LED) is forward biased, the free electrons from n-side and the holes from p-side are pushed
towards the junction.

When free electrons reach the junction or depletion region, some of the free electrons recombine
with the holes in the positive ions. We know that positive ions have less number of electrons than
protons. Therefore, they are ready to accept electrons. Thus, free electrons recombine with holes
in the depletion region. In a similar way, holes from p-side recombine with electrons in the
depletion region.

Image source : www.physics-and-radio-electronics.com

Because of the recombination of free electrons and holes in the depletion region, the width of the
depletion region decreases. As a result, more charge carriers will cross the p-n junction. Some of
the charge carriers from p-side and n-side will cross the p-n junction before they recombine in
the depletion region. For example, some free electrons from n-type semiconductor cross the p-n
junction and recombine with holes in p-type semiconductor. In a similar way, holes from p-type
semiconductor cross the p-n junction and recombine with free electrons in the n-type
semiconductor. Thus, recombination takes place in the depletion region as well as in p-type and
n-type semiconductor. The free electrons in the conduction band release energy in the form of
light before they recombine with holes in the valence band.

Procedure:
1. Write the assembly code in win8051 simulator , compile it and check for errors
2. Once the code is error free, run it and check the output in the simulator.
3. After checking the code in the simulator, load the code (in .HEX format) into Atmel 89C51
microcontroller using Universal SP3 Programmer.
4. Make connections as shown in the circuit diagram.
5. Switch on the power supply and observe the blinking of LED.
6. Now decrease the delay time in the code and observe the increase in blinking rate.
ASSEMBLY CODE:

8051 Assembly program to blink an LED connected to P1.0continuously

ORG 0000H ;Reset Address

MOVE PSW, #00 ;Selecting Bank 0 for temporary register

LOOP: CPL P1.0; Complementing the pin where LED was connected

MOV R0, #0FFH; R0, R1, R3 are temporary registers

L1: MOV R1, #0FFH; (Bank0) used for delay loop

L2: MOV R3, #0AH;

L3: DJNZ R3, L3; Decrement and Jump if not zero

DJNZ R1, L2;

DJNZ R0, L1;

AJMP LOOP; Delay loop which makes LED blinking visible

END

Circuit Diagram:

Fig . Circuit diagram for blinking LED experiment


Image source : Designed on CADSOFT EAGLE tool

Fig. Circuit assembly with breadboard

Observation:
If we decrease the delay loop time to a very small value, we cannot observe the blinking so try to
increase the delay loop time if blinking of LED is not visible.
Conclusion:
Successfully completed the blinking of LED using Atmel 89c51 microcontroller.
Interfacing of A/D and D/A with AT89C51

You might also like