Mca Lab-Ece-3014-Manual - Ay 2022-23

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 49

Micro Controller Application Laboratory Manual (ECE 3014)

Micro Controller Application


Laboratory
(ECE 3014)

for
VI Semester B. Tech.

Maintained by: Verified by :


Mr. SYED ABRAR AHMED Mrs. Kehkeshan Jallal S
Mr. Tony Aby Varkey M

Department of Electronics and Communication Engineering

Presidency University
School of Engineering
Itagalpura, Rajanukunte, Yelahanka,
Bangalore-560064

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

CONTENTS Page
No.
I Course Handout 3-9

II Precautions 10

10
III Tools and operating system required

LIST OF EXPERIMENTS USING KEIL SOFTWARE


1. Data Transfer - Block move, Exchange, Sorting, Finding largest element in an array 16-26

2. Arithmetic Instructions - Addition/subtraction, multiplication and division, square, 21-27


Cube – (16 bits Arithmetic operations – bit addressable)
3. Counters 28

4. Boolean & Logical Instructions (Bit manipulations) 29 - 30

5. Code conversion: BCD – ASCII; ASCII – Decimal; HEX – Decimal and Decimal –
31 - 33
HEX

LIST OF EXPERIMENTS USING HARDWARE INTERFACE

6. External ADC and Temperature control interface to 8051


34-38

7. Generate different waveforms Sine, Square, Triangular, Ramp etc. using DAC
39-44
interface to 8051; change the frequency and amplitude

8. Stepper and DC motor control interface to 8051 45-49

SAMPLE VIVA QUESTIONS 50

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

(Established under the Presidency University Act, 2013 of the Karnataka Act 41 of 2013)
[2022-23 EVEN/ WINTER SEMESTER]
COURSE HAND OUT [Revision 02 - Jan 2022]
SCHOOL: SOE DEPT.: ECE DATE OF ISSUE: 23-1-2023

NAME OF THE PROGRAM : B. Tech. Electronics and Communication Engineering

P.R.C. APPROVAL REF. : PU/AC-18.4/ECE15/ECE/2020-24

SEMESTER/YEAR : 6th Semester / AY 2022-23

COURSE TITLE & CODE : Microcontroller Applications & ECE3014

COURSE CREDIT STRUCTURE : 4 Credits (L=3, T=0, P=2, C=4)

CONTACT HOURS : 3 Periods per Week Theory and 2 Periods for Lab

INSTRUCTOR INCHARGE : Mr. Syed Abrar Ahmed

COURSE INSTRUCTOR : Mr. Syed Abrar Ahmed, Mr. Tony Aby Varkey M,
Mrs. Kehkeshan Jallal S
COURSE URL : www.camu.in

PROGRAM OUTCOMES: (Bolded outcomes are met by this course. Others are not met.)

Graduates of the B. Tech. Program in Electronics and Communication Engineering will be able to:

PO.1.Engineering Knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering problems.
PO.2. Problem Analysis: Identify, formulate, research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences,
and engineering sciences.

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

PO.3. Design/development of Solutions: Design solutions for complex engineering problems and design
system components or processes that meet th e specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
PO.4. Conduct Investigations of Complex Problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
PO.5. Modern Tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modelling to complex engineering activities with an
understanding of the limitations.
PO.6. The Engineer and Society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
PO.7. Environment and Sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO.8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
PO.9. Individual and Team Work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
PO.10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive clear
instructions.
PO.11. Project Management and Finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
PO.12. Life-long Learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.

COURSE PREREQUISITES:
Student should have successfully completed ECE 3014
COURSE DESCRIPTION:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

 Microcontroller Application Laboratory is a required course for under-graduate students in


the ECE program. The purpose of this course is to teach students the fundamentals
microcontroller systems.
 The student will be able to incorporate these concepts into their electronic designs for other
courses where control can be achieved via controller implementation. This course include
assembly language programming, I/O programming, I/O interface design, I/O peripheral
devices, data communications, and data acquisition systems.

COURSE OUTCOMES:
After the completion of the course students shall be able to:

TABLE 1: COURSE OUTCOMES


CO Expected BLOOMS
CO
Number LEVEL
Discuss the architecture and working principles of 8051
1 Comprehension
microcontrollers.
Develop assembly language programming problems using
2 Application
coding and debugging skills.
Apply timer-programming instructions to generate different
3 timing signal, also use it as synchronizing factor in serial Application
communication.
Interpret ALP/C program to realize various arithmetic and
4 logical operations that can be carried in an ALU unit using Application
instruction set.
Demonstrate basic operations and Analyze the 8051 C
5 Application
Microcontroller interfacing with external hardware.
Understand the difference between Microcontrollers and ARM
6 Comprehension
controller in terms of instruction set and processing.

MAPPING OF C.O. WITH P.O.

TABLE 2: CO PO Mapping ARTICULATION MATRIX

CO. PO1
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO11 P12
NO. 0
1. H L L
2. H H M M L
3. H H H H H M M
4. H H H H H M M
5. H H M H H M M
6. H H M H M M M

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

List of Experiments

Sl. Experi
Experiment Name List of skill set CO
No ment no

1. Introduction to assembly language programming using Keil Software

i) Understand the various types of


data operations.
Data Transfer - Block move,
Exchange, Sorting, Finding largest ii) Write the assembly language
2. 1 element in an array code to perform data transfer CO1
operations. iii) Obtain the
simulation output and analyse the
results.

i) Understand the various types of


Arithmetic Instructions -
Arithmetic Instructions.
Addition/subtraction,
multiplication and division, square, ii) Write the assembly language CO2,
3. 2 Cube – (16 bits Arithmetic code to perform data Arithmetic C03
operations – bit addressable) operations. iii) Obtain the
simulation output and analyse the
results.

i) Understand the various types of


Arithmetic Instructions.

4. 3 Counters ii) Write an ALP to perform count CO2,


decimal up iii) Obtain the CO3
simulation output and analyse the
results.

CO2,
i) Understand the various types of CO3
bit manipulation instructions.
Boolean & Logical Instructions
5. 4 (Bit manipulations) ii) Write an ALP to realize the
given Boolean expression .iii)
Obtain the simulation output and
analyze the results.

6. 5 Code conversion: BCD – ASCII; i) Understand the various types of CO2,


ASCII – Decimal; HEX - Decimal instructions for code conversion. CO3
and Decimal - HEX
ii) Write an ALP to perform BCD –
ASCII; ASCII – Decimal; HEX -

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

Decimal and Decimal – HEX


conversion
iii) Obtain the simulation output
and analyze the results.

i) Understand the various types of


External ADC and Temperature instructions for interfacing.
control interface to 8051 ii) a) To interface External ADC
7 6 and temperature control to 8051. CO4
iii) Analyse the result.

Generate different waveforms i) Understand the various types of


Sine, Square, Triangular, Ramp instructions for interfacing.
etc. using DAC interface to 8051; CO4
8 7 a) Write an ALP To interface DAC
change the frequency and
and to write a C program to
amplitude
generate sine, square, triangle and
ramp waveforms

i) Understand the various types of


instructions for interfacing
Stepper and DC motor control
9 8 ii) To interface stepper and DC CO4
interface to 8051
motor control interface to 8051

REFERENCE MATERIALS: “Microcontroller Application Lab Manual” Presidency University.


GUIDELINES TO STUDENTS: Observation book (Rough records) and Fair record are needed to record
the experiments conducted in the laboratory. Observation book are needed to be certified immediately on
completion of the experiment. Fair records are due at the beginning of the next lab session. Fair records must
be submitted as neat, legible and complete. Proper discipline should be maintained in the LAB and hardware
should be handled carefully.
LAB EXPERIMENT SCHEDULE:

SL. DATE* ACTIVITY


NO.

1. P1 Over View of the lab

2. P2 Experiment 1

3. P3 Experiment 2

4. P4 Experiment 2

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

5. P5 Experiment 3

6. P6 Experiment 4

7. P7 Practice session I

8. P8 Mid-term Evaluation

9. P9 Experiment 5

10. P10 Demonstration of Experiments ( Exp 6 to Exp 8)

11. P11 Experiment 6

12. P12 Experiment 7

13. P13 Experiment 8

14. P14 Practice session II

15. P15 Mini Project Expo

16. P16 End-term Evaluation

* These dates are only indicative - applicable to one section handled by subject IC. Dates will vary from
section to section.

ASSESSMENT SCHEDULE:

Sl. Course
Assessment type Duration Venue, DATE
No List of Tasks outcome Marks weightage
In Hours &TIME
. Number
Experiment
Lab Exercises 1 to MCA Lab
(Conduction Experiment 9 Every week 2
of lab exercises CO
1. And the NA 40 20% hours
conducted in every 2,3,4
assignment
lab including lab
and seminar
records(20 M))
tasks

EVALUATION FOR DAILY EXPERIMENTS

Write up + Lab Conduction of


Logic buildup Viva-voce Total marks
Record experiment

3 2 2 3 10

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

PRECAUTIONS

1. Switch on the systems as per the procedure.


2. Save all you work in your folder only (name given to the folder should be your University ID
number).
3. Handle all the devices and chips carefully.
4. After completion of the lab switch off the system.

TOOLS AND OPERATING SYSTEM REQUIRED

1. Tools : KEIL µVISION3


2. Operating System : Microsoft Windows
3. Andriod App: 8051 Simulator by Roshani Kanoje : https://play.google.com/store/apps/details?
id=com.sanspirit.ui_sample
4. Andriod Smart phone

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

INTRODUCTION

A microcontroller can be compared to a small standalone computer; it is a very powerful device,


which is capable of executing a series of preprogramed tasks and interacting with other hardware
devices. Being packed in a tiny integrated circuit (IC) who’s size and weights usually negligible,
it is becoming the perfect controller for robots or any machines requiring some kind of intelligent
automation. A single microcontroller can be sufficient to control a small mobile robot, an
automatic washer machine or a security system. Any microcontroller contains a memory to store
the program to be executed, and a number of input/output lines that can be used to interact with
other devices, like reading the state of a sensor or controlling a motor.
Nowadays, microcontrollers are so cheap and easily available that it is common to use them
instead of simple logic circuits like counters for the sole purpose of gaining some design
flexibility and saving some space. Some machines and robots will even rely on a multitude of
microcontrollers, each one dedicated to a certain task. Most recent microcontrollers are 'In
System Programmable', meaning that you can modify the program being executed, without
removing the microcontroller from its place.
Today, microcontrollers are an indispensable tool for the robotics hobbyist as well as for the
engineer. Starting in this field can be a little difficult, because you usually can't understand how
everything works inside that integrated circuit, so you have to study the system gradually, a
small part at a time, until you can figure out the whole image and understand how the system
works.

Comparison of Microprocessor and Microcontroller

Microprocessor and Microcontroller differ in their functionalities. Microprocessor has more


generalized functions, whereas Microcontroller is more specific to its task.
A Microprocessor may not be programmed to handle real-time tasks but Microcontroller in
devices that need to control temperature of water or perhaps measure the temperature of a room
require real time monitoring and therefore with its inbuilt set of instructions the microcontroller
works on its own.
Microprocessor requires constant input by a human such as in a personal computer so that
instructions can be booted. Microprocessor is the memory of the computing machine whereas the
microcontroller integrates the entire computer in a single chip. Not only does it has the memory
embedded in it but also has input and output ports plus peripherals such as timers and converters.
All this can be handled with a single touch.
The 8051 microcontroller architecture

The 8051 is the name of a big family of microcontrollers. The device which we are going to use
along this tutorial is the 'AT89S52' which is a typical 8051 microcontroller manufactured by
Atmel™. Note that this part doesn't aim to explain the functioning of the different components of

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

a 89S52 microcontroller, but rather to give you a general idea of the organization of the chip and
the available features, which shall be explained in detail along this tutorial.
The block diagram provided by Atmel™ in their datasheet showing the architecture the
89S52 device can seem very complicated, and since we are going to use the C high level
language to program it, a simpler architecture can be represented as the figure
This figures shows the main features and components that the designer can interact with.
You can notice that the 89S52 has 4 different ports, each one having 8 Input/output lines
providing a total of 32 I/O lines. Those ports can be used to output DATA and orders do other
devices, or to read the state of a sensor, or a switch. Most of the ports of the 89S52have 'dual
function' meaning that they can be used for two different functions: the first one is to perform
input/output operations and the second one is used to implement special features of the
microcontroller like counting external pulses, interrupting the execution of the program
according to external events, performing serial data transfer or connecting the chip to a computer
to update the software.
Each port has 8 pins, and will be treated from the software point of view as an 8-bit variable
called 'register', each bit being connected to a different Input/output pin. You can also notice two
different memory types: RAM and EEPROM. Shortly, RAM is used to store variable during
program execution, while the EEPROM memory is used to store the program itself, that's why it
is often referred to as the 'program memory'. The memory organization will be discussed in
detail later.
The special features of the 89S52 microcontroller are grouped in the blue box at the bottom of
figure At this stage of the tutorial, it is just important to note that the 89S52 incorporates
hardware circuits that can be used to prevent the processor from executing various repetitive
tasks and save processing power for more complex calculations. Those simple tasks can be
counting the number of external pulses on a pin, or generating precise timing sequences.
Features of 8051:
The main features of 8051 microcontroller are:
1) RAM – 128 Bytes (Data memory)
2) ROM – 4Kbytes (ROM signify the on – chip program space)
3) Serial Port – Using UART makes it simpler to interface for serial communication.
4) Two 16 bit Timer/ Counter
5) Input/output Pins – 4 Ports of 8 bits each on a single chip.
6) Five Interrupt Sources
7) 8 – bit ALU (Arithmetic Logic Unit)

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

8) Harvard Memory Architecture – It has 16 bit Address bus (each of RAM and ROM) and 8 bit Data
Bus.
9) 8051 can execute 1 million one cycle instructions per second with a clock frequency of 12MHz.
This microcontroller is also called as “System on a chip” because it has all the features on a single chip

AT89C51ED2 MICROCONTROLLER

Description
AT89C51RD2/ED2 is high performance CMOS Flash version of the 80C51 CMOS single chip
8- bit microcontroller. It contains a 64-Kbyte Flash memory block for code and for data. The 64-
Kbytes Flash memory can be programmed either in parallel mode or in serial mode with the ISP
capability or with software. The programming voltage is internally generated from the standard
VCC pin.
The AT89C51RD2/ED2 retains all of the features of the Atmel 80C51 with 256 bytes of internal
RAM, a 5 source 4-level interrupt controller and three timer/counters. TheAT89C51ED2
provides 2048 bytes of EEPROM for non-volatile data storage. In addition, the
AT89C51RD2/ED2 has a Programmable Counter Array, an XRAM of 1792bytes, a Hardware

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

Watchdog Timer, SPI interface, Keyboard, a more versatile serial channel that facilitates
multiprocessor communication (EUART) and a speed improvement mechanism (X2 Mode). The
fully static design of the AT89C51RD2/ED2 allows reducing system power consumption by
bringing the clock frequency down to any value, including DC, without loss of data.
Clock prescaler for further reduction in power consumption. In the Idle mode the CPU is frozen
while the peripherals and the interrupt system are still operating. In the Power-down mode the
RAM is saved and all other functions are inoperative.
The added features of the AT89C51RD2/ED2 make it more powerful for applications that need
pulse width modulation, high speed I/O and counting capabilities such as alarms, motor control,
corded phones, and smart card readers.

INTERUPTS
Five sources of interrupt (both external and internal).
Two External interrupts INTO and INTI are provided with push button switches: these can
also be used as general-purpose switches.
I/O (Port) Lines Four 10-pin connectors for all the 32 I/O lines.

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

P0,P1 and P2 Port lines are available on a 26-pin connector,


16X2 LCD & SERIAL I/O are also available.

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

I. PROCEDURE FOR USING KEIL µVISION3 FOR 8051 PROGRAMMING

1. Create a project folder in a particular students folder

2. Click on keil µvision3 icon in desktop

3. To create project: click on projectnew µvision project in the create new

project window browse for the created project folder  type the project name

<pro1.µv2> click ok

4. To create a file:gotofile menu  click new type the program in editor window

 click save in File menu  save the file as < filename.asm>

5. Toadd the files to source group : right click source group in project work space 

click on add files to project select <filename.asm> file addclose

6. Build the project:gotoProject menu  click Build Project (note: if the target not

created then fix the errors, build again).

7. To run the program:gotoDebug menu  click Start/Stop Debug session. Again

gotoDebug menu  click RUN for running the program

8. Memory window option:

1. For internal RAM: D:0x40h

2. For external RAM:X:0x8900h

3. For internal ROM:C:0x00

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

Experiment 1
1. Data Transfer - Block move, Exchange, Sorting, Finding largest element in an array
1a) Data Transfer
Aim: To write an ALP to transfer block data from one memory location to another
Program: 8051 program
ORG 00H
MOV R2 ,#04H ; No of elements = 4
MOV R0, #40H ; block 1 address
MOV R1, #50H ; block 2 address
NXT_LOC:
MOV A,@R0 ; transfer the element in present address
MOV @R1, A
INC R0 ; go to next element address of block1
INC R1 ; go to next element address of block2
DJNZ R2, NXT_LOC ; jump to NXT_LOC for next element
; Transfer till the end of an array
END

Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

1b) Block Exchange


Aim: To write an ALP to exchange block data from one memory location to another memory location
Program: 8051 program
ORG 00H
MOV R2,#04H ;No of elements = 4
MOV R0,#40H ;block 1 address
MOV R1,#50H ;block 2 address
NXT_LOC:
MOV A,@R0 ; exchange the element in present address
XCH A,@R1
MOV @R0,A
INC R0 ; go to next element address of block1
INC R1 ; go to next element address of block2
DJNZ R2,NXT_LOC ; jump to NXT_LOC for next element
; Transfer till the end of an array

END

Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

1c) Sorting (Ascending order)


Aim: To write an ALP to sort an array by using Bubble sort algorithm
Program: 8051 program
ORG 00H
MOV R7,#04H ;No of elements
DEC R7 ;no of iterations = no of elements -1
NXT_ITN: MOV R0,#40H ;array address
MOV R6,#03H ;no of exchanges = iteration no-1
NXT_NO: MOV A,@R0 ;A= present element in array
INC R0 ;
MOV B,@R0 ; B= next element in array
CJNE A,B,N_E ;compare present with next element
N_E: JNC NO_EXG ; no. are equal/ A>B exchange not required
MOV @R0,A ;exchange the elements
DEC R0
MOV @R0,B
INC R0 ; go to next number address
NO_EXG: DJNZ R6,NXT_NO ; jump to NXT_NO for next 2 numbers
; Comparison. If all the number are Compared go to next iteration
DJNZ R7,NXT_ITN; If all the iterations are over then exit
END
Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

1d) Finding Largest


Aim: To write an ALP to find largest number in an array
Program: 8051 program
ORG 00H
MOV R3,#04H ; N-1 WHERE N LENGTH OF AN ARRAY
MOV R0,#40H ; array address
MOV A,@R0 ; A= present element in array
NXT_NO: INC R0
MOV B,@R0 ;B= next element in array
CJNE A,B,NT_E ; compare present with next element
SJMP AGB ;A=B
NT_E: JNC AGB ; if carry = 0, then A>B
MOV A,@R0 ;else B>A, move B to A
AGB: DJNZ R3,NXT_NO ; go to next no. In an array till last no.
MOV 50H,A ;A has the largest no save it in internal
;memory

END
Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

Experiment 2
2. Arithmetic Instructions - Addition/subtraction, multiplication and division, square, Cube – (16
bits Arithmetic operations – bit addressable)
2a) Multi byte addition
Aim: To write an ALP to find the sum of 2 16 bit number
Program:
ORG 00H
MOV R0,#40H ;address of Lower byte of 1st number
MOV R1,#50H ; address of Lower byte of 2nd number
MOV A,@R0
ADDC A,@R1 ; add lower bytes of 2 numbers
MOV 60H,A ; save the lower byte of sum in 60h
INC R0 ; address of higher byte of 1st number
INC R1 ; address of higher byte of 2nd number
MOV A,@R0 ; add the higher bytes of 2 numbers with
ADDC A,@R1 ; along with carry generated by lower byte Addition
MOV 61H,A ; save the second byte of sum in 61h
MOV 62H,#00H
JNC N_C
MOV 62H,#01H ; save the third byte of sum in 62h
N_C: END
Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

2b) Multi byte subtraction


Aim: To write an ALP to find the difference of 2 16 bit number
Program:
ORG 00H
MOV R0,#40H ;address of Lower byte of 1st number
MOV R1,#50H ; address of Lower byte of 2nd number
MOV A,@R0
SUBB A,@R1; subtract lower bytes of 2 numbers
MOV 60H,A ; save the lower byte of difference in 60h
INC R0 ; address of higher byte of 1st number
INC R1 ; address of higher byte of 2nd number
MOV A,@R0 ; subtract the higher bytes of 2 numbers
SUBB A,@R1; with along with carry generated by lower
; byte Addition
MOV 61H,A ; save the 2nd byte of difference in 61h
MOV 62H,#00H
JNC N_C
MOV 62H,#0FFH ; save the 3rd byte of difference in 62h
N_C: END

Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

2c) Multi byte Multiplication


Aim: To write an ALP to find the product of 2 16 bit number
Program: 8051 program
Logic:
( where B4B3 are 2 bytes of 2 nd number & B2B1
B4 B3x B2 B1 2 bytes of 1st number

P2 P1 B3B1
+ P4 P3 B4B1
P6 P5 P1
+ P8 P7 B3B2
P11 P10 P9 P1
+ P13 P12 B4B2
P15 P14 P9 P1
Save in 63h 62h 61h 60h

ORG 00H
MOV A,20H ;lower byte of 1st number (say B1)
MOV B,40H ;lower byte of 2nd number (say B3)
MUL AB ; B3xB1= product of 16 bit say (P2 P1)
MOV 60H,A ;[60h]=P1
MOV 61H,B ;[61h]=P2

MOV A,20H ; lower byte of 1st number (say B1)


MOV B,41H ; higher byte of 2nd number (say B4)
MUL AB ; B4xB1= product of 16 bit say (P4 P3)
ADD A,61H
MOV 61H,A
MOV A,B
ADDC A,62H
MOV 62H,A

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

MOV A,21H
MOV B,40H
MUL AB
ADD A,61H
MOV 61H,A
MOV A,B
ADDC A,62H
MOV 62H,A
MOV A,#00
ADDC A,#00
MOV 63H,A
MOV A,21H
MOV B,41H
MUL AB
ADD A,62H
MOV 62H,A
MOV A,B
ADDC A,63H
MOV 63H,A
END
Result:

I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

2d) Division
Aim: To write an ALP to divide 16 bit number by 8 bit number
Program: 8051 program
ORG 00H
MOV DPTR,#2000H
MOVX A,@DPTR
MOV B,A
MOV DPTR,#2001H
MOVX A,@DPTR

DIV AB
MOV DPTR,#2010H
MOVX @DPTR,A
END

Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

2e) Square & Cube


Aim: To write an ALP to find the square & cube of a given 8 bit number
ORG 00H
MOV A,20H
MOV B,20H
MUL AB
MOV 40H,A
MOV 41H,B
MOV A,20H
MOV B,40H
MUL AB
MOV 60H,A
MOV 61H,B
MOV A,20H
MOV B,41H
MUL AB
ADD A,61H
MOV 61H,A
MOV A,B
ADDC A,62H
MOV 62H,A
END
Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

Experiment 3
Counters
Aim: To write an ALP to count decimal UP
Program: 8051 program
ORG 00H

MOV A,40H
NXT_CNT: MOV P1,A
ADD A,#01H ADD A,#0FFH (FOR BINARY DOWN) ,
ADD A,#99H ( FOR DECIMAL DOWN)
DA A ; DELETE THIS INSTRUCTION FOR BINARY COUNTER
ACALL DELAY
CJNE A,41H,NXT_CNT
MOV P1,A
RET

DELAY: MOV R0,#40H


MOV R1,#0FFH
MOV R2,#0FFH
BACK: DJNZ R2,BACK
DJNZ R1,BACK
DJNZ R0,BACK
RET
END
Result:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

Experiment 4
4. Boolean & Logical Instructions (Bit manipulations)
Aim: To write an ALP to realise the given Boolean expression
Program: 8051 program
Y=ABC'+AB'C+AB'C'

ORG 00H
MOV C,20H
ANL C,01H
ANL C,/00H
MOV 8H,C
MOV C,20H
ANL C,/01H
ANL C,00H
ORL C,8
MOV 8,C
MOV C,20H
ANL C,/01H
ANL C,/00H
ORL C,8
MOV 8,C
END

Result:
Truth Table
A B C Y=ABC'+AB'C+AB'C'

0 0 0 0
0 0 1 0
0 1 0 0

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 0

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

Experiment 5
5. Code conversion: BCD – ASCII; ASCII – Decimal; HEX - Decimal and Decimal - HEX
5a) BCD - ASCII
Aim: To write an ALP to find the ASCII code of given BCD number
Program: 8051 program
ORG 0000
MOV A,40H
ANL A,#0F0H
SWAP A
ADD A,#30H
MOV 41H,A
MOV A,40H
ANL A,#0FH
ADD A,#30H
MOV 42H,A
SJMP $
END

Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

5b) ASCII - BCD


Aim: To write an ALP to find the BCD code of given ASCII number
Program: 8051 program
ORG 0000
MOV A,40H
ANL A,#0FH
SWAP A
MOV B,A
MOV A,41H
ANL A,#0FH
ADD A,B
MOV 42H,A
SJMP $
END

Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

5c) HEX - Decimal


Aim: To write an ALP to find the hexadecimal value of given decimal number
Program: 8051 program
ORG 00H
MOV A,40H
MOV B,#0AH
DIV AB
MOV 43H,B
MOV B,#0AH
DIV AB
MOV 42H,B
MOV 41H,A
SJMP $
END

Result:
I/P:

O/P:

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

5d) Decimal - HEX


Aim: To write an ALP to find the decimal value of given hexadecimal number
Program: 8051 program
ORG 00H
MOV A,40H
MOV B,#10H
DIV AB
MOV R2,B
MOV B,#0AH
MUL AB
ADD A,R2
MOV 41H,A
SJMP $
END

Result:
Run 1

Run 2

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

6. External ADC and Temperature control interface to 8051


Aim: To interface External ADC and temperature control to 8051
12V -12V 5V GND

8051
ADC Interface
& relay control
P0 for heater

P3 LCD Interface

P2

Interfacing Diagram
Program:

/* This program displays the ADC output of the ADC0809 IC. */

//#include "D:\Keil\C51\INC\Atmel\reg51f.h"

#include<at89c51xd2.h>
#include<stdio.h>
// LCD FUNCTION PROTOTYPE
voidlcd_init(void);
voidlcd_comm(void);
voidlcd_data(void);

void delay(int);

unsigned char temp1;


unsigned char temp2,buf[8];

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

floatadc_temp;
sbit EOC = P0^4;
sbit START_ALE = P0^7;
unsigned char xdata arr1[12]={"ADC O/P = "};
unsigned char xdata arr2[12]={"ADC I/P = "};
unsigned char i,a,temp_hi,temp_low;
unsignedint vtemp1,adc_val;
unsigned char temp_msg[]={" "};

void main ()
{
START_ALE = 0;

lcd_init();

temp1 = 0x80; // Display the data from first position of first line
lcd_comm(); // Command Writing

for(i=0;i<10;i++)
{
temp2 = arr1[i];
lcd_data(); // Data Writing
}

P1 = 0xff; // Configure P1 as input to read the ADC o/p

delay(200);

while(1)
{
P0 &= 0xF0; // Select the as input channel

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

START_ALE=1; // Generate H->L transition on ALE line to start ADC


delay(5);
START_ALE = 0;

do // Wait until End of conversion


takes place
{
vtemp1=P0;
vtemp1=vtemp1 & 0x10;
} while(vtemp1 == 0x10); // POLL EOC LINE HI TO LOW
do
{
vtemp1=P0;
vtemp1=vtemp1 & 0x10;
} while(vtemp1 == 0x00); // LOW TO HIGH

adc_val = P1; // display adc result on the data field

adc_temp = (((float)adc_val * 5)/255);

temp_hi=adc_val>>4;
temp_hi=temp_hi& 0x0f;

temp_low=adc_val& 0x0f;

if(temp_hi>9) // Convert the received ADC o/p into


ASCII code
temp_hi = temp_hi + 0x37;
else

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

temp_hi = temp_hi + '0';

if(temp_low>9)
temp_low = temp_low + 0x37;
else
temp_low = temp_low + '0';

delay(100);
temp_msg[1] = temp_hi ;
temp_msg[2] = temp_low ;

temp1 = 0x8A;
lcd_comm(); // Command Writing
temp2 = temp_hi;
lcd_data();

temp2 = temp_low;
lcd_data();

adc_temp = (int)(adc_temp*100);
i=100;

for(a=0;a<4;a++)
{
buf[a] = adc_temp / i;
adc_temp -= buf[a] * i;
buf[a] += '0';
i /= 10;
}
buf[3] = buf[2];

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

buf[2] = buf[1];
buf[1] = '.';
buf[4] = '\0';

temp1 = 0xC0;
lcd_comm(); // Displaying at 1st line of LCD
for(i=0;i<10;i++)
{
temp2 = arr2[i];
lcd_data(); // Data Writing
}

for(i=0;(buf[i]!='\0');i++)
{
temp2 = buf[i];
lcd_data();
}
} // end of while(1)
}

Result:
Thus the program was executed successfully and the output is seen.

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

7. Generate different waveforms Sine, Square, Triangular, Ramp etc. using DAC interface
to 8051; change the frequency and amplitude.

Aim: To interface DAC and to write a C program to generate sine, square, triangle and ramp
waveforms

12V -12V GND

8051
P0 DAC Interface CRO
Module

Fig: Interfacing Diagram

7.a Sine Wave


Program:
// program to generate sine wave with DAC interface
// Port P0 is use to output the values
// This project includes the following files:
// 1. sine.c the source program
#include <at89c51xd2.h>
// variables used:
// sine_tab: array of sine values in hex for different angles.
// See the attached note for how these values are derived.
// count : index variable for loop count
xdata unsigned char sine_tab[49]=
{ 0x80,0x90,0xA1,0xB1,0xC0,0xCD,0xDA,0xE5,0xEE,0xF6,0xFB,0xFE,
0xFF,0xFE,0xFB,0xF6,0xEE,0xE5,0xDA,0xCD,0xC0,0xB1,0xA1,0x90,
0x80,0x70,0x5F,0x4F,0x40,0x33,0x26,0x1B,0x12,0x0A,0x05,0x02,
0x00,0x02,0x05,0x0A,0x12,0x1B,0x26,0x33,0x40,0x4F,0x5F,0x70,0x80};

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

Idata int count;


void main ()
{

// the program is in a endless loop


// ie it executes the code within while(1) for ever
// program ouputs different values correspoding
// different sine angles in hex
// to port P0
// user can observe sine waveform at dac output
while(1)
{
for(count=0;count<49;count++)
{
P0 = sine_tab[count];

}
}

7.b. Square Wave


Program:
// program to generate square wave with DAC interface
// Port P0 is use to output the values
// This project includes the following files:
// 1. sq.c the source program

#include<at89c51xd2.h>

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

// variables used:
// msg : a character array contains the string to output
// on to lcd
// cptr : character pointer used to point to msg array
// required to pass to function lcd_outstr()
void delay(void);
//unsigned char xdatamsg[]={"Square"};
//unsigned char xdata *cptr;
void main ()
{
// the program is in a endless loop
// ie it executes the code within while(1) for ever
// program ouputs 0 and 0xff alternatively to port P0
// with a delay in between
// user can observe square waveform at dac output

while(1)
{
P0 = 0x0;
delay();
P0 = 0xff;
delay();

// function to generate delay


// input: none
// returns : none
void delay(void)

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

{
Int i;
for(i=0;i<=300;i++);
}

7c) Triangle Wave


Program:
// program to generate triangular wave with DAC interface
// Port P0 is use to output the values
// This project includes the following files:
// 1. tri.c the source program
#include <at89c51xd2.h>
// variables used:
// count : unsigned char to output the value to P0 port
idata unsigned char count;
void main ()
{

// the program is in a endless loop


// ie it executes the code within while(1) for ever
// program ouputs 0 and 0x7f to port P0 and
// 0x7f to 0 to port P0
// user can observe triangular waveform at dac output
while(1)
{
// output 0 to 0x7f to P0 port
for(count=0;count!=0xff;count++)
{
P0=count;

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

// output 0x7f to 0 to P0 port

for(count=0xff; count>0;count--)
{
P0=count;
}
}
}

7d) Ramp Wave


Program:
// program to generate ramp wave with DAC interface
// Port P0 is use to output the values
// This project includes the following files:
// 1. ramp.c the source program
// 2. reg51f.h all register and sfr definitions
// 3. lcd.h containsprogtotype declarations of lcd functions
// 4. lcdlib.lib contians all lcd functions in library mode
#include <at89c51xd2.h>
// variables used:
// count : character variable used to output count to digital input
idata unsigned char count;
void main ()
{
// initialise count varaible to 0x0
count = 0x0;
// the program is in a endless loop
// ie it executes the code within while(1) for ever
// program ouputs 0 to 0xff to port P0
// it increments the count variable from 0 to 0xff
// user can observe ramp waveform at dac output

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

while(1)
{
P0 = count; // output count to Port P0
count++; // increment count
}
}

Result:
Thus the program was executed successfully and the output is seen.

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

8. Stepper and DC motor control interface to 8051.

Aim: To interface stepper and DC motor control interface to 8051


8. a) Stepper motor

5V GND

8051
Stepper Motor
P0 Interface Stepper
Module Motor

Fig: Interfacing Diagram


/****************************
Stepper Motor *******************************

Object : To demonstrate the Stepper motor interface.


Connection : Connect the stepper motor interface to 26 pin FRC connector J7
of ESAMCB51.
Output: whenever you run the program the motor rotates in clockwise.
If you want to change the direction press the interrupt button
( P3.2/INTO*). when you press the button, INT0 interrupts the main program
and changes the direction of the motor .

**************************************************************************/
Program:

#include "at89c51xd2.h"
static bit Dir=0;
sbit buzzer = P0^5;

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

voidChangeDir(void) interrupt 0 /* Int Vector at 000BH, Reg Bank 1 */


{
Dir = ~Dir; /* Complement the Direction flag */
}
void delay(unsigned int x) /* Delay Routine */
{
for(;x>0;x--);
}
main()
{
unsigned char Val,i;
EA=0x1; /* Enable Interrupt flag and Interrupt 0 & Serial Interrupt */
EX0=0x1;
ES=1; /*since the monitor is using the serial interrupt it has to be
enabled*/

while(1)
{
if(Dir) //* If Dir Clockwise
{

Val = 0x08;
for(i=0;i<4;i++)
{
P0 = Val; //* Write data for clock wise direction
Val = Val>>1;
delay(575);
}
}
else // AntiClockwise Direction
{

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

Val = 0x01;
for(i=0;i<4;i++)
{
P0 = Val; // Write data for anticlock wise direction
Val = Val<<1;
delay(575);
}
}
}
}

10b) DC motor

8051
DC Motor
P0 Interface DC Motor
Module

Fig: Interfacing Diagram


Program:
// program to test nifc55 dc motor
// by varying off-time and on-time with different values
// user can observe different speed on dc motor
// typically the off values are 30,24,18& 12
// on values are 10,16,12& 28

#include "at89c51xd2.h"

sbit DC1 = P0^6; //Selecting P0.6


sbit DC2 = P0^7; //Selecting P0.7

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

idata unsigned char off_time,on_time;


idata unsigned inti;
void main ()
{

off_time = 1000;
on_time = 1000;

while(1)
{
DC1 = DC2 = 0 ; // make P0.6 & P0.7 lo
// 0;
for(i=0;i<on_time;i++)
{
TL0 = 0x00 ; //timer count set for delay
TH0 = 0x10 ;
TR0 =1; // Timer-0 ON
while(!TF0); // Wait untill Timer-0 Overflows
TF0 = 0; // Clear Overflow flag
TR0 = 0; // Timer-0 OFF
}
DC1 = 0 ; // make P0.6 high & make P0.7 low
DC2 = 1;
for(i=0;i<off_time;i++)
{
TL0 = 0x00; //timer count set for delay
TH0 = 0x10;
TR0 =1; // Timer-0 ON
while(!TF0); // Wait untill Timer-0 Overflows
TF0 = 0; // Clear Overflow flag

ECE DEPT, PRESIDENCY UNIVERSITY


Micro Controller Application Laboratory Manual (ECE 3014)

TR0 = 0; // Timer-0 OFF


}
}

}
Result: Thus the program was executed successfully and the output is seen.
SAMPLE VIVA QUESTIONS

1. Write an alp to convert two digit HEX to Decimal using 8051


2. Write an alp to convert two digit Decimal to HEX using 8051
3. Write an ALP to implement a down counter (9-0 ) & display in LCD
4. Write an ALP to flash ‘JYOTHI’ N times in ROW1 of A LCD screen
5. Write an ALP to add two 8 bit numbers and display its result in 20X2 LCD
6. Write an ALP to add two 16 bit numbers using 8051
7. Write a 8051 program to display your name and college name in row1
alternatively
8. Design a dancing light with 8051
9. Design a square wave with desired frequency
10.press a key
11.Rotate stepper motor clock wise
12.Rotate stepper motor anti clock wise
13.Rotate stepper motor up to 90degree
14.Implement Boolean expression F=AB+AB’

ECE DEPT, PRESIDENCY UNIVERSITY

You might also like